-
Notifications
You must be signed in to change notification settings - Fork 115
feat: add Z.AI Coding Plan provider support #1774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add Z.AI Coding Plan provider support #1774
Conversation
Users on Z.AI coding plan subscription need to use a different API endpoint (https://api.z.ai/api/coding/paas/v4) instead of the general API (https://api.z.ai/api/paas/v4). This adds a new 'zai_coding/' provider prefix that: - Detects 'zai_coding/' model prefix - Rewrites it to 'zai/' for LiteLLM compatibility - Sets the correct base_url to the coding API endpoint Fixes: OpenHands/OpenHands#12268
all-hands-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good overall and correctly handles the model prefix rewrite. However, there are two issues: an important inconsistency with base_url handling and missing test coverage.
| if model_val.startswith("zai_coding/"): | ||
| model_name = model_val.removeprefix("zai_coding/") | ||
| d["model"] = f"zai/{model_name}" | ||
| d["base_url"] = "https://api.z.ai/api/coding/paas/v4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Important: The base_url is unconditionally set here, which differs from the openhands/ provider pattern (line 366) and will override any custom base_url that users provide.
The existing openhands/ provider uses d.get("base_url") or ... to respect user-provided custom URLs, and there are explicit tests (test_base_url_for_openhands_provider_with_custom_url) demonstrating this expected behavior.
| d["base_url"] = "https://api.z.ai/api/coding/paas/v4" | |
| d["base_url"] = d.get("base_url") or "https://api.z.ai/api/coding/paas/v4" |
This change ensures:
- If no base_url is provided → sets the coding API endpoint
- If base_url is explicitly None → sets the coding API endpoint
- If a custom base_url is provided → respects the user's choice
This maintains consistency with other provider rewrites and allows for testing/debugging with custom endpoints.
| # - Coding Plan API: https://api.z.ai/api/coding/paas/v4 (for coding plan subscriptions) | ||
| # LiteLLM's zai/ prefix uses the general API by default, but coding plan users | ||
| # need the dedicated endpoint. See: https://github.com/All-Hands-AI/OpenHands/issues/12268 | ||
| if model_val.startswith("zai_coding/"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Consider adding tests for this new provider rewrite to ensure it works correctly and consistently. The openhands/ provider has comprehensive test coverage in tests/sdk/llm/test_llm.py:
test_base_url_for_openhands_provider()- automatic base_url settingtest_base_url_for_openhands_provider_with_explicit_none()- explicit None handlingtest_base_url_for_openhands_provider_with_custom_url()- respecting custom URLs
Similar tests for zai_coding/ would help verify:
- Model prefix rewriting (
zai_coding/glm-4.5→zai/glm-4.5) - Automatic base_url setting to the coding endpoint
- Custom base_url handling (especially after fixing the issue above)
enyst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Using coding plan is very helpful.
Could you please tell, does it work for you, or doesn't it require auth?
|
@enyst Thank you for the review! To answer your question: Yes, it does require authentication. The Z.AI Coding Plan API requires an API key just like the standard Z.AI API. Users need to:
The only difference between the two endpoints is:
Both endpoints use the same authentication mechanism (Bearer token with API key). This PR just ensures that users with the coding plan subscription get routed to the correct endpoint automatically when they use the Regarding the bot's suggestions:
I'll push these fixes shortly. |
|
✅ Pushed the fixes! Changes made in commit
All tests pass locally. Ready for re-review! 🚀 |
Summary
Users on Z.AI coding plan subscription need to use a different API endpoint (
https://api.z.ai/api/coding/paas/v4) instead of the general API (https://api.z.ai/api/paas/v4). Currently, when users select the "zai" provider, it uses the general API URL, causing errors for coding plan users.Root Cause
Z.AI (Zhipu AI) has two different API endpoints:
https://api.z.ai/api/paas/v4- for standard subscriptionshttps://api.z.ai/api/coding/paas/v4- for coding plan subscriptionsLiteLLM's
zai/prefix uses the general API by default, but coding plan users need the dedicated endpoint.Solution
This PR adds a new
zai_coding/provider prefix that:zai_coding/model prefix in the model validatorzai/for LiteLLM compatibilitybase_urlto the coding API endpointUsage
Users on Z.AI coding plan can now use models like
zai_coding/glm-4.5without needing to manually configure the base URL.Related PRs
Fixes
Resolves OpenHands/OpenHands#12268