Fix 401, 403, 429 and 5xx Errors
Claude Code shows 401 Invalid API key or Auth conflict? Each error with its cause and a one-line fix: 403 expired key, 404 wrong base URL, 429 no balance, 5xx.
Concrete failure modes we see week-in, week-out. Symptom → cause → one-line fix.
All models, capabilities, and prices Documentation index for AI agents:https://oneprovider.dev/docs/llms.txt Before you start Run curl -s https://api.oneprovider.dev/v1/models -H "x-api-key: $ANTHROPIC_API_KEY". If it returns a non-empty JSON model list, your network reach and auth are fine — whatever you’re hitting is request-specific, not infrastructure. Top questions
Do I need to log into Claude Code? What about 401 and “Auth conflict”
No. The OneProvider key works without a Claude account. For Claude Code set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN (the key is sent as Authorization: Bearer). This variable takes precedence over a saved login and over the other variables, and needs no approval prompt. Our gateway also accepts ANTHROPIC_API_KEY (x-api-key header), but in interactive mode Claude Code asks you once to approve such a key and silently ignores a declined one (re-enable it under /config → Use custom API key).
If you see the login screen, 401 Invalid API key or Auth conflict, go step by step:
- Run
/status: it should show the OneProviderAnthropic base URLand anAuth tokenorAPI keyline naming your variable. ALogin methodline with a claude.ai account means the variable did not reach the session. Auth conflict(both a claude.ai login and a key): run/logout; your variables stay.401 Invalid API key: a foreignANTHROPIC_AUTH_TOKEN(a token from another service) overrides your key, or the value has a stray quote or space. Set it to the full OneProvider key, without quotes.- The login screen stays although the variables are in a project’s
.claude/settings.json: that block is read after first-run setup, so put the variables in your shell or in~/.claude/settings.json.
# macOS / Linux: what is actually set
env | grep -E 'ANTHROPIC_(BASE_URL|AUTH_TOKEN|API_KEY)' | sed -E 's/(sk-.{4}).*/\1.../'
grep -nE 'ANTHROPIC_(AUTH_TOKEN|API_KEY)' ~/.zshrc ~/.bashrc 2>/dev/null Do I need to log into ChatGPT for Codex CLI?
No. Codex works on the key alone when the oneprovider provider in ~/.codex/config.toml is active (env_key = "ONEPROVIDER_API_KEY"). A ChatGPT sign-in prompt or "You've hit your usage limit" means the provider is not active and the request went to ChatGPT.
Check in this order: the model_provider and model lines stand at the very top of the file, above any [table]; Codex is fully restarted and the task is new; the key is exported in the same terminal:
codex logout
export ONEPROVIDER_API_KEY="sk-..."
# quick test without editing the file:
codex -c model_provider=oneprovider Full walkthrough on the Codex (OpenAI) page.
Do I need a VPN? Any regional restrictions?
No VPN is needed — OneProvider has no regional restrictions. The endpoint api.oneprovider.dev is reachable worldwide and does not geoblock traffic.
Worse, VPN / VLESS proxies often break the API connection in two ways:
- SSE streaming is buffered inside the proxy — the stream gets cut off mid-token.
- HTTP/2 + ALPN negotiation breaks at relay hops — the client sees
connection reset.
If you’re seeing cut-off streams, connection reset, or random timeouts, disable the VPN / VLESS proxy and retry. We do not buffer streams on our side.
JSON parse error in config (or a 429)
The most common cause is “smart” quotes (“ ”) in your JSON config. They appear when you copy from a messenger, Notion, Google Docs, or a browser that auto-replaces ASCII quotes with typographic ones. JSON parsers only accept plain ASCII ".
Sometimes a broken config doesn’t surface as “JSON parse error” but as a 429: the client treats the missing answer as a rate limit. Same fix:
- Replace every
“”with"by hand. - Copy configs directly from this documentation — the quotes are already correct here.
- Validate with
cat -v config.jsonorjq . config.json— both flag the bad byte.
# Quick check: jq fails on the first smart quote
jq . ~/.claude/settings.json
# Auto-replace smart quotes with straight quotes
sed -i.bak $'s/[\u201c\u201d]/"/g' ~/.claude/settings.json Symptom matrix
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 authentication_error on every request | Key is unset, malformed, or has a stray newline / quote from a copy-paste. | echo "${ANTHROPIC_API_KEY:?missing}" | wc -c # expect 68 (sk- + 64 hex + newline) |
| 429 'Insufficient balance on this API key' | The key has no balance left. Retries will not help: the response has x-should-retry: false. | curl -sH "Authorization: Bearer $ANTHROPIC_API_KEY" https://api.oneprovider.dev/v1/dashboard/balance # then top up your cabinet (bot or app.oneprovider.dev) |
| 403 permission_error 'API key expired' | The key is past its expiry date. | Renew the key or issue a new one in your cabinet (Keys page). |
| 404 'The requested API endpoint does not exist' | Wrong base URL: /v1 is missing or doubled (/v1/v1). | OpenAI clients: https://api.oneprovider.dev/v1. Claude Code and Anthropic SDKs: https://api.oneprovider.dev (no /v1). |
| 429 rate_limit_error in spikes | Too many requests in a short time. | Respect Retry-After and retry with a growing pause. Lower parallel requests. |
| 400 'The requested model is not available' or 'Model X is not available on this API key' | The model ID is misspelled or outdated (for example claude-3-5-sonnet), or your key's plan does not include this model. | Pick a model from GET /v1/models or the table on /docs/api/models. |
| Empty answer, or the text stops after a few words | max_tokens is too small. Thinking counts against it too, so the reply can end before any text: stop_reason is max_tokens (finish_reason is length and content is null on /v1/chat/completions). | Raise max_tokens (for example to 4096) or turn off extended thinking. Check stop_reason in the response. |
| A program says the key has a wrong format (it expects sk-ant- or sk-proj-), or it has no field for a base URL | The program checks the key prefix itself, or talks only to its vendor's servers. Our key starts with sk- and works only with our base URL. | Use the program's custom provider or OpenAI-compatible mode with the base URL https://api.oneprovider.dev/v1 (Anthropic-style clients: https://api.oneprovider.dev). A program without a base URL setting cannot use OneProvider: pick a client from the clients list in the docs. |
| 401 'API key is disabled' | The key was switched off in the cabinet, or the account is inactive. | Open the Keys page of your cabinet and switch the key on or issue a new one. If the key is on, message @Oneproviderhelpbot. |
| 502 or 503 'Service temporarily unavailable' on an image or video request | The image or video service for this model is busy for the moment. Nothing is wrong with your key or request. | Retry in a minute with the same request, or try another model from the pricing table. A video that did not finish is not charged. |
| 503 'Service temporarily unavailable; retry later' | A temporary failure on our side. Your key and request are fine. | Retry with a growing pause: 1 s, 2 s, 4 s, up to a minute. |
| 504 'Service timed out; retry later' on a non-streaming call | A long generation (big context + tools) did not start answering within 6 minutes, or ran past 10 minutes. | Pass stream:true: a stream starts answering right away. If one answer needs more than 10 minutes, split the task. |
| Tool call replaced with prose ('I would have called X...') | Client sent tool_choice:{any|tool} → the API rewrote it to auto + hint; model didn't take the hint. | Tighten the user prompt ("Use the X tool to do Y"), or switch to a stronger model. |
| OPENAI_API_KEY is overriding my OneProvider key | An old export in your shell rc (~/.zshrc, ~/.bashrc) shadows the new value. | unset OPENAI_API_KEY in this shell, then grep -nE 'OPENAI_API_KEY' ~/.zshrc and clean it up. |
| Codex asks to sign in with ChatGPT or says 'You've hit your usage limit' | The oneprovider provider is not active: the request went to ChatGPT, not to us. | model_provider = "oneprovider" at the very top of ~/.codex/config.toml (above any [table]), the key in ONEPROVIDER_API_KEY, a new local task. See /docs/clients/codex. |
| Cursor / Claude Code: streaming response gets cut off mid-token | Almost always a client-side network proxy or VPN buffering SSE chunks. | Disable the proxy/VPN and retry. We send chunks as soon as they are ready, with no buffering. |
Diagnostic one-liners
If the symptom matrix didn’t hit your case, capture these three pieces of evidence:
bash# 1. Confirm reach + auth
curl -sS -o /dev/null -w "HTTP %{http_code} total %{time_total}s\n" \
https://api.oneprovider.dev/v1/models -H "x-api-key: $ANTHROPIC_API_KEY"
# 2. Reproduce the failing call with -v (verbose headers)
curl -sv https://api.oneprovider.dev/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":32,"messages":[{"role":"user","content":"hi"}]}'
# 3. Check your current balance (also shown in the cabinet: the @oneprovider_robot bot or app.oneprovider.dev)
curl -s https://api.oneprovider.dev/v1/dashboard/balance \
-H "Authorization: Bearer $ANTHROPIC_API_KEY" When to escalate
Send the three outputs above + the first 8 characters of your key + a UTC timestamp to @Oneproviderhelpbot . That’s enough for us to find your request in our logs within minutes. See Get support for what we don’t need (and never ask for).
Last updated: 2026-11-28 Found a bug? @Oneproviderhelpbot