AI APIs
How do you get a Claude API key, and keep it safe?
How to create an Anthropic API key in the Claude Console, add credits, use it from your server, and protect it from leaking into browsers and repositories.
To get a Claude API key, sign in to the Claude Console at platform.claude.com, add billing or credits, open the API keys page and create a key, which is shown only once. Store it as an environment variable on your server and send it in the x-api-key header. Never put it in frontend code, and set a workspace spend limit.
Published · Last updated
Creating the key
- Sign in to the Claude Console, Anthropic's developer platform, at platform.claude.com.
- Add a payment method or buy credits. API usage is billed separately from Claude.ai subscriptions such as Pro or Max.
- Go to API keys and create a key, ideally in a workspace for this project.
- Copy it immediately. The full key is shown only once.
Using it from your server
This example uses a reserved domain. Replace the host and model with the current endpoint and model ID from the provider's documentation before running it.
curl https://api.claude.example/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-sonnet-5-5", "max_tokens": 512, "messages": [{"role": "user", "content": "Hello"}]}'The official SDKs read ANTHROPIC_API_KEY from the environment automatically. Check the models page in the documentation for current model names before choosing one.
Keeping it safe
- Store it in server-side environment variables only. Call the API from an API route or serverless function, not from the browser.
- Use separate keys for development and production, and separate workspaces for separate projects.
- Set workspace spend limits in the Console, so a leaked key or a runaway loop cannot run up an unlimited bill.
- Rate limit your own endpoints that call Claude, per user and per IP.
- Revoke and replace any key that appears in a repository, screenshot or chat.
A Claude-powered feature with no rate limit and no spend limit is the most expensive kind of bug. Set both before launch.
Common errors
- 401 authentication error: the key is missing, mistyped, revoked or sent in the wrong header.
- 400 with a credit balance message: the account has no credits left.
- 429 rate limit: your usage tier's limit was reached. Retry with backoff and check your tier.
- 529 overloaded: the API is temporarily under heavy load. Retry later.
In AI app builders
Tools such as Lovable, Bolt and v0 can connect to the Claude API. Use their secrets or environment settings for the key, and make sure the call runs in a backend function. If the generated code calls api.anthropic.com from the browser, the key is exposed.
What a scan can and cannot tell you
WebAuditOS does not currently detect API keys inside your JavaScript. It checks related exposure on your site, such as wide-open CORS, HTML error pages with recognizable debug output, and directory listings.
Search your built frontend for the key prefix before launch, and watch usage in the Claude Console.
If usage appears that you cannot explain, revoke the key first and investigate second.
Short answers
Is the Claude API free? No. It is billed per token, separately from Claude.ai plans.
Does Claude Pro include API access? No. The API has its own billing in the Claude Console.
Where do I find my existing key? You cannot view it again. Create a new one and revoke the old one if lost.
Can I use the key in a mobile app? Not directly. Route calls through your own backend.
In the product
The checks this maps to
Every check named here runs on every scan, on every plan - what a plan changes is how many pages are crawled, how long the history is kept and what you can do with the result. These are the ids the findings carry, so you can match a line in a report to the explanation above.
- sec.cors.wildcard - CORS is not wide open
- sec.error-disclosure - Error pages do not leak stack traces
- sec.directory-listing - No directory listing exposed
Read next
AI APIs
How much does the Claude API cost?
Claude API prices per model, checked in November 2026, how batch processing and prompt caching cut costs, and how to keep a Claude feature from overspending.
AI APIs
What is an API key, and how do you keep it secret?
An API key identifies your account to a service and often decides what you are billed. Where keys belong, how they leak, and what to do when one is exposed.