fix(zai): resolve model list for China API users (endpoint-aware) - #46724
fix(zai): resolve model list for China API users (endpoint-aware)#46724Icather wants to merge 3 commits into
Conversation
Two independent fixes: 1. URL routing: provider_model_ids resolved the correct China base URL (open.bigmodel.cn) via resolve_api_key_provider_credentials but fetch_models still used the hardcoded international URL (api.z.ai). China API keys were rejected by the international endpoint, falling back to fallback_models (glm-5 + glm-4-9b). Fix: temporarily swap the ProviderProfile base_url to the resolved URL before calling fetch_models. 2. Free model visibility: Z.AI /v1/models omits universally-free Flash models (glm-4v-flash, glm-4.6v-flash, glm-4.1v-thinking-flash, glm-4.5-flash, glm-4-flash-250414) even though they accept real API calls. Fix: override fetch_models on the Z.AI ProviderProfile to append ZAI_FREE_MODELS after the live API response with dedup. All Z.AI-specific logic lives in plugins/model-providers/zai/__init__.py. models.py only gains the base_url swap — zero zai-specific branches.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for Z.AI “universally-free” models that are not returned by the provider’s /v1/models endpoint, and updates CLI model fetching to respect a resolved per-region base URL.
Changes:
- Add a Z.AI free-model allowlist and a wrapper around
fetch_models()to append them. - Remove
glm-5.2from Z.AI fallback models. - In
hermes_cli, temporarily apply the resolvedbase_urlwhile fetching live models.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| plugins/model-providers/zai/init.py | Adds free-model list and wraps fetch_models to append those models. |
| hermes_cli/models.py | Ensures fetch_models uses the resolved (possibly regional) base_url. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the targeted Z.AI investigation. The resolved-endpoint part has since landed on current main in 1b962f001: hermes_cli/models.py:2485 passes the credential-resolved base_url, and providers/base.py:189-194 uses it for /models.
Problems
- The proposed wrapper at
plugins/model-providers/zai/__init__.py:14does not acceptbase_url, but current main now callsfetch_models(api_key=..., base_url=...)athermes_cli/models.py:2485; salvaging this unchanged would raiseTypeError. - Its call at
plugins/model-providers/zai/__init__.py:16also omitsbase_url, which would discard the resolved China endpoint. - Current main already has
ZaiProfile(plugins/model-providers/zai/__init__.py:85), so an override there is preferable to replacing a method on one instance.
Suggested changes
- Rework the remaining free-model addition as a
ZaiProfile.fetch_modelsoverride that accepts and forwardsbase_url, normalizes an empty live result, and deduplicates the appended IDs. - Add an offline regression test for the resolved URL and empty-catalog path.
Automated hermes-sweeper review.
| "glm-4.6v-flash", | ||
| "glm-4.1v-thinking-flash", | ||
| "glm-4.5-flash", | ||
| "glm-4-flash-250414", |
There was a problem hiding this comment.
Current main invokes API-key profiles as fetch_models(api_key=..., base_url=...) in hermes_cli/models.py:2485. This keyword-only wrapper does not accept base_url, so salvaging it unchanged raises TypeError; add and forward that parameter.
| "glm-4.5-flash", | ||
| "glm-4-flash-250414", | ||
| ) | ||
|
|
There was a problem hiding this comment.
Forward the resolved base_url here. Current ProviderProfile.fetch_models uses that override to select the endpoint (providers/base.py:189-194); omitting it would fall back to the profile's international default and undo the China routing fix.
What does this PR do?
Fixes Z.AI model listing for two bugs:
Bug 1 --
provider_model_idsresolves the correct endpoint URL (e.g. China'sopen.bigmodel.cn) viaresolve_api_key_provider_credentials, butfetch_modelsstill hits the hardcoded international URL (api.z.ai). China API keys are rejected, falling back tofallback_models(only 2 models).Bug 2 -- Z.AI's
/v1/modelsomits universally-free Flash models (glm-4v-flash,glm-4.6v-flash,glm-4.1v-thinking-flash,glm-4.5-flash,glm-4-flash-250414) even though they accept real API calls. The fix appends them via an override on the Z.AIProviderProfile.fetch_models.Related Issue
Type of Change
Changes Made
plugins/model-providers/zai/__init__.py-- AddedZAI_FREE_MODELSconstant (5 universally-free models). Overrodefetch_modelsto append these after the live API response with dedup.hermes_cli/models.py-- Added base_url swap in the generic live-fetch path sofetch_modelshits the resolved endpoint instead of the hardcoded profile default.How to Test
open.bigmodel.cn)glm-4v-flash) as auxiliary vision model -- confirm it worksChecklist
Code
pytest tests/ -q-- N/A (no new tests; fix is integration-level)Documentation & Housekeeping
cli-config.yaml.example-- N/ACONTRIBUTING.mdorAGENTS.md-- N/A