Skip to content

feat: Add Z.AI provider support#177

Open
hopyky wants to merge 1 commit intosipeed:mainfrom
hopyky:feat/add-zai-provider
Open

feat: Add Z.AI provider support#177
hopyky wants to merge 1 commit intosipeed:mainfrom
hopyky:feat/add-zai-provider

Conversation

@hopyky
Copy link

@hopyky hopyky commented Feb 14, 2026

Summary

  • Add Z.AI (z.ai) as a new LLM provider, the international AI platform by Zhipu AI.
  • Automatic endpoint routing between the standard API and the dedicated Coding API based on model name.
  • Auto-detection of Z.AI models by name (GLM, CogView, CogVideo, AutoGLM, Vidu) when the zai provider key is configured, with priority over the existing zhipu provider.

Details

Endpoints

Type Base URL
Standard https://api.z.ai/api/paas/v4
Coding https://api.z.ai/api/coding/paas/v4

The Coding endpoint is automatically selected when the model name contains coding. Users can also override this via the api_base config field.

Supported models

Category Models
LLM glm-5, glm-4.7, glm-4.6, glm-4.5, glm-4-32b-0414-128k
Vision/Multimodal glm-4.6v, glm-4.5v, glm-ocr
Image generation glm-image, cogview-4
Audio glm-asr-2512
Video cogvideox-3, vidu-q1, vidu-2
Agent autoglm-phone-multilingual

Files changed

  • pkg/config/config.go — Added ZAI field to ProvidersConfig, initialized in defaults, included in GetAPIKey() fallback chain.
  • pkg/providers/http_provider.go — Added case "zai", "z.ai" in explicit provider switch; added model-name auto-detection fallback (Z.AI takes priority over Zhipu when configured); added zai/ prefix stripping for model names.
  • config/config.example.json — Added zai provider 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

  • Configure zai provider with a valid API key and verify chat completion with glm-5
  • Verify coding endpoint is auto-selected when model name contains coding
  • Verify zai/glm-4.7 prefix stripping works correctly
  • Verify zhipu provider still works independently when zai is not configured
  • Verify model auto-detection routes to Z.AI when both zai and zhipu keys are set

🤖 Generated with Claude Code

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>
@Leeaandrob
Copy link
Collaborator

@Zepan Z.AI provider support. Same situation as other provider PRs — PR #213 (Provider Refactor — roadmap #283) should land first.

Recommendation: Wait for #213. Adding providers to the old architecture creates rework.

@yinwm
Copy link
Collaborator

yinwm commented Feb 20, 2026

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 model_list configuration. See the design doc: provider-refactoring.md

Current Workaround:

Users can already use Z.AI via OpenAI-compatible API with model_list:

{
  "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 pkg/providers/factory_provider.go:

  1. Add to CreateProviderFromConfig() switch:
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
  1. Add to getDefaultAPIBase():
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants