Kimi Code CLI is Moonshot AI's terminal coding agent. It connects to Tokens through its openai provider type, which sends chat completions to https://tokens.bd/v1; an anthropic type against https://tokens.bd also works.
The old Kimi CLI is archived
The Python Kimi CLI (MoonshotAI/kimi-cli) is archived, and Moonshot says existing installations will stop working. This guide is for its successor, Kimi Code CLI (MoonshotAI/kimi-code), which uses a different config file.
The Tokens CLI doesn't configure Kimi Code, so add the provider by hand. It's one short TOML file.
Install Kimi Code CLI#
curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash
# or: npm install -g @moonshot-ai/kimi-code
# or: brew install kimi-codeirm https://code.kimi.com/kimi-code/install.ps1 | iexCreate a key at /dashboard/keys. API keys explains spend caps and model allow-lists.
Export TOKENS_API_KEY#
export TOKENS_API_KEY="tok_live_your_key"$env:TOKENS_API_KEY = "tok_live_your_key" # this window
setx TOKENS_API_KEY "tok_live_your_key" # new windowsConfigure ~/.kimi-code/config.toml#
Kimi Code reads ~/.kimi-code/config.toml; set KIMI_CODE_HOME to move it. Add a provider and at least one model:
default_model = "tokens/deepseek-v4.1-flash"
[providers.tokens]
type = "openai"
base_url = "https://tokens.bd/v1"
api_key_env = "TOKENS_API_KEY"
[models."tokens/deepseek-v4.1-flash"]
provider = "tokens"
model = "deepseek/deepseek-v4.1-flash"
max_context_size = 128000
capabilities = [ "tool_use" ]How the pieces fit:
[providers.tokens]defines the connection.type = "openai"means Chat Completions. The other types arekimi,anthropic,openai_responses,google-genaiandvertexai.[models."..."]is a local alias. Its name is what you see in Kimi Code;modelis the id sent to Tokens and must match our catalog exactly.- The alias contains a
/, so it must be quoted in the table header. Any TOML key with a.in it needs quotes too. max_context_size = 128000is a placeholder. Copy the real context window from the model's page in /models.
Set exactly one of api_key_env or api_key. Kimi Code doesn't fall back to other environment variables, so if neither resolves, it fails at startup.
With type = "openai", Kimi Code handles DeepSeek-style reasoning_content in responses automatically. If a model returns its reasoning under a different field, reasoning_key lets you name it.
Anthropic-compatible variant#
To use the Messages API instead, change the provider:
[providers.tokens]
type = "anthropic"
base_url = "https://tokens.bd"
api_key_env = "TOKENS_API_KEY"Leave /v1 off: this type follows the Anthropic SDK, which appends /v1/messages itself. See Messages API for what that endpoint supports.
Add the provider interactively#
You can also run /provider inside the TUI, or kimi provider from the shell, instead of editing the file.
Switch models#
Add one [models."..."] table per Tokens model, each pointing at the tokens provider:
[models."tokens/kimi-k3"]
provider = "tokens"
model = "moonshotai/kimi-k3"
max_context_size = 128000
capabilities = [ "tool_use" ]The id in model is an example; copy the exact one from /models or GET /v1/models, and set its real context size. Then switch with /model inside kimi, or change default_model to make it the default. Choosing a model has guidance for agent work.
Verify it works#
Run kimi in a project folder, then /model to confirm the Tokens alias is active, and send a short prompt. The request should appear in Usage analytics on the dashboard. If no credential resolves, Kimi Code says so loudly at startup rather than failing on the first request.
To check the key and model without Kimi Code involved:
curl https://tokens.bd/v1/chat/completions \
-H "Authorization: Bearer $TOKENS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "deepseek/deepseek-v4.1-flash", "messages": [{"role": "user", "content": "Reply with OK"}], "max_tokens": 10}'Troubleshooting#
Startup error about missing credentials. TOKENS_API_KEY isn't set in the shell that started kimi, or both api_key and api_key_env are set. Use exactly one. After setx on Windows, open a new terminal.
TOML parse error. A model alias with / or . isn't quoted. Write [models."tokens/deepseek-v4.1-flash"], not [models.tokens/deepseek-v4.1-flash].
404 model_not_found. The model field, not the alias, must be the exact Tokens id. deepseek/deepseek-v4.1-flash is the id; tokens/deepseek-v4.1-flash is only your local name.
404 on every request. For type = "openai", base_url must end in /v1. For type = "anthropic", it must not.
Tools never get called. Make sure the model entry lists capabilities = [ "tool_use" ], and that the model you picked supports tool calling.
403 model_not_allowed_on_key, 402 or 429. These are key, balance and plan limits. See Troubleshooting.