The two sides of this change are more than 400 edits apart, too far apart to line up, so this is the differ's own diff of it and the words inside a line are not marked.
from line 1
11---
22title: Authentication
33url: https://platform.claude.com/docs/en/manage-claude/authentication
4description: "Choose how your code proves who it is to the Claude API: CLI sign-in, Workload Identity Federation, App Attest, or an API key."
4description: "Choose how your code authenticates to call Claude: CLI sign-in, Workload Identity Federation, App Attest, or a Developer API key."
55---
66
7Every request to the Claude API carries a credential that tells the API who is calling, such as you or a service account that gives a program its own identity. Choose the method by where your code runs. Every method but an API key sends a short-lived token instead of a long-lived secret, which limits the damage if a token leaks.
7Every request to the Claude API carries a credential, which tells the API who is calling, such as you or a service account in your organization. This page helps you choose the credential your code uses to call Claude, for example to send a message. The methods on this page are for accounts and organizations in the Claude Console (`platform.claude.com`).
88
9| Method | Credential | Best for |
10| ----- | ----- | ----- |
11| CLI sign-in (see the `ant` CLI’s [Interactive login](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication#interactive-login) section) | Short-lived access token that `ant auth login` stores on your computer | Local development and scripting on your own computer |
12| [Workload Identity Federation (WIF)](https://platform.claude.com/docs/en/manage-claude/authentication#workload-identity-federation) | Short-lived bearer token exchanged from your identity provider’s identity token | Production workloads on cloud platforms (AWS, Google Cloud, and Azure), CI/CD pipelines, and Kubernetes, where you want to eliminate static secrets |
13| [App Attest](https://platform.claude.com/docs/en/manage-claude/authentication#app-attest) | Short-lived access token issued to a genuine, attested installation of your registered iOS or macOS app | iOS and macOS apps distributed to end users, where the app calls the Claude API directly with no back end or proxy |
14| [API key](https://platform.claude.com/docs/en/manage-claude/authentication#api-keys) | Static `sk-ant-api...` secret sent as a bearer token in the `Authorization` header | A server with no identity provider or a tool that asks for a key |
9To manage an organization instead, such as inviting members or reading usage, see [Admin API keys and tokens](https://platform.claude.com/docs/en/manage-claude/admin-api-keys).
1510
16On your own computer, sign in with the `ant` CLI. The SDK and the CLI then find your credentials on their own as long as `ANTHROPIC_API_KEY` isn’t set. Use Workload Identity Federation in CI or on a server or cluster with an identity provider. Use App Attest for iOS and macOS apps you distribute to end users. Choose an API key for a server with no identity provider or a tool that asks for a key. Pick a personal key for your own use or a service account key for anything shared.
11## Choose your path
12
13Choose by where your code runs:
14
15<CardGroup cols={2}>
16 <Card title="CLI sign-in" image="https://platform.claude.com/docs/images/authentication/cli-sign-in.svg" imageHeight={32} href="https://platform.claude.com/docs/en/manage-claude/authentication#sign-in-with-the-cli">
17 On your own computer, as you work
18
19 Scoped to one workspace, as you
20 </Card>
21
22 <Card title="Workload Identity Federation" image="https://platform.claude.com/docs/images/authentication/workload-identity-federation.svg" imageHeight={32} href="https://platform.claude.com/docs/en/manage-claude/workload-identity-federation">
23 In CI or on a server or cluster with an identity provider
24
25 Scoped to one workspace, as a service account
26 </Card>
27
28 <Card title="App Attest" image="https://platform.claude.com/docs/images/authentication/app-attest.svg" imageHeight={32} href="https://platform.claude.com/docs/en/manage-claude/app-attest">
29 In an iOS or macOS app
30
31 Reaches Messages and token counting in one workspace
32 </Card>
33
34 <Card title="Developer API key" image="https://platform.claude.com/docs/images/authentication/developer-api-key.svg" imageHeight={32} href="https://platform.claude.com/docs/en/manage-claude/api-keys">
35 On a server with no identity provider or in a tool that asks for a key
36
37 Reaches one workspace or several
38 </Card>
39</CardGroup>
40
41CLI sign-in, Workload Identity Federation, and App Attest give your code a short-lived access token for one workspace in your organization (see [Workspaces](https://platform.claude.com/docs/en/manage-claude/workspaces)). There’s no key to create, copy, or rotate.
42
43With Workload Identity Federation, your code acts as a service account: a named identity in your organization that isn’t a person. For more, see [Service accounts](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#service-accounts) on the Workload Identity Federation page.
44
45For a web app, see [Browser-based applications](https://platform.claude.com/docs/en/manage-claude/authentication#browser-based-applications) on this page.
46
47On a cloud platform, use that platform’s credentials:
48
49* [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws)
50* [Claude Models on Google Cloud](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/overview)
51* [Claude in Microsoft Foundry](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry)
52* [Claude in Amazon Bedrock (`bedrock-mantle`)](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock), for the Messages API at `/anthropic/v1/messages`
53* [Claude on Amazon Bedrock (`bedrock-runtime`)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy), for the `InvokeModel` and `Converse` APIs and for SDK clients such as `AnthropicBedrock`
54
55## Sign in with the CLI
56
57On your own computer, you can sign in with the `ant` CLI instead of creating a key.
58
59<Steps>
60 <Step title="Install the CLI">
61 <Tabs noDeepLinks>
62 <Tab title="Homebrew (macOS)">
63 ```bash
64 brew install anthropics/tap/ant
65 ```
66 </Tab>
67
68 <Tab title="curl (Linux/WSL)">
69 For Linux environments, download the release binary directly.
70
71 ```bash
72 VERSION=2.14.0
73 OS=$(uname -s | tr '[:upper:]' '[:lower:]')
74 case $(uname -m) in
75 x86_64) ARCH=amd64 ;;
76 aarch64) ARCH=arm64 ;;
77 esac
78 curl -fsSL "https://github.com/anthropics/anthropic-cli/releases/download/v${VERSION}/ant_${VERSION}_${OS}_${ARCH}.tar.gz" \
79 | sudo tar -xz -C /usr/local/bin ant
80 ```
81
82 You can find all releases on the [GitHub releases page](https://github.com/anthropics/anthropic-cli/releases).
83 </Tab>
84
85 <Tab title="go install">
86 You can also install the CLI from source with `go install`, which requires Go 1.26.10 or later.
87
88 ```bash
89 go install github.com/anthropics/anthropic-cli/v2/cmd/ant@latest
90 ```
91
92 `go install` places the binary in `$(go env GOPATH)/bin`. Add that directory to your `PATH` if it isn’t already there:
93
94 ```bash
95 export PATH="$PATH:$(go env GOPATH)/bin"
96 ```
97 </Tab>
98 </Tabs>
99
100 On Windows, you can install the CLI inside [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/windows/wsl/install) with the Linux steps. If you sign in with the CLI inside WSL, also run your code there so that it finds your sign-in.
101 </Step>
102
103 <Step title="Sign in">
104 ```bash CLI
105 ant auth login
106 ```
107
108 Your browser opens. The first time you sign in, select an organization if you belong to more than one, and then a workspace.
109 </Step>
110</Steps>
111
112The CLI then stores an access token on your computer for the workspace you selected. How your code sends the token depends on the tool:
113
114* **SDK and CLI:** They find the token on their own. A client created with no arguments uses it (in Java, with `fromEnv()`).
115* **cURL:** Add `-H "Authorization: Bearer $(ant auth print-credentials --access-token)"` to each request. Each time it runs, `ant auth print-credentials` renews the token first if it has expired or is about to. For an example, see [Authenticate curl requests with CLI credentials](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/scripting#authenticate-curl-requests-with-cli-credentials) on the CLI scripting and automation page.
116
117If `ant auth print-credentials` warns that it couldn’t renew the token, run `ant auth login` again.
118
119If another credential is also set, see [Which credential is used](https://platform.claude.com/docs/en/manage-claude/authentication#which-credential-is-used).
120
121To switch workspaces or organizations, see [CLI authentication options](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication). That page also covers signing in on a computer with no browser.
122
123## Workload Identity Federation
124
125Workload Identity Federation (WIF) lets code in CI, on a server, or in a cluster call the API without a stored secret. WIF needs an identity provider: a service that gives your workload a signed token saying what it is. GitHub Actions, AWS, Google Cloud, and Kubernetes all do this, and many platforms call these tokens OIDC tokens. For how WIF uses these tokens, see the [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation) page.
126
127If your host gives your code no such token, use a [Developer API key](https://platform.claude.com/docs/en/manage-claude/api-keys).
128
129An organization admin sets up WIF in the Claude Console. To set it up, follow the guide for your identity provider, such as [Use WIF with GitHub Actions](https://platform.claude.com/docs/en/manage-claude/wif-providers/github-actions). For the other providers, see [Identity providers](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#identity-providers). For what each part of the setup does, see [Set up federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#set-up-federation).
130
131## App Attest
132
133App Attest lets an iOS or macOS app call Claude straight from the device, with no key inside the app.
134
135To register your app and learn how App Attest works, see [App Attest for iOS and macOS apps](https://platform.claude.com/docs/en/manage-claude/app-attest).
17136
18137## API keys
19138
20API keys are static secrets that you generate in the Claude Console and send on every request as a bearer token in the `Authorization` header.
139An API key is a secret that you create and send with each request.
21140
22### Key types
141There are two kinds of API key, each named for its main job:
23142
24When you create a key, you choose its type, which determines what the key can do, where it works, and when it stops working:
143| Key | What it works with |
144| ----- | ----- |
145| **Developer API key** | The APIs that call Claude, such as Messages, Files, and Managed Agents |
146| **Admin API key** | The APIs that manage and report on an organization, such as the [Admin API](https://platform.claude.com/docs/en/manage-claude/admin-api) and the [Compliance API](https://platform.claude.com/docs/en/manage-claude/compliance-api) |
25147
26| Key type | Acts as | Works in | Stops working when |
27| ----- | ----- | ----- | ----- |
28| **Personal key** | You, the user, with your roles and permissions | Either a single workspace or the workspaces where your role allows API use, chosen when the key is created | You lose access to the organization. A single-workspace key also stops working when you lose access to that workspace or that workspace is archived. Personal keys are archived when you are removed from the organization. If you are re-invited, create new keys; archived keys are not restored |
29| **Service account key** | A [service account](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#service-accounts) | Either a single workspace or anything the service account has access to, chosen when the key is created. A service account has access to the Default Workspace and to workspaces it has been added to | The service account is archived. A single-workspace key also stops working when the service account is removed from that workspace or that workspace is archived |
30| **Workspace key** (legacy) | No one: it belongs to the workspace it was created in | That workspace | It expires, is disabled or deleted, or its workspace is archived, regardless of whether its creator leaves the organization |
148An Admin API key can’t call Claude. The Claude Console calls a Developer API key an “API key” and lists these keys on its **API keys** page.
31149
32Personal keys and service account keys are identity-backed: each belongs to a user or service account your organization already manages, and every request acts as that identity. When that identity is removed from the organization, the key stops working. This means that keys don’t accidentally outlive the people or workloads that own them. Prefer them over workspace keys for new integrations.
150To create a Developer API key, see [Get your Claude API key](https://platform.claude.com/docs/en/get-api-key). For the types of Developer API key, such as personal and service account keys, and how to send one, see [Developer API keys](https://platform.claude.com/docs/en/manage-claude/api-keys).
33151
34If a tool that only you run asks for a key, use a personal key. A shared personal key acts as one person and breaks when they leave. For shared or automated workloads (CI, production services), have an organization admin create a service account so the workload has its own identity.
152## Which credential is used
35153
36Workspace API keys work but are legacy. Prefer identity-backed keys or [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation). To migrate, see [Replacing workspace API keys](https://platform.claude.com/docs/en/manage-claude/authentication#replacing-workspace-api-keys).
154If `ANTHROPIC_API_KEY` is set, the SDK and the CLI use it and don’t look for a CLI sign-in or Workload Identity Federation. A credential that your code passes to the SDK comes before that variable.
37155
38### Create and use a key
156To stop using a key, follow these steps:
39157
40* **Create a key:** In the Claude Console, go to the [API keys](https://platform.claude.com/settings/keys) page (`platform.claude.com/settings/keys`) and click **Create key**. Name the key and select an [expiration](https://platform.claude.com/docs/en/manage-claude/authentication#key-expiration). Set **Linked account** to yourself for a personal key, or to a service account for a key shared across multiple users. You can also scope the key to a specific workspace, which lets you skip setting a workspace ID manually in future requests.
41* **Use the key:** Send it as `Authorization: Bearer <key>` on direct HTTP requests, or set the `ANTHROPIC_API_KEY` environment variable and the [client SDK](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) picks it up automatically.
1581. Unset `ANTHROPIC_API_KEY` everywhere your code runs.
1592. To check which credential the CLI now uses, run `ant auth status` (see [Check authentication status](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication#check-authentication-status) on the CLI authentication options page).
42160
43```http
44POST /v1/messages
45Authorization: Bearer YOUR_API_KEY
46anthropic-version: 2026-10-21
47content-type: application/json
48```
161For the order of every credential, including `ANTHROPIC_AUTH_TOKEN` and credentials passed in code, see [Credential precedence](https://platform.claude.com/docs/en/manage-claude/wif-reference#credential-precedence) on the WIF reference page.
49162
50You can also send the key in the legacy `x-api-key: YOUR_API_KEY` header in place of `Authorization`.
163## Browser-based applications
51164
52Store API keys in a secrets manager, rotate them periodically, and disable or delete any key you suspect has leaked. On the [API keys](https://platform.claude.com/settings/keys) page in the Claude Console, **Disable** is reversible (the Admin API reports the key’s `status` as `"inactive"`, and **Re-enable** returns it to `"active"`), whereas **Delete** is permanent: the key is archived and still appears in [List API Keys](https://platform.claude.com/docs/en/api/organization/api_keys/list) with `status: "archived"`. Expired keys can only be deleted. You can also set an [expiration](https://platform.claude.com/docs/en/manage-claude/authentication#key-expiration) when you create a key to limit how long a leaked credential stays usable. To limit where a leaked key works, turn on [IP allowlisting](https://platform.claude.com/docs/en/manage-claude/ip-allowlist).
165Call the Claude API from your own back end, not from code that runs in your users’ browsers. Anyone who uses a webpage can read a credential in that page’s code. Typically, your web front end calls your back end, which holds the credential and calls the Claude API.
53166
54<CodeGroup>
55 ```bash cURL
56 curl https://api.anthropic.com/v1/messages \
57 -H "x-api-key: $ANTHROPIC_API_KEY" \
58 -H "anthropic-version: 2026-10-21" \
59 -H "content-type: application/json" \
60 -d '{
61 "model": "claude-opus-5-5",
62 "max_tokens": 1024,
63 "messages": [{"role": "user", "content": "Hello, Claude"}]
64 }'
65 ```
66
67 ```bash CLI
68 # See /docs/en/cli-sdks-libraries/cli/authentication#api-key for zsh, bash, and Windows variants
69 export ANTHROPIC_API_KEY=sk-ant-api03-...
70 ```
71
72 ```python Python
73 client = Anthropic(api_key="my-anthropic-api-key")
74 # or, with ANTHROPIC_API_KEY set in the environment:
75 client = Anthropic()
76 ```
77
78 ```typescript TypeScript
79 const client = new Anthropic({ apiKey: "my-anthropic-api-key" });
80 // or, with ANTHROPIC_API_KEY set in the environment:
81 // const client = new Anthropic();
82 ```
83
84 ```csharp C#
85 AnthropicClient client = new() { ApiKey = "my-anthropic-api-key" };
86 // Or, with ANTHROPIC_API_KEY set in the environment:
87 // AnthropicClient client = new();
88 ```
89
90 ```go Go
91 client := anthropic.NewClient(
92 option.WithAPIKey("my-anthropic-api-key"), // defaults to os.LookupEnv("ANTHROPIC_API_KEY")
93 )
94 ```
95
96 ```java Java
97 // Explicit
98 AnthropicClient client = AnthropicOkHttpClient.builder()
99 .apiKey("my-anthropic-api-key")
100 .build();
101
102 // From ANTHROPIC_API_KEY (or anthropic.apiKey system property)
103 AnthropicClient clientFromEnv = AnthropicOkHttpClient.fromEnv();
104 ```
105
106 ```php PHP
107 // Reads ANTHROPIC_API_KEY from the environment
108 $client = new Client();
109 // Or pass the key explicitly:
110 $client = new Client(apiKey: 'my-anthropic-api-key');
111 ```
112
113 ```ruby Ruby
114 anthropic = Anthropic::Client.new(api_key: "my-anthropic-api-key")
115 # or, with ANTHROPIC_API_KEY set in the environment:
116 anthropic = Anthropic::Client.new
117 ```
118</CodeGroup>
119
120### Select a workspace
121
122API keys that are created for a specific workspace only work in that workspace, and API requests using these keys can omit the workspace ID.
123
124If your API key isn’t scoped to a workspace, you must specify the workspace ID in the `anthropic-workspace-id` header for each request. See the following example for how to set this header in a request or in the SDK.
125
126The [Admin API](https://platform.claude.com/docs/en/manage-claude/admin-api) accepts a personal key or service account key only if the key isn’t scoped to a specific workspace.
127
128You can find a workspace’s ID in the **ID** column on the [Workspaces](https://platform.claude.com/settings/workspaces) page (`platform.claude.com/settings/workspaces`) in the Claude Console, or by calling the [List Workspaces](https://platform.claude.com/docs/en/api/organization/workspaces/list) endpoint. List Workspaces includes the Default Workspace only when you pass `include_default=true`; its ID is also in the `anthropic-workspace-id` [response header](https://platform.claude.com/docs/en/manage-claude/workspaces#identify-the-workspace-behind-an-api-response) of any request that runs there.
129
130<CodeGroup>
131 ```bash cURL
132 # Required on every request for a key that isn't scoped to a workspace.
133 # Omit the anthropic-workspace-id header for a key scoped to one workspace.
134 curl https://api.anthropic.com/v1/messages \
135 -H "x-api-key: $ANTHROPIC_API_KEY" \
136 -H "anthropic-version: 2026-10-21" \
137 -H "anthropic-workspace-id: wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ" \
138 -H "content-type: application/json" \
139 -d '{
140 "model": "claude-opus-5-5",
141 "max_tokens": 1024,
142 "messages": [{"role": "user", "content": "Hello, Claude"}]
143 }'
144 ```
145
146 ```bash CLI
147 # Required on every command for a key that isn't scoped to a workspace.
148 # Omit --workspace-id for a key scoped to one workspace.
149 ant messages create \
150 --workspace-id wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ \
151 --model claude-opus-5-5 \
152 --max-tokens 1024 \
153 --message '{role: user, content: "Hello, Claude"}'
154 ```
155
156 ```python Python
157 client = Anthropic() # reads ANTHROPIC_API_KEY
158
159 # Required on every request for a key that isn't scoped to a workspace.
160 # Omit extra_headers for a key scoped to one workspace.
161 message = client.messages.create(
162 model="claude-opus-5-5",
163 max_tokens=1024,
164 messages=[{"role": "user", "content": "Hello, Claude"}],
165 extra_headers={"anthropic-workspace-id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"},
166 )
167 print(message.content)
168
169 # Or set it once for every request from this client:
170 workspace_client = Anthropic(
171 default_headers={"anthropic-workspace-id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"},
172 )
173 ```
174
175 ```typescript TypeScript
176 const client = new Anthropic(); // reads ANTHROPIC_API_KEY
177
178 // Required on every request for a key that isn't scoped to a workspace.
179 // Omit the second argument for a key scoped to one workspace.
180 const message = await client.messages.create(
181 {
182 model: "claude-opus-5-5",
183 max_tokens: 1024,
184 messages: [{ role: "user", content: "Hello, Claude" }]
185 },
186 { headers: { "anthropic-workspace-id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ" } }
187 );
188 console.log(message.content);
189
190 // Or set it once for every request from this client:
191 const workspaceClient = new Anthropic({
192 defaultHeaders: { "anthropic-workspace-id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ" }
193 });
194 ```
195
196 ```csharp C#
197 AnthropicClient client = new(); // reads ANTHROPIC_API_KEY
198
199 MessageCreateParams parameters = new()
200 {
201 Model = Model.ClaudeOpus5_5,
202 MaxTokens = 1024,
203 Messages = [new UserMessageParam { Content = "Hello, Claude" }],
204 };
205
206 // Required on every request for a key that isn't scoped to a workspace.
207 // Call client.Messages.Create(parameters) directly for a key scoped to one workspace.
208 var message = await client
209 .WithOptions(options =>
210 options with
211 {
212 ExtraHeaders = new Dictionary<string, string>
213 {
214 ["anthropic-workspace-id"] = "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
215 },
216 }
217 )
218 .Messages.Create(parameters);
219 Console.WriteLine(message);
220
221 // Or set it once for every request from this client:
222 AnthropicClient workspaceClient = new(new ClientOptions
223 {
224 ExtraHeaders = new Dictionary<string, string>
225 {
226 ["anthropic-workspace-id"] = "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
227 },
228 });
229 ```
230
231 ```go Go
232 client := anthropic.NewClient() // reads ANTHROPIC_API_KEY
233
234 // Required on every request for a key that isn't scoped to a workspace.
235 // Omit the option for a key scoped to one workspace.
236 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
237 Model: anthropic.ModelClaudeOpus5_5,
238 MaxTokens: 1024,
239 Messages: []anthropic.MessageParam{
240 anthropic.NewUserMessage(anthropic.NewTextBlock("Hello, Claude")),
241 },
242 }, option.WithHeader("anthropic-workspace-id", "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"))
243 if err != nil {
244 log.Fatal(err)
245 }
246 fmt.Println(message.Content)
247
248 // Or set it once for every request from this client:
249 workspaceClient := anthropic.NewClient(
250 option.WithHeader("anthropic-workspace-id", "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"),
251 )
252 ```
253
254 ```java Java
255 AnthropicClient client = AnthropicOkHttpClient.fromEnv(); // reads ANTHROPIC_API_KEY
256
257 // Required on every request for a key that isn't scoped to a workspace.
258 // Omit putAdditionalHeader for a key scoped to one workspace.
259 Message message = client.messages().create(MessageCreateParams.builder()
260 .model(Model.CLAUDE_OPUS_5_5)
261 .maxTokens(1024)
262 .addUserMessage("Hello, Claude")
263 .putAdditionalHeader("anthropic-workspace-id", "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ")
264 .build());
265
266 IO.println(message.content());
267
268 // Or set it once for every request from this client:
269 AnthropicClient workspaceClient = AnthropicOkHttpClient.builder()
270 .fromEnv()
271 .putHeader("anthropic-workspace-id", "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ")
272 .build();
273 ```
274
275 ```php PHP
276 $client = new Client(); // reads ANTHROPIC_API_KEY
277
278 // Required on every request for a key that isn't scoped to a workspace.
279 // Omit requestOptions for a key scoped to one workspace.
280 $message = $client->messages->create(
281 model: Model::CLAUDE_OPUS_5_5,
282 maxTokens: 1024,
283 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
284 requestOptions: [
285 'extraHeaders' => ['anthropic-workspace-id' => 'wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ'],
286 ],
287 );
288
289 echo json_encode($message->content), PHP_EOL;
290 ```
291
292 ```ruby Ruby
293 client = Anthropic::Client.new # reads ANTHROPIC_API_KEY
294
295 # Required on every request for a key that isn't scoped to a workspace.
296 # Omit request_options for a key scoped to one workspace.
297 message = client.messages.create(
298 model: Anthropic::Model::CLAUDE_OPUS_5_5,
299 max_tokens: 1024,
300 messages: [{ role: "user", content: "Hello, Claude" }],
301 request_options: { extra_headers: { "anthropic-workspace-id" => "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ" } }
302 )
303
304 puts message.content
305 ```
306</CodeGroup>
307
308If a request made with a key that isn’t scoped to a workspace omits the header, the API returns a 400 `invalid_request_error`:
309
310```json JSON
311{
312 "type": "error",
313 "error": {
314 "type": "invalid_request_error",
315 "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."
316 },
317 "request_id": "req_011CSHoEeqs5C35K2UUqR7Fy"
318}
319```
320
321A header value that isn’t a valid workspace ID returns a 400 `invalid_request_error` with the message `anthropic-workspace-id header must be a valid workspace ID.` If the workspace doesn’t exist, or the key’s user or service account doesn’t have access to it, the API returns a 404 `not_found_error` with the message ``Workspace `<id>` not found.``, the same response as for any unknown workspace.
322
323Workload Identity Federation selects a workspace at token exchange instead; see the [WIF reference](https://platform.claude.com/docs/en/manage-claude/wif-reference) for details.
324
325### Key expiration
326
327When you create an API key from the [API keys](https://platform.claude.com/settings/keys) page in the Claude Console, you choose an expiration: a preset (3 hours, 1 day, 7 days, or 30 days), a custom duration, or **Never** for keys you store in a secrets manager and rotate yourself. If your organization has a maximum expiration policy, the Console limits presets and custom durations to the policy maximum, and **Never** is unavailable. Expiration is set at creation time and cannot be changed afterward. The same expiration choice applies when you [create an Admin API key](https://platform.claude.com/docs/en/manage-claude/admin-api-keys) in the Claude Console.
328
329Anthropic emails the key’s creator as the expiration approaches: 7 days before expiration for keys created with a lifetime of at least 14 days, and 1 day before for keys with a lifetime of at least 7 days. Keys with shorter lifetimes expire without a warning email.
330
331After a key expires, requests made with it return a `401 authentication_error`. Create a new key to restore access; expired keys cannot be reactivated.
332
333The Console API keys table shows each key’s expiration, and the Admin API reports each key’s `expires_at` timestamp on the [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) endpoints, so you can audit and rotate keys before they expire. The field is `null` for keys without an expiration.
334
335Expiration limits the lifetime of a leaked credential, but it is not a substitute for secret hygiene. Regardless of expiration, store keys in a secrets manager and disable or delete any key you suspect has leaked.
336
337### Replacing workspace API keys
338
339If you have a workspace key, you might want to replace it with [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation) or a personal or service account key. This provides better security and observability.
340
341See the [WIF reference](https://platform.claude.com/docs/en/manage-claude/wif-reference) for details on configuring Workload Identity Federation, which is preferred over long-lived keys.
342
343To replace a workspace key with a personal or service account key:
344
3451. **Decide the key type.** Your own tooling should use a personal key. A shared or unattended workload should use a service account key.
3462. **Create a service account** if necessary. You might have to ask an organization admin to create one on the [Service accounts](https://platform.claude.com/settings/service-accounts) page (`platform.claude.com/settings/service-accounts`) in the Claude Console and add it to the relevant workspace.
3473. **Create the new key.** Create it specifically for the integration’s workspace unless the integration needs multiple workspaces.
3484. **Deploy the new key.** Replace the old key wherever the integration reads it, typically the `ANTHROPIC_API_KEY` environment variable or a secrets manager entry. For a key that isn’t scoped to a workspace, also send the `anthropic-workspace-id` header as shown in [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace).
3495. **Delete the old key.** Confirm that requests succeed, then delete the workspace key on the [API keys](https://platform.claude.com/settings/keys) page in the Claude Console.
350
351### Browser-based applications
352
353Call the Claude API from your own back end, not from code that runs in your users’ browsers. Anyone who uses a webpage can read an API key in that page’s code. Typically, your web front end calls your back end, which holds the key and calls the Claude API.
167### Requests sent from a browser
354168
355169A request sent directly from a browser is a cross-origin (CORS) request. The API accepts one only when it includes the `anthropic-dangerous-direct-browser-access: true` header. The TypeScript SDK sends this header when you set `dangerouslyAllowBrowser` to `true`. For the cases where exposing a key this way is acceptable, see [Runtime support](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#runtime-support) in the TypeScript SDK guide.
356170
357Organizations that have [zero data retention (ZDR)](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#zero-data-retention-zdr-scope) cannot call the API directly from a browser, even with that header. Other organization or workspace settings can have the same effect, and no setting allows browser requests for these organizations. The API returns a 401 `authentication_error` whose message begins `CORS requests are not allowed for this Organization`, even though the API key is valid.
171Some organization and workspace settings block browser requests, even with that header. These settings include the following:
358172
359The restriction applies only to requests that include an `Origin` header, which browsers add and server-side HTTP clients normally do not. Requests from your own back end are not affected. If your back end forwards requests that start in a browser, have it create a new request to the Claude API. Don’t pass the browser’s request through. That request still includes the browser’s `Origin` header, and the API rejects it the same way.
173* [Zero data retention (ZDR)](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#zero-data-retention-zdr-scope)
174* A [customer-managed encryption key](https://platform.claude.com/docs/en/manage-claude/cmek) attached to a workspace
360175
361## Workload Identity Federation
176No Claude Console setting overrides the block. For a blocked request, the API returns a 401 `authentication_error`, even though the credential is valid. The error’s message begins `CORS requests are not allowed for this Organization`.
362177
363Workload Identity Federation (WIF) lets a workload authenticate with a short-lived identity token issued by an identity provider (IdP) you already trust. Such IdPs include AWS IAM, Google Cloud, and any standards-compliant OIDC issuer (such as GitHub Actions, Kubernetes service accounts, SPIFFE, Microsoft Entra ID, or Okta). The workload exchanges its IdP-issued JWT at `POST /v1/oauth/token` for a short-lived Claude API access token, and the SDK refreshes that token automatically before it expires. There is no `sk-ant-api...` string to mint, distribute, or rotate.
178Both the `anthropic-dangerous-direct-browser-access` header rule and the block apply only to requests that include an `Origin` header. Browsers add that header, and server-side HTTP clients normally don’t.
364179
365Federation removes long-lived Claude API keys from your environment, which limits the damage that a leaked credential can cause and lets you manage access with the same IdP controls you already use for cloud resources. It does not, on its own, guarantee end-to-end security: the trust chain is only as strong as your identity provider’s configuration, and a long-lived secret one step earlier in that chain (for example, a static cloud credential that can mint IdP tokens) can still undermine it. Pair federation with your provider’s controls, such as IP allowlists, MFA, and audit logging.
366
367To configure federation, you create three resources in the Claude Console (a service account, a federation issuer, and a federation rule) and then point your SDK at the rule. See [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation) for the full setup walkthrough.
368
369## App Attest
370
371App Attest authenticates iOS and macOS apps that call the Claude API directly from the device. Each installation proves that it is a genuine, unmodified build of an app you registered in the Claude Console, using Apple’s App Attest service. Anthropic then issues the device a short-lived access token that bills usage to your workspace. Tokens are scoped to your workspace, expire after 1 hour, and authorize only [Messages API](https://platform.claude.com/docs/en/api/messages/create) calls.
372
373To register your app and get a client ID, see [App Attest for iOS and macOS apps](https://platform.claude.com/docs/en/manage-claude/app-attest).
374
375## Next steps
376
377<CardGroup cols={2}>
378 <Card title="Set up Workload Identity Federation" icon="lock" href="https://platform.claude.com/docs/en/manage-claude/workload-identity-federation">
379 Configure issuers, rules, and service accounts, then exchange tokens
380 </Card>
381
382 <Card title="Identity provider guides" icon="cloud" href="https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#identity-providers">
383 Step-by-step guides for AWS, Google Cloud, Azure, GitHub Actions, Kubernetes, SPIFFE, and Okta
384 </Card>
385
386 <Card title="WIF reference" icon="book" href="https://platform.claude.com/docs/en/manage-claude/wif-reference">
387 Environment variables, validation rules, profile configuration, and error reference
388 </Card>
389
390 <Card title="App Attest for iOS and macOS apps" icon="fingerprint" href="https://platform.claude.com/docs/en/manage-claude/app-attest">
391 Let genuine installations of your app call the Claude API without shipping an API key
392 </Card>
393
394 <Card title="Client SDKs" icon="code" href="https://platform.claude.com/docs/en/cli-sdks-libraries/overview">
395 Python, TypeScript, C#, Go, Java, PHP, Ruby, and the CLI
396 </Card>
397</CardGroup>
180If your back end passes on requests that start in a browser, have it create a new request to the Claude API. A request forwarded as it is keeps the browser’s `Origin` header, so the API treats it as a request from a browser.
398181
No line in this hunk matches that.