# API Keys

## Create

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

**post** `/compute/v1/admin/api-keys`

Create a workspace API key

### Parameters

- `body AdminAPIKeyNewParams`

  - `Name param.Field[string]`

    API key name

  - `AllowedIPs param.Field[[]string]`

    IP addresses allowed to use this key (IPv4 or IPv6). An empty array (the default) means all IPs are allowed.

  - `ExpiresInDays param.Field[int64]`

    Days until the key expires. Omit for a key that does not expire.

  - `Mode param.Field[AdminAPIKeyNewParamsMode]`

    Key mode. Test keys create test-mode resources with synthetic data.

    - `const AdminAPIKeyNewParamsModeLive AdminAPIKeyNewParamsMode = "live"`

    - `const AdminAPIKeyNewParamsModeTest AdminAPIKeyNewParamsMode = "test"`

  - `WorkspaceID param.Field[string]`

    Workspace ID to scope this key to. Omit for default workspace.

### Returns

- `type AdminAPIKeyNewResponse struct{…}`

  - `Key string`

    The full API key. This is only shown once — store it securely.

  - `KeyDetails AdminAPIKeyNewResponseKeyDetails`

    - `ID string`

      API key ID

    - `AllowedIPs []string`

      IP addresses allowed to use this key. An empty array means all IPs are allowed.

    - `CreatedAt Time`

    - `ExpiresAt Time`

      When the key expires. Null if the key does not expire.

    - `IsActive bool`

    - `KeyPrefix string`

      First 12 characters of the key

    - `KeyType Workspace`

      - `const WorkspaceWorkspace Workspace = "workspace"`

    - `LastUsedAt Time`

    - `Livemode bool`

      Whether this is a live API key (false for test keys).

    - `Name string`

      API key name

    - `WorkspaceID string`

      Workspace this key is scoped to

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/boltz-bio/boltz-api-go"
  "github.com/boltz-bio/boltz-api-go/option"
)

func main() {
  client := boltzapi.NewClient(
    option.WithAPIKey("My API Key"),
  )
  apiKey, err := client.Admin.APIKeys.New(context.TODO(), boltzapi.AdminAPIKeyNewParams{
    Name: "x",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", apiKey.Key)
}
```

## List

`client.Admin.APIKeys.List(ctx, query) (*CursorPage[AdminAPIKeyListResponse], error)`

**get** `/compute/v1/admin/api-keys`

List API keys

### Parameters

- `query AdminAPIKeyListParams`

  - `AfterID param.Field[string]`

    Return results after this ID

  - `BeforeID param.Field[string]`

    Return results before this ID

  - `Limit param.Field[int64]`

    Max items to return

  - `WorkspaceID param.Field[string]`

    Filter by workspace ID. If not provided, returns keys across all workspaces.

### Returns

- `type AdminAPIKeyListResponse struct{…}`

  - `ID string`

    API key ID

  - `AllowedIPs []string`

    IP addresses allowed to use this key. An empty array means all IPs are allowed.

  - `CreatedAt Time`

  - `ExpiresAt Time`

    When the key expires. Null if the key does not expire.

  - `IsActive bool`

  - `KeyPrefix string`

    First 12 characters of the key

  - `KeyType AdminAPIKeyListResponseKeyType`

    - `const AdminAPIKeyListResponseKeyTypeAdmin AdminAPIKeyListResponseKeyType = "admin"`

    - `const AdminAPIKeyListResponseKeyTypeWorkspace AdminAPIKeyListResponseKeyType = "workspace"`

  - `LastUsedAt Time`

  - `Livemode bool`

    Whether this is a live API key (false for test keys).

  - `Name string`

    API key name

  - `WorkspaceID string`

    Workspace ID if workspace-scoped

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/boltz-bio/boltz-api-go"
  "github.com/boltz-bio/boltz-api-go/option"
)

func main() {
  client := boltzapi.NewClient(
    option.WithAPIKey("My API Key"),
  )
  page, err := client.Admin.APIKeys.List(context.TODO(), boltzapi.AdminAPIKeyListParams{

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

## Revoke

`client.Admin.APIKeys.Revoke(ctx, apiKeyID) (*AdminAPIKeyRevokeResponse, error)`

**post** `/compute/v1/admin/api-keys/{api_key_id}/revoke`

Revoke an API key

### Parameters

- `apiKeyID string`

### Returns

- `type AdminAPIKeyRevokeResponse struct{…}`

  - `ID string`

    API key ID

  - `AllowedIPs []string`

    IP addresses allowed to use this key. An empty array means all IPs are allowed.

  - `CreatedAt Time`

  - `ExpiresAt Time`

    When the key expires. Null if the key does not expire.

  - `IsActive bool`

  - `KeyPrefix string`

    First 12 characters of the key

  - `KeyType AdminAPIKeyRevokeResponseKeyType`

    - `const AdminAPIKeyRevokeResponseKeyTypeAdmin AdminAPIKeyRevokeResponseKeyType = "admin"`

    - `const AdminAPIKeyRevokeResponseKeyTypeWorkspace AdminAPIKeyRevokeResponseKeyType = "workspace"`

  - `LastUsedAt Time`

  - `Livemode bool`

    Whether this is a live API key (false for test keys).

  - `Name string`

    API key name

  - `WorkspaceID string`

    Workspace ID if workspace-scoped

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/boltz-bio/boltz-api-go"
  "github.com/boltz-bio/boltz-api-go/option"
)

func main() {
  client := boltzapi.NewClient(
    option.WithAPIKey("My API Key"),
  )
  response, err := client.Admin.APIKeys.Revoke(context.TODO(), "api_key_id")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.ID)
}
```
