AI SpaceJun 16, 20265 min read

How to Run GLM-5.2 in opencode (CLI Setup via AI Space)

Point opencode at GLM-5.2 through AI Space: store your key with the interactive prompt, add a short provider block, switch models, and troubleshoot.

On this page
  1. Before you start
  2. Step 1: Get an AI Space API key
  3. Step 2: Store the key in opencode
  4. Step 3: Tell opencode where AI Space lives
  5. Step 4: Run opencode
  6. GLM-5.2 vs Kimi K2.7 Code on AI Space
  7. If something's off
  8. Why route through AI Space

opencode is a coding agent that lives in your terminal. You run it, it reads your project, edits files, runs commands, and works through a task the way Claude Code or Cursor's agent does, except it never leaves your shell. Out of the box it talks to the usual hosted providers. This guide points it at GLM-5.2 through AI Space instead, so inference runs on Cloudflare's network rather than Z.ai's China endpoint, and your bill is a flat monthly number rather than per-token.

One thing to know up front: opencode's terminal flow stores your API key interactively, but it never asks for a custom endpoint URL. So the setup is two short steps. You paste your key through opencode's prompt, then add a few lines to opencode.json telling it where AI Space lives. If you'd rather avoid the config file entirely, the opencode desktop app does all of this through a form. This is the terminal path.

Before you start

  • opencode installed (curl -fsSL https://opencode.ai/install | bash, or via Homebrew or npm; check opencode's install docs for your platform)
  • An AI Space account (free to create, no card required)
  • An AI Space API key, which you'll generate in a moment

Step 1: Get an AI Space API key

Sign in to AI Space, open the dashboard, and go to API Keys. Create a key, give it a name like opencode so you can find it later, and copy it. Keys start with sk-sota- and are shown once, so paste it somewhere before you close the dialog.

Step 2: Store the key in opencode

Run the auth command:

opencode auth login

opencode walks you through a short series of prompts. Answer them like this:

  • Select provider: scroll to the bottom of the list and choose Other.
  • Enter provider id: type sota. This is the name opencode uses for the provider internally, and the next step has to match it.
  • Enter your API key: paste your sk-sota-… key.

opencode saves the credential and reminds you to finish the provider setup in config, which is the next step. You can reach this same flow from inside opencode by typing /connect.

Step 3: Tell opencode where AI Space lives

The prompt stored your key but didn't ask for an endpoint, so opencode still doesn't know AI Space's URL or which models to offer. That goes in opencode.json. The global file is at ~/.config/opencode/opencode.json, or you can use a project-level opencode.json in your repo root, which takes precedence. Open it (create it if it's missing) 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": {
        "glm-5.2": { "name": "GLM-5.2" }
      }
    }
  },
  "model": "sota/glm-5.2"
}

This is the only file you'll touch, and here's what each part is for:

  • The provider key, sota, has to match the provider id you entered in Step 2. That's how opencode pairs this config with the key it stored.
  • npm picks the adapter. @ai-sdk/openai-compatible is the right one, since AI Space speaks the OpenAI format.
  • baseURL is AI Space's endpoint. opencode appends /chat/completions to it, so keep the /v1. There's no apiKey line because opencode already has your key from Step 2.
  • models lists what shows up in the picker, and model sets the default so you don't pass it every time. The format is provider/model.

Step 4: Run opencode

opencode

opencode launches with GLM-5.2 active, routed through AI Space. Type /models to confirm GLM-5.2 appears under the AI Space provider and is selected. Then ask it something about your actual code, like "what does the auth middleware in this repo do?", and check the answer reflects your files rather than a generic guess. You can also pin the model at launch with opencode -m sota/glm-5.2.

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

AI Space serves two open coding models, and both handle long context and long agent runs well, so the choice between them is about capability versus speed rather than memory.

GLM-5.2 is the more capable of the two. On coding leaderboards like Design Arena it ranks above Kimi, and it's the one to reach for when you want the strongest output: tricky refactors, dense logic, the tasks where a weaker model returns something that almost works. It costs more to run, which is the trade for that capability.

Kimi K2.7 Code is the faster alternative. It's a strong long-context coder in its own right, and it gives up a little of GLM-5.2's top-end quality for quicker responses, which is often the better deal when you're iterating fast. To offer both, add Kimi to the models block:

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

Then switch with /models or opencode -m sota/kimi-k2.7-code. No new key, no second account. We compare the two in more depth in GLM-5.2 vs Kimi K2.7 Code.

If something's off

opencode can't find the model. The provider key in opencode.json (sota) has to match both the provider id you set in Step 2 and the prefix in your model line (sota/glm-5.2). A mismatch anywhere breaks the lookup.

Authentication fails. Re-run opencode auth login and confirm you pasted the full sk-sota-… key under provider id sota. You can list stored credentials with opencode auth list.

Requests aren't reaching AI Space. Check the baseURL is exactly https://ai.xyspace.dev/v1, with no trailing slash. opencode builds the request path from that string.

Config isn't being read. opencode merges global and project config, with project winning. If a repo-level opencode.json also sets model, it overrides the global default. Make the two agree, or delete the one you don't need.

Why route through AI Space

GLM-5.2's native API runs inference in China. AI Space serves the same model from Cloudflare's network across the US, UK, Germany, Japan, and Australia, so the code opencode sends never lands on infrastructure your security team hasn't signed off on. And opencode's agent loops can burn a lot of tokens; per-token pricing turns that into a number you can't predict ahead of time, while AI Space charges a flat monthly rate ($25 Starter, $125 Pro) with per-user spend ceilings, so a runaway loop costs you time, not money.

Get started with AI Space and have GLM-5.2 answering inside opencode in about five minutes.

Written by

Cho Yin Yong

Principal AI Solutions Engineer, XY Space

Principal AI Solutions Engineer at XY Space. University of Toronto lecturer for five years, co-author of two patents, winner of two competitive AI awards, and nine years of regulated engineering leadership.

More from Cho Yin Yong

Share this article

Work with us

We build the systems these posts describe, and we'll tell you in the first call whether yours is worth building.

Start a project
Work with us

Book a call.We'll come back with specifics.

Start with the map of your organization, or with the one job that hurts. Measured in hours and money, and everything we build stays yours.

Loading form…