api.foo
api.foo / Docs / Get a Claude API key

How to Get a Claude API Key (2026): Step by Step, Costs, Limits and Common Errors

Updated
On this page

Short answer: sign in at platform.claude.com, add credits on the Billing page, then open Settings → API keys (platform.claude.com/settings/keys), click Create key, and copy the key right away. It starts with sk-ant- and is never shown again.

This page covers the full process: what a key costs, which type to create, a one-line test, the limits on a new account, and what each error means. The error messages below come from real responses from the Claude API, recorded on October 15, 2026.

API key vs Claude subscription

A Claude API key is for code: your scripts, apps and developer tools that call Claude directly. It's billed per token from prepaid credits in the Claude Console.

A Claude.ai subscription (Free, Pro, Max, Team) is for using Claude in the chat app, desktop app and Claude Code, with usage limits instead of per-token billing.

They're separate accounts and separate bills, with two exceptions worth knowing about (as of October 2026):

Plan API credits included
Free, Pro None
Max 5x / Max 20x $100 / $200 per month
Team Up to $500 per month, pooled

If you only want Claude Code, you don't need an API key. A Pro or Max subscription covers it. See Claude Code pricing.

Step 1: Create a Claude Console account

Go to platform.claude.com and sign up, or sign in with your existing Claude account. You'll get an organization (your account) with a default workspace.

The API is only offered in Anthropic's supported countries. Check that list first if you're outside the US or EU.

Step 2: Add credits

New accounts get a small amount of free credit for testing. For anything beyond that, open Settings → Billing (platform.claude.com/settings/billing), add a credit card, and buy credits. Usage is deducted from that balance as you go.

On the same page you can set a spend limit, a monthly ceiling you choose that sits below your tier's cap (see limits). Setting one before you hand a key to any tool is a good habit.

Step 3: Create the key

  1. Open API keys (platform.claude.com/settings/keys).
  2. Click Create key and give it a name you'll recognize later, like laptop-dev or ci-pipeline.
  3. Choose the key type:
    • Personal key: acts as you. Use it for your own development. It stops working if you leave the organization.
    • Service account key: belongs to a service account. Use it for CI, servers and agents that outlive any one person.
    • Workspace keys still exist but are legacy. Prefer the two above.
  4. Pick an expiration, and optionally scope the key to a workspace.
  5. Click create, then copy the key immediately. The Console shows the full secret only once.

If the Create key button is greyed out, your role in the organization doesn't allow creating keys. Ask an admin.

Step 4: Test it

Store the key in an environment variable, so it doesn't end up in your shell history or code:

export ANTHROPIC_API_KEY="sk-ant-api03-..."

Then send one small request:

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-haiku-5-5","max_tokens":50,"messages":[{"role":"user","content":"Say hello"}]}'

A working key returns a JSON message with Claude's reply in content and token counts in usage. With Claude Haiku 5.5 at $0.10 per million input tokens, the test costs a tiny fraction of a cent.

Here's what a bad key returns. We sent this request with a deliberately invalid key:

{"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"},"request_id":"req_011Cg2m…"}

What the API costs

You pay per million tokens (MTok), with separate rates for input and output. Official prices for the current models as of October 17, 2026:

Model Input Output Cache read
Claude Fable 5.1 $10 / MTok $50 / MTok $0.25 / MTok
Claude Opus 5.5 $4 / MTok $20 / MTok $0.20 / MTok
Claude Sonnet 5.5 $2 / MTok $10 / MTok $0.10 / MTok
Claude Haiku 5.5 (prompts up to 100K tokens) $0.10 / MTok $0.50 / MTok $0.01 / MTok

The Batch API halves these prices for jobs that can wait. For every model, caching and a worked cost example, see Claude API pricing.

Limits on a new account

Every organization sits in a usage tier that sets its rate limits and a monthly spend cap. You move up automatically as your account builds a payment history.

Tier Monthly spend cap
Start $500
Build $1,000
Scale $200,000
Custom Arranged with sales

Brand-new organizations may start in an Evaluation tier with lower limits while Anthropic builds trust in the account. You can see your tier and current limits at platform.claude.com/usage/limits, and ask for more with Request tier increase.

When you hit the monthly cap, requests fail with HTTP 429 until the first of next month (UTC), with a message like:

You have reached your API usage limits: your organization has crossed its monthly API usage threshold, set based on your organization's API tier.

Keep the key safe

  • Never put it in front-end code, mobile apps or a public repository. Anyone who has the key can spend your credits.
  • Use one key per app or machine, so you can revoke one without breaking the rest.
  • Set an expiration and a spend limit.
  • Rotate immediately if a key leaks: create a new one, update your app, delete the old one.

Use the key in your tools

  • SDKs (Python, TypeScript, Go, Java and others) read ANTHROPIC_API_KEY automatically.
  • Claude Code: set ANTHROPIC_API_KEY and start claude. It asks once whether to use the key, and after that usage is billed to your API account. See Install Claude Code.
  • Direct HTTP: send the key in the x-api-key header along with anthropic-version: 2023-06-01.

Common errors

HTTP status Error What it usually means
401 invalid x-api-key Wrong, revoked or expired key, or a stray space or newline when you pasted it
401 x-api-key header is required The request has no key. Check that your environment variable is actually set (echo $ANTHROPIC_API_KEY)
402 billing_error A problem with your billing or payment details. Check Billing in the Console
403 permission_error The key isn't allowed to use that resource, often a workspace or organization setting
404 not_found_error Wrong endpoint path or model ID
429 rate_limit_error Too many requests or tokens per minute, or you hit the monthly spend cap
529 overloaded_error Anthropic is temporarily overloaded. Retry with backoff

Every error response includes a request_id. Include it if you contact Anthropic support.

Can't get a key?

If the Console isn't available where you are, or you can't add a card it accepts, there are two common routes:

  • Cloud platforms: Claude models are sold through Amazon Bedrock and Google Cloud, billed to your cloud account.
  • API gateways: services that resell Claude access with their own keys and billing. api.foo, which publishes these docs, is one of them. Check how any gateway handles your data and billing before you use it. Our guide on choosing an API relay is currently available in Chinese.

FAQ

Is a Claude API key free?

Creating a key is free, but API usage is billed per token from prepaid credits. Anthropic gives new accounts a small amount of free credit for testing. After that, you buy credits on the Billing page of the Claude Console.

Does a Claude Pro or Max subscription include API access?

Not Pro. Claude.ai subscriptions and the API are billed separately. As of October 2026, Max plans include $100 (Max 5x) or $200 (Max 20x) of monthly API credits, and Team plans include up to $500 a month in pooled API credits. Pro includes none.

Where do I find my Claude API key?

Keys are listed at platform.claude.com/settings/keys, but the full secret is shown only once, when you create it. If you lost it, create a new key and delete the old one.

What does a Claude API key look like?

It starts with sk-ant-. Standard keys look like sk-ant-api03- followed by a long random string.

Can I use a Claude API key with Claude Code?

Yes. Set ANTHROPIC_API_KEY in your environment or in ~/.claude/settings.json. Claude Code asks you once to approve the key, then bills usage to your API account instead of a subscription.

Why does the API say "invalid x-api-key"?

The key is wrong, revoked or expired, or it has extra characters such as a trailing space or line break. Copy it again, or create a new key if you no longer have the original.

Found a mistake? Email [email protected].