← Blog

Anthropic API Key Not Working? Here's the Fix

2026-10-01 · 5 min read · SubToAPI Team

If your Anthropic API key isn't working, it's almost always one of five things: a malformed request header, an expired or revoked key, a billing problem, a workspace/permissions mismatch, or you're mixing up keys from different environments. This guide walks through each cause in order of likelihood so you can find the fix in minutes instead of guessing.

The fastest way to diagnose this is to look at the actual error response, not just the fact that "it's not working." Anthropic's API returns a JSON body with an error.type field that tells you exactly what's wrong. Start there before trying random fixes.

Step 1: Check the Error Type, Not Just the Status Code

Run a minimal request and inspect the full response body:

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-3-5-sonnet-20241022",
    "max_tokens": 10,
    "messages": [{"role": "user", "content": "hi"}]
  }'

Common error types and what they mean:

A 401 with authentication_error is the classic "key not working" symptom. The rest of this guide focuses on fixing that.

Step 2: Verify You're Using the Right Header

A surprisingly common mistake is sending the key in the wrong header or format. Anthropic's native API expects:

x-api-key: sk-ant-api03-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
anthropic-version: 2023-06-01

Not Authorization: Bearer sk-ant-.... If you copy-pasted code from an OpenAI-style example, you may have the wrong header name entirely. Double check:

Step 3: Confirm the Key Hasn't Been Revoked or Rotated

Keys can stop working if:

Log into the Anthropic Console and check the key's status directly. If it shows as revoked or disabled, generate a new one — there's no way to "un-revoke" a leaked key.

Step 4: Check Billing and Account Status

Even a perfectly valid key will fail if the underlying account has no billing set up or has exceeded its credit balance. This shows up as a billing_error rather than authentication_error, but it's easy to misread as "the key doesn't work" since the request still fails.

Things to check:

If you've recently upgraded or added billing, it can take a few minutes to propagate — retry after a short wait before assuming something is broken.

Step 5: Make Sure You're Not Mixing Environments

If you work across multiple projects, it's easy to paste a key from workspace A into an app that's configured for workspace B, or to leave a stale key in a CI/CD secret store after rotating it locally. Checklist:

A quick way to isolate this: hardcode the key temporarily (never commit it) and run the curl command from Step 1 directly. If that works but your app still fails, the bug is in how your app loads environment variables, not the key itself.

Step 6: Rule Out Model Access Restrictions

Some organizations restrict which models are available to which API keys or workspaces. If your key authenticates fine (no authentication_error) but fails specifically when calling a particular model, you're likely looking at a permission_error or not_found_error tied to model access rather than a broken key. Check your organization's model access settings in the Console, or try a different model name to confirm.

If You're Building on Top of the API

If key management, rotation, and multi-environment headaches keep coming up, it's worth separating your application's API layer from your raw Anthropic credentials. SubToAPI sits in front of your Claude access and issues scoped application keys (sub_live_...) per app or environment, so a leaked or rotated key in one service doesn't take down everything else. You get usage metadata per key, team seats, and the same streaming and tool-use behavior you'd expect — see the quickstart or pricing for details. It won't fix an underlying Anthropic billing issue, but it does make it much easier to tell which app, environment, or team member a bad key belongs to.

questions

Why does my Anthropic API key suddenly stop working after it worked before? The most common causes are key rotation by a teammate, automatic revocation after the key was exposed publicly (e.g., in a GitHub commit), or the account running out of billing credit. Check the Console for the key's current status and your account's billing page first.

Why am I getting a 401 error even though I copied the key correctly? Usually it's the header, not the key. Anthropic requires x-api-key (not Authorization: Bearer), plus a valid anthropic-version header. Also check for trailing whitespace or newlines pasted in from your .env file.

How do I test if my Anthropic API key is valid without running my whole app? Run a minimal curl request directly against https://api.anthropic.com/v1/messages with just the key and a short prompt, as shown in Step 1. If that succeeds but your app still fails, the problem is in your app's configuration, not the key.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →