Developer guide

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.

A laptop displaying lines of code in a dark terminal window

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!"}]
      }'

    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.

    StatusError typeWhat it usually means
    401authentication_errorKey is missing, mistyped, has stray spaces/quotes, or was revoked. Re-copy it from the Console.
    403permission_errorKey is valid but lacks access to that resource or model.
    400invalid_request_errorMalformed request body, bad model name, missing header โ€” or a low credit balance on the account.
    404not_found_errorWrong endpoint URL or a model ID that doesn't exist.
    429rate_limit_errorKey works! You've just hit a rate limit. Wait and retry with backoff.
    529overloaded_errorKey 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]