api-keys changedmanage-claude/api-keys
Nearest release: v2.1.333, published 4 hours after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
## Key types ### Scope ## Key expiration ## Who can create which key ## Create and use a key ### Run the docs’ samples with a key ## Select a workspace ## Keep a key safe ## Replace a workspace key ## Manage keys with the Admin API ## Special cases ### If you use Claude Platform on AWS
The whole hunk
430 lines, new pageA whole new page. There's nothing to diff it against, so here is what it says.
---
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.
Cut at 300 lines. The page has the rest.
No line in this hunk matches that.