Set Up Claude Code, Cursor & Cline with a Custom Base URL (2026)
Why Use a Custom Base URL for Claude Tooling
Claude Code, Cursor, and Cline all speak the Anthropic SDK wire protocol. That means any provider that exposes an Anthropic-compatible endpoint — same /v1/messages path, same JSON schema — can be dropped in as a replacement for api.anthropic.com. The practical payoff: you can route your agentic coding sessions through a gateway that charges significantly less per token while still hitting the same Claude Sonnet 4.6, Haiku 4.5, or Opus 4.8 models.
This guide walks through the exact environment variables and config files each tool reads, plus a troubleshooting checklist for the common failure modes.
Understanding the Two Key Variables
All three tools ultimately resolve to the same two Anthropic SDK settings:
| Variable | Purpose | Default |
|---|---|---|
ANTHROPIC_BASE_URL | Root URL of the API host (no trailing slash) | https://api.anthropic.com |
ANTHROPIC_AUTH_TOKEN | Bearer token sent in x-api-key header | (your key) |
Some tools also accept ANTHROPIC_API_KEY as an alias for ANTHROPIC_AUTH_TOKEN. Set both if you are unsure which the installed version reads.
Setting Up Claude Code
Claude Code is Anthropic’s own terminal agent. It respects shell environment variables directly.
Shell export (per-session)
export ANTHROPIC_BASE_URL="https://api.aiprimetech.io/v1"
export ANTHROPIC_AUTH_TOKEN="sk-apt-xxxxxxxxxxxxxxxxxxxx"
claude
Persistent setup in ~/.bashrc or ~/.zshrc
# AI Prime Tech gateway — cheaper Claude API
export ANTHROPIC_BASE_URL="https://api.aiprimetech.io/v1"
export ANTHROPIC_AUTH_TOKEN="sk-apt-xxxxxxxxxxxxxxxxxxxx"
export ANTHROPIC_API_KEY="sk-apt-xxxxxxxxxxxxxxxxxxxx"
Reload with source ~/.bashrc, then run claude --version to confirm startup doesn’t error before your first session.
Verify the connection
claude -p "say hello in one sentence"
If you see a response, the base URL and key are wired correctly. If you get 401 Unauthorized, the token is wrong. If you get Connection refused or a DNS error, check the ANTHROPIC_BASE_URL value — no trailing slash, and it must end at the gateway root, not at /v1/messages.
Setting Up Cursor
Cursor embeds its own model picker but also respects a “custom OpenAI-compatible” endpoint under Settings → Models → Add Model. For the Anthropic path, Cursor reads the ANTHROPIC_API_KEY environment variable when it launches, and you can override the base URL through the app settings.
Option 1 — Environment variable (recommended for teams)
Set in your shell profile before launching Cursor:
export ANTHROPIC_API_KEY="sk-apt-xxxxxxxxxxxxxxxxxxxx"
export ANTHROPIC_BASE_URL="https://api.aiprimetech.io/v1"
Then launch Cursor from the same terminal session (cursor .) so it inherits the environment.
Option 2 — Cursor settings UI
- Open Cursor Settings (
Ctrl+Shift+J/Cmd+Shift+J) - Navigate to Models
- Under Anthropic API Key, paste your gateway key
- There is currently no first-class “Anthropic base URL” field in Cursor’s UI; for full control use the environment variable method
Option 3 — .cursor/mcp.json for MCP-routed requests
If you are using Cursor’s MCP integration, point the server URL at your gateway:
{
"mcpServers": {
"claude-gateway": {
"url": "https://api.aiprimetech.io/mcp",
"headers": {
"x-api-key": "sk-apt-xxxxxxxxxxxxxxxxxxxx"
}
}
}
}
Setting Up Cline
Cline (the VS Code extension) has a dedicated API Provider dropdown that includes “Anthropic” and an explicit “Base URL” field — making it the most straightforward of the three.
Steps
- Open VS Code and click the Cline icon in the sidebar
- Go to Settings (gear icon at the top of the Cline panel)
- Set API Provider to
Anthropic - Paste your key into API Key
- Expand Advanced Settings and set Base URL to
https://api.aiprimetech.io/v1 - Choose your model from the dropdown (e.g.
claude-sonnet-4-6,claude-haiku-4-5) - Click Save
Cline stores these in VS Code’s settings JSON. You can also edit settings.json directly:
{
"cline.apiProvider": "anthropic",
"cline.apiKey": "sk-apt-xxxxxxxxxxxxxxxxxxxx",
"cline.anthropicBaseUrl": "https://api.aiprimetech.io/v1",
"cline.apiModelId": "claude-sonnet-4-6"
}
Model IDs to Use
When a tool requires you to specify a model string, use the exact IDs the gateway advertises. For AI Prime Tech:
claude-opus-4-8
claude-sonnet-4-6
claude-haiku-4-5
fable-5 # 1M context window
gpt-5-5
gemini-3
Using an unrecognized model ID typically returns a 404 or an empty model list in the tool’s picker. If Cursor or Cline shows “model not found,” hard-code the ID string rather than relying on the auto-populated list.
Troubleshooting
401 Unauthorized
- The
x-api-keyheader value is wrong. Double-check your token has no leading/trailing whitespace. - Some gateways use
Authorization: Bearer <token>instead. The Anthropic SDK always sendsx-api-key; confirm your provider accepts it.
404 on /v1/messages
- Your
ANTHROPIC_BASE_URLlikely has a double/v1(e.g.https://api.example.io/v1/v1/messages). The SDK appends/v1/messagesautomatically — set the base URL to the root, not to/v1.
Streaming cuts off mid-response
- Some reverse proxies buffer SSE. Check whether the gateway has a streaming endpoint and that your proxy (if any) passes
X-Accel-Buffering: no.
Cursor ignores the env variable
- Cursor must be launched from a shell that has the variable set. Opening it from a dock icon or Spotlight on macOS will use the GUI environment, which does not inherit shell exports. Use
cursor .from a terminal, or set the variable in/etc/launchd.conf(macOS) or system environment variables (Windows).
Cline reverts to api.anthropic.com
- This usually happens after a Cline extension update that resets advanced settings. Re-enter the base URL after updates or pin the extension version.
Cost Comparison at a Glance
Running agentic coding sessions with Sonnet 4.6 is token-heavy — a typical multi-file refactor can burn 200k–500k tokens. At official Anthropic pricing that adds up fast. A third-party gateway like AI Prime Tech charges up to 80% less on the same models, with pay-as-you-go billing and no monthly commitment. For solo developers or small teams, the setup cost (five minutes of config) pays back within the first few hours of use.
Takeaway
All three tools — Claude Code, Cursor, and Cline — treat ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN / ANTHROPIC_API_KEY as first-class configuration. Set those two variables, verify with a quick test prompt, and your entire local AI coding stack routes through whichever endpoint you choose. The troubleshooting section above covers the four failure modes that account for nearly every reported issue.
One API key for Claude Opus 4.8, Sonnet 4.6, Haiku 4.5, Fable 5, plus GPT & Gemini — up to 80% off official pricing, pay-as-you-go.
Get Your API Key →