How to use Claude Code with a cheaper API (ANTHROPIC_BASE_URL guide)

Updated June 10, 2026

Claude Code is the benchmark agent for autonomous coding — but the bill adds up fast, and since April 2026 you can no longer point third-party tools at a Claude subscription. The good news: Claude Code reads two environment variables, so you can route it through a cheaper, OpenAI/Anthropic-compatible gateway without changing how you work.

This guide shows how to use Claude Code with a cheaper API in under two minutes.

How it works

Claude Code talks to whatever endpoint ANTHROPIC_BASE_URL points to. By default that’s Anthropic. Point it at a unified gateway like nexinfer instead, and every request is routed to the same real models — just billed at a lower rate, with transparent multipliers and no prompt logging.

You are not changing the model or the tool. You are changing where the request goes.

Setup (2 steps)

1. Set the base URL and key

export ANTHROPIC_BASE_URL=https://api.nexinfer.com
export ANTHROPIC_AUTH_TOKEN=sk-nexinfer-xxxx   # your nexinfer key

Add these to your ~/.zshrc or ~/.bashrc to make them permanent.

2. Run Claude Code as usual

claude

That’s it. Streaming, tool calls, and the full context window work exactly as before — Claude Code doesn’t know the difference.

Verify it’s working

Run any prompt and check that responses come back normally. A trustworthy gateway will let you confirm:

  • Real model — the model you requested (e.g. claude-opus-4), never a quantized or substitute model dressed up as Claude.
  • Transparent billing — published input/output and cache multipliers, with real-time usage you can audit.
  • No logging — your prompts, code and key are not stored.

If a provider can’t show you those three things, treat it the way you’d treat cheap cloud credentials from a stranger.

Frequently asked questions

Does this break Claude Code’s features? No. Native Anthropic protocol means streaming, tool use and context all behave identically.

Is it the real Claude model? With nexinfer, yes — model substitution is exactly what we guarantee against. Always verify your provider does the same.

How much cheaper is it? Up to 40% below official list price on major models (verify current rates on the pricing section).

Can I switch back? Anytime — unset ANTHROPIC_BASE_URL and Claude Code goes straight back to Anthropic.

Try it in 2 minutes

Point your tool at nexinfer and get $3 in free credits — real models, transparent billing, zero logging.

Start free →