Home → Help

Claude Code and Codex need different base URLs on the same gateway

Anthropic-style clients (Claude Code, the Anthropic SDK) append /v1/messages themselves, so their base URL must stop at the host. OpenAI-style clients (Codex, the OpenAI SDK, Cursor, Cline) do not append anything, so theirs must end in /v1.

What you are seeing

Why it happens

Two SDK lineages, two conventions, one gateway hostname. Neither client is wrong; they simply disagree about who owns the /v1 segment. Getting it backwards produces either /v1/v1/… or a path with no version at all.

The resulting 404 is unusually hard to debug because it often never reaches the API. A gateway that serves its website on the same domain answers unknown paths with the marketing page — HTTP 200, Content-Type: text/html. The client then tries to parse HTML as JSON and reports a syntax error pointing nowhere near the real cause.

It also means the failure leaves no trace on the provider side. Support will say they see no requests from your key, and they are telling the truth: the request was answered by a web server before it ever became an API call.

Confirm it is this

Ask for the content type rather than reading the body — one command settles it:

curl -s -o /dev/null -w '%{http_code} %{content_type}\n' \
  -X POST 'YOUR_BASE_URL/chat/completions' \
  -H 'Authorization: Bearer YOUR_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"model":"YOUR_MODEL","messages":[{"role":"user","content":"hi"}]}'

application/json means the URL is right — even a wrong key answers in JSON. text/html means you are talking to a website, and the base URL is the problem.

How to fix it

  1. Decide by SDK lineage, not by product nameAnything built on the Anthropic SDK wants the bare host; anything OpenAI-compatible wants /v1. New tools slot into one of the two without needing their own instructions.
  2. Drop the trailing slashSome clients join paths naively, and a base URL ending in / can produce a double slash that routes to the website instead of the API.
  3. Check the content type before checking the keyAn HTML response means the request never reached the API. Rotating keys at that point changes nothing and costs an afternoon.
  4. Use the provider's own examples verbatim firstGet one known-good configuration working, then change one thing at a time. Most setup failures are two mistakes at once.
ClientBase URL should be
Claude Codehost only — no /v1
Anthropic SDKhost only — it appends /v1/messages
Codexends with /v1
OpenAI SDK (Python, Node, Go)ends with /v1
Cursor, Cline, Roo Codeends with /v1
Cherry Studio, Chatbox, LobeChatends with /v1
On APICLAN: https://apiclan.us for Claude Code and the Anthropic SDK, https://apiclan.us/v1 for Codex and everything OpenAI-compatible. Copy-paste configs for each client are in the quickstart.

Related

Unexpected token '<' when calling an OpenAI-compatible API401 invalid API key — when the key looks right but still fails

Last checked 2026-10-01. Written from problems diagnosed on a live OpenAI-compatible gateway, not collected from other sites.