Skip to content

Commit 6c00f6f

Browse files
authored
Add support to zai glm-4.7 model in Vertex (BerriAI#18782)
* Add support to zai glm-4.7 model in Vertex * Avoid failed on missing 'created' streaming chunk key
1 parent 2f80317 commit 6c00f6f

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

litellm/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ def identify(event_details):
486486
vertex_openai_models: Set = set()
487487
vertex_minimax_models: Set = set()
488488
vertex_moonshot_models: Set = set()
489+
vertex_zai_models: Set = set()
489490
ai21_models: Set = set()
490491
ai21_chat_models: Set = set()
491492
nlp_cloud_models: Set = set()
@@ -664,6 +665,9 @@ def add_known_models():
664665
elif value.get("litellm_provider") == "vertex_ai-moonshot_models":
665666
key = key.replace("vertex_ai/", "")
666667
vertex_moonshot_models.add(key)
668+
elif value.get("litellm_provider") == "vertex_ai-zai_models":
669+
key = key.replace("vertex_ai/", "")
670+
vertex_zai_models.add(key)
667671
elif value.get("litellm_provider") == "ai21":
668672
if value.get("mode") == "chat":
669673
ai21_chat_models.add(key)
@@ -950,7 +954,8 @@ def add_known_models():
950954
| vertex_language_models
951955
| vertex_deepseek_models
952956
| vertex_minimax_models
953-
| vertex_moonshot_models,
957+
| vertex_moonshot_models
958+
| vertex_zai_models,
954959
"ai21": ai21_models,
955960
"bedrock": bedrock_models | bedrock_converse_models,
956961
"petals": petals_models,

litellm/llms/openai/chat/gpt_transformation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,9 @@ def chunk_parser(self, chunk: dict) -> ModelResponseStream:
771771
return ModelResponseStream(
772772
id=chunk["id"],
773773
object="chat.completion.chunk",
774-
created=chunk["created"],
775-
model=chunk["model"],
776-
choices=chunk["choices"],
774+
created=chunk.get("created"),
775+
model=chunk.get("model"),
776+
choices=chunk.get("choices", []),
777777
)
778778
except Exception as e:
779779
raise e

litellm/llms/vertex_ai/vertex_ai_partner_models/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class PartnerModelPrefixes(str, Enum):
4040
GPT_OSS_PREFIX = "openai/gpt-oss-"
4141
MINIMAX_PREFIX = "minimaxai/"
4242
MOONSHOT_PREFIX = "moonshotai/"
43+
ZAI_PREFIX = "zai-org/"
4344

4445

4546
class VertexAIPartnerModels(VertexBase):
@@ -66,6 +67,7 @@ def is_vertex_partner_model(model: str):
6667
or model.startswith(PartnerModelPrefixes.GPT_OSS_PREFIX)
6768
or model.startswith(PartnerModelPrefixes.MINIMAX_PREFIX)
6869
or model.startswith(PartnerModelPrefixes.MOONSHOT_PREFIX)
70+
or model.startswith(PartnerModelPrefixes.ZAI_PREFIX)
6971
):
7072
return True
7173
return False
@@ -79,6 +81,7 @@ def should_use_openai_handler(model: str):
7981
PartnerModelPrefixes.GPT_OSS_PREFIX,
8082
PartnerModelPrefixes.MINIMAX_PREFIX,
8183
PartnerModelPrefixes.MOONSHOT_PREFIX,
84+
PartnerModelPrefixes.ZAI_PREFIX,
8285
]
8386
if any(provider in model for provider in OPENAI_LIKE_VERTEX_PROVIDERS):
8487
return True

litellm/model_prices_and_context_window_backup.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28345,6 +28345,19 @@
2834528345
"supports_tool_choice": true,
2834628346
"supports_web_search": true
2834728347
},
28348+
"vertex_ai/zai-org/glm-4.7-maas": {
28349+
"input_cost_per_token": 3e-07,
28350+
"litellm_provider": "vertex_ai-zai_models",
28351+
"max_input_tokens": 200000,
28352+
"max_output_tokens": 128000,
28353+
"max_tokens": 128000,
28354+
"mode": "chat",
28355+
"output_cost_per_token": 1.2e-06,
28356+
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models",
28357+
"supports_function_calling": true,
28358+
"supports_reasoning": true,
28359+
"supports_tool_choice": true
28360+
},
2834828361
"vertex_ai/mistral-medium-3": {
2834928362
"input_cost_per_token": 4e-07,
2835028363
"litellm_provider": "vertex_ai-mistral_models",

model_prices_and_context_window.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28345,6 +28345,19 @@
2834528345
"supports_tool_choice": true,
2834628346
"supports_web_search": true
2834728347
},
28348+
"vertex_ai/zai-org/glm-4.7-maas": {
28349+
"input_cost_per_token": 3e-07,
28350+
"litellm_provider": "vertex_ai-zai_models",
28351+
"max_input_tokens": 200000,
28352+
"max_output_tokens": 128000,
28353+
"max_tokens": 128000,
28354+
"mode": "chat",
28355+
"output_cost_per_token": 1.2e-06,
28356+
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models",
28357+
"supports_function_calling": true,
28358+
"supports_reasoning": true,
28359+
"supports_tool_choice": true
28360+
},
2834828361
"vertex_ai/mistral-medium-3": {
2834928362
"input_cost_per_token": 4e-07,
2835028363
"litellm_provider": "vertex_ai-mistral_models",

tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,30 @@ def test_vertex_ai_moonshot_uses_openai_handler():
11751175
)
11761176

11771177

1178+
def test_vertex_ai_zai_uses_openai_handler():
1179+
"""
1180+
Ensure ZAI partner models re-use the OpenAI-format handler.
1181+
"""
1182+
from litellm.llms.vertex_ai.vertex_ai_partner_models.main import (
1183+
VertexAIPartnerModels,
1184+
)
1185+
1186+
assert VertexAIPartnerModels.should_use_openai_handler(
1187+
"zai-org/glm-4.7-maas"
1188+
)
1189+
1190+
1191+
def test_vertex_ai_zai_is_partner_model():
1192+
"""
1193+
Ensure ZAI models are detected as Vertex AI partner models.
1194+
"""
1195+
from litellm.llms.vertex_ai.vertex_ai_partner_models.main import (
1196+
VertexAIPartnerModels,
1197+
)
1198+
1199+
assert VertexAIPartnerModels.is_vertex_partner_model("zai-org/glm-4.7-maas")
1200+
1201+
11781202
def test_build_vertex_schema_empty_properties():
11791203
"""
11801204
Test _build_vertex_schema handles empty properties objects correctly.

0 commit comments

Comments
 (0)