Kimi Code API key setup

Kimi Code API Key: Set Your Own Key in config.toml

Paste the block below into config.toml, swap in your own API key, and Kimi Code can use Claude models. Pay as you go.

~/.kimi-code/config.tomltoml
config
# ~/.kimi-code/config.toml
default_model = "aicodewith/claude-haiku-4-5-20251001"

[providers.aicodewith]
type = "openai"
base_url = "https://api.aicodewith.ai/v1"
api_key = "sk-***"

[models."aicodewith/claude-haiku-4-5-20251001"]
provider = "aicodewith"
model = "claude-haiku-4-5-20251001"
max_context_size = 200000

Setup steps

These steps were tested on Linux (bash). macOS and Windows have not been tested yet, so they are not listed.

  1. No Kimi Code yet? Install it (skip if installed)

    Run Kimi's install script curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash, then kimi --version. A version number means it is installed.

    Install kimi-code with curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash. It installs to ~/.kimi-code/bin/kimi. KIMI_NO_MODIFY_PATH=1 in the screenshot is only for our test machine; you don't need it. kimi --version prints 2.1.1
  2. Paste the config into config.toml and add your API key

    Open ~/.kimi-code/config.toml, paste the block from the top of this page, and replace sk-*** with your API key (Get an API key). After saving, the file has an api_key = "sk-…" line.

    In [providers.aicodewith], set api_key = "sk-***" (masked)
  3. Open a new terminal and test Kimi Code

    Open a new terminal and run kimi -m aicodewith/claude-haiku-4-5-20251001 -p "Reply with exactly: OK". • OK means Kimi Code is using your API key.

    Verify: close the terminal, open a new one, run kimi -m aicodewith/claude-haiku-4-5-20251001 -p "Reply with exactly: OK"; a • OK reply means it is set up
  4. No OK? Match your error

    Compare the error in your terminal with Common errors below. Each one lists the cause and the fix.

  5. Switch Kimi Code models: change the model name

    Replace the model name in default_model and in the [models."…"] block with the new Model ID, and use the same name after -m in the test command. Model IDs are on Models and pricing.

Common errors

error: failed to run prompt: Provider "aicodewith" declares api_key_env = "AICODEWITH_API_KEY" in config.toml, but the environment variable is not set or is empty.

What you see

error: failed to run prompt: Provider "aicodewith" declares api_key_env = "AICODEWITH_API_KEY" in config.toml, but the environment variable is not set or is empty.
Cause
config.toml has api_key_env, but AICODEWITH_API_KEY is not set in the terminal
How to fix
Delete the api_key_env line and write api_key = "your key" as in step 2

Go back to step 2: Paste the config into config.toml →

No key set: config.toml uses api_key_env = "AICODEWITH_API_KEY" and the new terminal has no such variable. kimi fails with Provider "aicodewith" declares api_key_env … but the environment variable is not set or is empty.

error: failed to run prompt: provider.auth_error: 401 "请在请求中提供有效的 API Key。"

What you see

error: failed to run prompt: provider.auth_error: 401 "请在请求中提供有效的 API Key。"
(English: "Please provide a valid API key in the request.")
Cause
The api_key value is wrong
How to fix
Copy the key from the console again and replace the quoted value

Go back to step 2: Paste the config into config.toml →

With a wrong key (sk-wrong): error: failed to run prompt: provider.auth_error: 401 "请在请求中提供有效的 API Key。"

404 "不支持的请求路径" (unsupported request path)

What you see

error: failed to run prompt: provider.api_error: 404 "不支持的请求路径,请检查 API 地址是否正确 (request_id: req_1791793075991_6c21900c)"
English: failed to run prompt: provider API error 404, unsupported request path, please check that the API address is correct (request_id: req_1791793075991_6c21900c)
Cause
base_url set to "https://api.aicodewith.ai/nope"
How to fix
Restore base_url to https://api.aicodewith.ai/v1.

Go back to step 2: Paste the config into config.toml →

One window shows the wrong config line base_url = "https://api.aicodewith.ai/nope" and then kimi -m aicodewith/claude-haiku-4-5-20251001 -p "Reply with exactly: Hello from aicodewith.ai". Actual error: error: failed to run prompt: provider.api_error: 404 "不支持的请求路径,请检查 API 地址是否正确 (request_id: req_1791793075991_6c21900c)". English: failed to run prompt: provider API error 404, unsupported request path, please check that the API address is correct (request_id: req_1791793075991_6c21900c). base_url was restored to https://api.aicodewith.ai/v1 afterwards, and a normal run replied Hello from aicodewith.ai.

FAQ

How do I use my own API key in Kimi Code?

In ~/.kimi-code/config.toml under [providers.aicodewith], write api_key = "your key" and set base_url to https://api.aicodewith.ai/v1. A new terminal keeps it.

Why doesn't export OPENAI_API_KEY work?

Kimi Code does not read OPENAI_API_KEY. Put the API key in the config file.

Where is the Kimi Code config.toml?

Default ~/.kimi-code/config.toml. Relocate the data root with KIMI_CODE_HOME.

Can Kimi Code add the API key without editing the file?

Yes. Type /provider inside Kimi Code, or run kimi provider in the terminal and follow the prompts.

What does type = "openai" mean?

Kimi Code sends requests in the OpenAI API format. AI Code With accepts that format, so you only set base_url and api_key.

Sources

Related links