feat: Add Z.AI provider support#177
Conversation
Add Z.AI (z.ai) as a new LLM provider, the international platform by Zhipu AI. This includes automatic endpoint routing between the standard API and the dedicated Coding API based on model name. - Standard endpoint: https://api.z.ai/api/paas/v4 - Coding endpoint: https://api.z.ai/api/coding/paas/v4 Supported models: GLM-5, GLM-4.7, GLM-4.6, GLM-4.5, GLM-4.6V, GLM-4.5V, GLM-OCR, GLM-Image, CogView-4, CogVideoX-3, GLM-ASR-2512, AutoGLM-Phone-Multilingual, Vidu-Q1, Vidu-2. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
a6b8c90 to
50ef8fd
Compare
|
Thanks for the contribution! Z.AI support is valuable for international users of Zhipu AI. However, this PR needs to be reworked due to recent architecture changes. Architecture Update: PR #492 (Provider Refactoring) has been merged on 2026-02-20, introducing a protocol-based Current Workaround: Users can already use Z.AI via OpenAI-compatible API with {
"model_list": [
{
"model_name": "zai-glm5",
"model": "openai/glm-5",
"api_base": "https://api.z.ai/api/paas/v4",
"api_key": "your-key"
},
{
"model_name": "zai-coding",
"model": "openai/glm-5-coding",
"api_base": "https://api.z.ai/api/coding/paas/v4",
"api_key": "your-key"
}
]
}Good News - Simple Implementation: Since Z.AI uses OpenAI-compatible API, you only need to add protocol mappings. No new provider file needed! Just update
case "zai", "z.ai":
apiBase := cfg.APIBase
if apiBase == "" {
if strings.Contains(strings.ToLower(modelID), "coding") {
apiBase = "https://api.z.ai/api/coding/paas/v4"
} else {
apiBase = "https://api.z.ai/api/paas/v4"
}
}
return NewHTTPProviderWithMaxTokensField(cfg.APIKey, apiBase, cfg.Proxy, cfg.MaxTokensField), modelID, nil
case "zai":
return "https://api.z.ai/api/paas/v4"Example configuration after update: {
"model_list": [
{
"model_name": "my-glm",
"model": "zai/glm-5",
"api_key": "your-key"
}
]
}Would you like to rebase and update this PR? This should be a quick change! |
|
|
Summary
zaiprovider key is configured, with priority over the existingzhipuprovider.Details
Endpoints
https://api.z.ai/api/paas/v4https://api.z.ai/api/coding/paas/v4The Coding endpoint is automatically selected when the model name contains
coding. Users can also override this via theapi_baseconfig field.Supported models
glm-5,glm-4.7,glm-4.6,glm-4.5,glm-4-32b-0414-128kglm-4.6v,glm-4.5v,glm-ocrglm-image,cogview-4glm-asr-2512cogvideox-3,vidu-q1,vidu-2autoglm-phone-multilingualFiles changed
pkg/config/config.go— AddedZAIfield toProvidersConfig, initialized in defaults, included inGetAPIKey()fallback chain.pkg/providers/http_provider.go— Addedcase "zai", "z.ai"in explicit provider switch; added model-name auto-detection fallback (Z.AI takes priority over Zhipu when configured); addedzai/prefix stripping for model names.config/config.example.json— Addedzaiprovider entry with placeholder API key.Configuration example
{ "providers": { "zai": { "api_key": "your-z.ai-api-key", "api_base": "" } }, "agents": { "defaults": { "provider": "zai", "model": "glm-5" } } }Test plan
zaiprovider with a valid API key and verify chat completion withglm-5codingzai/glm-4.7prefix stripping works correctlyzhipuprovider still works independently whenzaiis not configuredzaiandzhipukeys are set🤖 Generated with Claude Code