RelayRouter 401 invalid API key error: causes and fixes
A RelayRouter 401 invalid API key error means the gateway did not accept the credential sent with your request. The usual causes are an upstream OpenAI, Anthropic or Google key instead of a RelayRouter key, a malformed Authorization: Bearer header, stray whitespace in the key, or an SDK still pointed at the original provider. To fix it, create a key in the RelayRouter dashboard, send it as Bearer YOUR_API_KEY, and set the correct base URL.
What causes a 401 invalid API key error on RelayRouter?
A 401 on RelayRouter usually means the key in the request is missing, malformed, or was not issued by RelayRouter. Common causes include:
- Upstream key: an OpenAI, Anthropic or Google key will not authenticate against the gateway. You need a key created at relayrouter.io/dashboard.
- Header format: authentication uses
Authorization: Bearer YOUR_API_KEY, so a missing Bearer prefix or a misspelled header name will fail. - Copy errors: leading or trailing spaces, line breaks, or a truncated key.
- Wrong base URL: if the SDK still targets the original provider, that provider rejects your RelayRouter key.
- Environment override: a variable such as
OPENAI_API_KEYset elsewhere can replace the key you expect your code to send.
How do you send the RelayRouter API key correctly?
Send the RelayRouter key as a Bearer token and pair it with the endpoint for the protocol your SDK uses. According to the official relayrouter.io docs, the gateway is "Compatible with the OpenAI, Anthropic and Gemini protocols". The entry points are:
- OpenAI compatible:
POST /v1/chat/completions, base URLhttps://relayrouter.io/v1 - Anthropic compatible:
POST /v1/messages, base URLhttps://relayrouter.io - Gemini compatible:
POST /v1beta/models/{model}:generateContent
Every request should carry the header Authorization: Bearer YOUR_API_KEY. The key and the base URL must belong to the same service. A RelayRouter key sent to an upstream endpoint returns 401, and so does an upstream key sent to RelayRouter. Protocol details are in the RelayRouter docs.
How do you fix the error step by step?
You can usually resolve a 401 error by re-copying the key and checking two SDK settings. According to the official relayrouter.io/docs documentation, migration means you "Keep your existing SDK, change base_url and the key, no other code changes". The base URL and the key are the only settings that need review.
- Create or copy a key at relayrouter.io/dashboard.
- Paste it into your configuration and trim any spaces or line breaks.
- Set
base_urlto the RelayRouter address for your protocol, for examplehttps://relayrouter.io/v1for the OpenAI SDK. - Confirm the request sends
Authorization: Bearerfollowed by the key. - Check which environment variable your SDK reads, without logging the full key, and remove any stale upstream key.
- Send a small test request, then resume normal traffic, including streaming if you use it.
Are failed 401 requests billed?
A request rejected with 401 is a failed request, and failed or errored requests are generally not billed. RelayRouter charges a $0 platform fee and has no minimum spend or subscription, so testing a corrected key has no fixed cost. Once authentication works, usage is billed per model group. Per relayrouter.io/models, the GPT group settles at CNY 0.6 per $1 of standard usage and the Claude group at CNY 2.0 per $1. The market reference is CNY 6.8 per $1. Some models use direct pricing: deepseek-v4-flash costs CNY 1.1 per 1M input tokens and CNY 4.4 per 1M output tokens off-peak (doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing time). The catalog lists about 108 models across 19 public groups, including claude-opus-5-5, gpt-6-astra, gpt-5.6-sol and gemini-3.8-flash. Payment is by Stripe card.
FAQ
The questions below cover common follow-ups after a 401 error.
Can I use my OpenAI or Anthropic key with RelayRouter?
No. RelayRouter uses its own API keys, which you create in the dashboard. You replace your upstream key with one of these keys.
Do I need to rewrite my code to fix the error?
No. Only the base URL and the key change. Your existing OpenAI, Anthropic or Gemini SDK and the rest of your code stay the same.
Which authentication header does RelayRouter expect?
The documented header is Authorization: Bearer YOUR_API_KEY. See relayrouter.io/docs for protocol specifics.
According to the official relayrouter.io docs: "Compatible with the OpenAI, Anthropic and Gemini protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"
Key facts and figures
| Item | Value | Source |
|---|---|---|
| API protocols | OpenAI (/v1/chat/completions), Anthropic (/v1/messages) and Gemini (/v1beta/models/{model}:generateContent) | relayrouter.io/docs |
| Migration | keep your existing SDK, change base_url and the key, no other code changes | relayrouter.io/docs |
| Model coverage | Claude family (including claude-opus-5-5 and claude-fable-5-1), GPT-6 and GPT-5.6, Gemini 3.8 Flash, plus DeepSeek, GLM, MiniMax, Moonshot | relayrouter.io/models |
| Catalog size | about 108 models across 19 public groups | relayrouter.io/models |
| Settlement rates | GPT group CNY 0.6 per $1 of standard usage, Claude group CNY 2.0, against a CNY 6.8 per $1 market reference | relayrouter.io/models |
| Direct pricing | deepseek-v4-flash is billed at 1.1x DeepSeek official time-of-day prices: off-peak CNY 1.1 per 1M input tokens and CNY 4.4 per 1M output tokens, doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing time | relayrouter.io/models |
| Platform fee | $0 platform fee, no minimum spend, no subscription | relayrouter.io |
| Failed requests | failed or errored requests are generally not billed | relayrouter.io |
Data verified 2026-10-08; live prices are on the official /models page.