# Z.AI (Zhipu AI) Provider Reference

## Overview

Z.AI is Zhipu AI's international platform. Serves the GLM model family (text, vision, video, audio). OpenAI-compatible API.

## API Endpoint

**International:** `https://api.z.ai/api/paas/v4`
**Chinese domestic:** `https://open.bigmodel.cn/api/paas/v4`

Keys from one do NOT work on the other.

## API Key Format

`<64-char-hex>.<20-char-alphanumeric>`
Example: `f8d3ebd892ea4d879e39f9d9e14ee799.b83BuhZJAGCL18z9`

Store in `.env` as `Z_AI_API_KEY`.

## Available Models

### Flagship Models (paid, need balance)

| Model | Context | Input (¥/M) | Output (¥/M) |
|---|---|---|---|
| `glm-5.2` | 1M | 8 | 28 |
| `glm-5.1` | 128K | 6-8 | 24-28 |
| `glm-5-turbo` | 128K | 5-7 | 22-26 |
| `glm-5` | 128K | 4-6 | 18-22 |
| `glm-4.7` | 128K | 2-4 | 8-16 |
| `glm-4.5-air` | 128K | 0.8-1.2 | 2-8 |

### Flash Models (fast, lower cost)

| Model | Context | Input | Output |
|---|---|---|---|
| `glm-4.7-flash` | 200K | **Free** | **Free** |
| `glm-4.7-flashx` | 200K | ¥0.50/M | ¥3.00/M |

**Note:** Flash/FlashX do NOT appear in the `/models` endpoint listing but ARE callable directly.

## Pricing Notes

- GLM-5.2 and GLM-5-Turbo consume "3× standard rate during peak hours, 2× during off-peak hours" on coding plans
- Cache storage: temporarily free for all models
- Cache hit pricing: ¥0.10-2.00/M depending on model
- GLM-4.7 pricing is tiered by input length (<32K tokens vs 32K+) and output length (<200 tokens vs 200+)

## Billing / Top-up

1. Go to https://z.ai and sign in
2. Navigate to Billing page: https://z.ai/billing
3. Add credits

## Config Block

```yaml
  z-ai:
    base_url: https://api.z.ai/api/paas/v4
    api_key_env: Z_AI_API_KEY
    models:
      glm-4.7-flash:
        max_input_tokens: 204800
        max_output_tokens: 16384
      glm-4.7-flashx:
        max_input_tokens: 204800
        max_output_tokens: 16384
```

## Model Capability Mapping (from Z.AI docs)

- **GLM-4.7** ≈ Claude Sonnet-class — daily development, routine tasks
- **GLM-5.2 / GLM-5-Turbo** ≈ Claude Opus-class — complex reasoning, large engineering tasks
