AI SpaceJun 18, 20267 min read

How to Run GLM-5.2 in VS Code with the opencode Extension (via AI Space)

Run GLM-5.2 inside VS Code using the opencode extension and AI Space: install the extension, store your key, add a short provider block, and code from the editor.

On this page
  1. What you need
  2. Step 1: Install the extension
  3. Step 2: Get an AI Space API key
  4. Step 3: Store the key in opencode
  5. Step 4: Point opencode at AI Space
  6. Step 5: Drive it from the editor
  7. GLM-5.2 vs Kimi K2.7 Code on AI Space
  8. The extension vs the CLI and desktop app
  9. If something's off
  10. Why route through AI Space

opencode is a terminal coding agent, but it also ships a VS Code extension that brings the same agent into your editor. It opens in a split terminal pane, watches what file and selection you have open, and lets you drop file references into a prompt with a keystroke. The model doesn't change between the terminal and the editor, and neither does the setup: the extension reads the exact same opencode.json and stored credentials as the CLI. This guide installs the extension and points it at GLM-5.2 through AI Space, so inference runs on Cloudflare's network rather than Z.ai's China endpoint, at a flat monthly rate instead of per token.

One thing to know up front: there's no separate provider screen in the extension. You authenticate once through opencode's CLI prompt, add a few lines to opencode.json, and the editor picks it up. If you'd rather avoid the config file entirely, the opencode desktop app does provider setup through a form; the CLI guide covers the pure-terminal path. This is the VS Code path.

What you need

  • VS Code (or a fork like Cursor, Windsurf, or VSCodium)
  • 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: Install the extension

The simplest way is to let opencode install it for you. Open VS Code, open the integrated terminal (Ctrl+ ` ``), and run:

opencode

The extension detects your editor and installs itself automatically. If that doesn't happen, open the Extensions Marketplace, search OpenCode, and click Install. Auto-install relies on your editor's CLI command being on your PATH (code for VS Code, cursor, windsurf, or codium for the forks), so if it's missing, run "Shell Command: Install 'code' command in PATH" from the command palette and try again.

Step 2: Get an AI Space API key

Sign in to AI Space, open the dashboard, and go to API Keys. Create a key, name it something like opencode-vscode 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 3: Store the key in opencode

In the same integrated terminal, run:

opencode auth login

Work through the prompts:

  • Select provider: scroll to the bottom of the list and choose Other.
  • Enter provider id: type sota. This is opencode's internal name for the provider, 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 with the /connect command.

Step 4: Point opencode at AI Space

The prompt stored your key but never asked 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 drop 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"
}

What each part does:

  • The provider key, sota, has to match the provider id you entered in Step 3. 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 3.
  • 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.

Because the extension shares this file with the CLI, you only write it once and both surfaces use it.

Step 5: Drive it from the editor

Open a project folder, then bring up opencode with Cmd+Esc (Mac) or Ctrl+Esc (Windows/Linux). It opens in a split terminal pane alongside your code. Type /models to confirm GLM-5.2 appears under the AI Space provider and is selected.

Two things make the extension worth using over a bare terminal:

  • Context awareness. opencode automatically sees your active selection and the file you have open, so "explain what this function does" or "refactor this" works on whatever's in front of you without you pasting anything.
  • File references. Press Cmd+Option+K (Mac) or Alt+Ctrl+K (Windows/Linux) to insert a reference to a file into your prompt, so you can point the agent at code in other tabs by name.

Need a clean slate? Cmd+Shift+Esc / Ctrl+Shift+Esc starts a new session. To sanity-check the connection, select a function in your code, open opencode, and ask "what does this do?" — if the answer reflects your actual file rather than a generic guess, GLM-5.2 is answering through AI Space.

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 inside the opencode pane. No new key, no second account. We compare the two in more depth in GLM-5.2 vs Kimi K2.7 Code.

The extension vs the CLI and desktop app

The model and the routing are identical across all three: same GLM-5.2, same AI Space endpoint, same Cloudflare inference. What changes is where the agent lives. The VS Code extension keeps it next to your code, with the editor's current selection and open file fed in automatically and file references a keystroke away. The desktop app gives you a standalone window with a diff viewer. The CLI is the leanest, best for scripting and a pure-terminal workflow. Since they all read the same opencode.json, you can move between them without reconfiguring.

If something's off

The extension didn't install. Auto-install needs your editor's CLI command on PATH. Install it from the command palette ("Shell Command: Install 'code' command in PATH"), or just install OpenCode from the Extensions Marketplace by hand.

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

Authentication fails. Re-run opencode auth login in the integrated terminal 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 the extension 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 VS Code 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…