Back to Mastra

Z.AI Coding Plan | Models

docs/src/content/en/models/providers/zai-coding-plan.mdx

2025-12-184.8 KB
Original Source

Z.AI Coding Plan

Access 11 Z.AI Coding Plan models through Mastra's model router. Authentication is handled automatically using the ZHIPU_API_KEY environment variable.

Learn more in the Z.AI Coding Plan documentation.

bash
ZHIPU_API_KEY=your-api-key
typescript
import { Agent } from "@mastra/core/agent";

const agent = new Agent({
  id: "my-agent",
  name: "My Agent",
  instructions: "You are a helpful assistant",
  model: "zai-coding-plan/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 Z.AI Coding Plan documentation for details.

:::

Models

<ProviderModelsTable models={[ { "model": "zai-coding-plan/glm-4.5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 98304, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-4.5-air", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 98304, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-4.5-flash", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 98304, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-4.5v", "imageInput": true, "audioInput": false, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 64000, "maxOutput": 16384, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-4.6", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 204800, "maxOutput": 131072, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-4.6v", "imageInput": true, "audioInput": false, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 128000, "maxOutput": 32768, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-4.7", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 204800, "maxOutput": 131072, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-4.7-flash", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 131072, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-4.7-flashx", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 131072, "inputCost": 0.07, "outputCost": 0.4 }, { "model": "zai-coding-plan/glm-5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 204800, "maxOutput": 131072, "inputCost": null, "outputCost": null }, { "model": "zai-coding-plan/glm-5-turbo", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 131072, "inputCost": null, "outputCost": null } ]} />

Advanced configuration

Custom headers

typescript
const agent = new Agent({
  id: "custom-agent",
  name: "custom-agent",
  model: {
    url: "https://api.z.ai/api/coding/paas/v4",
    id: "zai-coding-plan/glm-4.5",
    apiKey: process.env.ZHIPU_API_KEY,
    headers: {
      "X-Custom-Header": "value"
    }
  }
});

Dynamic model selection

typescript
const agent = new Agent({
  id: "dynamic-agent",
  name: "Dynamic Agent",
  model: ({ requestContext }) => {
    const useAdvanced = requestContext.task === "complex";
    return useAdvanced
      ? "zai-coding-plan/glm-5-turbo"
      : "zai-coding-plan/glm-4.5";
  }
});