---
title: Developer API keys
url: https://platform.claude.com/docs/en/manage-claude/api-keys
description: 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](https://platform.claude.com/docs/en/manage-claude/authentication#workload-identity-federation) is available.

**Is this the key you need?** A Developer API key calls Claude, and an [Admin API key](https://platform.claude.com/docs/en/manage-claude/admin-api-keys) manages an organization. To compare them, see the [two kinds of API key](https://platform.claude.com/docs/en/manage-claude/authentication#api-keys).

**You might not need a key.** To choose a method that doesn’t use one, see [Choose your path](https://platform.claude.com/docs/en/manage-claude/authentication#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](https://platform.claude.com/docs/en/manage-claude/workspaces#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](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#service-accounts). 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](https://platform.claude.com/docs/en/manage-claude/api-keys#replacing-workspace-api-keys).

### 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](https://platform.claude.com/docs/en/manage-claude/api-keys#select-a-workspace)).

## Key expiration

You choose a key’s expiration when you create it on the [API keys](https://platform.claude.com/settings/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](https://platform.claude.com/docs/en/manage-claude/admin-api) reports each key’s `expires_at` on [List API Keys](https://platform.claude.com/docs/en/api/organization/api_keys/list) and [Retrieve API Key](https://platform.claude.com/docs/en/api/organization/api_keys/retrieve), so you can rotate keys before they expire.

## Who can create which key

| Key | Who can create it |
| ----- | ----- |
| Personal key, scoped to one workspace | Workspace 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 organization | Organization developers and admins |
| Service account key | Organization 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](https://platform.claude.com/docs/en/manage-claude/admin-api#organization-roles-and-permissions) on the Admin API page and [Workspace roles and permissions](https://platform.claude.com/docs/en/manage-claude/workspaces#workspace-roles-and-permissions) on the Workspaces page.

An organization admin can turn off key creation on the [Security](https://platform.claude.com/settings/identity) 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](https://platform.claude.com/settings/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](https://platform.claude.com/docs/en/get-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:

```http
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](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication#api-key) on the CLI authentication options page.

The following samples show how each tool takes the key:

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2026-10-21" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 1024,
      "messages": [{"role": "user", "content": "Hello, Claude"}]
    }'
  ```

  ```bash CLI
  export ANTHROPIC_API_KEY=sk-ant-...
  ```

  ```python Python
  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)
  ```

  ```typescript TypeScript
  const client = new Anthropic(); // reads ANTHROPIC_API_KEY
  // Or pass a key that you load from a secrets manager:
  // const client = new Anthropic({ apiKey: keyFromYourSecretsManager });
  ```

  ```csharp C#
  AnthropicClient client = new(); // reads ANTHROPIC_API_KEY
  // Or pass a key that you load from a secrets manager:
  // AnthropicClient client = new() { ApiKey = keyFromYourSecretsManager };
  ```

  ```go Go
  client := anthropic.NewClient() // reads ANTHROPIC_API_KEY
  // Or pass a key that you load from a secrets manager
  // (import github.com/anthropics/anthropic-sdk-go/v2/option):
  // client := anthropic.NewClient(option.WithAPIKey(keyFromYourSecretsManager))
  ```

  ```java Java
  AnthropicClient client = AnthropicOkHttpClient.fromEnv(); // reads ANTHROPIC_API_KEY
  // Or pass a key that you load from a secrets manager:
  // AnthropicClient client = AnthropicOkHttpClient.builder()
  //     .apiKey(keyFromYourSecretsManager)
  //     .build();
  ```

  ```php PHP
  $client = new Client(); // reads ANTHROPIC_API_KEY
  // Or pass a key that you load from a secrets manager:
  // $client = new Client(apiKey: $keyFromYourSecretsManager);
  ```

  ```ruby Ruby
  client = Anthropic::Client.new # reads ANTHROPIC_API_KEY
  # Or pass a key that you load from a secrets manager:
  # client = Anthropic::Client.new(api_key: key_from_your_secrets_manager)
  ```
</CodeGroup>

### 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](https://platform.claude.com/docs/en/manage-claude/api-keys#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](https://platform.claude.com/settings/workspaces) page in the Claude Console. The page lists the default workspace too.
* [List Workspaces](https://platform.claude.com/docs/en/api/organization/workspaces/list) 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:

<CodeGroup>
  ```bash cURL
  # Required on every Claude API request for a key scoped to the organization.
  # Omit the anthropic-workspace-id header for a key scoped to one workspace.
  curl https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2026-10-21" \
    -H "anthropic-workspace-id: wrkspc_01AbCdEfGhJkLmNpQrStUvWx" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 1024,
      "messages": [{"role": "user", "content": "Hello, Claude"}]
    }'
  ```

  ```bash CLI
  # Required on every Claude API request for a key scoped to the organization.
  # Omit --workspace-id for a key scoped to one workspace.
  ant messages create \
    --workspace-id wrkspc_01AbCdEfGhJkLmNpQrStUvWx \
    --model claude-opus-5-5 \
    --max-tokens 1024 \
    --message '{role: user, content: "Hello, Claude"}'
  ```

  ```python Python
  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"},
  )
  ```

  ```typescript TypeScript
  const client = new Anthropic(); // reads ANTHROPIC_API_KEY

  // Required on every Claude API request for a key scoped to the organization.
  // Omit the second argument for a key scoped to one workspace.
  const message = await client.messages.create(
    {
      model: "claude-opus-5-5",
      max_tokens: 1024,
      messages: [{ role: "user", content: "Hello, Claude" }]
    },
    { headers: { "anthropic-workspace-id": "wrkspc_01AbCdEfGhJkLmNpQrStUvWx" } }
  );
  console.log(message.content);

  // Or set it once for every request from this client:
  const workspaceClient = new Anthropic({
    defaultHeaders: { "anthropic-workspace-id": "wrkspc_01AbCdEfGhJkLmNpQrStUvWx" }
  });
  ```

  ```csharp C#
  AnthropicClient client = new(); // reads ANTHROPIC_API_KEY

  MessageCreateParams parameters = new()
  {
      Model = Model.ClaudeOpus5_5,
      MaxTokens = 1024,
      Messages = [new UserMessageParam { Content = "Hello, Claude" }],
  };

  // Required on every Claude API request for a key scoped to the organization.
  // Call client.Messages.Create(parameters) directly for a key scoped to one workspace.
  var message = await client
      .WithOptions(options =>
          options with
          {
              ExtraHeaders = new Dictionary<string, string>
              {
                  ["anthropic-workspace-id"] = "wrkspc_01AbCdEfGhJkLmNpQrStUvWx",
              },
          }
      )
      .Messages.Create(parameters);
  Console.WriteLine(message);

  // Or set it once for every request from this client:
  AnthropicClient workspaceClient = new(new ClientOptions
  {
      ExtraHeaders = new Dictionary<string, string>
      {
          ["anthropic-workspace-id"] = "wrkspc_01AbCdEfGhJkLmNpQrStUvWx",
      },
  });
  ```

  ```go Go
  client := anthropic.NewClient() // reads ANTHROPIC_API_KEY

  // Required on every Claude API request for a key scoped to the organization.
  // Omit the option for a key scoped to one workspace.
  message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeOpus5_5,
  	MaxTokens: 1024,
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("Hello, Claude")),
  	},
  }, option.WithHeader("anthropic-workspace-id", "wrkspc_01AbCdEfGhJkLmNpQrStUvWx"))
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(message.Content)

  // Or set it once for every request from this client:
  workspaceClient := anthropic.NewClient(
  	option.WithHeader("anthropic-workspace-id", "wrkspc_01AbCdEfGhJkLmNpQrStUvWx"),
  )
  ```

  ```java Java
  AnthropicClient client = AnthropicOkHttpClient.fromEnv(); // reads ANTHROPIC_API_KEY

  // Required on every Claude API request for a key scoped to the organization.
  // Omit putAdditionalHeader for a key scoped to one workspace.
  Message message = client.messages().create(MessageCreateParams.builder()
      .model(Model.CLAUDE_OPUS_5_5)
      .maxTokens(1024)
      .addUserMessage("Hello, Claude")
      .putAdditionalHeader("anthropic-workspace-id", "wrkspc_01AbCdEfGhJkLmNpQrStUvWx")
      .build());

  IO.println(message.content());

  // Or set it once for every request from this client:
  AnthropicClient workspaceClient = AnthropicOkHttpClient.builder()
      .fromEnv()
      .putHeader("anthropic-workspace-id", "wrkspc_01AbCdEfGhJkLmNpQrStUvWx")
      .build();
  ```

  ```php PHP
  use Psr\Http\Message\RequestInterface;
  use Psr\Http\Message\ResponseInterface;

  $client = new Client(); // reads ANTHROPIC_API_KEY

  // Required on every Claude API request for a key scoped to the organization.
  // Omit workspaceID for a key scoped to one workspace.
  $message = $client->messages->create(
      model: Model::CLAUDE_OPUS_5_5,
      maxTokens: 1024,
      messages: [['role' => 'user', 'content' => 'Hello, Claude']],
      workspaceID: 'wrkspc_01AbCdEfGhJkLmNpQrStUvWx',
  );

  echo json_encode($message->content), PHP_EOL;

  // Or set it once for every request from this client:
  $workspaceMiddleware = function (RequestInterface $request, callable $next): ResponseInterface {
      if (!$request->hasHeader('anthropic-workspace-id')) {
          $request = $request->withHeader('anthropic-workspace-id', 'wrkspc_01AbCdEfGhJkLmNpQrStUvWx');
      }

      return $next($request);
  };

  $workspaceClient = new Client(requestOptions: ['middleware' => [$workspaceMiddleware]]);
  ```

  ```ruby Ruby
  client = Anthropic::Client.new # reads ANTHROPIC_API_KEY

  # Required on every Claude API request for a key scoped to the organization.
  # Omit workspace_id for a key scoped to one workspace.
  message = client.messages.create(
    model: Anthropic::Model::CLAUDE_OPUS_5_5,
    max_tokens: 1024,
    messages: [{ role: "user", content: "Hello, Claude" }],
    workspace_id: "wrkspc_01AbCdEfGhJkLmNpQrStUvWx"
  )

  puts message.content

  # Or set it once for every request from this client:
  workspace_middleware = lambda do |request, call_next|
    headers = { "anthropic-workspace-id" => "wrkspc_01AbCdEfGhJkLmNpQrStUvWx", **request.headers }
    call_next.call(request.with(headers:))
  end

  workspace_client = Anthropic::Client.new(middleware: [workspace_middleware])
  ```
</CodeGroup>

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

```json 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](https://platform.claude.com/settings/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](https://platform.claude.com/docs/en/manage-claude/api-keys#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 Keys](https://platform.claude.com/docs/en/api/organization/api_keys/list) with `status: "archived"`.

To limit how long a key stays usable if it leaks, set a [key expiration](https://platform.claude.com/docs/en/manage-claude/api-keys#key-expiration) when you create it. To limit where a leaked key works, turn on [IP allowlisting](https://platform.claude.com/docs/en/manage-claude/ip-allowlist), 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](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#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](https://platform.claude.com/docs/en/manage-claude/authentication#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](https://platform.claude.com/settings/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](https://platform.claude.com/docs/en/manage-claude/api-keys#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](https://platform.claude.com/docs/en/manage-claude/api-keys#select-a-workspace)).
4. **Retire the old key.** Disable the workspace key on the [API keys](https://platform.claude.com/settings/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](https://platform.claude.com/docs/en/api/organization), such as [List API Keys](https://platform.claude.com/docs/en/api/organization/api_keys/list) and [Retrieve API Key](https://platform.claude.com/docs/en/api/organization/api_keys/retrieve). For the credentials these endpoints accept, see [Admin API authentication](https://platform.claude.com/docs/en/manage-claude/admin-api#authentication). To get a Console Admin API key, see [Create a key for a Claude Console organization](https://platform.claude.com/docs/en/manage-claude/admin-api-keys#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](https://platform.claude.com/settings/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](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#api-key-authentication) on the Claude Platform on AWS page.
