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]

Add support to zai glm-4.7 model in Vertex (#18782)

Emerson Gomes6c00f6f342cc
diff --git a/litellm/__init__.py b/litellm/__init__.py
index 1bc690e561f..77e487fca24 100644
--- a/litellm/__init__.py
+++ b/litellm/__init__.py
@@ -486,6 +486,7 @@ vertex_mistral_models: Set = set()
vertex_openai_models: Set = set()
vertex_minimax_models: Set = set()
vertex_moonshot_models: Set = set()
+vertex_zai_models: Set = set()
ai21_models: Set = set()
ai21_chat_models: Set = set()
nlp_cloud_models: Set = set()
@@ -664,6 +665,9 @@ def add_known_models():
elif value.get("litellm_provider") == "vertex_ai-moonshot_models":
key = key.replace("vertex_ai/", "")
vertex_moonshot_models.add(key)
+ elif value.get("litellm_provider") == "vertex_ai-zai_models":
+ key = key.replace("vertex_ai/", "")
+ vertex_zai_models.add(key)
elif value.get("litellm_provider") == "ai21":
if value.get("mode") == "chat":
ai21_chat_models.add(key)
@@ -950,7 +954,8 @@ models_by_provider: dict = {
| vertex_language_models
| vertex_deepseek_models
| vertex_minimax_models
- | vertex_moonshot_models,
+ | vertex_moonshot_models
+ | vertex_zai_models,
"ai21": ai21_models,
"bedrock": bedrock_models | bedrock_converse_models,
"petals": petals_models,
diff --git a/litellm/llms/openai/chat/gpt_transformation.py b/litellm/llms/openai/chat/gpt_transformation.py
index 034ccae94ad..04a10bd7fbe 100644
--- a/litellm/llms/openai/chat/gpt_transformation.py
+++ b/litellm/llms/openai/chat/gpt_transformation.py
@@ -771,9 +771,9 @@ class OpenAIChatCompletionStreamingHandler(BaseModelResponseIterator):
return ModelResponseStream(
id=chunk["id"],
object="chat.completion.chunk",
- created=chunk["created"],
- model=chunk["model"],
- choices=chunk["choices"],
+ created=chunk.get("created"),
+ model=chunk.get("model"),
+ choices=chunk.get("choices", []),
)
except Exception as e:
raise e
diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/main.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/main.py
index 712a06dece1..123d925f7c1 100644
--- a/litellm/llms/vertex_ai/vertex_ai_partner_models/main.py
+++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/main.py
@@ -40,6 +40,7 @@ class PartnerModelPrefixes(str, Enum):
GPT_OSS_PREFIX = "openai/gpt-oss-"
MINIMAX_PREFIX = "minimaxai/"
MOONSHOT_PREFIX = "moonshotai/"
+ ZAI_PREFIX = "zai-org/"
class VertexAIPartnerModels(VertexBase):
@@ -66,6 +67,7 @@ class VertexAIPartnerModels(VertexBase):
or model.startswith(PartnerModelPrefixes.GPT_OSS_PREFIX)
or model.startswith(PartnerModelPrefixes.MINIMAX_PREFIX)
or model.startswith(PartnerModelPrefixes.MOONSHOT_PREFIX)
+ or model.startswith(PartnerModelPrefixes.ZAI_PREFIX)
):
return True
return False
@@ -79,6 +81,7 @@ class VertexAIPartnerModels(VertexBase):
PartnerModelPrefixes.GPT_OSS_PREFIX,
PartnerModelPrefixes.MINIMAX_PREFIX,
PartnerModelPrefixes.MOONSHOT_PREFIX,
+ PartnerModelPrefixes.ZAI_PREFIX,
]
if any(provider in model for provider in OPENAI_LIKE_VERTEX_PROVIDERS):
return True
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index fb00f636409..73579db75cd 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -28345,6 +28345,19 @@
"supports_tool_choice": true,
"supports_web_search": true
},
+ "vertex_ai/zai-org/glm-4.7-maas": {
+ "input_cost_per_token": 3e-07,
+ "litellm_provider": "vertex_ai-zai_models",
+ "max_input_tokens": 200000,
+ "max_output_tokens": 128000,
+ "max_tokens": 128000,
+ "mode": "chat",
+ "output_cost_per_token": 1.2e-06,
+ "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models",
+ "supports_function_calling": true,
+ "supports_reasoning": true,
+ "supports_tool_choice": true
+ },
"vertex_ai/mistral-medium-3": {
"input_cost_per_token": 4e-07,
"litellm_provider": "vertex_ai-mistral_models",
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index fb00f636409..73579db75cd 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -28345,6 +28345,19 @@
"supports_tool_choice": true,
"supports_web_search": true
},
+ "vertex_ai/zai-org/glm-4.7-maas": {
+ "input_cost_per_token": 3e-07,
+ "litellm_provider": "vertex_ai-zai_models",
+ "max_input_tokens": 200000,
+ "max_output_tokens": 128000,
+ "max_tokens": 128000,
+ "mode": "chat",
+ "output_cost_per_token": 1.2e-06,
+ "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models",
+ "supports_function_calling": true,
+ "supports_reasoning": true,
+ "supports_tool_choice": true
+ },
"vertex_ai/mistral-medium-3": {
"input_cost_per_token": 4e-07,
"litellm_provider": "vertex_ai-mistral_models",
diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
index 591b33911dc..b5637db3e52 100644
--- a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
+++ b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
@@ -1175,6 +1175,30 @@ def test_vertex_ai_moonshot_uses_openai_handler():
)
+def test_vertex_ai_zai_uses_openai_handler():
+ """
+ Ensure ZAI partner models re-use the OpenAI-format handler.
+ """
+ from litellm.llms.vertex_ai.vertex_ai_partner_models.main import (
+ VertexAIPartnerModels,
+ )
+
+ assert VertexAIPartnerModels.should_use_openai_handler(
+ "zai-org/glm-4.7-maas"
+ )
+
+
+def test_vertex_ai_zai_is_partner_model():
+ """
+ Ensure ZAI models are detected as Vertex AI partner models.
+ """
+ from litellm.llms.vertex_ai.vertex_ai_partner_models.main import (
+ VertexAIPartnerModels,
+ )
+
+ assert VertexAIPartnerModels.is_vertex_partner_model("zai-org/glm-4.7-maas")
+
+
def test_build_vertex_schema_empty_properties():
"""
Test _build_vertex_schema handles empty properties objects correctly.