Claude Code: connect a cheap AI API
Claude Code talks to the native /v1/messages endpoint, so extended thinking and native tool_use arrive intact and prompt caching really bills as cache. Setup is two environment variables — no Anthropic account needed.
Claude Code
Official Anthropic CLI
Create an API key — Keys page → click Create key, name it (e.g. claude-code), copy the key. We won't show the plaintext again.
Install Node.js 18+ first (it bundles npm) — nodejs.org/download. Check with node -v. Then install Claude Code:
npm install -g @anthropic-ai/claude-codeCheck that it installed: claude --version.
On macOS / Linux — add env vars to your shell rc (~/.bashrc or ~/.zshrc) and reload (source ~/.zshrc):
export ANTHROPIC_BASE_URL="https://cheapai.io"
export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"On Windows PowerShell — set them for the current session:
$env:ANTHROPIC_BASE_URL = "https://cheapai.io"
$env:ANTHROPIC_AUTH_TOKEN = "YOUR_API_KEY"For a permanent setup add them via [System.Environment]::SetEnvironmentVariable(...) or System Properties → Environment Variables.
Alternative — per-project via .claude/settings.json (no global env needed):
{
"env": {
"ANTHROPIC_BASE_URL": "https://cheapai.io",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY"
}
}In the project folder run claude — and ask a simple question (e.g. «what files are here?»). If you see a response, the integration works.
claudeOptional — pin specific model versions. By default Claude Code uses the latest alias, which may resolve to a model not yet enabled on our gateway when Anthropic releases an update. Pin versions explicitly to control when your agent moves to a new model — set ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL:
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-6"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"Or add them to .claude/settings.json under env alongside ANTHROPIC_BASE_URL. Check the current catalog on the Models page — pin to an ID that actually exists.
Replace YOUR_API_KEY with a real key from the Keys section.
Claude Code — common questions
Why is the base URL without /v1?
The SDK appends /v1/messages itself. Set https://cheapai.io/v1 and you get https://cheapai.io/v1/v1/messages and an «Invalid URL» error. It's the single most common Claude Code setup mistake.
What if Claude Code drops the connection?
Run claude --debug — it shows the real error instead of a generic «API error». Drops 15-20 seconds after the first byte are usually timeouts: API_TIMEOUT_MS, CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS, CLAUDE_STREAM_IDLE_TIMEOUT_MS.
Can I pin specific model versions?
Yes — ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL. It saves you when Anthropic ships a new model that isn't on the gateway yet: the unversioned alias would resolve to a name that doesn't exist.
Get a key and plug it into Claude Code
Claude, GPT, Gemini and Grok on one key · pay in ₽, USDT or by card · no VPN
Get API keyGuides for other tools
See also: model prices · API reference and FAQ