Skip to content

fix(vlm): skip zhipu prefix when model already uses zai/ (LiteLLM)#789

Merged
qin-ctx merged 2 commits intovolcengine:mainfrom
Protocol-zero-0:fix/zai-model-prefix
Mar 21, 2026
Merged

fix(vlm): skip zhipu prefix when model already uses zai/ (LiteLLM)#789
qin-ctx merged 2 commits intovolcengine:mainfrom
Protocol-zero-0:fix/zai-model-prefix

Conversation

@Protocol-zero-0
Copy link
Copy Markdown
Contributor

Summary

Fixes incorrect LiteLLM model rewriting: when the configured model already uses LiteLLM's zai/ prefix (e.g. zai/glm-4.5), the VLM backend no longer prepends zhipu/, which produced invalid names like zhipu/zai/glm-4.5.

Context

Change

In _resolve_model, skip adding the zhipu prefix if the model string already starts with zai/.

Made with Cursor

When the model string already uses LiteLLM's zai/ prefix (e.g. zai/glm-4.5),
do not prepend zhipu/. Otherwise LiteLLM receives zhipu/zai/... which it does
not recognize.

Fixes volcengine#784

Made-with: Cursor
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 19, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes LiteLLM VLM model name rewriting so Z.AI/GLM models that already use LiteLLM’s zai/ prefix are not incorrectly rewritten into invalid zhipu/zai/... model identifiers.

Changes:

  • Update _resolve_model() to skip prefixing when the model string already starts with zai/.
  • Add an inline comment documenting the Z.AI/LiteLLM prefix behavior and linking to #784.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@qin-ctx qin-ctx self-assigned this Mar 20, 2026
Copy link
Copy Markdown
Collaborator

@qin-ctx qin-ctx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix correctly identifies the root cause (#784), but the zai/ guard needs to be scoped to the zhipu provider only. Also, a regression test for _resolve_model would be valuable.

prefix = PROVIDER_CONFIGS[provider]["litellm_prefix"]
if prefix and not model.startswith(f"{prefix}/"):
# LiteLLM uses the `zai/` prefix for Zhipu GLM; do not prepend `zhipu/` (see #784).
if prefix and not model.startswith(f"{prefix}/") and not model.startswith("zai/"):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Bug] (blocking) The not model.startswith("zai/") guard applies to every provider, not just zhipu. If any other provider's model happened to start with zai/, its prefix would be silently skipped. This was also flagged by the previous Copilot review and hasn't been addressed.

Minimal fix — scope to zhipu:

Suggested change
if prefix and not model.startswith(f"{prefix}/") and not model.startswith("zai/"):
# LiteLLM uses the `zai/` prefix for Zhipu GLM; do not prepend `zhipu/` (see #784).
if prefix and not model.startswith(f"{prefix}/") and not (provider == "zhipu" and model.startswith("zai/")):

Alternatively, encode this as provider-specific config so future alternative prefixes are declarative:

# in PROVIDER_CONFIGS["zhipu"]
"alt_prefixes": ["zai"],

# in _resolve_model
alt_prefixes = PROVIDER_CONFIGS[provider].get("alt_prefixes", [])
all_prefixes = [p for p in [prefix] + alt_prefixes if p]
if prefix and not any(model.startswith(f"{p}/") for p in all_prefixes):
    return f"{prefix}/{model}"

prefix = PROVIDER_CONFIGS[provider]["litellm_prefix"]
if prefix and not model.startswith(f"{prefix}/"):
# LiteLLM uses the `zai/` prefix for Zhipu GLM; do not prepend `zhipu/` (see #784).
if prefix and not model.startswith(f"{prefix}/") and not model.startswith("zai/"):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] (non-blocking) No regression test for this fix. There are currently no tests for _resolve_model at all. Consider adding at least:

def test_resolve_model_zai_prefix_not_double_prefixed():
    provider = LiteLLMVLMProvider({"model": "zai/glm-4.5", "provider": "litellm"})
    assert provider._resolve_model("zai/glm-4.5") == "zai/glm-4.5"

@Protocol-zero-0
Copy link
Copy Markdown
Contributor Author

Updated. I scoped the zai/ exception to the Zhipu provider only, so other providers still apply their normal LiteLLM prefixing behavior. I also added focused regression tests covering both the Zhipu zai/ case and a non-Zhipu provider case.

@qin-ctx qin-ctx merged commit d245c02 into volcengine:main Mar 21, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 21, 2026
@Protocol-zero-0 Protocol-zero-0 deleted the fix/zai-model-prefix branch March 21, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenViking v0.2.8 litellm VLM backend rewrites Z.AI model prefix incorrectly (zai/... → zhipu/zai/...)

4 participants