⚡ New — Kimi K3 is live: bring your own Moonshot key →

← Blog

Kimi K3 in your coding agent — four ways through BharatRouter

Moonshot's Kimi K3 is a 2.8-trillion-parameter open MoE with a 1M-token context, native vision and always-on "thinking mode". It's live on BharatRouter as kimi-k3 — so you can drive it from whichever coding agent you already like. This post wires it into four of them (brcode, OpenCode, Claude Code, Codex CLI), plus the raw API, and compares what K3 costs across providers.

Kimi K3 in your coding agent — one BharatRouter key routes brcode, OpenCode, Claude Code and Codex to Moonshot's Kimi K3 (2.8T MoE, 1M context, always-on reasoning, native vision) via BYOK.

The one thing to set up first: your Moonshot key (BYOK)

On BharatRouter, kimi-k3 is BYOK-only — it serves on your Moonshot key, never a shared platform key. There are two ways to supply it, and which one you use decides everything below:

You'll also need a BharatRouter key (br-…) — new orgs get ₹100 credit. BYOK inference debits ₹0 from your BharatRouter balance; you pay Moonshot on your own key (more on cost below).

Warm-up: the raw API call

The one place you can pass the Moonshot key per-request. Everything else is the same OpenAI-shaped call you already know:

curl https://api.bharatrouter.com/v1/chat/completions \
  -H "Authorization: Bearer $BR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3",
    "upstream_key": "sk-…your-moonshot-key",
    "max_tokens": 800,
    "messages": [
      {"role": "user", "content": "Refactor this function to be pure. …"}
    ]
  }'

Two K3-specific notes that save you a confused five minutes:

Way 1 — brcode (BharatRouter Code)

brcode is our one-command coding agent. It defaults to GLM, but every harness it launches honours a single model setting — so pointing the whole thing at Kimi K3 is one line. (Live on production today.)

brew install bharatrouter/tap/brcode   # or: curl -fsSL https://bharatrouter.com/install/code.sh | bash
brcode login && brcode init            # zero-paste browser login, writes configs
brcode model kimi-k3                   # persists across every harness
brcode                                 # OpenCode front-end, now on Kimi K3
# …or the Claude-Code front-end, same key, same model:
brcode claude

Because kimi-k3 is BYOK, run this after saving your Moonshot key on the dashboard — otherwise brcode doctor will report the model won't route. Once the key is saved, brcode doctor shows a green tool-bearing route and you're coding. Switch back anytime with brcode model default.

Way 2 — OpenCode (Codex-style, direct)

Fastest path — one line. This installs OpenCode if you don't have it, writes the provider config below, defaults you to Kimi K3 and launches. Note the BR_KEY sits in front of bash, not curl — in VAR=x curl … | bash the variable is scoped to curl and the script never sees it:

curl -fsSL https://bharatrouter.com/install/kimi.sh | BR_KEY=br-… bash

The hosted script bakes in no key — yours travels only in your command. It needs your Moonshot BYOK key saved first (see above). And because it writes the br- key inline into the 0600 ~/.config/opencode/opencode.json, the desktop GUI works too, with none of the LaunchAgent setup below — the app reads the key straight from the config, so there's no shell-env 401.

Prefer to wire it by hand? Add BharatRouter as an OpenAI-compatible provider and name the model — drop this in ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "bharatrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "BharatRouter",
      "options": {
        "baseURL": "https://api.bharatrouter.com/v1",
        "apiKey": "{env:BHARATROUTER_API_KEY}"
      },
      "models": { "kimi-k3": { "name": "Kimi K3" } }
    }
  },
  "model": "bharatrouter/kimi-k3"
}
export BHARATROUTER_API_KEY="br-…"
opencode

The Moonshot key stays on the BharatRouter dashboard (BYOK) — it never touches your local config. Your machine only ever holds the br- key.

…and the OpenCode desktop app (GUI)

The OpenCode desktop app reads the same ~/.config/opencode/opencode.json — so the provider block above already points it at Kimi K3. If you used the one-line installer, you can skip the rest of this section — it writes the key inline, so the GUI already works. The gotcha below only applies to the hand-edited env-var config: apps launched from the Dock or Finder don't read your shell's ~/.zshrc, so {env:BHARATROUTER_API_KEY} resolves to nothing and the app returns 401. Two ways to fix it:

cat > ~/Library/LaunchAgents/com.bharatrouter.env.plist <<'PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0"><dict>
  <key>Label</key><string>com.bharatrouter.env</string>
  <key>RunAtLoad</key><true/>
  <key>ProgramArguments</key><array>
    <string>/bin/bash</string><string>-c</string>
    <string>. "$HOME/.config/bharatrouter/env"; launchctl setenv BHARATROUTER_API_KEY "$BHARATROUTER_API_KEY"</string>
  </array>
</dict></plist>
PLIST
launchctl load ~/Library/LaunchAgents/com.bharatrouter.env.plist
# then fully quit and relaunch OpenCode

Inside the app, pick BharatRouter › Kimi K3 from the model switcher and you're coding. (The cookbook recipe below ships this as launchagent.sh.)

One keyless command for either

Don't want to hand-edit JSON? The recipe's setup.sh does the whole thing and embeds no key — it asks for your BharatRouter key first, checks whether Kimi K3 already routes, only then asks for your Moonshot key (saving it server-side via BYOK), and writes a config that references the key by environment variable, never inline:

curl -fsSL https://raw.githubusercontent.com/bharatrouter/cookbook/main/recipes/13-kimi-k3-coding-agents/setup.sh | bash

Way 3 — Claude Code

Claude Code speaks the Anthropic Messages wire. BharatRouter translates that to Moonshot's OpenAI wire and back — streaming and thinking blocks included — so the real claude CLI drives Kimi K3 unchanged. Export the env and launch:

export ANTHROPIC_BASE_URL="https://api.bharatrouter.com"
export ANTHROPIC_API_KEY="br-…"
export ANTHROPIC_CUSTOM_HEADERS="x-br-api-key: br-…"
export ANTHROPIC_DEFAULT_OPUS_MODEL="kimi-k3"
export ANTHROPIC_DEFAULT_SONNET_MODEL="kimi-k3"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="kimi-k3"
claude

The same br- key goes in both ANTHROPIC_API_KEY and the x-br-api-key header (without the API-key slot filled, Claude Code refuses to start). Setting all three model tiers to kimi-k3 keeps the agent's background calls on K3 too. Requires the Moonshot BYOK key saved on the dashboard.

Way 4 — Codex CLI

Recent Codex CLI talks the OpenAI Responses API. BharatRouter serves a /v1/responses endpoint, so Codex points cleanly at the gateway. Add a provider to ~/.codex/config.toml:

model = "kimi-k3"
model_provider = "bharatrouter"

[model_providers.bharatrouter]
name = "BharatRouter"
base_url = "https://api.bharatrouter.com/v1"
wire_api = "responses"
env_key = "BHARATROUTER_API_KEY"
export BHARATROUTER_API_KEY="br-…"
codex

Codex reads the repo's AGENTS.md for project context, exactly as it does on its native backend — nothing to change there.

What does Kimi K3 cost — Moonshot vs OpenRouter vs everyone else?

K3 is new (launched 16 July 2026), and right now it has exactly one first-party host: Moonshot. Third-party GPU hosts haven't picked up the open weights yet — expect that to change over the coming weeks. Today's landscape, per million tokens:

ProviderInputOutput≈ INR (₹96/$)Notes
Moonshot direct
api.moonshot.ai
$3.00$15.00₹288 / ₹1,440 The only first-party host today. Offers context-cache discounts on repeated input — a real lever for coding agents that resend a big repo context.
OpenRouter
moonshotai/kimi-k3
$3.00$15.00₹288 / ₹1,440 A pass-through to Moonshot's single (int4, 1M-ctx) endpoint — same token price. OpenRouter's margin is the credit top-up fee, or ~5% if you BYOK your Moonshot key to it.
BharatRouter
kimi-k3 (BYOK)
$3.00$15.00₹288 / ₹1,440 Routes to Moonshot on your key — you pay Moonshot's $3/$15, and BharatRouter debits ₹0 for BYOK inference. The x-br-cost-inr header is indicative only.
Baseten · Together · Fireworks · Novita · DeepInfra · SiliconFlow — not serving K3 yet — These host older Kimi models today (K2 / K2.6 / K2.7-Code) and typically undercut first-party once they onboard a model. Watch for K3 endpoints appearing here.

The takeaway: K3's token price is the same everywhere right now — it's all Moonshot underneath. So pick your host on what wraps the tokens. Through BharatRouter you get INR metering, per-agent spend attribution, India-residency policy on the routes that support it, circuit-breaker failover, and a single key across all four agents above — with no markup on the BYOK tokens themselves.

Cost-sensitive and don't need K3's frontier reasoning? The older kimi-k2.7-code ($1.00 / $4.40) and kimi-k2.6 ($0.95 / $4.00) are a fraction of the price and are already served by multiple hosts — swap the model id in any config above. And on pure price-for-coding, an open GLM route can be cheaper still — see the GLM-vs-frontier benchmark.

Sample code

Every config in this post — the raw call, the OpenCode provider block, the Claude Code env, the Codex TOML, the keyless installer and a small "does it route?" check — lives in the cookbook:

github.com/bharatrouter/cookbook → 13-kimi-k3-coding-agents ↗

Related reading

Kimi and Moonshot are trademarks of Moonshot AI; OpenCode, Claude Code and Codex are their respective owners' — BharatRouter is not affiliated. Full reference: API reference · BYOK · the brcode guide.