Working base_url + API key configurations for every major AI coding agent — Cline, Claude Code, Kilo Code, OpenCode, Aider, Codex, Cursor, Gemini CLI and more.
Every agent below supports pointing at a custom OpenAI-compatible or Anthropic-compatible endpoint. This repo collects the exact config file, the exact field, and the exact URL format for each one, plus the errors you hit when you get it wrong.
中文说明见 README.zh-CN.md
Every AI coding agent handles custom endpoints differently:
- Some want
https://host/v1, some wanthttps://hostwith no suffix - Some use
ANTHROPIC_BASE_URL, some useopenAiBaseUrl, some usebaseURLin a JSONC file - Some speak the OpenAI Chat Completions protocol, some speak the Anthropic Messages protocol, and mixing them up produces a 404 that looks like an auth problem
Getting this wrong costs an hour. The tables below are the answers.
| Agent | Config location | URL format | Protocol |
|---|---|---|---|
| Cline | Settings UI → API Configuration | https://host/v1 |
OpenAI |
| Kilo Code | Settings → Providers → Custom provider | https://host/v1 |
OpenAI |
| OpenCode | ~/.config/opencode/opencode.jsonc |
https://host/v1 |
OpenAI |
| Claude Code | ~/.claude/settings.json |
https://host (no /v1) |
Anthropic |
| Aider | CLI flags / .env |
https://host/v1 |
OpenAI |
| Codex CLI | ~/.codex/config.toml |
https://host/v1 |
OpenAI |
| Cursor | Settings → Models → Override base URL | https://host/v1 |
OpenAI |
| Gemini CLI | env vars | varies | Google / OpenAI shim |
| LiteLLM | api_base param |
https://host/v1 |
OpenAI |
| LangChain | base_url param |
https://host/v1 |
OpenAI |
The single most common mistake: using an OpenAI-format URL (
/v1) with an Anthropic-protocol client, or vice versa. See Protocol mismatch below.
Extension id: saoudrizwan.claude-dev
code --install-extension saoudrizwan.claude-dev
Open the Cline sidebar → gear icon → API Configuration:
| Field | Value |
|---|---|
| API Provider | OpenAI Compatible |
| Base URL | https://apimaster.ai/v1 |
| API Key | your key |
| Model ID | e.g. claude-sonnet-4-6, gpt-5.5 |
Click Done. Send a test message — the footer should read openai-compat:<model-id>.
Troubleshooting
| Symptom | Cause |
|---|---|
| 401 | Key has a trailing space, or was copied from the wrong console |
| 404 | Model ID doesn't exist on this endpoint — check the provider's model list |
| Ignores your settings | Provider not set to OpenAI Compatible, or you didn't click Done |
Full walkthrough: cline-openai-compatible-setup
Claude Code speaks the Anthropic Messages protocol, so the base URL is the site root with no /v1. This trips up almost everyone.
~/.claude/settings.json (macOS/Linux) or %userprofile%\.claude\settings.json (Windows):
{
"env": {
"ANTHROPIC_BASE_URL": "https://apimaster.ai",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
}
}Then:
claude /model claude-sonnet-4-6
Troubleshooting
| Symptom | Cause |
|---|---|
| Prompts you to log in to Anthropic | ANTHROPIC_BASE_URL is wrong, or has /v1 appended |
| 401 | Try ANTHROPIC_API_KEY instead of ANTHROPIC_AUTH_TOKEN — which one works is version-dependent |
| Unknown model | Model id not offered by your endpoint |
If your provider only speaks the OpenAI protocol, Claude Code can't talk to it directly. Use claude-code-router as a translation layer, and set api_base_url to the full endpoint path (https://host/v1/chat/completions) so CCR doesn't mis-join the path.
Full walkthrough: claude-code-custom-api-setup
Settings → Providers → Custom provider → + Connect:
| Field | Value |
|---|---|
| Provider ID | apimaster |
| Display name | APIMaster.ai |
| Base URL | https://apimaster.ai/v1 |
| API key | your key |
Leave Headers empty. On the next screen check the model ids you want, click Add N model(s), then Submit. The provider appears under Connected providers with a CUSTOM tag.
Full walkthrough: kilo-code-custom-provider-setup
UI path: gear icon → Providers → Custom provider → + Connect, same fields as Kilo Code.
For reasoning-effort tiers you need the config file. ~/.config/opencode/opencode.jsonc (Windows: C:\Users\<you>\.config\opencode\opencode.jsonc):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"apimaster": {
"npm": "@ai-sdk/openai-compatible",
"name": "APIMaster.ai",
"options": {
"baseURL": "https://apimaster.ai/v1"
},
"models": {
"claude-sonnet-4-6": { "name": "Claude Sonnet 4.6" },
"gpt-5.5": { "name": "GPT-5.5" }
}
}
}
}Two URL traps specific to OpenCode:
- Must include
/v1. OpenCode appends/chat/completionsitself. Without/v1you gethttps://host/chat/completions→ 404. - Don't use an
api.subdomain unless the provider documents one — it can fail at TLS.
Never put your API key in opencode.jsonc. Use /connect in the terminal or the Providers UI; the key belongs in OpenCode's auth store. Restart or start a new session after editing.
Full walkthrough: opencode-openai-compatible-setup
export OPENAI_API_BASE=https://apimaster.ai/v1 export OPENAI_API_KEY=YOUR_API_KEY aider --model openai/claude-sonnet-4-6
The openai/ prefix matters — it tells LiteLLM (which Aider uses internally) to route through the OpenAI-compatible path rather than trying to reach Anthropic directly.
~/.codex/config.toml:
model = "gpt-5.5" model_provider = "custom" [model_providers.custom] name = "custom" base_url = "https://apimaster.ai/v1" env_key = "CUSTOM_API_KEY"
export CUSTOM_API_KEY=YOUR_API_KEY
codexSettings → Models → enable Override OpenAI Base URL:
- Base URL:
https://apimaster.ai/v1 - API Key: your key
- Add your model id under Model Names, then click Verify
Note: Cursor's own agent features (Composer, Tab) route through Cursor's backend regardless of this setting. The override only affects direct chat model calls.
LiteLLM
import litellm response = litellm.completion( model="openai/claude-sonnet-4-6", api_key="YOUR_API_KEY", api_base="https://apimaster.ai/v1", messages=[{"role": "user", "content": "Hello!"}], ) print(response.choices[0].message.content)
LangChain
from langchain_openai import ChatOpenAI llm = ChatOpenAI( model="claude-sonnet-4-6", api_key="YOUR_API_KEY", base_url="https://apimaster.ai/v1", ) print(llm.invoke("Hello!").content)
Open WebUI
docker run -d \ -e OPENAI_API_KEY="YOUR_API_KEY" \ -e OPENAI_API_BASE_URL="https://apimaster.ai/v1" \ -p 3000:8080 \ ghcr.io/open-webui/open-webui
OpenAI Python SDK
from openai import OpenAI client = OpenAI( api_key="YOUR_API_KEY", base_url="https://apimaster.ai/v1", ) resp = client.chat.completions.create( model="claude-sonnet-4-6", messages=[{"role": "user", "content": "Hello!"}], ) print(resp.choices[0].message.content)
The two protocols are not interchangeable, and the error messages don't tell you which one you got wrong.
| OpenAI Chat Completions | Anthropic Messages | |
|---|---|---|
| Path | POST /v1/chat/completions |
POST /v1/messages |
| Base URL you configure | https://host/v1 |
https://host |
| Auth header | Authorization: Bearer sk-... |
x-api-key: sk-... |
| Used by | Cline, Kilo, OpenCode, Aider, Cursor, Codex | Claude Code |
Diagnosing: curl the endpoint directly first. If this works, the endpoint is fine and your client config is wrong:
curl https://apimaster.ai/v1/chat/completions \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"claude-sonnet-4-6","messages":[{"role":"user","content":"ok"}]}'
A 404 with a valid key almost always means a path-joining problem: your client appended a path segment that the base URL already contained, or vice versa.
If you're routing through any third-party endpoint — a gateway, a relay, an aggregator, your own proxy — the model id in your request is a label, not a guarantee. Worth checking:
- Response metadata. Compare the
modelfield in the response against what you asked for. - Token accounting. Tokenizer differences between model families show up in
usagecounts on identical inputs. - Behavioral fingerprinting. Model families have stable, distinguishable response patterns on targeted prompts. This is the most reliable method and the hardest to fake.
A free tester for this: APIMaster Model Tester — works against any OpenAI-compatible endpoint, not just APIMaster's.
Config for an agent that isn't here? Open a PR. Useful format:
- Agent name and version tested
- Exact config file path per OS
- Exact URL format including whether
/v1is required - One error you hit and what fixed it
Corrections to existing entries are just as welcome — these tools change fast and stale config is worse than none.
Examples use https://apimaster.ai/v1, an OpenAI-compatible endpoint that fronts multiple model providers with one key. Substitute your own — every config here works with any OpenAI-compatible endpoint, including a self-hosted new-api or LiteLLM proxy instance.
If you want to try the one in the examples: get a key · docs
MIT