Two clients, same relay, opposite conventions. This costs people an afternoon more often than any other setup issue, so here's the whole thing in one place.
Claude Code (Anthropic protocol) Codex / OpenAI-compatible
--- --- ---
Path the client calls `/v1/messages` `/v1/chat/completions`
Auth header `x-api-key` `Authorization: Bearer`
`base_url` should end with **nothing** (`https://host`) **`/v1`** (`https://host/v1`)
The client appends the path itself. Put /v1 in a base_url that already expects to append it and you get:
POST /v1/v1/messages -> 404
That's it. That's the bug.
Claude Code:
export ANTHROPIC_BASE_URL="https://your-relay.example"
export ANTHROPIC_AUTH_TOKEN="sk-..."
Codex / OpenAI-compatible:
export OPENAI_BASE_URL="https://your-relay.example/v1"
export OPENAI_API_KEY="sk-..."
If you switch clients often, generating these by hand is how typos get in. I wrote a small script that emits the right block per client and corrects the /v1 suffix automatically — it's on PyPI as ttapi-relay-switch:
pip install ttapi-relay-switch
ttapi-relay-switch --client claude-code --base https://your-relay.example --key sk-...
# OpenAI shape
curl -s https://your-relay.example/v1/models -H "Authorization: Bearer $OPENAI_API_KEY" | head -c 200
# Anthropic shape
curl -s https://your-relay.example/v1/messages \
-H "x-api-key: $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"<model>","max_tokens":16,"messages":[{"role":"user","content":"ping"}]}'
If curl returns a model list / a message object, the relay path is fine and the problem is in client config. If curl also fails, it's the endpoint or the key.
*Setup docs and a benchmark script: kuku-momo.github.io/ai-relay.*