Skip to content

Setting up Moonshot AI (Kimi) in OpenClaw

I spent a lot of time trying to find an LLM that handles long context windows without costing a fortune. I eventually tried Kimi, and the speed for large files is impressive. If you are using OpenClaw, getting Moonshot (Kimi) running is pretty simple once you realize there are two separate paths you can take depending on your needs.

  • A Moonshot API key from their developer platform.
  • A separate Kimi Coding key if you want to use their specialized coding models.
  • OpenClaw installed on your local machine.
  • Basic familiarity with your config.json5 file.

You can get things moving in about five minutes. I recommend using the kimi-k2.5 model for general tasks because it is fast and handles long prompts well.

Open your terminal and run the onboarding tool. If you are using the standard Moonshot API, use this:

Terminal window
openclaw onboard --auth-choice moonshot-api-key

If you are specifically using Kimi Coding, run this instead:

Terminal window
openclaw onboard --auth-choice kimi-code-api-key

Open your config file and add the Moonshot provider. I usually use the .ai endpoint for international access, but you can use .cn if you are based in China. Here is the full block you can copy:

{
env: { MOONSHOT_API_KEY: "sk-..." },
agents: {
defaults: {
model: { primary: "moonshot/kimi-k2.5" },
models: {
"moonshot/kimi-k2.5": { alias: "Kimi K2.5" },
"moonshot/kimi-k2-0905-preview": { alias: "Kimi K2" },
"moonshot/kimi-k2-turbo-preview": { alias: "Kimi K2 Turbo" },
"moonshot/kimi-k2-thinking": { alias: "Kimi K2 Thinking" },
"moonshot/kimi-k2-thinking-turbo": { alias: "Kimi K2 Thinking Turbo" },
},
},
},
models: {
mode: "merge",
providers: {
moonshot: {
baseUrl: "https://api.moonshot.ai/v1",
apiKey: "${MOONSHOT_API_KEY}",
api: "openai-completions",
models: [
{
id: "kimi-k2.5",
name: "Kimi K2.5",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
{
id: "kimi-k2-thinking",
name: "Kimi K2 Thinking",
reasoning: true,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
],
},
},
},
}

If things aren’t working as expected, check these four common issues:

  1. Mixing up API Keys: Moonshot and Kimi Coding are different providers. You cannot use a Moonshot key for a kimi-coding/ model.
  2. Wrong Base URL: If you have connection timeouts, try switching between https://api.moonshot.ai/v1 and https://api.moonshot.cn/v1.
  3. Model ID Prefixes: Always remember that Moonshot models need the moonshot/ prefix, while Kimi Coding uses kimi-coding/.
  4. Context Window Limits: If your long prompts are failing, check if Moonshot updated their limits and adjust the contextWindow value in your config.

If you hit a wall and can’t figure out why the connection is failing, talk to the AI Setup Assistant for real-time help.

OpenClaw

OpenClaw Expert

Still stuck?

If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.