Authentication
Choose how your code authenticates to call Claude: CLI sign-in, Workload Identity Federation, App Attest, or a Developer API key.
Every 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).
To manage an organization instead, such as inviting members or reading usage, see Admin API keys and tokens.
Choose your path
Choose by where your code runs:
On your own computer, as you work
Scoped to one workspace, as you
In CI or on a server or cluster with an identity provider
Scoped to one workspace, as a service account
In an iOS or macOS app
Reaches Messages and token counting in one workspace
On a server with no identity provider or in a tool that asks for a key
Reaches one workspace or several
CLI sign-in, Workload Identity Federation, and App Attest give your code a short-lived access token for one workspace in your organization (see Workspaces). There’s no key to create, copy, or rotate.
With 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 on the Workload Identity Federation page.
For a web app, see Browser-based applications on this page.
On a cloud platform, use that platform’s credentials:
- Claude Platform on AWS
- Claude Models on Google Cloud
- Claude in Microsoft Foundry
- Claude in Amazon Bedrock (
bedrock-mantle), for the Messages API at/anthropic/v1/messages - Claude on Amazon Bedrock (
bedrock-runtime), for theInvokeModelandConverseAPIs and for SDK clients such asAnthropicBedrock
Sign in with the CLI
On your own computer, you can sign in with the ant CLI instead of creating a key.
Install the CLI
brew install anthropics/tap/antFor Linux environments, download the release binary directly.
VERSION=2.16.0 OS=$(uname -s | tr '[:upper:]' '[:lower:]') case $(uname -m) in x86_64) ARCH=amd64 ;; aarch64) ARCH=arm64 ;; esac curl -fsSL "https://github.com/anthropics/anthropic-cli/releases/download/v${VERSION}/ant_${VERSION}_${OS}_${ARCH}.tar.gz" \ | sudo tar -xz -C /usr/local/bin antYou can find all releases on the GitHub releases page.
You can also install the CLI from source with
go install, which requires Go 1.26.10 or later.go install github.com/anthropics/anthropic-cli/v2/cmd/ant@latestgo installplaces the binary in$(go env GOPATH)/bin. Add that directory to yourPATHif it isn’t already there:export PATH="$PATH:$(go env GOPATH)/bin"On Windows, you can install the CLI inside Windows Subsystem for Linux (WSL) 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.
Sign in
CLIant auth loginYour browser opens. The first time you sign in, select an organization if you belong to more than one, and then a workspace.
The CLI then stores an access token on your computer for the workspace you selected. How your code sends the token depends on the tool:
- SDK and CLI: They find the token on their own. A client created with no arguments uses it (in Java, with
fromEnv()). - cURL: Add
-H "Authorization: Bearer $(ant auth print-credentials --access-token)"to each request. Each time it runs,ant auth print-credentialsrenews the token first if it has expired or is about to. For an example, see Authenticate curl requests with CLI credentials on the CLI scripting and automation page.
If ant auth print-credentials warns that it couldn’t renew the token, run ant auth login again.
If another credential is also set, see Which credential is used.
To switch workspaces or organizations, see CLI authentication options. That page also covers signing in on a computer with no browser.
Workload Identity Federation
Workload 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 page.
If your host gives your code no such token, use a Developer API key.
An 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. For the other providers, see Identity providers. For what each part of the setup does, see Set up federation.
App Attest
App Attest lets an iOS or macOS app call Claude straight from the device, with no key inside the app.
To register your app and learn how App Attest works, see App Attest for iOS and macOS apps.
API keys
An API key is a secret that you create and send with each request.
There are two kinds of API key, each named for its main job:
| Key | What it works with |
|---|---|
| Developer API key | The APIs that call Claude, such as Messages, Files, and Managed Agents |
| Admin API key | The APIs that manage and report on an organization, such as the Admin API and the Compliance API |
An 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.
To create a Developer API key, see Get your Claude 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.
Which credential is used
If 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.
To stop using a key, follow these steps:
- Unset
ANTHROPIC_API_KEYeverywhere your code runs. - To check which credential the CLI now uses, run
ant auth status(see Check authentication status on the CLI authentication options page).
For the order of every credential, including ANTHROPIC_AUTH_TOKEN and credentials passed in code, see Credential precedence on the WIF reference page.
Browser-based applications
Call 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.
Requests sent from a browser
A 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 in the TypeScript SDK guide.
Some organization and workspace settings block browser requests, even with that header. These settings include the following:
- Zero data retention (ZDR)
- A customer-managed encryption key attached to a workspace
No 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.
Both 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.
If 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.
Was this page helpful?