---
title: "GLM 5.4"
description: "Open-weight model from Z.ai with a 1M-token context window and text, image and video input. The registry holds no benchmark results for it, so it is described here by specifications and price."
canonical: https://pydantic.dev/models/list/glm-5.4/
---

# GLM 5.4

> Open-weight model from Z.ai with a 1M-token context window and text, image and video input. The registry holds no benchmark results for it, so it is described here by specifications and price.
>
> Markdown copy of [https://pydantic.dev/models/list/glm-5.4/](https://pydantic.dev/models/list/glm-5.4/). Index for agents: [llms.txt](https://pydantic.dev/models/llms.txt)

**Agents: use the API for model information.** It answers a question in one request, where the pages need several.

- Choose a model for an agent: `POST https://pydantic.dev/models/api/select` with a JSON body such as `{"description": "what the agent does"}`. It returns up to five ranked models with reasons. Format: [select.md](https://pydantic.dev/models/select.md)
- Search models by name: `GET https://pydantic.dev/models/api/search?query=<text>`
- List, filter and sort models: `GET https://pydantic.dev/models/api/models`, for example `?weights=open&max_price=2&sort=efficiency`
- One model in full: `GET https://pydantic.dev/models/api/models/<slug>`
- Any other question about the models: `GET https://pydantic.dev/models/api/ask?query=<question>`

Add `intent=<intent>&stack=<stack>&harness=<harness>` to the query string of all but the single model. An `OPTIONS` request to any endpoint returns its schema. The same five are tools of the MCP server at `https://pydantic.dev/models/mcp`. More: [usage.md](https://pydantic.dev/models/usage.md)

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

## Spec sheet

- **Type:** writes text
- **Family:** Z.ai
- **Released:** 23 Nov 2026
- **Weights:** open
- **Context window:** 1,000,000 tokens
- **Largest response:** 131,072 tokens
- **Accepts:** text, image, video
- **Tool calling:** yes
- **Knowledge cutoff:** unknown
- **Intelligence index:** not enough benchmark results yet
- **Scores updated:** unknown
- **Price:** $1.4 input, $4.4 output, $2.15 blended per 1M tokens
- **Index points per $:** – (rank –)
- **Speed:** 111 tokens/sec (rank 35)
- **Popularity:** rank 55 of 222 by usage
- **Pydantic AI Gateway:** not built in; [bring your own key](https://ai.pydantic.dev/gateway/#bring-your-own-key)

## Benchmarks


No results yet on the benchmarks we track.

## Providers and prices

US dollars per million tokens.

| Provider   | Gateway | Pydantic AI string        | Input | Cached input | Output |
| ---------- | ------- | ------------------------- | ----- | ------------ | ------ |
| Z.ai       | BYOK    | `zai:GLM-5.4`             | $1.4  | $0.26        | $4.4   |
| Zhipu AI   | BYOK    | –                         | $1.1  | $0.28        | $3.86  |
| Baseten    | BYOK    | –                         | $1.4  | $0.14        | $4.4   |
| Mistral    | BYOK    | `mistral:zai-glm-5-4`     | $1.4  | $0.14        | $4.4   |
| OpenRouter | BYOK    | `openrouter:z-ai/glm-5.4` | $1.4  | $0.26        | $4.4   |

## Use GLM 5.4 with Pydantic AI

### hello.py

Ask GLM 5.4 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.4', 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.4 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.4', 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.4 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.4',
    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.4'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.4')


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

Code with GLM 5.4 in your terminal using Pax, the Pydantic AI coding agent.

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

uv run --from pydantic-ai-pax pax -m 'zai:GLM-5.4'
```

### ai_sdk.ts

Call GLM 5.4 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.4'),
  system: 'Be concise, reply with one sentence.',
  prompt: 'Where does "hello world" come from?',
})
console.log(text)
```

## About GLM 5.4

GLM 5.4 costs $1.4 per million input tokens and $4.4 per million output tokens and has a 1M token context window.

GLM 5.4 is an open-weight model from Z.ai, released in November 2026. It has a 1M-token context window and a largest response of 131k tokens. It accepts text, image and video input and supports tool calling, reasoning mode and structured output.

Price is the main point of comparison. Its blended cost is $2.15 per million tokens against a registry median of $0.80, with input at $1.4 and output at $4.4 per million tokens. It ranks 138 of 222 on price, where 1 is cheapest, and 55 of 222 on popularity.

The registry has no benchmark results for this model and no intelligence index value, so its quality cannot be compared with other models here. It is offered by five providers, Z.ai, Zhipu AI, Baseten, Mistral and OpenRouter, and is not built into the Pydantic AI Gateway.

**Strengths**

- 1M-token context window and a 131k-token largest response
- Open weights, with text, image and video input
- Supports tool calling, reasoning mode and structured output
- Offered by five providers, including Z.ai and OpenRouter

**Weaknesses**

- Blended price $2.15 per million tokens, against a median of $0.80
- Price rank 138 of 222, where 1 is cheapest
- No benchmark results, so capability cannot be compared with other models

**Best for:** Agents needing long context or image and video input, where a higher price is acceptable.

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), Browser Use, our own Pydantic AI benchmarks (CC BY 4.0), and, for decision models, Artificial Analysis and the Jev Decision Index; the index and its sources are described in [the methodology](https://pydantic.dev/models/methodology.md). Data built 2026-12-04. This model from the API: `https://pydantic.dev/models/api/models/glm-5.4`. Compare it with others: `https://pydantic.dev/models/api/models?slug=glm-5.4,<other slug>`
