GLM-5 vs Kimi K2 for Coding Agents: Context Windows, Pricing, and Long-Horizon Task Tradeoffs
GLM-5.2 ships a solid 1M-token context with 128K output and MIT-licensed 753B weights. Kimi K2.7 Code counters with 256K context, mandatory thinking, and MCP-optimized tool calling at roughly half the per-token cost. We compared specs, benchmarks, pricing, and routing strategies to help you pick the right Chinese coding model — or use both.
If you are building coding agents that need to run against Chinese-domestic API endpoints — whether for compliance, latency, or cost reasons — two model families keep coming up: GLM-5 from Z.ai (formerly Zhipu AI) and Kimi K2 from Moonshot AI. Both are open-weight, both expose OpenAI-compatible APIs, and both are explicitly optimized for long-horizon agentic engineering tasks.
The difference is in the design tradeoffs. GLM-5.2 bets everything on context scale: a solid 1M-token window with 128K max output, purpose-built for project-level codebase takeover. Kimi K2.7 Code bets on token efficiency: mandatory deep thinking with 30% fewer reasoning tokens than its predecessor, and best-in-class MCP tool invocation accuracy. Picking the right one depends on whether your bottleneck is context size or cost per agent run.
Sources: GLM-5.2 Overview — Z.ai Developer Docs, retrieved 2026-06-18; Kimi K2.7 Code Quick Start, retrieved 2026-06-18; VentureBeat: GLM-5.2 launch analysis, retrieved 2026-06-18.
TL;DR — At a Glance
| Dimension | GLM-5.2 (Z.ai) | Kimi K2.7 Code (Moonshot AI) |
|---|---|---|
| Parameters | 753B (dense) | 1T MoE, 32B active |
| Context window | 1,000,000 tokens | 256,000 tokens |
| Max output | 128,000 tokens | 65,536 tokens |
| Input / Output per 1M tokens | $1.40 / $4.40 | $0.95 / $4.00 |
| Thinking modes | Selectable (High / Max) | Mandatory (always on) |
| Tool calling | Function calling, MCP | Function calling, MCP-optimized |
| Vision input | No (text-only for 5.2) | Yes (MoonViT 400M) |
| License | MIT (unrestricted) | Modified MIT |
| SWE-bench Pro | 62.1% | 60.4% (SWE-bench Verified) |
| MCP-Atlas | 77.0 | 76.0 |
| MCP Mark Verified | — | 81.1 |
| FrontierSWE (Dominance) | 74.4% | — |
| Best for | Massive-context project takeover, long-horizon engineering | Cost-sensitive agent loops, MCP workflows, token-efficient reasoning |
What Makes Coding Agents Different
A coding agent is not a chatbot. It calls the model dozens or hundreds of times per task — reading files, planning edits, writing code, running tests, iterating on failures. The dimensions that matter most are:
- Context capacity — how much project state can the model hold in a single call?
- Output length — can the model generate a full module in one response, or does it have to chunk?
- Tool-calling reliability — does the model produce valid function calls consistently across long sessions?
- Token efficiency — how many reasoning tokens does the model burn to reach the same answer?
- Cost per agent run — total spend across a multi-step session, not just per-token price.
GLM-5.2 and Kimi K2.7 Code each optimize for different subsets of these dimensions. That is what makes them complementary rather than directly substitutable.
GLM-5.2: The 1M-Context Engineering Flagship
GLM-5.2 launched on June 13, 2026 as Z.ai's newest flagship. The model introduces IndexShare — a technique that reuses a single indexer across every four sparse attention layers, reducing per-token compute FLOPs by 2.9× at 1M context length. Key specs:
- Architecture: 753B parameters (dense). Not a MoE model — every parameter is active per token.
- Context: 1,000,000 tokens. Z.ai's docs describe this as "solid 1M" — tested to remain coherent through project-scale engineering context across multi-hour autonomous runs.
- Max output: 128,000 tokens per response. This is 2× Kimi K2.7 Code's limit, enabling full-module generation in a single call.
- Thinking modes: Selectable between "High" (balanced performance/latency) and "Max" (peak reasoning, ~85K output tokens per task). You can turn thinking off for simple operations.
- Vision: Text-only for GLM-5.2. The previous GLM-5.1 supported multimodal input via BigModel; 5.2 is code-focused.
- License: MIT — unrestricted commercial use, modification, and redistribution. No regional limitations.
- API pricing (Z.ai): $1.40 / 1M input tokens, $4.40 / 1M output tokens.
Where GLM-5.2 excels:
- Project-level codebase takeover. Feed an entire repository — backend, frontend, tests, configs, documentation — into a single context window. The model maintains module boundaries, architectural constraints, and API contracts across sustained execution.
- Long-horizon refactoring. Multi-file, multi-step engineering tasks where the model needs to hold all dependencies in context for hours. Z.ai reports 34.3% on PostTrainBench (vs GPT-5.5's 25.0%) and 13.0% on SWE-Marathon (vs GPT-5.5's 12.0%).
- SWE-bench Pro: 62.1% — beating GPT-5.5 (58.6%) and GLM-5.1 (58.4%).
- FrontierSWE (Dominance): 74.4% — surpassing GPT-5.5 (72.6%), near-tie with Claude Opus 4.8 (75.1%).
- 128K output. When you need the model to generate a complete module — not fragments — the 128K output ceiling matters. Most competitors cap at 32K–65K.
Where GLM-5.2 is more expensive:
- Per-token cost. At $1.40/$4.40, GLM-5.2 costs roughly 47% more on input than Kimi K2.7 Code ($0.95/$4.00). In high-volume agent loops with modest context usage, the premium adds up.
- Dense architecture. Every parameter is active per forward pass. This means higher compute per token than Kimi K2.7's MoE architecture (32B active out of 1T total).
- No vision input. If your agent pipeline includes screenshot-to-code workflows, GLM-5.2 cannot process images natively. Kimi K2.7 Code can.
Sources: GLM-5.2 Overview — Z.ai Developer Docs, retrieved 2026-06-18; VentureBeat: GLM-5.2 beats GPT-5.5 on long-horizon benchmarks, retrieved 2026-06-18; Fireworks.ai: GLM 5.2 day-zero launch, retrieved 2026-06-18.
Kimi K2.7 Code: The Token-Efficient MCP Specialist
K2.7 Code shipped on June 12, 2026 as Moonshot AI's coding-focused model. It shares the K2 MoE backbone but adds instruction-compliance and token-efficiency optimizations. Key specs:
- Architecture: 1T total parameters, 32B active per token (MoE). This means dramatically lower compute per token than GLM-5.2's dense 753B.
- Context: 256,000 tokens. Sufficient for most single-repository workloads, but 4× smaller than GLM-5.2's window.
- Max output: 65,536 tokens per response.
- Thinking mode: Mandatory. Cannot be disabled. Every response includes reasoning tokens. Temperature locked at 1.0, top_p at 0.95.
- Vision: MoonViT 400M encoder supports text, image, and video input.
- License: Modified MIT (open weight, commercial use with attribution).
- API pricing (Moonshot): $0.95 / 1M input tokens, $4.00 / 1M output tokens.
Where K2.7 Code excels:
- MCP tool invocation. 81.1 on MCP Mark Verified — the highest reported score among Chinese-domestic models, and higher than Claude Opus 4.8 (76.4) on this specific benchmark. If your agent framework is MCP-based, this is a material advantage.
- Token efficiency. 30% fewer reasoning tokens than K2.6 for equivalent tasks. In agent loops with 20+ turns, this compounds into significant cost savings.
- Cost per agent run. At $0.95/$4.00, K2.7 Code is the cheapest competitive coding model from a major Chinese provider. A typical 20-turn session costs ~$0.18, versus ~$0.35 on GLM-5.2 (see cost comparison below).
- HighSpeed variant. kimi-k2.7-code-highspeed delivers ~180 tokens/s (up to 260 tokens/s in short context) — useful for latency-sensitive agent loops.
- Vision input. Screenshot-to-code, video understanding, and multimodal debugging are native capabilities.
Where K2.7 Code is constrained:
- Mandatory thinking. You pay for reasoning tokens even on trivial "read this file" tool-call responses. No way to turn it off. In agent loops with many simple operations, this inflates output token count.
- Locked sampling. Temperature and top_p cannot be adjusted. This rules out deterministic output for CI/CD testing pipelines.
- Context ceiling. At 256K, K2.7 Code can handle most single-repository workloads — but cannot ingest an entire multi-project monorepo the way GLM-5.2's 1M window can.
- Max output. 65,536 tokens. For tasks that require generating a complete module in one shot, the ceiling is half of GLM-5.2's.
Sources: Kimi K2.7 Code Quick Start, retrieved 2026-06-18; Kimi K2.7 Code Pricing, retrieved 2026-06-18; AtlasCloud: Kimi K2.6 vs GLM 5.1, retrieved 2026-06-18.
The Full Model Family at a Glance
Both vendors maintain a model lineup. Here is how the coding-relevant models stack up:
| Model | Context | Max Output | Input $/M | Output $/M | Thinking | License | Released |
|---|---|---|---|---|---|---|---|
| GLM-5.2 | 1M | 128K | $1.40 | $4.40 | Selectable (High/Max) | MIT | 2026-06-13 |
| GLM-5.1 | 200K | 8K | $1.34 | $6.05 | Supported | MIT | 2026-04-09 |
| GLM-5 | 200K | 8K | $1.34 | $6.05 | Supported | MIT | 2026-02-17 |
| Kimi K2.7 Code | 256K | 65K | $0.95 | $4.00 | Mandatory | Modified MIT | 2026-06-12 |
| Kimi K2.6 | 256K | — | $1.14 | $5.40 | Optional | Open weight | 2026-04 |
| Kimi K2.5 | 256K | — | $1.14 | $5.40 | Optional | Open weight | 2026-02 |
Pricing is Z.ai and Moonshot official API pay-as-you-go rates. Sources: Z.ai Pricing, retrieved 2026-06-18; Moonshot Pricing, retrieved 2026-06-18; TheRouter models-data.ts.
Benchmark Comparison: Coding and Agentic Tasks
All numbers below are vendor-reported or from named third-party evaluators. We note where independent verification is pending. Benchmarks use different evaluation setups, so cross-vendor comparisons are directional, not absolute.
| Benchmark | GLM-5.2 | K2.7 Code | GPT-5.5 | Claude Opus 4.8 | Notes |
|---|---|---|---|---|---|
| SWE-bench Pro | 62.1% | — | 58.6% | 69.2% | Z.ai reported |
| SWE-bench Verified | — | 60.4% | — | 69.2% | Moonshot reported |
| FrontierSWE (Dominance) | 74.4% | — | 72.6% | 75.1% | Long-horizon task completion |
| MCP-Atlas | 77.0 | 76.0 | 75.3 | 77.8 | Tool-usage evaluation |
| MCP Mark Verified | — | 81.1 | 92.9 | 76.4 | Correct MCP tool invocation |
| PostTrainBench | 34.3% | — | 25.0% | — | Multi-hour engineering |
| SWE-Marathon | 13.0% | — | 12.0% | — | Extended workloads |
| Terminal-Bench 2.1 | 81.0 | — | 84.0 | 85.0 | Terminal coding tasks |
| GPQA-Diamond | 91.4% | — | — | — | Fireworks-validated reasoning |
| Kimi Code Bench v2 | — | 62.0 | 69.0 | 67.4 | Moonshot in-house benchmark |
Key takeaways:
- GLM-5.2 dominates on long-horizon benchmarks (FrontierSWE, PostTrainBench, SWE-Marathon) — tasks that run for hours, not minutes. The 1M context window gives it a structural advantage here.
- K2.7 Code leads on MCP Mark Verified (81.1 vs Opus 4.8's 76.4) — the benchmark that specifically measures correct tool invocation via MCP. This is the strongest signal for MCP-heavy agent frameworks.
- Neither model matches Claude Opus 4.8 or GPT-5.5 on raw SWE-bench scores. The gap is meaningful (~7–9 percentage points on SWE-bench Pro/Verified).
- GLM-5.2 and K2.7 Code are tested on different benchmark sets, making direct comparison difficult. SWE-bench Pro (GLM-5.2) and SWE-bench Verified (K2.7 Code) are related but not identical evaluations.
Sources: VentureBeat: GLM-5.2 benchmark analysis, retrieved 2026-06-18; Kimi K2.7 Code Quick Start — benchmarks, retrieved 2026-06-18; Fireworks.ai: GPQA-Diamond validation, retrieved 2026-06-18.
The Same Task, Two Models
Both models work with the OpenAI SDK. The only differences are base_url, api_key, and model:
GLM-5.2 via Z.ai API:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_ZAI_KEY",
base_url="https://open.bigmodel.cn/api/paas/v4/",
)
response = client.chat.completions.create(
model="glm-5.2",
messages=[
{"role": "system", "content": "You are a coding assistant."},
{"role": "user", "content": "Refactor this Django project into domain-driven modules."},
],
tools=[{
"type": "function",
"function": {
"name": "read_file",
"description": "Read a file from the project",
"parameters": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"],
},
},
}],
)
Kimi K2.7 Code via Moonshot API:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_MOONSHOT_KEY",
base_url="https://api.moonshot.ai/v1",
)
response = client.chat.completions.create(
model="kimi-k2.7-code",
messages=[
{"role": "system", "content": "You are a coding assistant."},
{"role": "user", "content": "Refactor this Django project into domain-driven modules."},
],
tools=[{
"type": "function",
"function": {
"name": "read_file",
"description": "Read a file from the project",
"parameters": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"],
},
},
}],
)
The API surface is identical. The routing decision is about context capacity, cost, and task fit — not API plumbing.
Source: Z.ai Developer Docs — API Overview, retrieved 2026-06-18; Kimi API Overview, retrieved 2026-06-18.
Cost per Coding Agent Run
Benchmarks aside, total cost per agent run is what matters in production. Here is a rough model for a typical 20-turn coding agent session (refactoring a medium-sized module):
| Cost Component | GLM-5.2 | K2.7 Code |
|---|---|---|
| Avg input tokens per turn | ~3,000 | ~3,000 |
| Avg output tokens per turn | ~1,200 (High thinking) | ~1,500 (mandatory thinking) |
| Input cost (20 turns) | 60K × $1.40/M = $0.084 | 60K × $0.95/M = $0.057 |
| Output cost (20 turns) | 24K × $4.40/M = $0.106 | 30K × $4.00/M = $0.12 |
| Total per session | ~$0.19 | ~$0.18 |
| Large-context session (200K input per turn) | 4M × $1.40/M = $5.60 input | Not feasible (256K limit) |
At modest context usage, the two models cost nearly the same per session. K2.7 Code's lower input price is offset by its mandatory thinking tokens inflating output volume.
The cost equation flips dramatically at scale:
- If your bottleneck is context size (loading entire repositories), GLM-5.2 is the only option — K2.7 Code physically cannot hold 1M tokens. You pay the premium for capability that does not exist elsewhere in the Chinese-domestic model landscape.
- If your bottleneck is volume (running thousands of modest-context agent sessions per day), K2.7 Code's lower input price ($0.95 vs $1.40) saves ~32% on input costs across the fleet.
- If you need flexible thinking, GLM-5.2's selectable modes let you skip reasoning tokens on simple turns, reducing output cost. K2.7 Code forces thinking on every response.
DashScope: Both Available on Bailian
Both model families are available through Alibaba Cloud's DashScope (Bailian) platform, which provides unified billing and a single API endpoint for multiple providers. This is particularly useful if you already use DashScope for Qwen models.
- GLM-5.1 is available via DashScope under the
glm-5.1model ID (GLM-5.2 availability on DashScope pending at time of writing). - Kimi K2.6 is available via DashScope under the
kimi-k2.6model ID.
If you use TheRouter, both Z.ai and Moonshot models are routable through our Zhipu provider integration. This means you can set up fallback chains between GLM and Kimi models without changing application code.
Note: GLM-5.2 is not yet in TheRouter's model catalog — availability will be added when verified. GLM-5/5.1 and Kimi K2.6/K2.7 Code are available. See our Zhipu GLM API complete guide and Kimi K2 API integration guide for setup details.
Decision Matrix: Pick GLM-5.2 If…
- Your codebase exceeds 256K tokens. Monorepos, multi-project workspaces, or legacy systems with extensive documentation — GLM-5.2's 1M context is the only Chinese-domestic option that holds it all.
- You need maximum output length. 128K tokens per response means full modules, not fragments. If your agent generates large files, the 2× ceiling advantage matters.
- You want flexible thinking. Toggle between High (fast) and Max (deep) reasoning. Skip thinking entirely on simple tool calls. This granularity cuts output costs in heterogeneous agent pipelines.
- You prioritize long-horizon reliability. FrontierSWE 74.4% and PostTrainBench 34.3% are the strongest long-horizon scores among open-weight models.
- You want MIT-licensed weights. No attribution requirements, no regional restrictions, full commercial freedom.
Decision Matrix: Pick K2.7 Code If…
- Budget is the primary constraint. At $0.95/M input, K2.7 Code is ~32% cheaper on input tokens. For high-volume, modest-context workloads, this compounds.
- Your agent framework uses MCP. 81.1 on MCP Mark Verified is best-in-class for Chinese-domestic models. If tool-calling accuracy is your bottleneck, K2.7 Code is measurably better.
- You need vision input. Screenshot-to-code, video understanding, and multimodal debugging are built in via MoonViT 400M. GLM-5.2 does not support image input.
- You need a HighSpeed variant. kimi-k2.7-code-highspeed at ~180 tokens/s is useful for latency-sensitive agent loops.
- You operate in China and need sub-256K context. For standard repository-scale operations, 256K is sufficient, and K2.7 Code delivers it at the lowest cost.
Routing Both Through TheRouter
For many production deployments, the answer is both models in a routing configuration:
- Primary: GLM-5.2 for tasks requiring massive context (architecture reviews, full-codebase refactoring, long-horizon autonomous runs).
- Fallback: K2.7 Code for high-volume, cost-sensitive agent loops and MCP-heavy workflows.
We route Zhipu/Z.ai models through TheRouter, which means your application code stays the same — only the routing configuration changes. See our fallback routing guide for the pattern.
You can also split by thinking requirement: route tasks needing deep reasoning to GLM-5.2 in Max mode, and route routine code generation to K2.7 Code. TheRouter supports this kind of model-level routing through configured provider priorities where supported.
Production Checklist
Before deploying either model in a coding agent pipeline:
- Test tool-calling format. Both follow the OpenAI function-calling spec, but verify your agent framework handles both models' response shapes — particularly K2.7 Code's mandatory thinking tokens in every response.
- Handle context limits. If your pipeline might exceed 256K tokens, you must use GLM-5.2 or implement chunking for K2.7 Code. Build context-length checks into your routing logic.
- Set max_tokens carefully. GLM-5.2 supports up to 128K output tokens; K2.7 Code up to 65K. Agent loops generating very long outputs will hit K2.7's limit first.
- Monitor thinking token overhead. K2.7 Code's mandatory thinking inflates every response. Track thinking vs. content tokens separately to understand true costs.
- Test sampling behavior. K2.7 Code locks temperature at 1.0 and top_p at 0.95. If your CI pipeline depends on deterministic output, use GLM-5.2 with temperature 0.
- Plan for rate limits. Both Z.ai and Moonshot have rate limits. Build retry logic with exponential backoff. DashScope provides an alternative path with its own rate-limit tiers.
- Evaluate self-hosting. Both models are open-weight. For latency-sensitive or compliance-constrained deployments, self-hosting on Fireworks, DeepInfra, or your own infrastructure is an option.
Sources
| Source | Retrieved |
|---|---|
| GLM-5.2 Overview — Z.ai Developer Docs | 2026-06-18 |
| VentureBeat: GLM-5.2 beats GPT-5.5 on long-horizon benchmarks | 2026-06-18 |
| Fireworks.ai: GLM 5.2 day-zero launch | 2026-06-18 |
| Kimi K2.7 Code Quick Start | 2026-06-18 |
| Kimi K2.7 Code Pricing | 2026-06-18 |
| AtlasCloud: Kimi K2.6 vs GLM 5.1 | 2026-06-18 |
| Z.ai API Pricing | 2026-06-18 |
| GLM-5 arXiv Paper | 2026-06-18 |