---
title: "Z.AI (Zhipu) GLM API with LiteLLM: Setup"
url: "/docs/providers/zai"
canonical_url: "https://docs.litellm.ai/docs/providers/zai"
type: "docs"
last_updated: "2026-11-24"
summary: "Call Z.AI (Zhipu AI) GLM models from glm-4.7 to the free glm-4.5-flash with streaming, per-model pricing and -latest aliases, from the SDK or AI Gateway."
related:
  - "/docs/providers/xiaomi_mimo"
  - "/docs/providers/zerogpu"
---
# Z.AI (Zhipu) GLM API with LiteLLM: Setup

> Index of all LiteLLM docs: https://docs.litellm.ai/llms.txt


Z.AI (Zhipu AI) makes the GLM model family; LiteLLM calls the GLM text and chat models with the `zai/` prefix from the Python SDK or AI Gateway.

https://z.ai/

**We support Z.AI GLM text/chat models, just set `zai/` as a prefix when sending completion requests**

## API Key
```python
# env variable
os.environ['ZAI_API_KEY']
```

## Sample Usage
```python
from litellm import completion
import os

os.environ['ZAI_API_KEY'] = ""
response = completion(
    model="zai/glm-4.7",
    messages=[
       {"role": "user", "content": "hello from litellm"}
   ],
)
print(response)
```

## Sample Usage - Streaming
```python
from litellm import completion
import os

os.environ['ZAI_API_KEY'] = ""
response = completion(
    model="zai/glm-4.7",
    messages=[
       {"role": "user", "content": "hello from litellm"}
   ],
    stream=True
)

for chunk in response:
    print(chunk)
```

## Supported Models

We support ALL Z.AI GLM models, just set `zai/` as a prefix when sending completion requests.

| Model Name | Function Call | Notes |
|------------|---------------|-------|
| glm-4.7 | `completion(model="zai/glm-4.7", messages)` | **Latest flagship**, 200K context, **Reasoning** |
| glm-4.6 | `completion(model="zai/glm-4.6", messages)` | 200K context |
| glm-4.5 | `completion(model="zai/glm-4.5", messages)` | 128K context |
| glm-4.5v | `completion(model="zai/glm-4.5v", messages)` | Vision model |
| glm-4.5-x | `completion(model="zai/glm-4.5-x", messages)` | Premium tier |
| glm-4.5-air | `completion(model="zai/glm-4.5-air", messages)` | Lightweight |
| glm-4.5-airx | `completion(model="zai/glm-4.5-airx", messages)` | Fast lightweight |
| glm-4-32b-0414-128k | `completion(model="zai/glm-4-32b-0414-128k", messages)` | 32B parameter model |
| glm-4.5-flash | `completion(model="zai/glm-4.5-flash", messages)` | **FREE tier** |

## Latest model aliases

Available in LiteLLM v1.109.0 and later.

`zai/<family>-latest` names follow a model family as LiteLLM moves them to newer models, so your application keeps one model string. Use them like any other Z.AI model name. LiteLLM sends Z.AI the current target model and bills at that model's price. See [Latest model aliases](../model_latest_aliases.md) for how aliases work and the full list across providers.

| Alias | Model family |
| --- | --- |
| `zai/glm-latest` | GLM |
| `zai/glm-flash-latest` | GLM Flash |

## Model Pricing

| Model | Input ($/1M tokens) | Output ($/1M tokens) | Cached Input ($/1M tokens) | Context Window |
|-------|---------------------|----------------------|---------------------------|----------------|
| glm-4.7 | $0.60 | $2.20 | $0.11 | 200K |
| glm-4.6 | $0.60 | $2.20 | - | 200K |
| glm-4.5 | $0.60 | $2.20 | - | 128K |
| glm-4.5v | $0.60 | $1.80 | - | 128K |
| glm-4.5-x | $2.20 | $8.90 | - | 128K |
| glm-4.5-air | $0.20 | $1.10 | - | 128K |
| glm-4.5-airx | $1.10 | $4.50 | - | 128K |
| glm-4-32b-0414-128k | $0.10 | $0.10 | - | 128K |
| glm-4.5-flash | **FREE** | **FREE** | - | 128K |

## Using with LiteLLM Proxy

**SDK**

```python
from litellm import completion
import os

os.environ['ZAI_API_KEY'] = ""
response = completion(
    model="zai/glm-4.7",
    messages=[{"role": "user", "content": "Hello, how are you?"}],
)

print(response.choices[0].message.content)
```

**PROXY**

1. Setup config.yaml

```yaml
model_list:
  - model_name: glm-4.7
    litellm_params:
        model: zai/glm-4.7
        api_key: os.environ/ZAI_API_KEY
  - model_name: glm-4.5-flash  # Free tier
    litellm_params:
        model: zai/glm-4.5-flash
        api_key: os.environ/ZAI_API_KEY
```

2. Run proxy

```bash
litellm --config config.yaml
```

3. Test it!

```bash
curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-d '{
    "model": "glm-4.7",
    "messages": [
      {
        "role": "user",
        "content": "Hello, how are you?"
      }
    ]
}'
```

## Related pages

- [Xiaomi MiMo](https://docs.litellm.ai/docs/providers/xiaomi_mimo.md)
- [ZeroGPU](https://docs.litellm.ai/docs/providers/zerogpu.md)
