From 74a2ac1c1c213c429324c219b1f5702abf4eacee Mon Sep 17 00:00:00 2001 From: "Mountain Ghost. W" Date: Thu, 2 Jul 2026 19:23:17 +0800 Subject: [PATCH] feat(llm): add z-ai-coding provider for GLM Coding Plan endpoint (#258) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(llm): add z-ai-coding provider for GLM Coding Plan endpoint Z.AI (智谱) subscribers to the GLM Coding Plan must route requests through the dedicated coding endpoint (https://open.bigmodel.cn/api/coding/paas/v4) for them to be billed against the subscription quota. The existing z-ai provider points at the generic pay-as-you-go endpoint (https://open.bigmodel.cn/api/paas/v4), so Coding Plan keys silently drain the wallet balance instead of consuming the plan quota, surfacing as a spurious "1113 余额不足" error even when the plan is barely used. Add a dedicated z-ai-coding provider following the existing *-tokenplan pattern (dashscope/dashscope-tokenplan, tencent-tokenhub/hy-tokenplan). It reuses Z_AI_API_KEY — the same key authenticates against both endpoints, so selecting this provider is all that's needed to activate the plan. The model list is restricted to the models officially supported by the Coding Plan to avoid selecting a non-plan model that falls back to wallet billing. - internal/llm/providers.go: register z-ai-coding preset - extensions/vscode/src/shared/providers.ts: mirror the preset (kept in sync with the Go registry per the file header) - internal/llm/providers_test.go: update the sorted provider list assertion Co-Authored-By: Oz * docs(pages): add Z.AI GLM Coding Plan config tip to docs page Subscribers to the Z.AI (Zhipu) GLM Coding Plan must route requests through the dedicated coding endpoint (https://open.bigmodel.cn/api/coding/paas/v4) to bill against the plan quota. The default z-ai preset points at the generic pay-as-you-go endpoint, so coding-plan keys silently drain the wallet and surface a spurious "1113 余额不足" error — a recurring trap for new users. Add a provider-specific callout at the end of the Docs config section showing the one-line fix that works today on any released version: ocr config set providers.z-ai.url https://open.bigmodel.cn/api/coding/paas/v4 This complements the z-ai-coding provider added in the previous commit: the provider gives a native first-class option going forward, while this doc tip rescues users already running released builds. Copy/localized for zh/en/ja. Co-Authored-By: Oz * fix(llm): address review feedback for z-ai-coding provider - Switch z-ai-coding to a dedicated Z_AI_CODING_API_KEY env var instead of reusing Z_AI_API_KEY, matching the tokenplan-provider convention so pay-as-you-go and Coding Plan keys can be configured independently - Remove comment blocks from the z-ai-coding presets (Go and TS) to keep the registry as plain data consistent with the other entries - Revert pages/ changes (i18n + DocsPage.tsx); provider docs are out of scope for a provider-registration PR Co-Authored-By: Oz --------- Co-authored-by: mountainwu Co-authored-by: Oz --- extensions/vscode/src/shared/providers.ts | 8 ++++++++ internal/llm/providers.go | 13 +++++++++++++ internal/llm/providers_test.go | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/extensions/vscode/src/shared/providers.ts b/extensions/vscode/src/shared/providers.ts index ef03f51..684fb7a 100644 --- a/extensions/vscode/src/shared/providers.ts +++ b/extensions/vscode/src/shared/providers.ts @@ -95,6 +95,14 @@ export const PROVIDER_PRESETS: OcrProviderPreset[] = [ envVar: 'Z_AI_API_KEY', models: ['glm-5.2', 'glm-5.1', 'glm-5-turbo', 'glm-4.7'], }, + { + name: 'z-ai-coding', + displayName: 'Z.AI Coding Plan API', + protocol: 'openai', + baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4', + envVar: 'Z_AI_CODING_API_KEY', + models: ['glm-5.2', 'glm-5.1', 'glm-5-turbo', 'glm-4.7'], + }, { name: 'mimo', displayName: 'Xiaomi MiMo API', diff --git a/internal/llm/providers.go b/internal/llm/providers.go index 83b1e16..9a80981 100644 --- a/internal/llm/providers.go +++ b/internal/llm/providers.go @@ -168,6 +168,19 @@ var registry = []Provider{ "glm-4.7", }, }, + { + Name: "z-ai-coding", + DisplayName: "Z.AI Coding Plan API", + Protocol: "openai", + BaseURL: "https://open.bigmodel.cn/api/coding/paas/v4", + EnvVar: "Z_AI_CODING_API_KEY", + Models: []string{ + "glm-5.2", + "glm-5.1", + "glm-5-turbo", + "glm-4.7", + }, + }, { Name: "mimo", DisplayName: "Xiaomi MiMo API", diff --git a/internal/llm/providers_test.go b/internal/llm/providers_test.go index c4f5e07..4f3fdf4 100644 --- a/internal/llm/providers_test.go +++ b/internal/llm/providers_test.go @@ -40,7 +40,7 @@ func TestListProviders_Order(t *testing.T) { if len(providers) < 3 { t.Fatalf("expected at least 3 providers, got %d", len(providers)) } - expected := []string{"anthropic", "baidu-qianfan", "dashscope", "dashscope-tokenplan", "deepseek", "hy-tokenplan", "kimi", "mimo", "minimax", "openai", "tencent-tokenhub", "volcengine", "z-ai"} + expected := []string{"anthropic", "baidu-qianfan", "dashscope", "dashscope-tokenplan", "deepseek", "hy-tokenplan", "kimi", "mimo", "minimax", "openai", "tencent-tokenhub", "volcengine", "z-ai", "z-ai-coding"} if len(providers) != len(expected) { t.Fatalf("expected %d providers, got %d", len(expected), len(providers)) }