Claude Code

Configure Claude Code to use models through the Kimchi gateway: hosted open-source models, Claude models via your organization's connected providers, or a metered Claude subscription.

This tutorial walks you through using the Kimchi Inference API with Claude Code, Anthropic's agentic coding tool. You'll route Claude Code through Kimchi's Anthropic-compatible endpoint and pin Kimchi-hosted models into the /model picker, alongside the built-in Anthropic entries, so you can switch between them at any time.

One Kimchi API key covers it all: Kimchi-hosted models, Claude models your organization exposes through connected providers, and Claude models on your own subscription login.

Overview

By the end of this tutorial, you'll be able to:

  • Point Claude Code at Kimchi as a gateway
  • Authenticate requests with your Kimchi API key sent as an X-API-Key header
  • Use Kimchi-hosted models for agentic tasks in addition to Anthropic
  • Switch between Kimchi and Anthropic models on demand using the /model picker
  • With a Claude Pro, Max, or Teams plan: meter subscription traffic through the gateway for usage tracking and cost visibility
📘

Kimchi exposes an Anthropic-compatible endpoint for Claude Code, so the same API key and base URL work with any tool that speaks the Anthropic Messages API.

Prerequisites

  1. A Kimchi API key - Go to Kimchi → API Keys and click + Create key. Copy the key and store it securely. See API Keys and Service Keys for the difference between the two key types.
  2. Node.js 18 or higher - Check your version with node --version
  3. Claude Code v2.1.242 or later - the modelPicker setting requires it. Install or update Claude Code:
npm install -g @anthropic-ai/claude-code
claude --version

Configure Claude Code

Two settings connect Claude Code to Kimchi: ANTHROPIC_BASE_URL routes traffic to the Anthropic-compatible endpoint, and ANTHROPIC_CUSTOM_HEADERS attaches your Kimchi API key to every request as an X-API-Key header, which is how the gateway authenticates and attributes your usage.

Store them in ~/.claude/settings.json, Claude Code's persistent configuration file: that applies them to every project and to GUI-launched apps like the VS Code and JetBrains extensions, and keeps your key out of shell history. For a single-session setup instead, see Alternative: environment variables.

Add Kimchi settings to settings.json

Open ~/.claude/settings.json (create it if it doesn't exist) and merge in the following keys, replacing YOUR_KIMCHI_API_KEY with your key:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://llm.kimchi.dev/anthropic",
    "ANTHROPIC_CUSTOM_HEADERS": "X-API-Key: YOUR_KIMCHI_API_KEY",
    "ANTHROPIC_API_KEY": ""
  },
  "model": "glm-5.3[1m]",
  "modelPicker": {
    "options": [
      {
        "model": "glm-5.3[1m]",
        "label": "GLM 5.3 (Kimchi)"
      },
      {
        "model": "glm-5.3-flash[1m]",
        "label": "GLM 5.3 Flash (Kimchi)"
      },
      {
        "model": "kimi-k3",
        "label": "Kimi K3 (Kimchi)"
      }
    ],
    "replaceBuiltInOptions": false
  }
}
⚠️

If your settings.json already has an env block, add the three ANTHROPIC_* entries to it - don't replace the whole block, or you'll drop unrelated variables like telemetry endpoints. Remove any existing ANTHROPIC_AUTH_TOKEN entry: Claude Code sends the first non-empty value of ANTHROPIC_API_KEY then ANTHROPIC_AUTH_TOKEN as the request credential, which would override the header setup.

KeyPurpose
env.ANTHROPIC_BASE_URLRoutes Claude Code traffic to Kimchi's Anthropic-compatible endpoint
env.ANTHROPIC_CUSTOM_HEADERSSends your Kimchi API key as the X-API-Key header on every request; leaves any saved Anthropic login untouched
env.ANTHROPIC_API_KEYSet to empty so no leftover key can claim the credential slot
modelDefault model Claude Code starts new sessions with
modelPicker.optionsModels listed in the /model picker, in your order, under your own labels
modelPicker.replaceBuiltInOptionsWhen false, Kimchi models are appended after the built-in picker entries; when true, the picker shows only your lineup

The [1m] suffix tells Claude Code to plan local context management (auto-compaction, the context display) against a 1M-token window, and is stripped before requests are sent to the API. Include it only for models the model overview lists with a 1M context window: on a smaller-window model like Kimi K3, Claude Code would plan for space the model does not have, and requests fail once the conversation passes the real limit. There is no suffix for other sizes - Claude Code assumes a 200K window for model IDs it doesn't recognize, and CLAUDE_CODE_MAX_CONTEXT_TOKENS pins an exact size if you need one.

📘

The lineup above is a starting point, not the full catalog. You can add any model available on Kimchi as another modelPicker.options entry - set model to the model's API identifier (optionally with the [1m] suffix for 1M-context models) and label to whatever you want to see in the picker. See the model overview for the full list of available models and their identifiers.

Verify the connection

Navigate to a project directory and start Claude Code:

cd ~/your-project
claude

In the interactive prompt, ask a simple question:

> Explain what this project does in one paragraph

If the response streams back, Claude Code is successfully routing through Kimchi. To confirm the requests are billed to your account, open the Kimchi console, go to the Analytics dashboard, and set the time range to 24h. Look for your test request in the request count and cost totals; you can filter by your API key to isolate it. Requests typically appear within seconds of completing.

Switch models with the /model picker

Run /model inside Claude Code. Your Kimchi entries appear after the built-in options under the labels you set - select one to switch the active model for the session. To change the model new sessions start with, update the model key in settings.json.

📘

On a Claude Pro, Max, or Teams plan? Keep your Anthropic login - this setup doesn't disturb it. Claude models keep going to Anthropic under your subscription while the gateway meters the traffic for your organization's reporting; Kimchi-hosted models bill per token against your key. If your organization instead connects Anthropic to Kimchi through external providers, the one key serves everything and all usage bills through Kimchi. Either way, all of it shows up on the Analytics and Usage pages in the Kimchi console.

Alternative: environment variables

For a single shell session, set the variables directly instead of editing settings.json:

export ANTHROPIC_BASE_URL="https://llm.kimchi.dev/anthropic"
export ANTHROPIC_CUSTOM_HEADERS="X-API-Key: YOUR_KIMCHI_API_KEY"
claude

The header value must be exactly X-API-Key: followed by a space and your key. The exports last until you close the shell.

⚠️

The export lines are recorded in your shell history, so the API key sits in a plaintext history file. Prefer the settings.json path above so the key stays out of your history.

Switching models

Run /model in a session and pick an entry, or edit the model key in settings.json to change the default for new sessions. Common choices:

ModelBest for
glm-5.3Complex reasoning and agentic coding
glm-5.3-flashFast code execution and edits
kimi-k3Agentic coding, image and video analysis

To pin a default model without editing the file, export ANTHROPIC_MODEL (for example export ANTHROPIC_MODEL="glm-5.3-flash[1m]") - when set, it outranks the saved model key for new sessions.

Troubleshooting

401 Authorization Required, or "Not logged in - Please run /login"

Claude Code can't get a request authenticated and reports it as a login failure. Check, in order:

  1. The header name is exactly X-API-Key, followed by a colon, a space, and your key:

    # Correct
    ANTHROPIC_CUSTOM_HEADERS="X-API-Key: YOUR_KIMCHI_API_KEY"
    
    # Wrong - the gateway does not recognize these header names
    ANTHROPIC_CUSTOM_HEADERS="X-Kimchi-Key: YOUR_KIMCHI_API_KEY"
    ANTHROPIC_CUSTOM_HEADERS="ApiKey: YOUR_KIMCHI_API_KEY"
  2. ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY are not set anywhere in your settings files or shell: Claude Code sends the first non-empty one as the request credential, which overrides the header setup.

  3. The key itself is valid. If it was rotated or revoked, create a fresh one from the API Keys page.

  4. If Kimchi-hosted models work but Claude models fail, the request reaches Anthropic without a credential it accepts: keep your subscription login active (run /login in Claude Code), or have your organization connect Anthropic as an external provider.

Requests fail with login prompts but no 401

Check that ANTHROPIC_BASE_URL is set to exactly https://llm.kimchi.dev/anthropic in the same shell or settings.json you're launching from. Missing or misspelled, Claude Code falls back to Anthropic's own endpoint: with a saved login everything keeps working but your traffic is unmetered by Kimchi, and without one you get repeated login prompts.

echo $ANTHROPIC_BASE_URL

Spend doesn't show in the console

In the Kimchi console, open the Analytics dashboard, set the time range to 24h, and filter by the API key you configured. If requests are missing, confirm Claude Code is running with the environment active (echo $ANTHROPIC_BASE_URL), and remember that the dashboard counts the requests the tool makes on your behalf, which can exceed what the tool itself reports. See Dashboard token usage.

Next steps


Did this page help you?