# GLM 5

> An open-weights model from Z.ai, released February 2026, with tool calling and structured output. Its clearest result is on Terminal-Bench, while math and abstract reasoning trail the registry.

Use it with Pydantic AI as `zai:GLM-5`.

## Spec sheet

- **Family:** Z.ai
- **Released:** 12 Feb 2026
- **Weights:** open
- **Context window:** 200,000 tokens
- **Largest response:** 131,072 tokens
- **Accepts:** text
- **Tool calling:** yes
- **Knowledge cutoff:** unknown
- **Intelligence index:** 54.5 (rank 67)
- **Price:** $1 input, $3.2 output, $1.55 blended per 1M tokens
- **Index points per $:** 35.2 (rank 59)
- **Speed:** 45.5 tokens/sec (rank 134)
- **Popularity:** rank 94 of 194 by usage
- **Pydantic AI Gateway:** not built in; [bring your own key](https://ai.pydantic.dev/gateway/#bring-your-own-key)

## Benchmarks

| Benchmark | Score | Rank among models tested | What it measures | Source |
| --- | --- | --- | --- | --- |
| Intelligence index | 54.5 | 70 | Our composite of the benchmarks below, 0-100 | Pydantic, from the sources credited below |
| GPQA Diamond | 87.8% | 59 | Graduate-level science questions, multiple choice | Epoch AI (CC BY 4.0) |
| OTIS Mock AIME | 80% | 81 | Competition mathematics problems with exact answers | Epoch AI (CC BY 4.0) |
| ARC-AGI-2 | 4.9% | 59 | Abstract visual puzzles that test learning a new rule from a few examples | ARC Prize, via Epoch AI (CC BY 4.0) |
| SWE-bench Verified | 72.1% | 18 | Real GitHub issues resolved, run by Epoch with one fixed scaffold | Epoch AI (CC BY 4.0) |
| Terminal-Bench | 52.4% | 13 | Tasks completed in a terminal; the best result of any agent using the model | Terminal-Bench, via Epoch AI (CC BY 4.0) |
| WebDev Arena | 1435.9 | 56 | Rating from human votes on web apps the models built | LMArena, via Epoch AI (CC BY 4.0) |
| LMArena text | 1445.9 | 45 | Rating from blind human votes between pairs of chat responses | LMArena (CC BY 4.0) |
| Epoch Capabilities Index | 146.5 | 77 | Epoch AI's own composite across about 40 benchmarks; shown for comparison, not part of our index | Epoch AI (CC BY 4.0) |

## Providers and prices

US dollars per million tokens.

| Provider | Gateway | Pydantic AI string | Input | Cached input | Output |
| --- | --- | --- | --- | --- | --- |
| Z.ai | BYOK | `zai:GLM-5` | $1 | $0.2 | $3.2 |
| Zhipu AI | BYOK | – | $0.55 | $0.14 | $2.48 |
| Novita | BYOK | – | $1 | $0.2 | $3.2 |
| OpenRouter | BYOK | `openrouter:z-ai/glm-5` | $1 | $0.2 | $3.2 |

## Example code

### hello.py

Ask GLM 5 a question with a Pydantic AI agent and print the answer. Run it with uv run hello.py.

```python
# /// script
# dependencies = ["pydantic-ai"]
# ///
import os

from pydantic_ai import Agent

os.environ['ZAI_API_KEY'] = '...'

agent = Agent('zai:GLM-5', instructions='Be concise, reply with one sentence.')

result = agent.run_sync('Where does "hello world" come from?')
print(result.output)
```

### structured_output.py

Get validated, typed output from GLM 5 by giving the agent a Pydantic model. Run it with uv run structured_output.py.

```python
# /// script
# dependencies = ["pydantic-ai"]
# ///
import os

from pydantic import BaseModel
from pydantic_ai import Agent

os.environ['ZAI_API_KEY'] = '...'


class CityLocation(BaseModel):
    city: str
    country: str


agent = Agent('zai:GLM-5', output_type=CityLocation)

result = agent.run_sync('Where were the olympics held in 2012?')
print(result.output)
#> city='London' country='United Kingdom'
```

### tools.py

Give GLM 5 two tools to call, one of which reads the agent's dependencies. Run it with uv run tools.py.

```python
# /// script
# dependencies = ["pydantic-ai"]
# ///
import os
import random

from pydantic_ai import Agent, RunContext

os.environ['ZAI_API_KEY'] = '...'

agent = Agent(
    'zai:GLM-5',
    deps_type=str,
    instructions="You're a dice game, roll the die and see if it matches the user's guess.",
)


@agent.tool_plain
def roll_dice() -> str:
    """Roll a six-sided die and return the result."""
    return str(random.randint(1, 6))


@agent.tool
def get_player_name(ctx: RunContext[str]) -> str:
    """Get the player's name."""
    return ctx.deps


result = agent.run_sync('My guess is 4', deps='Anne')
print(result.output)
```

### streaming.py

Stream GLM 5's reply to the terminal as it is generated. Run it with uv run streaming.py.

```python
# /// script
# dependencies = ["pydantic-ai"]
# ///
import asyncio
import os

from pydantic_ai import Agent

os.environ['ZAI_API_KEY'] = '...'

agent = Agent('zai:GLM-5')


async def main():
    async with agent.run_stream('Explain prompt caching in three bullet points.') as response:
        async for text in response.stream_text(delta=True):
            print(text, end='', flush=True)


asyncio.run(main())
```

### pax.sh

Chat with GLM 5 in your terminal using pax, the TUI for pydantic-ai-harness. Coming soon.

```sh
export ZAI_API_KEY='...'

uvx pax --model 'zai:GLM-5'
```

### pi.sh

Use GLM 5 as the model behind the pi coding agent, with your own Z.ai key.

```sh
# npm install -g @earendil-works/pi-coding-agent
export ZAI_API_KEY='...'

pi --model 'zai/GLM-5'
```

### ai_sdk.ts

Call GLM 5 from TypeScript with the Vercel AI SDK.

```ts
// npm install ai @ai-sdk/openai-compatible
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { generateText } from 'ai'

process.env.ZAI_API_KEY = '...'

const zai = createOpenAICompatible({
  name: 'zai',
  baseURL: 'https://api.zai.example/v1',
  apiKey: process.env.ZAI_API_KEY,
})

const { text } = await generateText({
  model: zai('GLM-5'),
  system: 'Be concise, reply with one sentence.',
  prompt: 'Where does "hello world" come from?',
})
console.log(text)
```

## About GLM 5

GLM 5 is an open-weights text model from Z.ai, released February 2026. It has a 200k context window, up to 131k output tokens, and supports tool calling, reasoning mode and structured output. Input costs $1 per million tokens and output $3.20, giving a blended price of $1.55, above the registry median of $1.01.

Its intelligence index of 54.5 ranks 70th of 114, below the median of 59.5. Terminal-Bench is its clearest strength at 52.4%, 13th of 35, and its LMArena text rating sits just above the median. Math and abstract reasoning lag behind: OTIS Mock AIME is at 80% and ARC-AGI-2 at 4.9%, both near the bottom of the registry.

The model is served by Z.ai, Zhipu AI, Novita and OpenRouter. It is a reasonable fit for agent workloads centred on tool use and terminal work, rather than on hard mathematical or abstract reasoning.

**Strengths**

- 52.4% on Terminal-Bench, 13th of 35, above the 43.2% median
- 1445.9 on LMArena text, 45th of 114, just above the median
- Open weights, with a 200k context window and 131k maximum output
- Supports tool calling, reasoning mode and structured output

**Weaknesses**

- 4.9% on ARC-AGI-2, 59th of 68, far below the 61.3% median
- 80.0% on OTIS Mock AIME, 81st of 95, below the 94.2% median
- Blended price of $1.55 per million tokens, above the $1.01 median

**Best for:** Agents running terminal tasks with tool calling and structured output, where math and abstract reasoning matter less.

Prices come from [genai-prices](https://github.com/pydantic/genai-prices), in US dollars per million tokens. Benchmark scores come from Epoch AI and LMArena (CC BY 4.0); the index and its sources are described at https://models.pydantic.dev/methodology.md. Data built 2026-11-25. Compare with other models: https://models.pydantic.dev/models.md
