🎬 New — watch the 2-minute guide videos →
Documentation

Govern Claude Code with BharatRouter

← Cookbook

Run Claude Code on your Claude Max plan, but never hard-stop at the monthly limit — BharatRouter uses your subscription first and automatically spills overflow to the Anthropic API, while metering, budgeting and residency-checking every call.

Max-subscription overflow → Anthropic API Agents Intermediate 8 min

This puts the gateway in front of Claude Code itself — the other half of Use Claude through BharatRouter (which calls Claude as a model from your own code). Your developers keep using Claude Code unchanged, while every request it makes is metered in ₹, capped by per-key budgets, residency-checked and logged for the org.

The gateway serves the native Anthropic Messages API (/v1/messages), so Claude Code and the Anthropic SDK work against it as a drop-in. Point ANTHROPIC_BASE_URL at BharatRouter and carry your br-… key on a side header — Claude Code reserves Authorization for its own Anthropic session, so the gateway key rides x-br-api-key.

Never stop mid-task when you hit the Max limit

A Claude Max plan covers most day-to-day Claude Code work, but it has a monthly usage allowance. When you hit that limit, requests start failing and your session stops mid-task. BharatRouter fixes this: it uses your Max subscription first, and the moment Anthropic throttles it (HTTP 429) it automatically falls back to your Anthropic API key, billed per token — so work continues uninterrupted. Same idea as TrueFoundry's subscription-priority virtual model, but as one header on a gateway that also meters, budgets and residency-checks every call.

Point Claude Code at the gateway

Add this to ~/.claude/settings.json (or a project .claude/settings.json). The x-br-overflow: byok header turns on subscription-first overflow:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.bharatrouter.com",
    "ANTHROPIC_CUSTOM_HEADERS": "x-br-api-key: br-...\nx-br-overflow: byok",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-8",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5"
  }
}

Model ids must contain a recognisable Anthropic id (claude-opus-4-8, claude-sonnet-4-6, claude-haiku-4-5) — Claude Code string-matches the id to detect each model's capabilities.

How the overflow works

Overflow needs both credentials present. (1) Sign into Claude Code with your Max plan as usual — Claude Code sends that session on Authorization, which the gateway forwards. (2) Save your org's Anthropic API key once under BYOK for the spillover. With x-br-overflow: byok set, the gateway tries the Max session first (free at the margin) and only injects the metered BYOK key when the subscription returns a 429:

curl -X PUT https://api.bharatrouter.com/me/byok/anthropic \
  -H "Authorization: Bearer br-..." \
  -d '{"key": "sk-ant-...", "label": "claude-code"}'

Overflow calls report x-br-upstream-mode: byok-overflow and meter like any BYOK call, so the spillover spend is attributed and capped by the key's ₹ budget. Without a saved BYOK key there is nothing to spill to — the 429 passes through to Claude Code as normal.

The three credential modes

1 · BYOK-inject — metered + budgeted. Save your org's Anthropic key under BYOK and don't forward a Max session. The gateway injects the key upstream; Claude Code needs only the br-… key. Every call is metered to the org and capped by the key's ₹ budget. This is the precedence when x-br-overflow is not set.

2 · Subscription passthrough — governed, not metered. Save no key — sign into Claude Code with Max. The gateway forwards the session untouched and Anthropic bills your subscription. You still get routing, logging and residency gates, but a subscription isn't token-priced, so ₹ spend isn't metered — and it hard-stops at the Max limit (use overflow to avoid that).

3 · Overflow — subscription first, BYOK on spillover. Both credentials present and x-br-overflow: byok set — the headline mode above. Max first, metered API on 429, work never stops.

Residency & budgets

Claude is a global (US) model. A Claude Code call leaves India — it can't satisfy india_only. To hard-block offshore on this surface, add x-br-data-policy: india_only to ANTHROPIC_CUSTOM_HEADERS — the gateway returns 403 instead of forwarding. Per-key ₹ budgets and daily limits apply to BYOK-inject and overflow calls automatically.

Every response carries x-br-provider: anthropic and x-br-upstream-mode (byok, passthrough or byok-overflow), and each call lands in the org's usage feed — see Activity.

Calling Claude as a model from your own app instead? Use the OpenAI-shaped recipe. Exposing BR models as tools to an agent? See MCP.

More recipes in the Cookbook, or see the full API reference.