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-haiku-5-5","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. But left alone, Claude Code starts on its default model, Claude Opus 5.5 with an API key according to its documentation, twice the price of Sonnet: choose your main model ("model" in step 5, or claude --model claude-sonnet-5-5) and pin the aliases to control what each one costs you:

Bash
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-5-5
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5-5

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-6-sol        # or deepseek-v4.1-flash, kimi-k3, qwen3.8-max

Cheaper background work

Keep the Haiku alias on a budget model: claude-haiku-5-5 at 0.22 credits per 1K input, or glm-5.3-flash at 0.18. And background tasks cost almost nothing, without touching the quality of your actual coding turns.

4. Cap the output size

Before each request, Tchavi sets aside enough credits to cover the longest answer the request allows, then refunds whatever is not used. Claude Code allows very long answers by default: on Claude Haiku 5.5 it asks for up to 128 000 output tokens, so every request sets aside about 141 credits, and about 2 816 on Claude Sonnet 5.5. If your balance is lower than that, every request is refused with a 402, even though a normal turn costs a few credits.

Set a cap and the amount set aside drops:

Bash
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=16000
ModelSet aside per request, defaultWith 16 000With 8 000
Claude Haiku 5.5about 141 creditsabout 18about 9
Claude Sonnet 5.5about 2 816about 352about 176
Claude Opus 5.5about 5 632about 704about 352

These figures cover the output part only, at today's rates; the input of the request is added on top. You are still charged only for the tokens actually produced. 16 000 is enough for normal coding turns; if Claude Code stops mid-answer with a message about the output limit, raise it.

On trial credits, or any balance under a few hundred credits, use Claude Haiku 5.5 or a budget model: a Sonnet or Opus request sets aside more than that even with the cap.

5. 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
{
  "model": "claude-sonnet-5-5",
  "env": {
    "ANTHROPIC_BASE_URL": "https://tchavi.com/api",
    "ANTHROPIC_AUTH_TOKEN": "sk-tch-your-key",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5",
    "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "16000"
  }
}

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.

6. 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-6-sol and deepseek-v4.1-flash do not, and you select those with ANTHROPIC_MODEL instead.

Prompt caching

Claude Code marks the stable part of the conversation as cacheable, and Tchavi passes those markers to Anthropic unchanged. On a Claude model, the part of each turn Anthropic serves from its cache is billed at the model's cache-read rate and the newly cached part at 1.25 × the input rate (see Credits). The usage block of each reply reports both counts (cache_read_input_tokens, cache_creation_input_tokens) and your usage log records them.

Only the default 5-minute cache is available. If you set CLAUDE_CODE_PROMPT_CACHE_TTL=1h, ENABLE_PROMPT_CACHING_1H=1 or the promptCacheTtl setting, Claude Code asks for the 1-hour cache and Tchavi refuses the request with a 400 naming cache_control.ttl: unset them. DISABLE_PROMPT_CACHING=1 turns caching off, and every turn is then billed as fresh input.

What does not carry over

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

  • Remote Control and voice dictation stop working. Both require a claude.ai identity, which a gateway credential replaces.
  • /fast reports disabled. Its availability check needs a claude.ai login or an Anthropic API key; with only ANTHROPIC_AUTH_TOKEN, Claude Code treats fast mode as disabled without running the check.
  • /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.

Next: OpenCode · Back to coding agents

On this page