Claude API Key Test
Got a fresh Anthropic API key and want to know if it actually works? Run a quick local sanity check, then fire off a one-line test request from your own terminal.
1. Local format check
This runs entirely in your browser. Nothing is sent anywhere โ no network calls, no storage. It only checks that your key looks right; it can't confirm the key is active.
๐ Tip: if you'd rather not paste a real key at all, try a dummy like sk-ant-api03-example to see how the checker works.
2. Live test from your machine
The real proof is a successful request. Run one of these from your own terminal โ your key stays on your computer.
Store the key as an environment variable
# macOS / Linux
export ANTHROPIC_API_KEY="sk-ant-..."
# Windows PowerShell
$env:ANTHROPIC_API_KEY="sk-ant-..."
Send a minimal 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-sonnet-4-5",
"max_tokens": 32,
"messages": [{"role": "user", "content": "Say: key works!"}]
}'
# pip install anthropic
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
msg = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=32,
messages=[{"role": "user", "content": "Say: key works!"}],
)
print(msg.content[0].text)
// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic(); // reads ANTHROPIC_API_KEY
const msg = await client.messages.create({
model: "claude-sonnet-4-5",
max_tokens: 32,
messages: [{ role: "user", content: "Say: key works!" }],
});
console.log(msg.content[0].text);
Read the result
A JSON response with "type": "message" and some text in content means your key is valid and has access. An "type": "error" response tells you what's wrong โ see the table below. Keeping max_tokens low makes the test cost a fraction of a cent.
3. Decoding common errors
If the test fails, the HTTP status and error type usually point straight at the fix.
| Status | Error type | What it usually means |
|---|---|---|
| 401 | authentication_error | Key is missing, mistyped, has stray spaces/quotes, or was revoked. Re-copy it from the Console. |
| 403 | permission_error | Key is valid but lacks access to that resource or model. |
| 400 | invalid_request_error | Malformed request body, bad model name, missing header โ or a low credit balance on the account. |
| 404 | not_found_error | Wrong endpoint URL or a model ID that doesn't exist. |
| 429 | rate_limit_error | Key works! You've just hit a rate limit. Wait and retry with backoff. |
| 529 | overloaded_error | Key works; the API is temporarily busy. Retry shortly. |
4. Keep your key safe
An API key is effectively a password tied to your billing. Treat it that way.
Never ship it to browsers
Keys in front-end JavaScript or mobile apps can be extracted by anyone. Call the API from a server you control.
Keep it out of git
Use environment variables or a secrets manager, and add .env to your .gitignore.
Rotate if exposed
If a key leaks, revoke it in the Anthropic Console immediately and create a new one.
Questions or stuck?
Spotted something out of date or have a suggestion for this guide? Drop a note. (Please don't email your actual API key!)
Email [email protected]