How to get a Claude API key (2026 guide)
Updated 2026-07-15
Create an account at console.anthropic.com, buy prepaid credits with a card, then generate a key under Settings and API Keys. If you cannot add a card, a prepaid gateway key arrives by email and works with the same code.
Quick answer: three steps to a Claude API key
To get a Claude API key from Anthropic: create an account at console.anthropic.com, buy prepaid credits under Plans and billing (a credit or debit card is required), then open Settings, go to API Keys, and click Create Key. The key starts with sk-ant- and is shown exactly once, so copy it into a password manager or an environment variable immediately. Two things trip people up. First, a Claude Pro or Max chat subscription does not include API access; the Console is a separate product with separate billing. Second, requests fail with a credit error until you have actually purchased credits, even though key creation itself works without payment. If your first call returns an error about your balance, that is the reason. If you cannot add a card, or you want one key that reaches Claude plus other model families, a prepaid gateway is the practical alternative. That route is covered at the end of this guide, with the trade-offs stated plainly.
Step 1: create an Anthropic Console account
The Console at console.anthropic.com is Anthropic's developer dashboard, and it is distinct from the claude.ai chat app. Sign up with an email address or a Google account. Anthropic asks you to verify a phone number during onboarding, and API access is limited to supported countries, so check Anthropic's availability list if the signup flow blocks you at this step. During setup you create an organization. Keys, credits, rate limits, and usage logs all belong to the organization rather than to your personal login. This matters later if you invite teammates: everyone shares the same credit pool, and admins can see usage broken down by key. Nothing costs money yet at this stage. You can browse the model list, read the API reference, and open the Workbench, a browser playground for testing prompts against Claude models, before adding any billing details. The Workbench is useful for checking that a prompt behaves the way you expect before you write a line of integration code.
Step 2: set up billing before your first request
Anthropic's API is prepaid. Under Plans and billing, add a card and buy an initial block of credits; the minimum purchase is small, historically five dollars. Every API call deducts from this balance at per-token rates, so there is no surprise invoice at the end of the month. When the balance hits zero, requests stop. Two settings are worth configuring on day one. Auto-reload tops the balance up automatically when it drops below a threshold you set. Enable it for production workloads so a drained balance never turns into an outage. Leave it off for experiments, so a runaway loop cannot spend more than you deliberately loaded. Rate limits scale with usage tiers. New organizations start at the lowest tier, and limits on requests per minute and tokens per minute rise as your cumulative spend grows. If you see 429 responses during a traffic burst on a young account, the tier system is usually the cause, not your code.
Step 3: create the key and make your first call
In the Console, open Settings, then API Keys, then Create Key. Give the key a name that identifies the app or environment it belongs to, because you will eventually have several and unnamed keys become impossible to audit. The full key value is displayed only at creation time; after you close the dialog, the Console shows only a truncated version. Export the key as an environment variable and test from the terminal before touching application code. Two Anthropic-specific details catch people migrating from other providers: authentication uses an x-api-key header rather than Authorization: Bearer, and every request must include an anthropic-version header. A missing version header fails with a clear error message, so read the response body when something breaks.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Say hello in five words."}]
}'Key security: five habits that prevent a bad week
These habits are cheap to adopt on day one and expensive to retrofit after an incident. If you do commit a key by accident, treat it as leaked even in a private repository: revoke it, rotate, and scrub the commit history. Secret scanners like gitleaks in a pre-commit hook catch the mistake before it leaves your machine.
- Environment variables or a secrets manager only. A key pasted into source code will eventually get committed, and scrapers watch public repositories for the sk-ant- prefix specifically.
- One key per app and per environment. Separate keys for development, staging, and production make usage logs readable and let you revoke one surface without breaking the others.
- Never ship a key in browser or mobile code. Anything in client-side JavaScript is public by definition. Route calls through your own backend and keep the key server-side.
- Revoke immediately on any suspected leak. Deleting a key in the Console kills it instantly; create the replacement key first if the app has to stay up during rotation.
- Set spend notifications. A billing alert threshold turns a leaked or looping key from a large bill into a small one, and it costs nothing to configure.
What a Claude call costs, with the cheaper seats nearby
Claude is billed per token, with separate input and output rates, and output tokens dominate the bill in long-form generation. Compare both columns, not just the headline input price. For scale, the table below lists Claude next to other models available through the gateway catalog described in the next section. DeepSeek is the approximate community favorite for high-volume budget traffic, and Claude remains the pick when prose quality is the priority.
| Model | Input / 1M tokens | Output / 1M tokens |
|---|---|---|
| claude-opus-4-7 | $4.00 | $20.00 |
| claude-sonnet-4-6 | $2.40 | $12.00 |
| gpt-5.5 | $4.00 | $24.00 |
| gemini-3.5-flash | $1.20 | $7.20 |
| glm-5 | $0.514 | $2.314 |
| deepseek-v4-pro | $0.3915 | $0.783 |
| deepseek-v4-flash | $0.126 | $0.252 |
No card? Get a working key through a gateway
If the card requirement, a region block, or the account setup itself is the obstacle, APIsRouter is the gateway route this site documents. It is an OpenAI-compatible gateway: the checkout at /topup requires no signup, you pay first, and the key arrives by email. Billing is pay-as-you-go with no subscription. Global models run 20% below official list pricing, Chinese models sit below their official rates, and your first top-up adds 100% to the balance. Point any OpenAI SDK at https://api.apisrouter.com/v1 and pass a catalog model ID: claude-sonnet-4-6 or claude-opus-4-7 for the Claude family, deepseek-v4-flash or glm-5 when you want cheaper tokens from the same key. The same key also works in end-user apps. SillyTavern users paste the base URL ending at /v1 and the model list fills in automatically from /v1/models. JanitorAI needs the full endpoint https://api.apisrouter.com/v1/chat/completions plus a model name and the key. The trade-off versus a direct Anthropic key is honest and simple: you are trusting an intermediary with your traffic, and Anthropic-side features arrive on the gateway's schedule. The upside is one balance and one endpoint across Claude, GPT, Gemini, DeepSeek, and GLM instead of a separate billing account per provider.
| Anthropic Console key | Gateway key | |
|---|---|---|
| Card required | Yes, credit or debit card | No, pay at checkout |
| Account setup | Console signup plus phone verification | None, key arrives by email |
| Billing model | Prepaid credits, optional auto-reload | Pay-as-you-go top-ups |
| Models covered | Claude family only | Claude, GPT, Gemini, DeepSeek, GLM, Kimi |
| API shape | Anthropic Messages API | OpenAI-compatible chat completions |
| Endpoint | https://api.anthropic.com/v1/messages | https://api.apisrouter.com/v1/chat/completions |
from openai import OpenAI
client = OpenAI(
api_key="sk-...", # arrives by email after checkout
base_url="https://api.apisrouter.com/v1",
)
response = client.chat.completions.create(
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(response.choices[0].message.content)FAQ
How do I get an Anthropic API key?
Create an account at console.anthropic.com, verify your phone number, buy prepaid credits under Plans and billing, then go to Settings, API Keys, Create Key. Copy the sk-ant- key immediately; it is shown only once.
Is the Claude API free to use?
No. There is no free API tier. The claude.ai chat app has a free plan, but API access is billed per token and requires purchased credits before requests succeed. A small prepaid top-up covers a surprising number of short test requests, so trying Claude costs cents, not dollars.
Can I use the Claude API without a credit card?
Not directly through Anthropic, which requires a card for credit purchases. The workaround is a prepaid gateway key: pay through a checkout that supports your payment method, receive a key by email, and call Claude models through an OpenAI-compatible endpoint.
Why is my Claude API key not working?
Four usual causes, in order of likelihood: no credits purchased yet (the key authenticates but requests are rejected), the wrong auth header (Anthropic expects x-api-key, not Authorization: Bearer), a missing anthropic-version header, or a mistyped model ID. The error body names the failing part, so read it before changing code.
Does a Claude Pro subscription include API access?
No. Claude Pro and Max cover the claude.ai apps only. The API is billed separately through the Console with prepaid credits, and neither balance transfers to the other.
Do Anthropic API keys expire?
No. Keys stay valid until you revoke them in the Console. That is exactly why per-app keys and periodic rotation matter: a forgotten key from an old side project keeps working until someone deletes it.