Claude Code

Point Claude Code at Tchavi with two environment variables and run it on credits topped up by mobile money.

Part of the coding agents guides.

Claude Code speaks the Anthropic Messages API and nothing else — it cannot be pointed at an OpenAI-compatible endpoint. Tchavi therefore serves it a dedicated /v1/messages endpoint. Everything else — credits, rate limits, request logs — works exactly as it does for the rest of the API.

1. Set the variables

Bash
export ANTHROPIC_BASE_URL=https://tchavi.com/api
export ANTHROPIC_AUTH_TOKEN=sk-tch-your-key

Note the base URL stops at /api: Claude Code appends /v1/messages itself.

Use ANTHROPIC_AUTH_TOKEN, not ANTHROPIC_API_KEY. Both work — Tchavi reads the key from either the Authorization or the x-api-key header — but ANTHROPIC_API_KEY needs a one-time approval inside Claude Code before it takes effect, and it is the more common source of a session that silently keeps using your old login.

If you were already signed in to claude.ai, run /logout once so the two credentials stop competing.

2. Check it before opening the agent

One request tells you whether the URL and the key are right, which is much easier to read than a failure inside the agent:

Bash
curl -sS -w '\n%{http_code}\n' -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-4-6","max_tokens":16,"messages":[{"role":"user","content":"Say OK"}]}'

A body starting with {"id":"msg_ and ending in 200 means you are done. A 401 means the key did not arrive — check for a typo and that you exported it in the shell you are about to run claude in.

3. Choose your models

Claude Code's built-in model names are Anthropic's, and Tchavi carries those same names, so it works with no model configuration at all. Pin them explicitly to control what each alias costs you:

Bash
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-8
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5-20251001

ANTHROPIC_DEFAULT_HAIKU_MODEL is worth setting deliberately: it also runs the background work — session titles, summaries — that you never see but do pay for.

You are not limited to Claude. Any tool-capable chat model in the catalogue works, because Tchavi translates between the two formats for you:

Bash
export ANTHROPIC_MODEL=gpt-5.4          # or deepseek-v4-pro, kimi-k3, qwen3.8-max

Cheaper background work

Pointing the Haiku alias at a budget model — deepseek-v4-flash at 0.72 credits per 1K input, or glm-5.3-flash at 0.11 — cuts the cost of background tasks sharply without touching the quality of your actual coding turns.

4. Make it permanent

Shell exports last one terminal. To apply everywhere Claude Code runs, put them in the env block of ~/.claude/settings.json:

JSON
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://tchavi.com/api",
    "ANTHROPIC_AUTH_TOKEN": "sk-tch-your-key",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5-20251001"
  }
}

Use ~/.claude/settings.json (yours, all projects) or .claude/settings.local.json (one project, git-ignored). Never a project's .claude/settings.json — that file is committed, and your key would go with it.

5. Show Tchavi models in the picker

Claude Code can read the catalogue from Tchavi and add it to /model:

Bash
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1

It calls GET /v1/models at startup and keeps only entries whose id contains claude or anthropic. So the Claude models appear; gpt-5.4 and deepseek-v4-pro do not, and you select those with ANTHROPIC_MODEL instead.

What does not carry over

These are worth knowing before you decide, rather than discovering mid-task:

  • Prompt caching is not applied to Claude models. Claude Code marks parts of the conversation as cacheable; that marking is lost translating to and from the OpenAI shape, so a long session on a Claude model bills every turn as fresh input. On a big repository this is the difference that matters most. Point ANTHROPIC_MODEL at an OpenAI-backed model instead and caching does apply — the provider caches long prompts on its own, with no marker needed, and Tchavi bills those tokens at a tenth of the input rate (see Credits).
  • Remote Control and voice dictation stop working. Both require a claude.ai identity, which a gateway credential replaces.
  • /fast reports unavailable. Its availability check goes to Anthropic directly and does not follow your base URL.
  • /context is approximate. Tchavi answers the token-counting endpoint with a character-based estimate, not a real tokenizer. It is accurate enough to steer compaction; your bill uses the real counts the provider reports.

A handful of models cap the prompt they can be billed for — gemini-3.1-pro and grok-4.6 at 180,000 tokens, qwen3.7-flash at 230,000. Claude Code does not recognise Tchavi's refusal as a too-long error, so it will not compact and retry by itself. If you use one of those, tell it the ceiling:

Bash
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=180000

Claude models carry no such cap.


Next: OpenCode · Back to coding agents

On this page