Kilo Code API key setup

Kilo Code API Key: Set Your Own Key in kilo.json

Paste the block below into kilo.json, swap in your own API key, and Kilo Code can use Claude and GPT models. Pay as you go.

~/.config/kilo/kilo.jsonjson
config
{
  "$schema": "https://app.kilo.ai/config.json",
  "model": "aicodewith/claude-haiku-4-5-20251001",
  "provider": {
    "aicodewith": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AI Code With",
      "options": {
        "baseURL": "https://api.aicodewith.ai/v1",
        "apiKey": "sk-***"
      },
      "models": {
        "claude-haiku-4-5-20251001": {
          "name": "Claude Haiku 4.5"
        },
        "gpt-5.5": {
          "name": "GPT-5.5"
        }
      }
    }
  }
}

Setup steps

Save this key for later terminals

Once you are signed in, this command includes your own key. Copy it, run it once, and the tool keeps the key in the location we tested.

bash
mkdir -p "$(dirname "$HOME/.config/kilo/kilo.json")"
cat > "$HOME/.config/kilo/kilo.json" << 'EOF'
{
  "$schema": "https://app.kilo.ai/config.json",
  "model": "aicodewith/claude-haiku-4-5-20251001",
  "provider": {
    "aicodewith": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AI Code With",
      "options": {
        "baseURL": "https://api.aicodewith.ai/v1",
        "apiKey": "sk-***"
      },
      "models": {
        "claude-haiku-4-5-20251001": {
          "name": "Claude Haiku 4.5"
        },
        "gpt-5.5": {
          "name": "GPT-5.5"
        }
      }
    }
  }
}
EOF

Signed-out visitors only see a placeholder. Sign in and we fill in your key. Get a key in the console

Copying only puts the command on the clipboard. You still need to run it in a terminal, or paste the key into the tool settings. How to get an API key

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

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

    Run npm i -g @kilocode/cli, then kilo --version. A version number means it is installed.

    Install the Kilo Code CLI with npm i -g @kilocode/cli, then kilo --version prints 7.8.8 to confirm it works
  2. Paste the config into kilo.json and add your API key

    Open ~/.config/kilo/kilo.json, 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 "apiKey": "sk-…" line, and a new terminal or a reboot keeps it.

    Put the key directly in provider.aicodewith.options.apiKey in ~/.config/kilo/kilo.json (masked as sk-*** here)
  3. Open a new terminal and test Kilo Code

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

    Verify: close the terminal, open a new one (no export), run kilo run -m aicodewith/claude-haiku-4-5-20251001 "Reply with exactly: OK"; an 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 Kilo Code models: change the name after -m

    After -m, write aicodewith/ plus a model listed under models in kilo.json, for example aicodewith/gpt-5.5. To add a model, list its Model ID under models first; see Models and pricing.

Common errors

No key set: Error: Unauthorized: 请在请求中提供有效的 API Key。

What you see

Error: Unauthorized: 请在请求中提供有效的 API Key。
(English: "Please provide a valid API key in the request.")
Cause
apiKey in kilo.json is {env:AICODEWITH_API_KEY}, and the new terminal has no such variable
How to fix
Write your key directly in apiKey, as in step 2

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

No key set: apiKey is still {env:AICODEWITH_API_KEY} and the new terminal has no such variable. Running kilo run -m aicodewith/claude-haiku-4-5-20251001 "Reply with exactly: OK" prints: Error: Unauthorized: 请在请求中提供有效的 API Key。 (English: "Please provide a valid API key in the request.")

Wrong key: Error: Unauthorized: 请在请求中提供有效的 API Key。

What you see

Error: Unauthorized: 请在请求中提供有效的 API Key。
(English: "Please provide a valid API key in the request.")
Cause
apiKey is wrong; the error is the same as with no key
How to fix
Copy the key from the console again and replace the value in the apiKey quotes

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

Wrong key: grep -n sk-wrong ~/.config/kilo/kilo.json shows line 10 is "apiKey": "sk-wrong". Running kilo run -m aicodewith/claude-haiku-4-5-20251001 "Reply with exactly: OK" prints: Error: Unauthorized: 请在请求中提供有效的 API Key。 (English: "Please provide a valid API key in the request.") — identical to the no-key error

Error: Model not found

What you see

Error: Model not found
Cause
The model after -m is not listed under models in kilo.json (for example aicodewith/no-such-model), so Kilo Code stops before sending a request
How to fix
Use a model listed under models, for example aicodewith/gpt-5.5

Go back to step 3: Open a new terminal and test Kilo Code →

Common error: if the model name is wrong (here aicodewith/no-such-model), kilo returns Error: Model not found. Kilo raises this itself (the model is not listed in kilo.json), before any request is sent. Use a model listed in the config, for example aicodewith/gpt-5.5

FAQ

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

In ~/.config/kilo/kilo.json, add an aicodewith provider with baseURL https://api.aicodewith.ai/v1 and write your key in apiKey. A new terminal keeps it.

Should the Kilo Code base URL include /v1?

Yes. Use https://api.aicodewith.ai/v1.

Where is the Kilo Code kilo.json?

The global config is ~/.config/kilo/kilo.json.

Kilo Code says Unauthorized. What now?

apiKey in kilo.json is missing or wrong. See Common errors above for the fix.

Sources

Related links