Back to the blog
Jun 10, 20265 min read
Guides

How to Use GLM-5.2 with Claude Code (Step-by-Step)

Route Claude Code's requests to GLM-5.2 via AI Space in under five minutes. Full setup guide: API key, env vars, model switching, and troubleshooting.

By XY Space

How to Use GLM-5.2 with Claude Code (Step-by-Step)

You can run Claude Code against GLM-5.2 today by pointing two environment variables at AI Space's API. No custom forks, no local GPU, no proprietary-model billing.

This guide walks through the full setup from a fresh AI Space account to a working Claude Code session, with notes on switching to Kimi K2.7 Code and debugging common problems.

What you'll need

  • Claude Code installed (npm install -g @anthropic-ai/claude-code or the equivalent for your shell)
  • An AI Space account (free to create, no credit card required to start)
  • Five minutes

That's it. AI Space's API is OpenAI-compatible and Claude Code supports custom base URLs out of the box, so no patching or wrapper scripts are needed.

Step 1: Get an AI Space API key

  1. Sign in to AI Space and open the dashboard.
  2. Navigate to API Keys and create a new key. Name it something you'll recognize later (e.g., claude-code-dev).
  3. Copy the key; it starts with sk-sota-. You won't be able to view it again after you close the modal.

AI Space's Starter plan is $25/month and covers most individual developer workflows with per-user daily and weekly spend ceilings, so your bill stays predictable even when Claude Code is running long agentic loops.

Step 2: Point Claude Code at AI Space

Set these two environment variables in your terminal before launching Claude Code:

export ANTHROPIC_BASE_URL="https://ai.xyspace.dev"
export ANTHROPIC_API_KEY="sk-sota-…"
# Pin GLM-5.2 (AI Space's default is Kimi K3)
export ANTHROPIC_MODEL="glm-5.2"
claude   # frontier open models, on Cloudflare's global network

The key points here:

  • ANTHROPIC_BASE_URL overrides where Claude Code sends its requests. AI Space's endpoint accepts the same request shape Claude Code produces, so nothing else changes.
  • ANTHROPIC_API_KEY is your AI Space key, not an Anthropic key. The variable name is the same because Claude Code reads it regardless of which provider is on the other end.
  • The ANTHROPIC_MODEL line pins GLM-5.2. Leave it out and you get Kimi K3, AI Space's default model. See the Switching models section below.

If you want these settings to persist across sessions, add the export lines to your shell profile (~/.zshrc, ~/.bashrc, or equivalent). You can also scope them per project by putting them in a .env file and sourcing it before launching Claude Code.

Step 3: Run Claude Code

With those variables set, launch Claude Code the same way you always have:

claude

Claude Code will connect to AI Space's API and route your prompts to GLM-5.2. From Claude Code's perspective, the interaction is identical: it issues the same tool calls and receives the same response shape. The model running the inference is different, served from Cloudflare's global network (US, UK, Germany, Japan, Australia) rather than a proprietary Anthropic endpoint.

Try a quick sanity check: ask Claude Code to explain a file in your current project. If you get a coherent response, you're live.

Switching models

GLM-5.2 is Z.ai's flagship agentic coder, a long-context model that's reliable across the kinds of tasks Claude Code runs most often. AI Space's default model is Kimi K3, so this guide pins GLM-5.2 explicitly with ANTHROPIC_MODEL.

If you want to switch to Kimi K2.7 Code from Moonshot instead, set the model environment variable:

export ANTHROPIC_MODEL="kimi-k2.7-code"

Kimi K2.7 Code is the faster, more cost-efficient model, built for agentic software engineering with deep investment in multi-step tool use. It's also a long-context model, so it holds up across long Claude Code sessions; the reason to pick it is speed and lower cost, which pay off in high-throughput or team-wide use. When you want the strongest output on a hard task, GLM-5.2 is the more capable choice, at a higher cost to run.

You can switch models per-session by setting the variable before launching Claude Code, or mid-project by restarting Claude Code with the new variable set. No account changes or API key rotation needed.

For a deeper look at how the two models compare, see our GLM-5.2 vs Claude Sonnet 4.6 comparison.

Troubleshooting

Claude Code says "invalid API key" Double-check the key starts with sk-sota- and that you copied the full string. AI Space keys don't have trailing spaces, but shell expansions can introduce them; run echo $ANTHROPIC_API_KEY to verify.

Requests are going to Anthropic instead of AI Space Confirm ANTHROPIC_BASE_URL is set in the same shell session where you launched Claude Code. If you added it to your shell profile, make sure you sourced the file (source ~/.zshrc) or opened a new terminal.

Responses look truncated AI Space normalizes responses to match the OpenAI/Claude expected shape, but some model responses include native formats that require normalization. If you're seeing cut-off replies, make sure you're on the latest version of AI Space's API endpoint and that your Claude Code version is up to date.

Model isn't switching If you set ANTHROPIC_MODEL but the behavior hasn't changed, restart Claude Code. Environment variables are read at startup; changing them in a running session won't take effect.

Rate limits or unexpected cost AI Space's plans include per-user spend ceilings. If you're hitting limits earlier than expected, check your plan's daily and weekly allowances in the dashboard. Upgrading to Pro ($125/month) raises those ceilings significantly.

Why route through AI Space

The practical reasons for routing Claude Code through AI Space rather than using native provider APIs:

Western inference. GLM-5.2's native API and Kimi K2.7 Code's native API both run inference in China. AI Space routes both through Cloudflare's network (New York, London, Frankfurt, Tokyo, and Australian infrastructure), so your code doesn't leave Western infrastructure. For teams with data residency requirements, this is non-negotiable.

Predictable billing. Native token-based billing for high-volume Claude Code use accumulates fast and varies with each session. AI Space's flat monthly pricing with per-user ceilings makes the cost predictable enough to budget and explain to finance.

One API for multiple models. AI Space lets you switch between GLM-5.2 and Kimi K2.7 Code by changing one environment variable, with no separate accounts, separate billing relationships, or separate API key management.

OpenAI compatibility. AI Space's API works with any tool that speaks OpenAI's request format. Claude Code works. Your own scripts calling the API work. Nothing needs to be rewritten.

For a full cost comparison between native Claude billing and open models via AI Space, see The Real Cost of Claude Code. For alternatives if you're evaluating other approaches, see Claude Code Alternatives.

Get started with AI Space and have GLM-5.2 running in Claude Code in under five 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…