Why Is My API Key Not Working? 7 Common Fixes
The Dreaded 401
You're mid-deploy and suddenly your app throws a 401 Unauthorized. The API key was fine yesterday. Here's how to diagnose and fix it — fast.
1. Key Is Actually Expired or Revoked
Symptoms: 401 on all endpoints, key was working previously.
Fix: Test the key directly:
- Use Api Key Chain for an instant validation
- Or curl the provider's models/user endpoint
If invalid, generate a new key from the provider dashboard and rotate immediately.
2. Wrong Key Type (Live vs Test)
Symptoms: Works in dev but not production, or vice versa.
Fix: Check your key prefix:
- Stripe:
sk_live_≠sk_test_ - OpenAI: Both start with
sk-, but created in different projects - Most providers: Test keys only work in test/sandbox environments
3. Billing or Quota Exceeded
Symptoms: 429 (Rate Limit) or 402 (Payment Required).
Fix:
- OpenAI: Check usage dashboard
- Anthropic: Check console billing. A 400 saying your credit balance is too low means the key is fine but the account has no credit. See the Anthropic (Claude) API key checker for every Claude error and its fix.
- Most providers: Add a payment method or upgrade your tier
4. Key Copied Incorrectly
Symptoms: Immediate failure with invalid format errors.
Fix:
- Make sure no leading/trailing whitespace
- Copy the full key — some are 100+ characters
- Watch for line breaks if copying from email or notes
- Use Api Key Chain's auto-trim feature
5. Wrong API Endpoint or Header Format
Symptoms: 401 even though the key works elsewhere.
Fix: Each provider expects a different header:
- OpenAI / Cohere / Mistral:
Authorization: Bearer KEY - Anthropic:
x-api-key: KEY - Gemini:
?key=KEYas query parameter - GitHub:
Authorization: Bearer KEY+Acceptheader
Api Key Chain handles all formats automatically.
6. IP Restriction or Region Block
Symptoms: Works from one location but not another.
Fix: Check your provider dashboard for:
- IP allowlists (Stripe, some enterprise tiers)
- Region restrictions (some providers geo-block)
7. CORS or Network Issues
Symptoms: Works in curl/Postman but not in browser.
Fix: Browser-to-provider requests may be blocked by CORS. Use:
- A server-side proxy (Vercel edge functions, Cloudflare Workers)
- Api Key Chain's built-in CORS handling
- A backend API route that proxies requests
Quick Diagnostic Checklist
| Check | How |
|---|---|
| Key valid? | Test on apikeychain.app |
| Right environment? | Compare prefix to provider docs |
| Billing OK? | Check provider dashboard |
| Correct header? | Match provider's API docs |
| CORS issue? | Try from terminal vs browser |
🛠️ Save time: Instead of debugging manually, paste your key into Api Key Chain. It auto-detects the provider, sends the correct request, and shows exactly what went wrong.
Related Posts
How to Share API Keys With Your Team Securely
Stop pasting API keys into chat. Share them through an encrypted folder where every person has their own login and PIN, and access can be removed in one click.
Get an Email When Your API Key Stops Working
API keys get revoked, expire or run out of credit without warning. Here is how to watch a key and get an email when it fails, and again when it works.
Never Miss an API Key Expiry Date Again
Many API keys and tokens expire on a fixed date. Record the date once and get reminder emails 30, 7 and 1 day before, and on the day it expires.