Jun 11, 2026 · 9 min · Dev Guides

Set Up Claude Code, Cursor & Cline with a Custom Base URL (2026)

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:

VariablePurposeDefault
ANTHROPIC_BASE_URLRoot URL of the API host (no trailing slash)https://api.anthropic.com
ANTHROPIC_AUTH_TOKENBearer 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

  1. Open Cursor Settings (Ctrl+Shift+J / Cmd+Shift+J)
  2. Navigate to Models
  3. Under Anthropic API Key, paste your gateway key
  4. 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

  1. Open VS Code and click the Cline icon in the sidebar
  2. Go to Settings (gear icon at the top of the Cline panel)
  3. Set API Provider to Anthropic
  4. Paste your key into API Key
  5. Expand Advanced Settings and set Base URL to https://api.aiprimetech.io/v1
  6. Choose your model from the dropdown (e.g. claude-sonnet-4-6, claude-haiku-4-5)
  7. 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

404 on /v1/messages

Streaming cuts off mid-response

Cursor ignores the env variable

Cline reverts to api.anthropic.com


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.

Get cheaper Claude API access

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 →
AI Prime Tech is an independent third-party API gateway. Claude™ and Anthropic® are trademarks of Anthropic, PBC. No affiliation or endorsement is implied.