Every coding agent worth using can talk to an endpoint other than its vendor's default. Almost none of them make it obvious how. The variable names are inconsistent, the precedence rules are undocumented, and the error you get when it's wrong is usually a bare 401 that tells you nothing. This page is the exact configuration for each tool.
An OpenAI-compatible endpoint expects requests at a path ending in /v1. An Anthropic-compatible endpoint expects /v1/messages. Nearly every tool below wants the BASE, not the full path — and the single most common mistake is including or omitting /v1 in the wrong place.
If your base URL already ends in /v1 and the tool appends /v1/chat/completions, you have just requested /v1/v1/chat/completions. That returns a 404, which most people misread as 'the model doesn't exist'. Check the doubled path before you change anything else.
Anthropic-compatible. Uses ANTHROPIC_ prefixed variables.
Claude Code reads its endpoint from ANTHROPIC_BASE_URL and its credential from ANTHROPIC_AUTH_TOKEN. The token variable matters: ANTHROPIC_API_KEY is the vendor-key variable, and when you are pointing at a third-party gateway the auth token variable is the one that carries a non-Anthropic credential.
Environment variables
# The base — no trailing slash, no /v1/messages suffix export ANTHROPIC_BASE_URL="https://your-endpoint.example/v1" # The credential your gateway issued you (NOT your Anthropic key) export ANTHROPIC_AUTH_TOKEN="your-gateway-token" # Optional: pin the model id your gateway actually serves export ANTHROPIC_MODEL="the-exact-model-id" # Verify the process really sees them env | grep ANTHROPIC_
A 404 that names the model — even though /v1/models on your gateway lists it — is usually not a gateway problem. Claude Code validates model ids against Anthropic's own model list before sending anything: a third-party id fails that check client-side and the request never reaches your endpoint.
The fix is to route the id through an alias slot instead of the raw model field. Set ANTHROPIC_DEFAULT_SONNET_MODEL (or the OPUS/HAIKU variants) to your gateway's exact id, and select "sonnet" rather than the raw id. Claude Code resolves the alias to whatever you mapped, skipping the built-in list. Setting ANTHROPIC_CUSTOM_MODEL_OPTION does not do this — it only adds an entry to the /model picker.
Model id rejected with 404 (custom/gateway models)
# Map a gateway id into an alias slot instead of ANTHROPIC_MODEL export ANTHROPIC_DEFAULT_SONNET_MODEL="your-gateway-model-id" # then pick "sonnet" in /model or settings — not the raw id # Confirm what the gateway really serves before mapping: curl -s "$ANTHROPIC_BASE_URL/v1/models" | python3 -m json.tool | grep '"id"'
Cline, Aider, Continue.dev, Roo Code and similar. Same shape, different spelling.
These tools all speak the OpenAI chat-completions wire format, so any OpenAI-compatible endpoint works. What differs is only where you put the base URL and what the field is called.
Aider — environment variables or .aider.conf.yml
# Env var form export OPENAI_API_BASE="https://your-endpoint.example/v1" export OPENAI_API_KEY="your-gateway-token" aider --model your-model-id # Or persist it in .aider.conf.yml in your project root: # openai-api-base: https://your-endpoint.example/v1 # openai-api-key: your-gateway-token # model: your-model-id
Cline / Roo Code — VS Code settings UI
Provider: OpenAI Compatible Base URL: https://your-endpoint.example/v1 API Key: your-gateway-token Model ID: the-exact-model-id-your-endpoint-serves The Model ID field is free text, not a dropdown. Nothing validates it until the first request fails, so a typo here surfaces as a 404.
Continue.dev — config.json provider block
{
"models": [
{
"title": "Custom endpoint",
"provider": "openai",
"model": "the-exact-model-id",
"apiBase": "https://your-endpoint.example/v1",
"apiKey": "your-gateway-token"
}
]
}Take the tool out of the loop. If curl fails, the tool was never the problem.
Two commands that isolate the fault
# 1. Does the endpoint accept your credential and list models?
curl -s https://your-endpoint.example/v1/models \
-H "Authorization: Bearer $YOUR_TOKEN" | head -40
# 2. Does it actually complete with the model id you configured?
curl -s https://your-endpoint.example/v1/chat/completions \
-H "Authorization: Bearer $YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"model":"the-exact-model-id",
"messages":[{"role":"user","content":"reply with OK"}],
"max_tokens":5}'Command 1 succeeding and command 2 failing means your credential is fine and your model id is wrong — compare it character by character against the ids command 1 returned. Both failing with 401 means it is the credential or the header. Both failing with 404 means it is the base URL path, most likely the doubled /v1.
| What you see | What it almost always is |
|---|---|
| 401 with a valid-looking key | Wrong variable. A gateway token in ANTHROPIC_API_KEY instead of ANTHROPIC_AUTH_TOKEN, or a stale export in the running shell. |
| 404 on every request | Doubled path — base URL ends in /v1 and the client appends /v1 again. |
| 404 'model not found' | Auth succeeded; the model id is not served by this endpoint. List models and copy the id exactly. |
| Connection refused | Nothing is listening. Wrong port, wrong host, or a local gateway that isn't running. |
| Works in curl, fails in the agent | The agent process does not see your env vars. Restart it from the shell where you exported them. |
| A different model answers than configured | A fallback chain silently replaced it. See the wrong-model page. |
Every configuration above needs a real base URL and token to be worth anything. AgentRouter documents setup for 15 tools — Claude Code, Codex, Cline, Aider, Continue.dev, OpenCode, Hermes, Cursor and more — and gets the surface distinction right, which is the thing that trips people up: https://agentrouter.org for Anthropic-compatible clients, https://agentrouter.org/v1 for OpenAI-compatible ones. Its own docs warn against mixing the two, which is exactly the /v1 mistake this page opened with.
Set up your tool →Referral link — we may earn a reward if you sign up, at no extra cost to you. This is the same advice we would give with no link at all. Check their current pricing and model list on their own site; we deliberately do not restate numbers that change.
The Setup Doctor walks through your tool, symptom, and setup and points at the likely cause — no account needed.