# <img src="https://models.dev/logos/zhipuai.svg" alt="Zhipu AI logo" className="inline w-8 h-8 mr-2 align-middle dark:invert dark:brightness-0 dark:contrast-200" />Zhipu AI
[EN] Source: https://mastra.ai/models/providers/zhipuai

Access 5 Zhipu AI models through Mastra's model router. Authentication is handled automatically using the `ZHIPU_API_KEY` environment variable.

Learn more in the [Zhipu AI documentation](https://docs.z.ai/guides/overview/pricing).

```bash
ZHIPU_API_KEY=your-api-key
```

```typescript
import { Agent } from "@mastra/core";

const agent = new Agent({
  name: "my-agent",
  instructions: "You are a helpful assistant",
  model: "zhipuai/glm-4.5"
});

// Generate a response
const response = await agent.generate("Hello!");

// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
  console.log(chunk);
}
```

:::info

Mastra uses the OpenAI-compatible `/chat/completions` endpoint. Some provider-specific features may not be available. Check the [Zhipu AI documentation](https://docs.z.ai/guides/overview/pricing) for details.

:::

## Models

<ProviderModelsTable
  models={[
  {
    "model": "zhipuai/glm-4.5",
    "imageInput": false,
    "audioInput": false,
    "videoInput": false,
    "toolUsage": true,
    "reasoning": true,
    "contextWindow": 131072,
    "maxOutput": 98304,
    "inputCost": 0.6,
    "outputCost": 2.2
  },
  {
    "model": "zhipuai/glm-4.5-air",
    "imageInput": false,
    "audioInput": false,
    "videoInput": false,
    "toolUsage": true,
    "reasoning": true,
    "contextWindow": 131072,
    "maxOutput": 98304,
    "inputCost": 0.2,
    "outputCost": 1.1
  },
  {
    "model": "zhipuai/glm-4.5-flash",
    "imageInput": false,
    "audioInput": false,
    "videoInput": false,
    "toolUsage": true,
    "reasoning": true,
    "contextWindow": 131072,
    "maxOutput": 98304,
    "inputCost": null,
    "outputCost": null
  },
  {
    "model": "zhipuai/glm-4.5v",
    "imageInput": true,
    "audioInput": false,
    "videoInput": true,
    "toolUsage": true,
    "reasoning": true,
    "contextWindow": 64000,
    "maxOutput": 16384,
    "inputCost": 0.6,
    "outputCost": 1.8
  },
  {
    "model": "zhipuai/glm-4.6",
    "imageInput": false,
    "audioInput": false,
    "videoInput": false,
    "toolUsage": true,
    "reasoning": true,
    "contextWindow": 204800,
    "maxOutput": 131072,
    "inputCost": 0.6,
    "outputCost": 2.2
  }
]}
/>

## Advanced Configuration

### Custom Headers

```typescript
const agent = new Agent({
  name: "custom-agent",
  model: {
    url: "https://open.bigmodel.cn/api/paas/v4",
    id: "zhipuai/glm-4.5",
    apiKey: process.env.ZHIPU_API_KEY,
    headers: {
      "X-Custom-Header": "value"
    }
  }
});
```

### Dynamic Model Selection

```typescript
const agent = new Agent({
  name: "dynamic-agent",
  model: ({ runtimeContext }) => {
    const useAdvanced = runtimeContext.task === "complex";
    return useAdvanced
      ? "zhipuai/glm-4.6"
      : "zhipuai/glm-4.5";
  }
});
```




---
title: "Reference: Agent Class | Agents"
description: "Documentation for the `Agent` class in Mastra, which provides the foundation for creating AI agents with various capabilities."
---