Back to the blog
Jun 18, 20265 min read
Guides

How to Run Kimi K2.7 Code in opencode (CLI Setup via AI Space)

Connect opencode to Kimi K2.7 Code through AI Space: store your key with the interactive prompt, add a short provider block, switch models, and fix issues.

By XY Space

How to Run Kimi K2.7 Code in opencode (CLI Setup via AI Space)

Kimi K2.7 Code is Moonshot's coding model, a fast long-context model built for agents that run long. opencode is exactly that kind of agent: it reads files, writes code, runs tests, reads the errors, and keeps going. This guide connects the two through AI Space, so inference runs on Cloudflare instead of Moonshot's China endpoint and you pay a flat rate instead of per token.

A note on the setup: opencode's terminal flow stores your API key interactively but doesn't ask for a custom endpoint URL. So this is two short steps. You paste your key through opencode's prompt, then add a few lines to opencode.json pointing at AI Space. If you'd rather skip the config file, the desktop app does all of it through a form. This is the terminal path.

Before you start

  • opencode installed (curl -fsSL https://opencode.ai/install | bash, or Homebrew or npm)
  • An AI Space account (free, no card)
  • An AI Space API key

Step 1: Create an AI Space API key

In the AI Space dashboard, open API Keys and create one. Name it opencode-kimi so you can tell it apart from other keys later. Copy it; keys start with sk-sota- and aren't shown again after you close the dialog.

Step 2: Store the key in opencode

Run:

opencode auth login

Work through the prompts:

  • Select provider: choose Other at the bottom of the list.
  • Enter provider id: type sota. Step 3 has to use this same id.
  • Enter your API key: paste your sk-sota-… key.

opencode saves the credential and tells you to finish setup in config, which is the next step. The same flow is available inside opencode as the /connect command.

Step 3: Point opencode at AI Space

The prompt took your key but not an endpoint, so opencode still needs AI Space's URL and the model list. Add them to opencode.json. The global file is at ~/.config/opencode/opencode.json, or use a project-level opencode.json that takes precedence. Create or open it and add:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "sota": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AI Space",
      "options": {
        "baseURL": "https://ai.xyspace.dev/v1"
      },
      "models": {
        "kimi-k2.7-code": { "name": "Kimi K2.7 Code" }
      }
    }
  },
  "model": "sota/kimi-k2.7-code"
}

The short version of what matters:

  • The provider key sota must match the id from Step 2. That's how opencode finds your stored key.
  • @ai-sdk/openai-compatible is the adapter for an OpenAI-shaped API like AI Space's.
  • baseURL keeps the /v1, since opencode appends /chat/completions. No apiKey line is needed, because opencode has it from Step 2.
  • model makes sota/kimi-k2.7-code the default.

Step 4: Launch and check

opencode

opencode comes up with Kimi K2.7 Code active. Type /models to confirm it's listed under AI Space and selected, then give it something with a few moving parts: point it at a feature that spans several files and ask it to trace how a request flows through them. Kimi holds long context well, so a multi-file question tests it better than a one-liner. To pin the model at launch, use opencode -m sota/kimi-k2.7-code.

Kimi K2.7 Code vs GLM-5.2 on AI Space

Both models on AI Space are long-context coders, so they both hold up across opencode's longer runs. The difference is pace versus capability.

Kimi K2.7 Code is the faster of the two. Its quicker responses make the back-and-forth of interactive coding feel snappier, and for most day-to-day work that speed is worth more than the last increment of model quality. It's a strong default.

GLM-5.2 is the more capable model when you want to push harder. It ranks above Kimi on coding leaderboards like Design Arena and costs more to run, and it's the one to reach for on the tasks where you want the strongest possible output and can spare a little speed to get it. To offer both, add GLM-5.2 to the block:

"models": {
  "kimi-k2.7-code": { "name": "Kimi K2.7 Code" },
  "glm-5.2": { "name": "GLM-5.2" }
}

Then /models or opencode -m sota/glm-5.2 switches between them. The comparison post goes deeper on the trade-off.

Troubleshooting

Model not found. The provider key sota has to match both the id from Step 2 and the prefix in your model line (sota/kimi-k2.7-code). Check all three.

Auth errors. Re-run opencode auth login, confirm the full sk-sota-… key went in under provider id sota, and use opencode auth list to see what's stored.

404s or no response. Almost always the baseURL. It needs to be exactly https://ai.xyspace.dev/v1, no trailing slash.

Long runs cut off. opencode and Kimi both handle large context, but check you're on a current opencode version. AI Space normalizes Kimi's output to the standard response shape, and an old client can mishandle it.

Why AI Space instead of Moonshot directly

Moonshot's native Kimi API runs inference in China. If your code can't leave Western infrastructure, that rules out the direct route no matter how good the model is. AI Space serves Kimi K2.7 Code from Cloudflare's network (US, UK, Germany, Japan, Australia), so what opencode sends stays where your policy allows. And because opencode's agent loops are token-heavy, AI Space's flat pricing ($25 Starter, $125 Pro, with per-user ceilings) keeps the cost predictable no matter how long the session runs.

Get started with AI Space and put Kimi K2.7 Code to work in opencode in a few minutes.

Work with us

Book a discovery call.Leave with a plan you can act on.

A paid map, a fixed-fee pilot on one workflow, then a build we run. Your people still decide. Everything we build stays yours.

Loading form…