Skip to content

feat(providers): add Z.AI GLM Coding Plan provider and glm-5.2 model - #47140

Closed
yuanmingyi wants to merge 3 commits into
NousResearch:mainfrom
yuanmingyi:feat/zai-provider-update
Closed

feat(providers): add Z.AI GLM Coding Plan provider and glm-5.2 model#47140
yuanmingyi wants to merge 3 commits into
NousResearch:mainfrom
yuanmingyi:feat/zai-provider-update

Conversation

@yuanmingyi

Copy link
Copy Markdown

What does this PR do?

Adds a dedicated zai-coding (Z.AI / GLM Coding Plan) provider as a sibling to the existing direct-API zai provider. The two share the same API-key env vars (GLM_API_KEY/ZAI_API_KEY/Z_AI_API_KEY) and may reuse each other's stored credential, but are kept on separate billing paths — direct /api/paas/v4 vs coding-plan /api/coding/paas/v4 — so a cached or legacy GLM_BASE_URL cannot bleed across endpoints (a direct key hitting the coding path returns "Insufficient balance", and vice versa). Also adds the glm-5.2 model to both providers' catalogs and to the Z.AI endpoint probe candidates.

The Z.AI endpoint-detection logic is generalized into reusable provider-family helpers (endpoint_family_providers, base_url_matches_endpoint_family, resolve_provider_endpoint_family_base_url) backed by an official-URL canonical key that normalizes default ports (:443), trailing dots/slashes, and casing, so cross-family official URLs are reliably rejected.

Related Issue

Supersedes #1 (closed prior attempt). No tracking issue — Fixes #.

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Changes Made

  • New provider: zai-coding ProviderConfig (hermes_cli/auth.py), ProviderProfile (plugins/model-providers/zai/__init__.py), HermesOverlay (hermes_cli/providers.py), with aliases (zai-coding-plan, z-ai-coding, glm-coding, glm-coding-plan, zhipu-coding, zhipu-coding-plan) and coding-plan base URL.
  • Model: add glm-5.2 to the zai and zai-coding catalogs (hermes_cli/models.py, hermes_cli/setup.py) and to the Z.AI endpoint probe candidates.
  • Endpoint-family isolation: split ZAI_ENDPOINTS into ZAI_DIRECT_ENDPOINTS / ZAI_CODING_ENDPOINTS; new _official_base_url_key + base_url_matches_endpoint_family guard; guards applied at all base-URL resolution sites (hermes_cli/runtime_provider.py, agent/credential_pool.py, hermes_cli/model_setup_flows.py).
  • Shared credentials: shared_credential_provider_ids() lets zai/zai-coding fall back to each other's stored pool key while the endpoint still follows the selected provider's family.
  • Setup flow: Z.AI endpoint picker (Global / China / custom proxy) in _select_endpoint_family_base_url, persisted to GLM_BASE_URL.
  • Wiring: aux model glm-5-turbo and vision model glm-5v-turbo for zai-coding (agent/auxiliary_client.py); /coding/ URL inference → zai-coding (agent/model_metadata.py); models.dev mapping (agent/models_dev.py); /model picker + PROVIDER_GROUPS, canonical providers, labels, doctor/status labels, model_normalize prefix-strip.
  • Tests: endpoint-family isolation (probe, env-override, cache), shared-credential reuse, family-guard canonicalization (:443/trailing-dot), picker fallback, and zai-coding/... normalization.

How to Test

  1. scripts/run_tests.sh tests/hermes_cli/test_api_key_providers.py tests/hermes_cli/test_runtime_provider_resolution.py tests/hermes_cli/test_model_provider_persistence.py tests/hermes_cli/test_model_validation.py tests/hermes_cli/test_model_normalize.py tests/agent/test_auxiliary_named_custom_providers.py tests/providers/test_provider_profiles.py — affected zai/coding tests pass (189 passed, 0 failed).
  2. hermes /model → Z.AI / GLM group → Coding Plan; confirm the endpoint picker offers Global / China / custom proxy and persists the choice to GLM_BASE_URL.
  3. Configure a Coding Plan key, start a session on zai-coding, and confirm requests hit https://api.z.ai/api/coding/paas/v4 (not the direct path).
  4. Switch between zai and zai-coding and confirm no cross-family base-URL bleed (stale cached/GLM_BASE_URL values are rejected with a warning and re-probed).

Checklist

Code

  • My commit messages follow Conventional Commits (feat(providers): …)
  • I searched for existing PRs to make sure this isn't a duplicate (supersedes closed Terminal tool #1)
  • My PR contains only changes related to this fix/feature (no unrelated commits; package-lock.json excluded)
  • I've run pytest tests/ -q and all tests pass — ran the affected test files (189 passed); full suite not yet run on this branch
  • I've added tests for my changes
  • I've tested on my platform: macOS 15 (darwin)

Documentation & Housekeeping

  • I've updated relevant documentation — or N/A (provider is auto-discovered via plugins/model-providers/zai/; no new config keys)
  • I've updated cli-config.yaml.example — N/A (reuses existing GLM_API_KEY / GLM_BASE_URL)
  • I've updated CONTRIBUTING.md or AGENTS.md — N/A
  • I've considered cross-platform impact — N/A (pure-Python provider logic; no platform-specific code)

Screenshots / Logs

N/A

Add a dedicated zai-coding provider as a sibling to the direct-API zai provider. They share API-key env vars (GLM_API_KEY/ZAI_API_KEY/Z_AI_API_KEY) and may reuse each other's stored credential, but are kept on separate billing paths so a cached or legacy base URL cannot bleed across the direct (/api/paas/v4) and coding-plan (/api/coding/paas/v4) endpoints.

Add the glm-5.2 model to both the zai (direct API) and zai-coding (Coding Plan) provider catalogs and to the Z.AI endpoint probe candidates.

Generalize Z.AI endpoint detection into provider-family helpers (endpoint_family_providers, base_url_matches_endpoint_family, resolve_provider_endpoint_family_base_url) with an official-URL canonical key that normalizes default ports, trailing dots/slashes, and casing. Add endpoint-family guards at all base-URL resolution sites (runtime, credential pool, setup picker), a Z.AI endpoint picker in the setup flow, and wire zai-coding across registries, overlays, profiles, aliases, model catalogs, aux/vision models, doctor/status labels, and model-metadata URL inference while keeping its curated model list separate from the direct catalog.

Includes focused tests for endpoint-family isolation, credential sharing, the family guard, picker fallback, cache invalidation, and model normalization.
@alt-glitch alt-glitch added type/feature New feature or request comp/cli CLI entry point, hermes_cli/, setup wizard provider/zai ZAI provider P3 Low — cosmetic, nice to have labels Jun 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #13500 and #13911 (open competing approaches that split zai into 4 explicit Global/China x direct/coding-plan providers). This PR takes a different mechanism — a single dedicated zai-coding sibling provider sharing keys but on a separate billing path, plus endpoint-family helpers and the new glm-5.2 model. Same goal, different approach; maintainer to pick the mechanism.

@yuanmingyi

Copy link
Copy Markdown
Author

Related: #13500 and #13911 (open competing approaches that split zai into 4 explicit Global/China x direct/coding-plan providers). This PR takes a different mechanism — a single dedicated zai-coding sibling provider sharing keys but on a separate billing path, plus endpoint-family helpers and the new glm-5.2 model. Same goal, different approach; maintainer to pick the mechanism.

these two are old & duplicate and can be closed. Thanks

…stings

Simplify the zai-coding provider surface introduced in the prior commit: drop the extra coding aliases and the generalized endpoint-family credential seeding in favor of the canonical "zai-coding" slug and dedicated, explicit provider listings.

Remove the zai-coding aliases (zai-coding-plan, z-ai-coding, glm-coding, glm-coding-plan, zhipu-coding, zhipu-coding-plan) from the provider/alias maps and the plugin profile, and drop the zai-coding aux/vision model overrides in auxiliary_client.

Revert credential-pool seeding to the zai-only _resolve_zai_base_url path (drop the endpoint_family_providers branch). Add dedicated doctor and status entries for "Z.AI / GLM Coding Plan API" with the coding /models URL.

Recognize zai-coding in anthropic dot-preservation (run_agent), the delegate provider error message, and trajectory-compression provider detection (z.ai / bigmodel.cn hosts with /api/coding/paas/). Drop the "provider" alias for the /model command and update tests accordingly.
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Closing as redundant — current main already supports Z.AI Coding Plan endpoints and glm-5.2.

Verified on origin/main (E2E):

  1. Coding-plan endpoints already in the probe list. ZAI_ENDPOINTS in hermes_cli/auth.py already includes coding-global (https://api.z.ai/api/coding/paas/v4) and coding-cn (https://open.bigmodel.cn/api/coding/paas/v4). A coding-plan key automatically resolves there: the probe hits direct endpoints first (401/403), then succeeds on coding-global.

  2. glm-5.2 already on main. It's in ZAI_ENDPOINTS probe candidates (["glm-5.2", "glm-5.1", "glm-5v-turbo", "glm-4.7"]), in provider_model_ids("zai"), and in _SUPPORTED_MODELS["zai"] in setup.py.

  3. GLM_BASE_URL env override already works for coding paths. Setting GLM_BASE_URL=https://api.z.ai/api/coding/paas/v4 resolves to that URL — env wins, probe skipped. No new provider needed to pin the coding endpoint.

  4. Cache-bleed already prevented by per-key-hash cache. The detected endpoint is cached in auth.json under sha256(api_key)[:16]. Switch keys → key_hash mismatches → re-probe. The PR's own description states a direct key hitting the coding path returns "Insufficient balance" (fails) — so the same key can't silently succeed on the wrong path.

The one genuine UX gap is that the setup flow uses a plain text input for base URL rather than a picker offering Global/China/Coding Plan options — that's a small setup-flow tweak, not a 1171-line provider split with endpoint-family isolation machinery.

Thanks for the thorough work and tests — the endpoint-family guard design is thoughtful, but main's probe + env override + per-key-hash cache already covers the use case.

@farangkao

Copy link
Copy Markdown

I can confirm, it works now with Coding Plan url entered during model setup

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

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have provider/zai ZAI provider type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants