Disclosure: I run ScaleMax, a prepaid API gateway that is option 3 below.

Claude Code is a terminal agent. It talks to whatever sits behind ANTHROPIC_BASE_URL using the Anthropic Messages API, so you have more billing choices than a monthly plan.

1. Anthropic's own API key (pay-as-you-go, Claude models)

If you want Claude models and you can pay by card in US dollars, this is the simplest option. You buy prepaid credit in the Anthropic Console, create a key, and Claude Code bills per token. Prompt caching is billed at the provider's cached rates, which matters a lot for an agent that resends the same context on every step.

2. A self-hosted gateway (LiteLLM and similar)

Run a proxy that speaks the Anthropic Messages API and routes to whichever providers you already pay for. You get full control and need one more service to operate. LiteLLM's docs have a Claude Code setup page.

3. A hosted Anthropic-compatible gateway

A hosted gateway gives you a key and a base URL and handles the routing. Use one when you want other model families in Claude Code, or a payment method the providers don't take.

With ScaleMax, for example:

export ANTHROPIC_BASE_URL="https://api.scalemax.pro" # no /v1, Claude Code adds it export ANTHROPIC_AUTH_TOKEN="YOUR_KEY" # sent as Authorization: Bearer export ANTHROPIC_MODEL="gpt-6.2-sol" # any ID your key includes export ANTHROPIC_DEFAULT_HAIKU_MODEL="gpt-6-luna" # cheap model for background work claude 

To keep it, put the same values in the env block of ~/.claude/settings.json.

Verify before a long session. A tiny request catches a wrong URL or key in seconds:

curl https://api.scalemax.pro/v1/messages \
-H "Authorization: Bearer YOUR_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"gpt-6-luna","max_tokens":16,"messages":[{"role":"user","content":"Reply with K"}]}'




What actually drives the bill

  • Context size per step. An agent turn often resends tens of thousands of tokens. Count them.
  • How cached input is billed. Option 1 bills cache reads at a discount. Gateways differ: some bill all input at the published input rate, others discount cache reads (ScaleMax bills cache reads below the input rate on models that support caching). Compare on your real workload, not the rate card.
  • The background model. Claude Code sends lightweight work to the "Haiku" slot. Pointing ANTHROPIC_DEFAULT_HAIKU_MODEL at a cheap model cuts cost without changing your main model.
  • Tool-use reliability. Non-Anthropic models differ in how well they follow Claude Code's tool protocol. Run a small task before a big refactor.

Quick decision

You want... Use
Claude models, USD card, first-party terms Anthropic API key
Full control, already paying several providers Self-hosted gateway
Other model families in Claude Code, one prepaid key, UPI or card Hosted gateway

I run ScaleMax. Setup guide: https://scalemax.pro/claude-code. Trial: $2 credit, no card.