Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

feat(zai): Add GLM-4.7 model with reasoning support (#18476)

cantalupo5559b1c5f7e360e
diff --git a/docs/my-website/docs/providers/zai.md b/docs/my-website/docs/providers/zai.md
index 5055d0c1cdd..937ccd67680 100644
--- a/docs/my-website/docs/providers/zai.md
+++ b/docs/my-website/docs/providers/zai.md
@@ -19,7 +19,7 @@ import os
os.environ['ZAI_API_KEY'] = ""
response = completion(
- model="zai/glm-4.6",
+ model="zai/glm-4.7",
messages=[
{"role": "user", "content": "hello from litellm"}
],
@@ -34,7 +34,7 @@ import os
os.environ['ZAI_API_KEY'] = ""
response = completion(
- model="zai/glm-4.6",
+ model="zai/glm-4.7",
messages=[
{"role": "user", "content": "hello from litellm"}
],
@@ -51,7 +51,8 @@ We support ALL Z.AI GLM models, just set `zai/` as a prefix when sending complet
| Model Name | Function Call | Notes |
|------------|---------------|-------|
-| glm-4.6 | `completion(model="zai/glm-4.6", messages)` | Latest flagship model, 200K context |
+| 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 |
@@ -62,16 +63,17 @@ We support ALL Z.AI GLM models, just set `zai/` as a prefix when sending complet
## Model Pricing
-| Model | Input ($/1M tokens) | Output ($/1M tokens) | Context Window |
-|-------|---------------------|----------------------|----------------|
-| 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 |
+| 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
@@ -84,7 +86,7 @@ import os
os.environ['ZAI_API_KEY'] = ""
response = completion(
- model="zai/glm-4.6",
+ model="zai/glm-4.7",
messages=[{"role": "user", "content": "Hello, how are you?"}],
)
@@ -98,9 +100,9 @@ print(response.choices[0].message.content)
```yaml
model_list:
- - model_name: glm-4.6
+ - model_name: glm-4.7
litellm_params:
- model: zai/glm-4.6
+ model: zai/glm-4.7
api_key: os.environ/ZAI_API_KEY
- model_name: glm-4.5-flash # Free tier
litellm_params:
@@ -121,7 +123,7 @@ curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
- "model": "glm-4.6",
+ "model": "glm-4.7",
"messages": [
{
"role": "user",
diff --git a/litellm/llms/zai/chat/transformation.py b/litellm/llms/zai/chat/transformation.py
index 47b314d4e0d..4380256f0a4 100644
--- a/litellm/llms/zai/chat/transformation.py
+++ b/litellm/llms/zai/chat/transformation.py
@@ -20,7 +20,7 @@ class ZAIChatConfig(OpenAIGPTConfig):
return api_base, dynamic_api_key
def get_supported_openai_params(self, model: str) -> list:
- return [
+ base_params = [
"max_tokens",
"stream",
"stream_options",
@@ -31,3 +31,12 @@ class ZAIChatConfig(OpenAIGPTConfig):
"tool_choice",
]
+ import litellm
+
+ try:
+ if litellm.supports_reasoning(model=model, custom_llm_provider=self.custom_llm_provider):
+ base_params.append("thinking")
+ except Exception:
+ pass
+
+ return base_params
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index c585dac9063..d32adf54b5e 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -29649,6 +29649,20 @@
"supports_vision": true,
"supports_web_search": true
},
+ "zai/glm-4.7": {
+ "cache_creation_input_token_cost": 0,
+ "cache_read_input_token_cost": 1.1e-07,
+ "input_cost_per_token": 6e-07,
+ "output_cost_per_token": 2.2e-06,
+ "litellm_provider": "zai",
+ "max_input_tokens": 200000,
+ "max_output_tokens": 128000,
+ "mode": "chat",
+ "supports_function_calling": true,
+ "supports_reasoning": true,
+ "supports_tool_choice": true,
+ "source": "https://docs.z.ai/guides/overview/pricing"
+ },
"zai/glm-4.6": {
"input_cost_per_token": 6e-07,
"output_cost_per_token": 2.2e-06,
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index df286e6540a..81b4469f24c 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -29691,6 +29691,20 @@
"supports_vision": true,
"supports_web_search": true
},
+ "zai/glm-4.7": {
+ "cache_creation_input_token_cost": 0,
+ "cache_read_input_token_cost": 1.1e-07,
+ "input_cost_per_token": 6e-07,
+ "output_cost_per_token": 2.2e-06,
+ "litellm_provider": "zai",
+ "max_input_tokens": 200000,
+ "max_output_tokens": 128000,
+ "mode": "chat",
+ "supports_function_calling": true,
+ "supports_reasoning": true,
+ "supports_tool_choice": true,
+ "source": "https://docs.z.ai/guides/overview/pricing"
+ },
"zai/glm-4.6": {
"input_cost_per_token": 6e-07,
"output_cost_per_token": 2.2e-06,
diff --git a/tests/test_litellm/llms/zai/test_zai_provider.py b/tests/test_litellm/llms/zai/test_zai_provider.py
index a3d47d666bc..d1e4359d048 100644
--- a/tests/test_litellm/llms/zai/test_zai_provider.py
+++ b/tests/test_litellm/llms/zai/test_zai_provider.py
@@ -1,6 +1,7 @@
"""
Tests for Z.AI (Zhipu AI) provider - GLM models
"""
+
import json
import math
@@ -50,10 +51,12 @@ def test_zai_in_provider_lists():
def test_zai_models_in_model_cost():
"""Test that ZAI models are in the model cost map"""
import os
+
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
litellm.model_cost = litellm.get_model_cost_map(url="")
zai_models = [
+ "zai/glm-4.7",
"zai/glm-4.6",
"zai/glm-4.5",
"zai/glm-4.5v",
@@ -72,6 +75,7 @@ def test_zai_models_in_model_cost():
def test_zai_glm46_cost_calculation():
"""Test the cost calculation for glm-4.6"""
import os
+
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
litellm.model_cost = litellm.get_model_cost_map(url="")
@@ -92,6 +96,7 @@ def test_zai_glm46_cost_calculation():
def test_zai_flash_model_is_free():
"""Test that glm-4.5-flash has zero cost"""
import os
+
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
litellm.model_cost = litellm.get_model_cost_map(url="")
@@ -102,6 +107,38 @@ def test_zai_flash_model_is_free():
assert info["output_cost_per_token"] == 0
+def test_glm47_supports_reasoning():
+ """Test that GLM-4.7 supports reasoning"""
+ import os
+
+ os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
+ litellm.model_cost = litellm.get_model_cost_map(url="")
+
+ key = "zai/glm-4.7"
+ assert key in litellm.model_cost, f"Model {key} not found in model_cost"
+
+ info = litellm.model_cost[key]
+ assert info["supports_reasoning"] is True
+
+
+def test_glm47_cost_calculation():
+ """Test cost calculation for GLM-4.7"""
+ import os
+
+ os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
+ litellm.model_cost = litellm.get_model_cost_map(url="")
+
+ prompt_cost, completion_cost = cost_per_token(
+ model="zai/glm-4.7",
+ prompt_tokens=1000000, # 1M tokens
+ completion_tokens=1000000,
+ )
+
+ # GLM-4.7: $0.6/M input, $2.2/M output (same as GLM-4.6)
+ assert math.isclose(prompt_cost, 0.6, rel_tol=1e-6)
+ assert math.isclose(completion_cost, 2.2, rel_tol=1e-6)
+
+
@pytest.mark.asyncio
async def test_zai_completion_call(respx_mock, zai_response, monkeypatch):
"""Test completion call with zai provider using mocked response"""