Claude Platform Docs
MessagesDeveloper API keys

Developer API keys

Compare the types of Developer API key, use a key, select a workspace, and manage expiration.

A Developer API key is a secret that you create in the Claude Console and send with each request. Keys suit tools that need one and servers where no identity provider is available.

Is this the key you need? A Developer API key calls Claude, and an Admin API key manages an organization. To compare them, see the two kinds of API key.

You might not need a key. To choose a method that doesn’t use one, see Choose your path on the Authentication page.

Key types

When you create a key, the Linked account setting determines its type. Choose yourself for a personal key or a service account for a service account key. Not linked makes a legacy workspace key.

If a tool that only you run asks for a key, use a personal key. If a shared or unattended workload has to use a key, give it a service account key, which doesn’t stop working when one person leaves.

The type determines who the key acts as, where it works, and when it stops working:

  • Personal key: It acts as you, with your roles. It works in one workspace or in the workspaces where your role allows API use (see Workspace roles and permissions on the Workspaces page). It stops working when you leave the organization or are removed from it.
  • Service account key: It acts as a service account. It works in one workspace or in the workspaces where the service account’s role allows API use. It stops working when the service account is archived.
  • Workspace key (legacy): It acts as no one. It works in the workspace it was created in. It stops working when that workspace is archived.

Personal keys and service account keys are tied to an identity, so they don’t outlive the people or service accounts that own them.

Workspace keys are legacy, so use a personal or service account key for new integrations. To move off a workspace key, see Replace a workspace key.

Scope

A personal or service account key is scoped to one workspace or to the organization:

  • Scoped to one workspace: The key works only in that workspace. It also stops working when its owner loses access to the workspace or when the workspace is archived.
  • Scoped to the organization: The key works in several workspaces, so each Claude API request names one (see Select a workspace).

Key expiration

You choose a key’s expiration when you create it on the API keys page (platform.claude.com/settings/keys) in the Claude Console, and you can’t change the expiration afterward. The choices are:

  • A preset: 3 hours, 1 day, 7 days, or 30 days
  • A custom date and time
  • Never, for keys you keep in a secrets manager and rotate yourself

If your organization has a maximum expiration policy, the Console limits presets and custom dates to that maximum and doesn’t offer Never.

If the key lasts at least 3 days, Anthropic emails the key’s creator before it expires.

After a key expires, requests made with it return a 401 authentication_error. An expired key can only be deleted, not turned back on, so create a new key to restore access.

The API keys table in the Console shows each key’s expiration. The Admin API reports each key’s expires_at on List API KeysPreview with links to the API reference available — press Tab until focus enters the card, Escape to return. and Retrieve API KeyPreview with links to the API reference available — press Tab until focus enters the card, Escape to return., so you can rotate keys before they expire.

Who can create which key

KeyWho can create it
Personal key, scoped to one workspaceWorkspace Developer, Workspace Limited Developer, or Workspace Admin in that workspace. Organization developers who are members of that workspace can too. Organization admins have the Workspace Admin role in every workspace.
Personal key, scoped to the organizationOrganization developers and admins
Service account keyOrganization admins
Workspace key (legacy)Workspace Developer, Workspace Limited Developer, or Workspace Admin in that workspace. Organization admins have the Workspace Admin role in every workspace.

The default workspace has no member list, so organization developers and admins can create personal and workspace keys there.

For what each role allows, see Organization roles and permissions on the Admin API page and Workspace roles and permissions on the Workspaces page.

An organization admin can turn off key creation on the Security page in the Claude Console. Allow creating new API keys controls the whole organization. Allow creating new API keys in default workspace controls only keys scoped to the default workspace.

If you can’t create the key you need, what to do depends on why:

  • You have the organization user role: Use a workspace where you’re a Workspace Developer, Workspace Limited Developer, or Workspace Admin. On the API keys page, click Create key. If the dialog first offers other ways to connect, click Somewhere else or Continue with an API key. Then, set Scope to that workspace.
  • Create key is missing or disabled, or the Console says you don’t have permission: Ask an organization admin. They can change your role, change the key creation settings, or create a service account key for your workload.

Create and use a key

To create a key step by step, see Get your Claude API key.

The SDK and the CLI read a key from the ANTHROPIC_API_KEY environment variable. A direct HTTP request sends the key in the Authorization header after Bearer. It can send it in the legacy x-api-key header instead. Send only one. With Authorization, a request looks like this:

POST /v1/messages
Authorization: Bearer YOUR_API_KEY
anthropic-version: 2026-10-21
content-type: application/json

Keep keys out of source control, client-side code, and prompts. To set ANTHROPIC_API_KEY in your shell, including on Windows, see API key on the CLI authentication options page.

The following samples show how each tool takes the key:

client = Anthropic()  # reads ANTHROPIC_API_KEY
# Or pass a key that you load from a secrets manager:
# client = Anthropic(api_key=key_from_your_secrets_manager)

Run the docs’ samples with a key

First, set ANTHROPIC_API_KEY to your key. If the key is scoped to the organization, every Claude API sample must also name a workspace (see Select a workspace). Anything else you change depends on the sample:

  • SDK and CLI samples, and cURL samples that send x-api-key: Nothing else. They read ANTHROPIC_API_KEY.
  • cURL samples that use CLI sign-in: These send Authorization: Bearer $(ant auth print-credentials --access-token). Change it to Authorization: Bearer $ANTHROPIC_API_KEY.

Select a workspace

Whether a request names a workspace depends on the key’s scope:

  • Scoped to one workspace: Requests can leave out the anthropic-workspace-id header. If you send the header, it must name the key’s own workspace.
  • Scoped to the organization: Each Claude API request must name a workspace in the anthropic-workspace-id header. Leave the header out of Admin API requests, which refuse it.

To find a workspace’s ID, use either of these:

  • The ID column on the Workspaces page in the Claude Console. The page lists the default workspace too.
  • List WorkspacesPreview with links to the API reference available — press Tab until focus enters the card, Escape to return. in the Admin API. It includes the default workspace only when you pass include_default=true.

The following samples set the header on one request. With the SDK, you can also set it once for every request from a client:

client = Anthropic()  # reads ANTHROPIC_API_KEY

# Required on every Claude API request for a key scoped to the organization.
# Omit extra_headers for a key scoped to one workspace.
message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello, Claude"}],
    extra_headers={"anthropic-workspace-id": "wrkspc_01AbCdEfGhJkLmNpQrStUvWx"},
)
print(message.content)

# Or set it once for every request from this client:
workspace_client = Anthropic(
    default_headers={"anthropic-workspace-id": "wrkspc_01AbCdEfGhJkLmNpQrStUvWx"},
)

If a request made with a key scoped to the organization leaves out the header, the API returns a 400 invalid_request_error:

JSON
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "This API key is not scoped to a workspace, so this request must include the anthropic-workspace-id header with the ID of the workspace to use. Add the header, or use an API key that is scoped to a workspace."
  },
  "request_id": "req_011CSHoEeqs5C35K2UUqR7Fy"
}

The header itself can also cause an error:

  • A value that isn’t a valid workspace ID: The API returns a 400 invalid_request_error with the message anthropic-workspace-id header must be a valid workspace ID.
  • A workspace outside the key’s reach: The API returns a 404 not_found_error with the message Workspace `<uuid>` not found., which names the workspace by its UUID, not its wrkspc_ ID. For example, the workspace doesn’t exist, or the key works only in another workspace. With a key scoped to the organization, the error can also mean that the key’s owner can’t access that workspace.
  • A workspace where the key’s owner has a role that doesn’t allow the request: The API returns a 403 permission_error with a message such as The account linked to this API key does not have permission for this endpoint. For example, the Workspace User and Workspace Billing roles can’t send Messages requests.

Keep a key safe

Store API keys in a secrets manager, rotate them on a schedule, and disable or delete any key you think has leaked. The API keys page in the Claude Console has two ways to stop a key:

  • Disable can be undone: Re-enable turns the key back on. You can’t re-enable a key while Allow creating new API keys is turned off (see Who can create which key).
  • Delete is permanent.

The Admin API reports a disabled key’s status as "inactive", and a re-enabled key’s as "active". A deleted key still appears in List API KeysPreview with links to the API reference available — press Tab until focus enters the card, Escape to return. with status: "archived".

To limit how long a key stays usable if it leaks, set a key expiration when you create it. To limit where a leaked key works, turn on IP allowlisting, which is in beta.

Replace a workspace key

A workspace key keeps working after the people who set it up have left. Replacing it provides better security and observability.

What to replace a workspace key with depends on where the code runs:

  • A workload with an identity provider: Use Workload Identity Federation, which needs no long-lived key. See Migrate from API keys on the Workload Identity Federation page.
  • Code that you run on your own computer: Use CLI sign-in. See the Authentication page’s Sign in with the CLI section.
  • Other code: Use a personal or service account key.

If you need a new service account, an organization admin creates it on the Service accounts page in the Claude Console. The admin also adds it to the workspace.

To replace a workspace key with a personal or service account key:

  1. Decide the key type. This page’s Key types section says which to use.
  2. Create the new key. Scope it to the old key’s workspace unless the integration needs more than one workspace. For a service account key, ask an organization admin to create it.
  3. Deploy the new key. Replace the old key wherever the integration reads it, usually the ANTHROPIC_API_KEY environment variable or a secrets manager entry. For a key scoped to the organization, also send the anthropic-workspace-id header (see Select a workspace).
  4. Retire the old key. Disable the workspace key on the API keys page in the Claude Console. Confirm that requests still succeed, then delete it.

Manage keys with the Admin API

Organization admins who automate key management can use the endpoints in the Admin API reference, such as List API KeysPreview with links to the API reference available — press Tab until focus enters the card, Escape to return. and Retrieve API KeyPreview with links to the API reference available — press Tab until focus enters the card, Escape to return.. For the credentials these endpoints accept, see Admin API authentication. To get a Console Admin API key, see Create a key for a Claude Console organization.

These endpoints return a partly hidden hint of a key’s secret, never the secret itself. To get a key, create one on the API keys page in the Claude Console.

Special cases

If you use Claude Platform on AWS

Claude Platform on AWS uses its own keys, which you create in the AWS Console. To send one, see API key authentication on the Claude Platform on AWS page.

Was this page helpful?