Most "my API key doesn't work" problems are not key problems. They are base URL problems.
You paste a key into a client. You get a 404, or a 401 that makes no sense, or an HTML page where JSON should be. You rotate the key, then rotate it again. The key was fine the whole time. The client was building a different URL from the one you had in mind.
This post is about that gap. It uses an OpenAI-compatible API as the example, and a small open-source quickstart repo so you can reproduce everything yourself.
The three spellings
An OpenAI-compatible endpoint can show up in a client's settings in three forms:
-
https://api.relayrouter.app(the root domain) -
https://api.relayrouter.app/v1(root plus version) -
https://api.relayrouter.app/v1/chat/completions(the full path)
They are not interchangeable. Each one is correct for a different kind of client, and the wrong one fails in a way that looks unrelated to URLs.
Why they differ
It comes down to who appends what.
-
SDKs append the resource path. The official OpenAI SDKs take a
base_urland add/chat/completionsthemselves. Give them form 2. If you give them form 3, they request/v1/chat/completions/chat/completionsand you get a 404. -
Hand-written HTTP code appends nothing. If you call
fetchorrequests.postyourself, you decide the final URL. Form 3 is the one you want, or form 2 plus a string you add. -
Some desktop clients add
/v1for you. They ask for the root domain and build the rest. Give them form 2 and you may end up with/v1/v1/.... -
Some clients speak a different protocol on the same host. An Anthropic-style client wants the root domain, because it appends its own path (
/v1/messages).
So the rule is not "use the right URL". The rule is "find out what your client appends, and give it the part it does not".
The quickstart repo says the same thing in its README: try the three forms in order, and use the SDK samples' default of form 2 as the starting point. That is good advice, and the rest of this post makes it concrete.
Setup: one .env, three variables
The repo (relayrouter-api-quickstart) keeps its configuration in a .env file. The template has three variables:
RELAYROUTER_API_KEY=your_api_key_here
RELAYROUTER_BASE_URL=https://api.relayrouter.app/v1
RELAYROUTER_MODEL=your_model_name
Two habits worth copying from it:
-
The key lives in
.env, and.envis in.gitignore. The README is blunt about this: never commit your API key. - The model name is a placeholder you must replace. Both sample scripts refuse to run until you set a real, currently available model name. That is better than silently falling back to a default that may not exist next month.
You can get an account and a key from the registration page. (Disclosure: that link carries a referral code. The repo is also linked below without one in the code samples; use whichever you prefer.)
Test 1: the SDK (form 2)
Install the two packages the sample needs:
pip install openai python-dotenv
Then a minimal script, in the same shape as the repo's examples/python/chat.py:
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
api_key = os.getenv("RELAYROUTER_API_KEY")
base_url = os.getenv("RELAYROUTER_BASE_URL", "https://api.relayrouter.app/v1")
model = os.getenv("RELAYROUTER_MODEL")
if not api_key:
raise SystemExit("RELAYROUTER_API_KEY is not configured.")
if not model or model == "your_model_name":
raise SystemExit("Set RELAYROUTER_MODEL to a currently available model name.")
client = OpenAI(api_key=api_key, base_url=base_url)
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "Hello from RelayRouter."}],
)
print(response.choices[0].message.content)
The SDK adds /chat/completions on its own, so base_url ends at /v1.
Test 2: plain HTTP (form 3)
Now the same call with no SDK. Here you are the one building the URL, which makes the rule visible:
import "dotenv/config";
const apiKey = process.env.RELAYROUTER_API_KEY;
const baseUrl = process.env.RELAYROUTER_BASE_URL ?? "https://api.relayrouter.app/v1";
const model = process.env.RELAYROUTER_MODEL;
if (!apiKey) throw new Error("RELAYROUTER_API_KEY is not configured.");
if (!model || model === "your_model_name") {
throw new Error("Set RELAYROUTER_MODEL to a currently available model name.");
}
const res = await fetch(`${baseUrl}/chat/completions`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model,
messages: [{ role: "user", content: "Hello from RelayRouter." }],
}),
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}: ${await res.text()}`);
}
const data = await res.json();
console.log(data.choices?.[0]?.message?.content);
Run it with node chat.mjs (Node 18+ and the dotenv package). Notice the template string: ${baseUrl}/chat/completions. If your .env already holds the full form 3, this becomes a double path. The base URL and the code have to agree on who owns the suffix.
Also notice the error branch. It prints the status code and the response body. When a URL is wrong, the body is usually the fastest clue: a JSON error from the API means you reached it; an HTML page means you reached something else.
A 60-second triage table
When a client fails right after setup, check in this order:
| Symptom | Likely cause | Try |
|---|---|---|
404 with a path that repeats (.../chat/completions/chat/completions) |
Full path given to a client that appends its own | Drop to form 2 |
404 on /v1/v1/...
|
Version given to a client that adds /v1
|
Drop to form 1 |
| 404 with no repeated segment | Client expects the full path, got a shorter one | Move up to form 3 |
| 401 | Key is wrong, or sent in the wrong header for the protocol | Check the key; confirm the client's protocol setting |
| HTML in the response | You hit a web page, not the API host | Check the hostname, not just the path |
| "model not found" | Placeholder or retired model name | Set a current model name |
The first three rows are the ones people mistake for key problems.
Per-client notes
The repo also has setup guides for a few desktop clients. The settings follow the same logic:
- A client that lets you choose the protocol (for example "OpenAI Chat Completions") wants form 2, with a provider ID of your choosing.
- A client with separate tabs per protocol wants the root domain for an Anthropic-style tab and form 2 for an OpenAI-style tab.
Do not copy these blindly. The client versions change, and so do the fields. Use them as a starting point, then confirm with one request and the triage table above.
What I would do differently
If you maintain a tool that takes a base URL from users, you can save them this whole class of bug:
- Normalise on input. Strip a trailing
/chat/completionsand trailing slashes, then add the suffix yourself. - Show the final resolved URL in your settings screen or debug log.
- Fail with a message that names the URL you actually called.
One line in a log, POST https://.../v1/chat/completions -> 404, saves more time than any amount of documentation.
Try it
The samples above follow the quickstart repo, which also has Node and PowerShell versions plus short FAQ and troubleshooting docs:
- Repo: whale0yep-ai/relayrouter-api-quickstart
- Sign-up (referral link): relayrouter.app/register
Which of the three forms has bitten you most often, and was the client or the docs to blame? I would like to hear which tools are the worst offenders.











Top comments (0)