Get 6% back at Conifer with an ernd card
SectionsClaude Code

Gateway

Use Conifer Gateway as a Claude Code router

Two environment variables run Claude Code through the gateway, on any model in the catalog or on a router.

Conifer Gateway works as a router for Claude Code: one base URL, and Claude Code runs on any model in the catalog, or on Conifer Router choosing the model for each message. Claude Code speaks Anthropic’s Messages format, which the gateway serves for every model.

Set it up

  1. Get a key

    Create one on the console’s API keys page, as the quickstart shows, and keep it in a variable.

    terminal
    export CONIFER_API_KEY="sk-cg-…"
  2. Point Claude Code at the gateway

    Set the base URL, with nothing after it, and pass the key as Claude Code’s token. Put these two lines in your shell’s profile, after the key’s line from the step before, so every terminal has all three.

    terminal
    export ANTHROPIC_BASE_URL="https://gateway-api.conifer.build"
    export ANTHROPIC_AUTH_TOKEN="$CONIFER_API_KEY"
  3. Start it on a model

    Give Claude Code any model id from the catalog, from any maker, or a router’s name.

    terminal
    claude --model claude-haiku-5-5

Send every call through a router

Claude Code also makes calls of its own in the background, by the model names it keeps for them. Set all four of those names to a router, and every call of the session goes to it, a resumed session among them:

terminal
export ANTHROPIC_MODEL="custom-router-coding"
export ANTHROPIC_DEFAULT_OPUS_MODEL="custom-router-coding"
export ANTHROPIC_DEFAULT_SONNET_MODEL="custom-router-coding"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="custom-router-coding"
claude

Here custom-router-coding is a router saved in the console as coding; Routing says how to make one, and auto works the same way. The router chooses again for each message, and recognises the session by the id Claude Code sends. Each answer names the model that served it, and the console’s Logs page lists every request with its cost.

When the conversation is too long

When a conversation is longer than the model’s provider takes, the gateway answers 400 context_length_exceeded, with “prompt is too long: ” at the front of the message. That is the refusal Claude Code compacts on, so it shortens the conversation by itself and goes on. A routed request whose model refuses the length moves first to a model of its chain with a wider context.

What to check

  • The base URL has no /v1 on the end: Claude Code adds the path itself.
  • A 401 means the token didn’t reach Claude Code: check that ANTHROPIC_AUTH_TOKEN holds the key in the shell you started it from.
  • A 404 model_not_found means the id isn’t in the catalog: check it in the console’s Models section, or in the catalog.
  • A 402 means the workspace’s balance doesn’t cover the request: add funds (Billing).
  • The errors page has every other code.