Back to blog

Tools & integrationsGuide

How to connect Claude Code to CheapTokens

Run Claude Code on open-weight models through the CheapTokens Anthropic-compatible API with four environment variables — and what Anthropic does not support.

By CheapTokens TeamPublished 1 min read

Claude Code connected to the CheapTokens Anthropic-compatible API
On this page
  1. Before you start
  2. Step 1. Set the variables
  3. Step 2. Check that it works
  4. How to switch back

Claude Code reads its API address from ANTHROPIC_BASE_URL — the setting Anthropic documents for gateways. Point it at CheapTokens and name one of our models, and Claude Code sends its requests to our Anthropic-compatible API instead of Anthropic's. The variables follow the Claude Code documentation as of October 2026; the setup has not been run on a live installation yet.

Before you start#

  • Claude Code is installed.
  • You have a CheapTokens API key and a positive balance — see Your first API request.

Step 1. Set the variables#

bash
export ANTHROPIC_BASE_URL="https://api.cheaptokens.dev"
export ANTHROPIC_API_KEY="your-cheaptokens-key"
export ANTHROPIC_MODEL="deepseek-ai/DeepSeek-V4-Flash-0731"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-ai/DeepSeek-V4-Flash-0731"
  • ANTHROPIC_BASE_URL — the address without /v1: Claude Code adds the path itself.
  • ANTHROPIC_API_KEY — your CheapTokens key.
  • ANTHROPIC_MODEL — the model for the session.
  • ANTHROPIC_DEFAULT_HAIKU_MODEL — the model for small background tasks. Without it Claude Code would request a Claude model, which our API does not have.

Other model IDs: zai-org/GLM-5.3-Flash and MiniMaxAI/MiniMax-M2.7; see GLM vs DeepSeek vs MiniMax.

Step 2. Check that it works#

Start Claude Code in the same terminal and ask a short question about the project. An answer means the requests go through CheapTokens. If you get an error, look at its status code in Connection errors and fixes.

How to switch back#

Unset the variables (or open a new terminal without them) and start Claude Code again — it returns to its own login and endpoint.

bash
unset ANTHROPIC_BASE_URL ANTHROPIC_API_KEY ANTHROPIC_MODEL ANTHROPIC_DEFAULT_HAIKU_MODEL

Agents resend the whole conversation on every step, so input tokens make up most of the bill — see What an AI agent costs.