## Create Api Key

`client.APIKeys.New(ctx, body) (*APIKey, error)`

**post** `/api/v1/beta/api-keys`

Create an API key.

Scope it to a project with `project_id`, which requires read access to that
project; omit it for a key that reaches every project you can read. A
project-scoped or agent key cannot create an API key. The response carries
the secret in `redacted_api_key`, and only this once.

### Parameters

- `body APIKeyNewParams`

  - `ExpiresAt param.Field[Time]`

    When the API key should expire. If not set, the key never expires.

  - `KeyType param.Field[APIKeyNewParamsKeyType]`

    - `const APIKeyNewParamsKeyTypeAgent APIKeyNewParamsKeyType = "agent"`

    - `const APIKeyNewParamsKeyTypeUser APIKeyNewParamsKeyType = "user"`

  - `Name param.Field[string]`

  - `ProjectID param.Field[string]`

    The project ID to associate with the API key.

  - `Role param.Field[APIKeyNewParamsRole]`

    Role capping what this key may do. A key can only ever be narrower than the user who created it, never broader. If not set, the key authorizes as its owner.

    - `const APIKeyNewParamsRoleAdmin APIKeyNewParamsRole = "admin"`

    - `const APIKeyNewParamsRoleAgentViewer APIKeyNewParamsRole = "agent_viewer"`

    - `const APIKeyNewParamsRoleViewer APIKeyNewParamsRole = "viewer"`

    - `const APIKeyNewParamsRoleViewerV2 APIKeyNewParamsRole = "viewer_v2"`

### Returns

- `type APIKey struct{…}`

  Schema for an API Key.

  - `ID string`

    Unique identifier

  - `RedactedAPIKey string`

    The key with its middle masked, except on the create response, which returns the full secret once and never again.

  - `UserID string`

  - `CreatedAt Time`

    Creation datetime

  - `ExpiresAt Time`

    When the API key expires. Null if the key never expires.

  - `KeyType APIKeyKeyType`

    - `const APIKeyKeyTypeAgent APIKeyKeyType = "agent"`

    - `const APIKeyKeyTypeUser APIKeyKeyType = "user"`

  - `Metadata map[string, any]`

  - `Name string`

  - `ProjectID string`

  - `Role APIKeyRole`

    Role capping what this key may do. Null if the key authorizes as its owner.

    - `const APIKeyRoleAdmin APIKeyRole = "admin"`

    - `const APIKeyRoleAgentViewer APIKeyRole = "agent_viewer"`

    - `const APIKeyRoleViewer APIKeyRole = "viewer"`

    - `const APIKeyRoleViewerV2 APIKeyRole = "viewer_v2"`

  - `UpdatedAt Time`

    Update datetime

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/run-llama/llamacloud-admin-go"
  "github.com/run-llama/llamacloud-admin-go/option"
)

func main() {
  client := llamacloudadmin.NewClient(
    option.WithAPIKey("My API Key"),
  )
  apiKey, err := client.APIKeys.New(context.TODO(), llamacloudadmin.APIKeyNewParams{

  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", apiKey.ID)
}
```

#### Response

```json
{
  "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
  "redacted_api_key": "redacted_api_key",
  "user_id": "user_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "expires_at": "2019-12-27T18:11:19.117Z",
  "key_type": "agent",
  "metadata": {
    "foo": "bar"
  },
  "name": "name",
  "project_id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
  "role": "admin",
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```
