Skip to main content
MindStudio
Pricing
Blog About
My Workspace

How to Use GLM 5.2 in Agent Harnesses: Cursor, OpenCode, and Claude Code

GLM 5.2 integrates with Cursor, OpenCode, and Claude Code for agentic coding tasks at roughly one-fifth the cost of frontier models.

MindStudio Team RSS
How to Use GLM 5.2 in Agent Harnesses: Cursor, OpenCode, and Claude Code

GLM 5.2 and Why It Makes Sense for Agentic Coding

The economics of running AI coding agents have a problem most developers feel immediately: frontier model costs spiral fast when you’re making hundreds of API calls per session. A long Cursor or Claude Code run against GPT-4o or Claude Sonnet can rack up real money, especially in multi-agent pipelines where one task triggers several downstream calls.

GLM 5.2, released by Zhipu AI, offers a practical alternative. It’s a capable reasoning and code model priced at roughly one-fifth the cost of frontier models, and it exposes an OpenAI-compatible API — which means it drops into Cursor, OpenCode, and Claude Code with minimal configuration. This guide covers exactly how to do that.


What GLM 5.2 Actually Is

Zhipu AI is a Beijing-based AI lab that’s been iterating on its GLM (General Language Model) series since 2021. GLM 5.2 is their latest general-purpose release with strong coding and instruction-following capabilities, built on a transformer architecture trained on multilingual data with particular depth in code, reasoning, and tool-use tasks.

Key technical characteristics

  • Context window: 128K tokens, suitable for large codebases and multi-file refactors
  • API format: OpenAI-compatible (same request/response schema as the OpenAI Chat Completions API)
  • Pricing: Approximately $0.14 per million input tokens and $0.28 per million output tokens for the standard tier — compared to roughly $3–15 per million tokens for frontier models
  • Tool calling: Supports function calling in the same format as OpenAI’s tool_call specification, which agent harnesses rely on heavily

Other agents start typing. Remy starts asking.

YOU SAID "Build me a sales CRM."
01 DESIGN Should it feel like Linear, or Salesforce?
02 UX How do reps move deals — drag, or dropdown?
03 ARCH Single team, or multi-org with permissions?

Scoping, trade-offs, edge cases — the real work. Before a line of code.

The OpenAI-compatible API is the critical detail. It means you’re not wrapping or translating — agent harnesses that accept a custom base URL will talk to GLM 5.2 the same way they talk to GPT-4o.

What it’s good at vs. where it falls short

GLM 5.2 performs well on:

  • Single-file and multi-file code generation in Python, TypeScript, Go, and Rust
  • Debugging and refactoring tasks where the context fits in a few thousand tokens
  • Code explanation and documentation generation
  • Tool-calling chains with well-defined schemas

It’s less reliable than frontier models on:

  • Complex multi-step architectural reasoning over very large codebases
  • Ambiguous open-ended tasks requiring strong world knowledge
  • Tasks that depend heavily on recent events post-training cutoff

For the majority of agentic coding tasks — “fix this bug,” “add this feature,” “refactor this module” — GLM 5.2 handles the work at a fraction of the cost.


Prerequisites Before You Configure Anything

Before touching any harness settings, get your GLM API credentials set up.

Step 1: Create a Zhipu AI account

Go to BigModel, the platform Zhipu AI uses to distribute API access, and register. You’ll need to verify your account before generating API keys.

Step 2: Generate an API key

In the BigModel dashboard, navigate to API Keys and create a new key. Copy it somewhere safe — you’ll use it across all three harnesses.

Step 3: Note the base URL

The GLM API base URL is:

https://open.bigmodel.cn/api/paas/v4/

This is the endpoint you’ll point Cursor, OpenCode, and Claude Code at.

Step 4: Confirm the model identifier

When making requests, use glm-4-5 as the model string (or check the BigModel dashboard for the current GLM 5.2 model ID — Zhipu AI occasionally adjusts naming conventions between versions).


Setting Up GLM 5.2 in Cursor

Cursor supports custom model endpoints natively through its settings panel. It uses the OpenAI API format, so GLM 5.2 works without any proxy layer.

Adding GLM 5.2 as a custom model

  1. Open Cursor and go to Settings (gear icon in the bottom left, or Cmd/Ctrl + ,)

  2. Navigate to Models in the left sidebar

  3. Scroll to the Custom Models section and click Add Model

  4. Fill in the fields:

    • Model name: glm-4-5 (this is what Cursor sends as the model parameter)
    • API Base URL: https://open.bigmodel.cn/api/paas/v4/
    • API Key: your BigModel API key
  5. Click Save and toggle the model on in your active model list

Selecting GLM 5.2 for a session

Once added, GLM 5.2 appears in the model dropdown in Cursor’s chat panel and in the inline editor (Cmd+K). You can switch to it per-session or set it as your default.

Practical tips for Cursor with GLM 5.2

  • Use it for Ctrl+K edits on smaller files: GLM 5.2 handles line-level and function-level edits well. Reserve frontier models for full project architecture sessions if you have Cursor’s multi-model setup.
  • Enable auto-indexing: Cursor’s codebase indexing feeds context into the prompt — GLM 5.2’s 128K window handles this fine for most projects.
  • Test tool-calling behavior: If you use Cursor’s agentic mode (where it can create files, run terminal commands), verify GLM 5.2’s tool-call responses are formatted correctly by running a simple test task first.
REMY IS NOT
  • a coding agent
  • no-code
  • vibe coding
  • a faster Cursor
IT IS
a general contractor for software

The one that tells the coding agents what to build.

One caveat: Cursor’s agentic features depend on reliable function-calling behavior. GLM 5.2 handles this well in practice, but if you see malformed tool responses, switch to a frontier model for those specific multi-step agent tasks.


Setting Up GLM 5.2 in OpenCode

OpenCode is an open-source terminal-based coding agent designed for developers who want a Claude Code-style experience without locking into a single provider. It supports multiple LLM backends through a YAML configuration file.

Installing OpenCode

If you don’t have OpenCode installed:

npm install -g opencode-ai

Or via the official install script — check the OpenCode GitHub repository for the current recommended method.

Configuring a custom provider

OpenCode uses a config file at ~/.config/opencode/config.json (or opencode.json in your project root for project-specific settings).

Add a custom provider entry:

{
  "providers": {
    "zhipu": {
      "name": "Zhipu AI",
      "apiKey": "YOUR_BIGMODEL_API_KEY",
      "baseUrl": "https://open.bigmodel.cn/api/paas/v4",
      "models": [
        {
          "id": "glm-4-5",
          "name": "GLM 5.2",
          "contextLength": 128000
        }
      ]
    }
  },
  "defaultProvider": "zhipu",
  "defaultModel": "glm-4-5"
}

Save the file and run opencode in any project directory — it’ll pick up the configuration automatically.

Using environment variables instead

If you prefer not to store your API key in a config file:

export OPENCODE_API_KEY=your_bigmodel_key
export OPENCODE_BASE_URL=https://open.bigmodel.cn/api/paas/v4
export OPENCODE_MODEL=glm-4-5

Add these to your .bashrc or .zshrc to persist them.

Running OpenCode with GLM 5.2

Once configured, OpenCode works the same way regardless of backend model. Start a session with:

opencode

Or pass the model explicitly:

opencode --model glm-4-5

OpenCode’s agentic loop — where it reads files, proposes changes, and iterates — works well with GLM 5.2 for bounded tasks. For large refactors touching dozens of files, you may want to break the work into smaller scoped sessions.


Setting Up GLM 5.2 in Claude Code

Claude Code is Anthropic’s CLI tool for agentic coding. It’s designed around Claude models, but it can work with OpenAI-compatible endpoints through a proxy layer. The most practical approach is using LiteLLM as a local translation proxy.

Why a proxy is needed

Claude Code communicates using the Anthropic Messages API format. GLM 5.2 uses the OpenAI Chat Completions format. LiteLLM acts as a local server that translates between them — Claude Code thinks it’s talking to Anthropic, and LiteLLM forwards the request to GLM 5.2.

Step 1: Install LiteLLM

pip install litellm[proxy]

Step 2: Start a LiteLLM proxy pointing at GLM 5.2

litellm \
  --model openai/glm-4-5 \
  --api_base https://open.bigmodel.cn/api/paas/v4 \
  --api_key YOUR_BIGMODEL_API_KEY

By default, LiteLLM starts a local server at http://localhost:4000. It exposes an Anthropic-compatible endpoint at http://localhost:4000/v1.

Step 3: Point Claude Code at the proxy

Set environment variables before launching Claude Code:

export ANTHROPIC_BASE_URL=http://localhost:4000
export ANTHROPIC_API_KEY=anything  # required by Claude Code but overridden by LiteLLM

Then start Claude Code normally:

claude

Claude Code will route its requests through LiteLLM, which translates and forwards them to GLM 5.2.

Using a config file for a persistent setup

Create ~/.litellm/config.yaml:

model_list:
  - model_name: glm-4-5
    litellm_params:
      model: openai/glm-4-5
      api_base: https://open.bigmodel.cn/api/paas/v4
      api_key: YOUR_BIGMODEL_API_KEY

general_settings:
  master_key: "sk-local-proxy"

Start LiteLLM with:

litellm --config ~/.litellm/config.yaml

Then set ANTHROPIC_BASE_URL=http://localhost:4000 in your shell profile.

Practical notes for Claude Code with GLM 5.2

  • Claude Code relies on extended thinking and multi-step planning — GLM 5.2 handles this reasonably well, but the proxy adds a small latency overhead
  • Test with a simple task first (claude "explain what this file does") before running complex agentic sessions
  • If Claude Code reports API errors, check LiteLLM’s logs first — most issues are request format mismatches that LiteLLM’s logs surface clearly

One coffee. One working app.

You bring the idea. Remy manages the project.

WHILE YOU WERE AWAY
Designed the data model
Picked an auth scheme — sessions + RBAC
Wired up Stripe checkout
Deployed to production
Live at yourapp.msagent.ai

Benchmarking Costs: GLM 5.2 vs. Frontier Models

Here’s a rough comparison based on public pricing at the time of writing:

ModelInput (per 1M tokens)Output (per 1M tokens)
GLM 5.2 (standard)~$0.14~$0.28
GPT-4o~$2.50~$10.00
Claude Sonnet 4~$3.00~$15.00
Gemini 1.5 Pro~$1.25~$5.00

A typical Cursor agentic session that makes 200 API calls with an average of 2,000 input tokens and 500 output tokens per call:

  • GLM 5.2: ~$0.08 total
  • GPT-4o: ~$1.00 total
  • Claude Sonnet 4: ~$1.50 total

For teams running agents continuously or developers doing extended daily coding sessions, those differences add up fast. If you’re running multi-agent workflows where several agents operate in parallel, cost control becomes a real architectural concern — not just a budget nicety.


Choosing When to Use GLM 5.2 vs. Frontier Models

GLM 5.2 isn’t always the right call. Here’s a practical decision framework:

Use GLM 5.2 for:

  • Routine bug fixes with clear reproduction steps
  • Adding features to existing, well-structured code
  • Writing tests for existing functions
  • Documentation and code comments
  • Refactoring within a single file or small module
  • High-volume agent tasks where cost compounds quickly

Use a frontier model for:

  • Greenfield architecture design where reasoning quality matters most
  • Debugging complex, non-obvious issues across many files
  • Tasks requiring nuanced judgment or trade-off analysis
  • Long agentic sessions where accumulated errors compound

A hybrid approach works well: configure GLM 5.2 as your default for routine coding work, and switch to a frontier model when you hit a problem that needs it. Cursor and OpenCode both make per-session model switching easy.


Where MindStudio Fits Into This

If you’re building AI agents that extend beyond the editor — automating development workflows, generating reports, sending notifications, or orchestrating multi-step pipelines — the model access pattern in MindStudio is worth knowing about.

MindStudio gives you access to 200+ models, including GLM variants, without managing API keys or separate accounts for each provider. You can build a workflow that uses GLM 5.2 for code generation tasks, routes quality-sensitive steps to a frontier model, and handles all the infrastructure (rate limiting, retries, auth) automatically.

For developers who want to expose agent capabilities to other systems, MindStudio’s Agent Skills Plugin (@mindstudio-ai/agent npm SDK) lets Claude Code, LangChain, and other agents call MindStudio’s typed capabilities as simple method calls — things like agent.runWorkflow() or agent.searchGoogle() — so the agent focuses on reasoning, not plumbing.

If you’re already thinking about which AI models work best for coding tasks, MindStudio’s model library lets you compare and switch without rebuilding your integration each time. You can try it free at mindstudio.ai.


Frequently Asked Questions

Is GLM 5.2 good enough for production coding agents?

For bounded, well-specified coding tasks — bug fixes, feature additions, test generation — GLM 5.2 performs well in production. It’s not a direct substitute for frontier models on complex architectural tasks, but it handles the majority of agentic coding work reliably at a much lower cost.

Does GLM 5.2 support function calling and tool use?

Catch up on Hermes — free 60-minute live workshop
The free Hermes Agent crash courseReserve your spot

Yes. GLM 5.2 supports function/tool calling in the same format as OpenAI’s API specification. This is critical for agent harnesses like Cursor and OpenCode, which rely on structured tool-call responses to perform actions like file edits and terminal commands.

Can I use GLM 5.2 in Claude Code without LiteLLM?

Not directly, because Claude Code uses the Anthropic Messages API format and GLM 5.2 uses the OpenAI format. LiteLLM (or a similar proxy like LiteLLM’s hosted option) is currently the most reliable translation layer. Some community-built proxies also work, but LiteLLM is the most actively maintained.

How does GLM 5.2 handle large codebases?

GLM 5.2 has a 128K token context window, which fits most individual projects. For very large monorepos, agent harnesses like Cursor use embedding-based retrieval to select relevant context rather than loading everything into the prompt — so the context window limit is less of a constraint in practice than it sounds.

Is there a rate limit on the GLM API?

Yes. Zhipu AI applies rate limits based on your account tier. Free and starter accounts have lower request-per-minute limits that can cause throttling during intensive agent sessions. If you’re running high-volume pipelines, upgrade to a higher tier or implement exponential backoff in your agent harness configuration. OpenCode’s config supports retry settings natively; for Cursor, it handles retries automatically.

Can I mix GLM 5.2 with other models in the same agent session?

In Cursor and OpenCode, model selection is per-session rather than per-task within a session. For true per-task model routing, you’d need to build that logic at the orchestration layer — which is where tools like MindStudio’s workflow builder or a custom LiteLLM configuration with multiple models becomes useful.


Key Takeaways

  • GLM 5.2 exposes an OpenAI-compatible API, making it directly configurable in Cursor and OpenCode with just a base URL and API key
  • Claude Code requires a LiteLLM proxy layer to translate between the Anthropic API format and GLM 5.2’s OpenAI format
  • At roughly one-fifth the cost of frontier models, GLM 5.2 makes sustained agentic coding sessions economically viable — especially in multi-agent or team settings
  • The model handles tool calling, large context windows (128K), and common coding tasks well; it’s less reliable on complex multi-file architectural reasoning
  • A hybrid approach — GLM 5.2 as default, frontier model as fallback — is often the most practical configuration

If you’re building workflows that go beyond the editor and need flexible model access across providers, MindStudio’s platform lets you integrate GLM 5.2 alongside 200+ other models without managing separate API credentials. Try it at mindstudio.ai.

Related Articles

AI Model Routing: When to Use Frontier Models vs Cheap Models in Your Agent Stack

Frontier models excel at imagining new tasks; cheap models execute known ones. Learn how to route intelligently and where each model tier creates real value.

LLMs & Models Workflows Optimization

What Is GLM 5.2? The Open-Weight Model With 1M Token Context for Agentic Workflows

GLM 5.2 is ZAI's flagship open-weight model with 1M token context, MCP support, and frontier-level coding at a fraction of the cost.

LLMs & Models Multi-Agent AI Concepts

How to Run GLM 5.2 in Claude Code Using OpenRouter: A 5-Minute Setup Guide

You can run GLM 5.2 inside Claude Code's harness via OpenRouter in minutes. This guide covers setup, the anthropic_base_url trick, and web search integration.

LLMs & Models Integrations Workflows

How to Use GLM 5.2 as a Backend for Your AI Agents: OpenRouter Setup Guide

Run GLM 5.2 inside Claude Code or any agent harness via OpenRouter. Step-by-step setup to cut API costs without sacrificing coding quality.

LLMs & Models Workflows Integrations

How to Set Up a Local AI Stack with Ollama, Open Web UI, and Continue in Under 2 Hours

Run your own AI stack locally with Ollama, Open Web UI, and Continue for VS Code. Full setup guide for privacy-first knowledge workers.

LLMs & Models Workflows Integrations

How to Build a Multi-Client AI Agent Architecture with Shared Skills

Manage multiple clients in one Claude Code project using context inheritance, per-client brand folders, and shared skill libraries that stay in sync.

Workflows Multi-Agent Integrations

Presented by MindStudio

No spam. Unsubscribe anytime.