Running Claude Code against token-share
Claude Code speaks the Anthropic Messages API, which this gateway serves at /v1/messages. Point the base URL at it, pin the tier variables, and set the context to the id you chose.
Why it works without a plugin
Claude Code talks to the Anthropic Messages API. Every Claude id in this catalog is served on the same shape — POST /v1/messages, authenticated with x-api-key, versioned with anthropic-version: 2023-06-01 — so redirecting the CLI is a base URL change and not an integration.
That covers all twelve Claude ids here, from stable-claude-haiku-4-5 at $1/$5 official up to the Fable lanes at $10/$50. Whichever you point at, the wire protocol the CLI uses is unchanged.
The catch is that Claude Code does not run one model. It picks a tier per task, so an unpinned setup silently routes some work to a tier you did not choose. Pinning every tier variable to the same id is what makes the bill match the id you selected.
export TOKEN_SHARE_KEY="<your-pool-api-key>"
export ANTHROPIC_BASE_URL="https://token-share.app"
export ANTHROPIC_API_KEY="$TOKEN_SHARE_KEY"
# Pin every tier, or the CLI picks one per task class.
export ANTHROPIC_MODEL="claude-sonnet-5"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-sonnet-5"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-sonnet-5"
export CLAUDE_CODE_SUBAGENT_MODEL="claude-sonnet-5"
# Match the context of the id above: 1000000 here, 200000 for a 200K id.
export CLAUDE_CODE_MAX_CONTEXT_TOKENS="1000000"
export CLAUDE_CODE_ATTRIBUTION_HEADER=0
claudeSet the context to the id you picked
CLAUDE_CODE_MAX_CONTEXT_TOKENS tells the CLI how much room it may use before it compacts the session. It has to match the id, not exceed it: nine of the twelve Claude ids here carry 1,000,000 tokens, while claude-sonnet-4-6, stable-claude-sonnet-4-6 and stable-claude-haiku-4-5 are served at 200,000.
Set it above the id ceiling and the CLI will build a request the model cannot accept. Set it far below and it compacts earlier than it needs to, which costs you the summarisation round trips a large window was supposed to remove.
Output matters too, for the same reason. The 1M ids emit up to 128,000 tokens per response and the 200K ids up to 64,000, so a single very long file generation behaves differently depending on which id the tiers are pinned to.
Picking the id you pin to
Cost per token varies by an order of magnitude across the Claude family, and Claude Code is a heavy consumer of both directions. On the pool lane, claude-sonnet-5 bills at $0.30 input and $1.50 output per million; claude-opus-5, claude-opus-4-8 and claude-opus-4-6 bill at $0.50 and $2.50 — 1.67× on both.
The stable-* ids are the same weights on a dedicated lane served on our own key rather than the shared pool, at 0.4× instead of 0.1×. stable-claude-opus-5 works out to $2.00 and $10.00 per million, which is 4× the pool-lane Opus figure. They do not participate in pool failover.
There is no id that is correct for everyone here, because a Claude Code session’s cost is dominated by how you use it — how large the working set is, how often you compact, how much of the transcript repeats. Pin one id for a day of real work, read the usage, then repin and compare. That measurement is worth more than any ranking.
Check the endpoint before you check the CLI
When something misbehaves, the way to separate a gateway problem from a CLI problem is one curl against /v1/messages with the same key and the same model id. If curl answers and claude does not, the credentials and the route are fine and the issue is in the environment the CLI is reading.
The usual cause is a stale variable. ANTHROPIC_API_KEY or ANTHROPIC_BASE_URL left over in a shell profile, a settings file, or an editor’s integrated terminal will quietly win over the export you just typed.
If curl fails too, the response body says why — the error tells you whether the key was rejected, the model id was not recognised, or the request was malformed, and that is a different fix from anything in the CLI configuration.