---
title: API Keys
url: https://platform.claude.com/docs/en/api/python/beta/organization/api_keys
---

# API Keys

## List API Keys

`beta.organization.api_keys.list(**kwargs)  -> SyncPage[BetaAPIKey]`

**GET** `/v1/organizations/api_keys`

List API Keys

### Parameters

- `after_id: Optional[str]` (query parameter)

  ID of the object to use as a cursor for pagination. When provided, returns the page of results immediately after this object.

- `before_id: Optional[str]` (query parameter)

  ID of the object to use as a cursor for pagination. When provided, returns the page of results immediately before this object.

- `created_by_user_id: Optional[str]` (query parameter)

  Filter by the ID of the User who created the object.

- `limit: Optional[int]` (query parameter)

  Number of items to return per page.

  Defaults to `20`. Ranges from `1` to `1000`.

  default: 20, minimum: 1, maximum: 1000

- `status: Optional[Literal["active", "archived", "expired", "inactive"]]` (query parameter)

  Filter by API key status.

  - `"active"`

  - `"archived"`

  - `"expired"`

  - `"inactive"`

- `workspace_id: Optional[str]` (query parameter)

  Filter by Workspace ID.

### Returns

- `class BetaAPIKey`

  - `type: Literal["api_key"]`

    Object type.

    For API Keys, this is always `"api_key"`.

    default: api_key

  - `id: str`

    ID of the API key.

  - `created_at: datetime`

    RFC 3339 datetime string indicating when the API Key was created.

    format: date-time

  - `created_by: Optional[BetaAPIKeyCreatedBy]`

    The ID and type of the actor that created the API key, or `null` when the
    creator is not recorded (legacy, workload-identity-federated, or
    system-created keys).

    - `type: Literal["service_account", "user"]`

      Type of the actor that created the object.

      - `"service_account"`

      - `"user"`

    - `id: str`

      ID of the actor that created the object.

  - `expires_at: Optional[datetime]`

    RFC 3339 datetime string indicating when the API Key expires, or `null` if it never expires.

    format: date-time

  - `name: str`

    Name of the API key.

  - `partial_key_hint: Optional[str]`

    Partially redacted hint for the API key.

  - `principal: Optional[Principal]`

    The principal the API key acts as (a User or a Service Account), or `null` if the API key is not bound to a principal.

    - `class BetaAPIKeyUserActor`

      - `type: Literal["user_actor"]`

        Principal type. Always `"user_actor"` for a User.

        default: user_actor

      - `user_id: str`

        ID of the User the API key acts as.

    - `class BetaAPIKeyServiceAccountActor`

      - `type: Literal["service_account_actor"]`

        Principal type. Always `"service_account_actor"` for a Service Account.

        default: service_account_actor

      - `service_account_id: str`

        ID of the Service Account the API key acts as.

  - `scope: Scope`

    Where the API key belongs: its Workspace (`{"type": "workspace", "workspace_id": "wrkspc_..."}`, with the Workspace's real ID even when it is the organization's default Workspace), or the organization (`{"type": "organization"}`) for a principal-bound API key that has no Workspace.

    - `class BetaAPIKeyOrganizationScope`

      - `type: Literal["organization"]`

        Scope type. Always `"organization"`: the API key has no Workspace. Only a principal-bound API key can have this scope.

        default: organization

    - `class BetaAPIKeyWorkspaceScope`

      - `type: Literal["workspace"]`

        Scope type. Always `"workspace"`: the API key belongs to one Workspace.

        default: workspace

      - `workspace_id: str`

        ID of the Workspace the API key belongs to. Unlike the deprecated top-level `workspace_id`, this is the Workspace's real ID even for the organization's default Workspace.

  - `status: Literal["active", "archived", "expired", "inactive"]`

    Status of the API key.

    - `"active"`

    - `"archived"`

    - `"expired"`

    - `"inactive"`

  - `workspace_id: Optional[str]`

    **Deprecated**: Use `scope` instead. `workspace_id` is `null` both for an API key in the default Workspace and for a principal-bound API key that has no Workspace.

    Deprecated: use `scope` instead. ID of the Workspace associated with the API key, or `null` if the API key belongs to the default Workspace. Also `null` for a principal-bound API key that has no Workspace; `scope` tells the two apart.

### Example

```python
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ.get(
        "ANTHROPIC_API_KEY"
    ),  # This is the default and can be omitted
)
page = client.beta.organization.api_keys.list()
page = page.data[0]
print(page.id)
```

#### Response (200)

```json
{
  "data": [
    {
      "id": "apikey_01Rj2N8SVvo6BePZj99NhmiT",
      "created_at": "2024-10-30T23:58:27.427722Z",
      "created_by": {
        "id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
        "type": "user"
      },
      "expires_at": "2024-10-30T23:58:27.427722Z",
      "name": "Developer Key",
      "partial_key_hint": "sk-ant-api03-R2D...igAA",
      "principal": {
        "type": "user_actor",
        "user_id": "user_01WCz1FkmYMm4gnmykNKUu3Q"
      },
      "scope": {
        "type": "workspace",
        "workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
      },
      "status": "active",
      "type": "api_key",
      "workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
    }
  ],
  "first_id": "first_id",
  "has_more": true,
  "last_id": "last_id"
}
```

## Retrieve API Key (Admin API)

`beta.organization.api_keys.retrieve(api_key_id)  -> BetaAPIKey`

**GET** `/v1/organizations/api_keys/{api_key_id}`

Retrieve information about a single API key in your organization, looked up by its ID. This Admin API endpoint requires an Admin API key, is intended for programmatic key management, and never returns the key's secret value. To view or create your own API keys, go to [API keys](https://platform.claude.com/settings/keys) in the Claude Console.

### Parameters

- `api_key_id: str` (path parameter)

  ID of the API key.

### Returns

- `class BetaAPIKey`

  - `type: Literal["api_key"]`

    Object type.

    For API Keys, this is always `"api_key"`.

    default: api_key

  - `id: str`

    ID of the API key.

  - `created_at: datetime`

    RFC 3339 datetime string indicating when the API Key was created.

    format: date-time

  - `created_by: Optional[BetaAPIKeyCreatedBy]`

    The ID and type of the actor that created the API key, or `null` when the
    creator is not recorded (legacy, workload-identity-federated, or
    system-created keys).

    - `type: Literal["service_account", "user"]`

      Type of the actor that created the object.

      - `"service_account"`

      - `"user"`

    - `id: str`

      ID of the actor that created the object.

  - `expires_at: Optional[datetime]`

    RFC 3339 datetime string indicating when the API Key expires, or `null` if it never expires.

    format: date-time

  - `name: str`

    Name of the API key.

  - `partial_key_hint: Optional[str]`

    Partially redacted hint for the API key.

  - `principal: Optional[Principal]`

    The principal the API key acts as (a User or a Service Account), or `null` if the API key is not bound to a principal.

    - `class BetaAPIKeyUserActor`

      - `type: Literal["user_actor"]`

        Principal type. Always `"user_actor"` for a User.

        default: user_actor

      - `user_id: str`

        ID of the User the API key acts as.

    - `class BetaAPIKeyServiceAccountActor`

      - `type: Literal["service_account_actor"]`

        Principal type. Always `"service_account_actor"` for a Service Account.

        default: service_account_actor

      - `service_account_id: str`

        ID of the Service Account the API key acts as.

  - `scope: Scope`

    Where the API key belongs: its Workspace (`{"type": "workspace", "workspace_id": "wrkspc_..."}`, with the Workspace's real ID even when it is the organization's default Workspace), or the organization (`{"type": "organization"}`) for a principal-bound API key that has no Workspace.

    - `class BetaAPIKeyOrganizationScope`

      - `type: Literal["organization"]`

        Scope type. Always `"organization"`: the API key has no Workspace. Only a principal-bound API key can have this scope.

        default: organization

    - `class BetaAPIKeyWorkspaceScope`

      - `type: Literal["workspace"]`

        Scope type. Always `"workspace"`: the API key belongs to one Workspace.

        default: workspace

      - `workspace_id: str`

        ID of the Workspace the API key belongs to. Unlike the deprecated top-level `workspace_id`, this is the Workspace's real ID even for the organization's default Workspace.

  - `status: Literal["active", "archived", "expired", "inactive"]`

    Status of the API key.

    - `"active"`

    - `"archived"`

    - `"expired"`

    - `"inactive"`

  - `workspace_id: Optional[str]`

    **Deprecated**: Use `scope` instead. `workspace_id` is `null` both for an API key in the default Workspace and for a principal-bound API key that has no Workspace.

    Deprecated: use `scope` instead. ID of the Workspace associated with the API key, or `null` if the API key belongs to the default Workspace. Also `null` for a principal-bound API key that has no Workspace; `scope` tells the two apart.

### Example

```python
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ.get(
        "ANTHROPIC_API_KEY"
    ),  # This is the default and can be omitted
)
beta_api_key = client.beta.organization.api_keys.retrieve(
    "api_key_id",
)
print(beta_api_key.id)
```

#### Response (200)

```json
{
  "id": "apikey_01Rj2N8SVvo6BePZj99NhmiT",
  "created_at": "2024-10-30T23:58:27.427722Z",
  "created_by": {
    "id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
    "type": "user"
  },
  "expires_at": "2024-10-30T23:58:27.427722Z",
  "name": "Developer Key",
  "partial_key_hint": "sk-ant-api03-R2D...igAA",
  "principal": {
    "type": "user_actor",
    "user_id": "user_01WCz1FkmYMm4gnmykNKUu3Q"
  },
  "scope": {
    "type": "workspace",
    "workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
  },
  "status": "active",
  "type": "api_key",
  "workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
}
```

## Update API Key

`beta.organization.api_keys.update(api_key_id, **kwargs)  -> BetaAPIKey`

**POST** `/v1/organizations/api_keys/{api_key_id}`

Update API Key

### Parameters

- `api_key_id: str` (path parameter)

  ID of the API key.

- `name: Optional[str]`

  Name of the API key.

  minLength: 1, maxLength: 500

- `status: Optional[Literal["active", "archived", "inactive"]]`

  Status of the API key.

  - `"active"`

  - `"archived"`

  - `"inactive"`

### Returns

- `class BetaAPIKey`

  - `type: Literal["api_key"]`

    Object type.

    For API Keys, this is always `"api_key"`.

    default: api_key

  - `id: str`

    ID of the API key.

  - `created_at: datetime`

    RFC 3339 datetime string indicating when the API Key was created.

    format: date-time

  - `created_by: Optional[BetaAPIKeyCreatedBy]`

    The ID and type of the actor that created the API key, or `null` when the
    creator is not recorded (legacy, workload-identity-federated, or
    system-created keys).

    - `type: Literal["service_account", "user"]`

      Type of the actor that created the object.

      - `"service_account"`

      - `"user"`

    - `id: str`

      ID of the actor that created the object.

  - `expires_at: Optional[datetime]`

    RFC 3339 datetime string indicating when the API Key expires, or `null` if it never expires.

    format: date-time

  - `name: str`

    Name of the API key.

  - `partial_key_hint: Optional[str]`

    Partially redacted hint for the API key.

  - `principal: Optional[Principal]`

    The principal the API key acts as (a User or a Service Account), or `null` if the API key is not bound to a principal.

    - `class BetaAPIKeyUserActor`

      - `type: Literal["user_actor"]`

        Principal type. Always `"user_actor"` for a User.

        default: user_actor

      - `user_id: str`

        ID of the User the API key acts as.

    - `class BetaAPIKeyServiceAccountActor`

      - `type: Literal["service_account_actor"]`

        Principal type. Always `"service_account_actor"` for a Service Account.

        default: service_account_actor

      - `service_account_id: str`

        ID of the Service Account the API key acts as.

  - `scope: Scope`

    Where the API key belongs: its Workspace (`{"type": "workspace", "workspace_id": "wrkspc_..."}`, with the Workspace's real ID even when it is the organization's default Workspace), or the organization (`{"type": "organization"}`) for a principal-bound API key that has no Workspace.

    - `class BetaAPIKeyOrganizationScope`

      - `type: Literal["organization"]`

        Scope type. Always `"organization"`: the API key has no Workspace. Only a principal-bound API key can have this scope.

        default: organization

    - `class BetaAPIKeyWorkspaceScope`

      - `type: Literal["workspace"]`

        Scope type. Always `"workspace"`: the API key belongs to one Workspace.

        default: workspace

      - `workspace_id: str`

        ID of the Workspace the API key belongs to. Unlike the deprecated top-level `workspace_id`, this is the Workspace's real ID even for the organization's default Workspace.

  - `status: Literal["active", "archived", "expired", "inactive"]`

    Status of the API key.

    - `"active"`

    - `"archived"`

    - `"expired"`

    - `"inactive"`

  - `workspace_id: Optional[str]`

    **Deprecated**: Use `scope` instead. `workspace_id` is `null` both for an API key in the default Workspace and for a principal-bound API key that has no Workspace.

    Deprecated: use `scope` instead. ID of the Workspace associated with the API key, or `null` if the API key belongs to the default Workspace. Also `null` for a principal-bound API key that has no Workspace; `scope` tells the two apart.

### Example

```python
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ.get(
        "ANTHROPIC_API_KEY"
    ),  # This is the default and can be omitted
)
beta_api_key = client.beta.organization.api_keys.update(
    api_key_id="api_key_id",
)
print(beta_api_key.id)
```

#### Response (200)

```json
{
  "id": "apikey_01Rj2N8SVvo6BePZj99NhmiT",
  "created_at": "2024-10-30T23:58:27.427722Z",
  "created_by": {
    "id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
    "type": "user"
  },
  "expires_at": "2024-10-30T23:58:27.427722Z",
  "name": "Developer Key",
  "partial_key_hint": "sk-ant-api03-R2D...igAA",
  "principal": {
    "type": "user_actor",
    "user_id": "user_01WCz1FkmYMm4gnmykNKUu3Q"
  },
  "scope": {
    "type": "workspace",
    "workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
  },
  "status": "active",
  "type": "api_key",
  "workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
}
```

## Domain types

### Beta API Key

- `class BetaAPIKey`

  - `type: Literal["api_key"]`

    Object type.

    For API Keys, this is always `"api_key"`.

    default: api_key

  - `id: str`

    ID of the API key.

  - `created_at: datetime`

    RFC 3339 datetime string indicating when the API Key was created.

    format: date-time

  - `created_by: Optional[BetaAPIKeyCreatedBy]`

    The ID and type of the actor that created the API key, or `null` when the
    creator is not recorded (legacy, workload-identity-federated, or
    system-created keys).

    - `type: Literal["service_account", "user"]`

      Type of the actor that created the object.

      - `"service_account"`

      - `"user"`

    - `id: str`

      ID of the actor that created the object.

  - `expires_at: Optional[datetime]`

    RFC 3339 datetime string indicating when the API Key expires, or `null` if it never expires.

    format: date-time

  - `name: str`

    Name of the API key.

  - `partial_key_hint: Optional[str]`

    Partially redacted hint for the API key.

  - `principal: Optional[Principal]`

    The principal the API key acts as (a User or a Service Account), or `null` if the API key is not bound to a principal.

    - `class BetaAPIKeyUserActor`

      - `type: Literal["user_actor"]`

        Principal type. Always `"user_actor"` for a User.

        default: user_actor

      - `user_id: str`

        ID of the User the API key acts as.

    - `class BetaAPIKeyServiceAccountActor`

      - `type: Literal["service_account_actor"]`

        Principal type. Always `"service_account_actor"` for a Service Account.

        default: service_account_actor

      - `service_account_id: str`

        ID of the Service Account the API key acts as.

  - `scope: Scope`

    Where the API key belongs: its Workspace (`{"type": "workspace", "workspace_id": "wrkspc_..."}`, with the Workspace's real ID even when it is the organization's default Workspace), or the organization (`{"type": "organization"}`) for a principal-bound API key that has no Workspace.

    - `class BetaAPIKeyOrganizationScope`

      - `type: Literal["organization"]`

        Scope type. Always `"organization"`: the API key has no Workspace. Only a principal-bound API key can have this scope.

        default: organization

    - `class BetaAPIKeyWorkspaceScope`

      - `type: Literal["workspace"]`

        Scope type. Always `"workspace"`: the API key belongs to one Workspace.

        default: workspace

      - `workspace_id: str`

        ID of the Workspace the API key belongs to. Unlike the deprecated top-level `workspace_id`, this is the Workspace's real ID even for the organization's default Workspace.

  - `status: Literal["active", "archived", "expired", "inactive"]`

    Status of the API key.

    - `"active"`

    - `"archived"`

    - `"expired"`

    - `"inactive"`

  - `workspace_id: Optional[str]`

    **Deprecated**: Use `scope` instead. `workspace_id` is `null` both for an API key in the default Workspace and for a principal-bound API key that has no Workspace.

    Deprecated: use `scope` instead. ID of the Workspace associated with the API key, or `null` if the API key belongs to the default Workspace. Also `null` for a principal-bound API key that has no Workspace; `scope` tells the two apart.

### Beta API Key Created By

- `class BetaAPIKeyCreatedBy`

  - `type: Literal["service_account", "user"]`

    Type of the actor that created the object.

    - `"service_account"`

    - `"user"`

  - `id: str`

    ID of the actor that created the object.

### Beta API Key Organization Scope

- `class BetaAPIKeyOrganizationScope`

  - `type: Literal["organization"]`

    Scope type. Always `"organization"`: the API key has no Workspace. Only a principal-bound API key can have this scope.

    default: organization

### Beta API Key Service Account Actor

- `class BetaAPIKeyServiceAccountActor`

  - `type: Literal["service_account_actor"]`

    Principal type. Always `"service_account_actor"` for a Service Account.

    default: service_account_actor

  - `service_account_id: str`

    ID of the Service Account the API key acts as.

### Beta API Key User Actor

- `class BetaAPIKeyUserActor`

  - `type: Literal["user_actor"]`

    Principal type. Always `"user_actor"` for a User.

    default: user_actor

  - `user_id: str`

    ID of the User the API key acts as.

### Beta API Key Workspace Scope

- `class BetaAPIKeyWorkspaceScope`

  - `type: Literal["workspace"]`

    Scope type. Always `"workspace"`: the API key belongs to one Workspace.

    default: workspace

  - `workspace_id: str`

    ID of the Workspace the API key belongs to. Unlike the deprecated top-level `workspace_id`, this is the Workspace's real ID even for the organization's default Workspace.
