iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤖

Running opencode + kimi-k2

に公開

Recently claude-code has been acting up, so I tried opencode kimi-k2.

I was able to get tools working with a configuration of openrouter+kimi-k2+opencode, but the setup was a bit tedious, so I'll leave a note here.

My motivation for trying it was this article by laiso:

https://blog.lai.so/kimi-k2/

It achieved a score of 65.8% on SWE-bench Verified. This measures the task of generating bug-fixing patches for OSS. This is a high level even compared to Gemini 2.5 Pro at 63.8% and Claude 4 Sonnet at 72.7%.

The API usage fees for Kimi K2 are very low. Depending on the provider, the output token price (1M) is set at $2.50, which is significantly cheaper compared to $15 for Claude 4 Sonnet and $10 for Gemini 2.5 Pro.

Since it's a Chinese model, please use it at your own risk.

First: OpenRouter API KEY

First, add credits to OpenRouter and issue an API key.

https://openrouter.ai/

I added $20.

opencode

https://opencode.ai/

npm install -g opencode-ai

$ opencode auth login
# Enter OpenRouter token
$ opencode
> models
kimi-k2
> hello
...

You can have a conversation at this point, but tool-related features do not work.

Setting up openrouter/kimi-k2 + tools to work

When I tried kimi-k2 with Roo Code, openrouter + kimi-k2 was working, so I looked into Roo's implementation and found that if you speak using an OpenAI-compatible protocol targeting moonshotai/kimi-k2 on OpenRouter, tools can be used.

Configure opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "moonshot": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "apiKey": "sk...",
        "baseURL": "https://openrouter.ai/api/v1"
      },
      "models": {
        "moonshotai/kimi-k2": {}
      }
    }
  }
}

Reference:

https://opencode.ai/docs/models/

With this, tools now work.

$ opencode
> models
# Specify moonshotai/kimi-k2
> write fib.ts

It worked.

Bonus: ai-sdk + kimi-k2

This is the version for using it via the AI SDK, which I came up with while testing Roo Code.

import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { generateText } from "ai";

const API_KEY = "...";

const openrouter = createOpenRouter({
  apiKey: API_KEY,
});

const { text, toolCalls, toolResults } = await generateText({
  model: openrouter.chat("moonshotai/kimi-k2"),
  prompt: "hello",
});

Impressions

Kimi-K2 is cheap and the benchmarks are reportedly good, but my impression is that while it can retrieve code it has learned, it doesn't feel like it can really apply it.

  • Japanese input in opencode is broken. It's a bit disappointing.
  • I'm not sure if the cause is OpenRouter or Kimi-K2, but requests fail periodically and recover after a restart.

I put in $20 and have spent about $5 using it casually.

I'll try using it a bit more.

Update: After about 3 hours of use

  • Regardless of the settings, Kimi-K2 is poor at using tools; it declares it will use a tool but then stops without doing anything.
  • qwen3 coder is relatively better.

Discussion