Skip to content

feat(providers): split zai into 4 plans (Global/China × direct API/Coding Plan) — salvage #13500 - #13911

Closed
kshitijk4poor wants to merge 3 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/zai-split
Closed

feat(providers): split zai into 4 plans (Global/China × direct API/Coding Plan) — salvage #13500#13911
kshitijk4poor wants to merge 3 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/zai-split

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Salvage of #13500 by @yuanmingyi — cherry-picked onto current main with authorship preserved.

Replaces the single zai provider (which used fragile runtime HTTP endpoint probing via detect_zai_endpoint) with 4 explicit static providers. Users pick their plan once; credentials resolve deterministically with no startup latency.

Hermes id Endpoint Env var Plan
zai api.z.ai/api/paas/v4 ZAI_API_KEY Z.AI (Global direct)
zai-cn open.bigmodel.cn/api/paas/v4 GLM_API_KEY Zhipu AI (China direct)
zai-coding-global api.z.ai/api/coding/paas/v4 ZAI_CODING_API_KEY Z.AI Coding Plan (Global)
zai-coding-cn open.bigmodel.cn/api/coding/paas/v4 GLM_CODING_API_KEY Zhipu AI Coding Plan (China)

Changes

  • hermes_cli/auth.py — 4 distinct PROVIDER_REGISTRY entries with per-plan env vars and static base URLs. Drops detect_zai_endpoint / _resolve_zai_base_url (eliminates ~8s probes). zai-cn declared before zai so auto-detect with only GLM_API_KEY prefers China plan.
  • hermes_cli/providers.pyHERMES_OVERLAYS gains 3 new entries. Aliases route glm/zhipuzai-cn; z-ai/z.aizai.
  • agent/models_dev.py — maps each Hermes id to its models.dev catalog (zhipuai, zai-coding-plan, zhipuai-coding-plan)
  • hermes_cli/models.py — curated model lists: direct plans (9 models), coding plans (4 coding-focused models)
  • agent/auxiliary_client.py — aux model defaults per plan; vision model for zai/zai-cn
  • run_agent.py_anthropic_preserve_dots() extended to all 4 plans
  • trajectory_compressor.py — path-based provider disambiguation (fixes dead code that only compared hostnames)
  • All other files: mechanical threading through config, doctor, status, setup, dump, main.py --provider choices, qqbot STT adapter

Follow-up fix

  • Added base_url_override to coding plan overlays in providers.py for resilience (matches the pattern used by direct plan overlays rather than relying solely on models.dev)

Compatibility

  • provider: zai + only GLM_API_KEY → key resolves via fallback tuple; request hits api.z.ai (may 401 if key was issued for bigmodel.cn — running hermes model re-picks the correct plan)
  • provider: zai-cn + GLM_API_KEY → clean
  • Auto-detect with only GLM_API_KEYzai-cn (registry order ensures this)
  • ZAI_API_KEY always wins over GLM_API_KEY when both present

Testing

574 tests pass across the affected test files (1 deselected is pre-existing on main):

tests/hermes_cli/test_api_key_providers.py
tests/hermes_cli/test_model_validation.py
tests/hermes_cli/test_model_provider_persistence.py
tests/agent/test_auxiliary_client.py
tests/agent/test_model_metadata.py
tests/agent/test_models_dev.py
tests/hermes_cli/test_model_normalize.py
tests/hermes_cli/test_doctor.py
tests/hermes_cli/test_status.py
tests/gateway/test_qqbot.py

Closes #13500

ymy and others added 3 commits April 22, 2026 13:07
…ding Plan)

Replace the single zai provider (with fragile runtime HTTP endpoint probing)
with 4 explicit static providers:

| Hermes id          | Endpoint                                  | Env var            |
|--------------------|-------------------------------------------|--------------------|
| zai                | api.z.ai/api/paas/v4                      | ZAI_API_KEY        |
| zai-cn             | open.bigmodel.cn/api/paas/v4              | GLM_API_KEY        |
| zai-coding-global  | api.z.ai/api/coding/paas/v4               | ZAI_CODING_API_KEY |
| zai-coding-cn      | open.bigmodel.cn/api/coding/paas/v4       | GLM_CODING_API_KEY |

- Remove detect_zai_endpoint / _resolve_zai_base_url (eliminates ~8s probes)
- Thread 4 plans through auth, providers, models, status, doctor, setup,
  auxiliary routing, model normalization, trajectory compressor
- Legacy GLM_API_KEY fallback on zai provider for upgrade safety
- zai-cn declared before zai in registry so auto-detect with only GLM_API_KEY
  prefers the China plan (backward compat)

Based on NousResearch#13500 by @yuanmingyi.
Hardcode the coding plan endpoint URLs in HERMES_OVERLAYS rather than
relying solely on models.dev API responses. Matches the pattern used
by zai and zai-cn direct plan overlays for resilience.
@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard provider/zai ZAI provider area/auth Authentication, OAuth, credential pools labels Apr 22, 2026
@yuanmingyi

Copy link
Copy Markdown

Both failing checks look unrelated to this PR — could someone confirm?

  • Supply Chain Audit: guessing it flagged hermes_cli/setup.py, but that's the CLI setup wizard module inside the hermes_cli package, not a setuptools install hook — repo packages via pyproject.toml, no root setup.py, and the diff there is purely data. Happy to be corrected if it was something else.
  • Tests: the same 8 failures reproduce on latest main (run 24760241591), none touching zai/providers — looks like pre-existing flakes.

@yuanmingyi

Copy link
Copy Markdown

@kshitijk4poor hello, can you please tell what is blocking in detail or help to bypass the failing checks?

Both failing checks look unrelated to this PR — could someone confirm?

  • Supply Chain Audit: guessing it flagged hermes_cli/setup.py, but that's the CLI setup wizard module inside the hermes_cli package, not a setuptools install hook — repo packages via pyproject.toml, no root setup.py, and the diff there is purely data. Happy to be corrected if it was something else.
  • Tests: the same 8 failures reproduce on latest main (run 24760241591), none touching zai/providers — looks like pre-existing flakes.

@teknium1

Copy link
Copy Markdown
Contributor

Dont worry about the failing tests, and the supply chain audit is just for us to take more caution when reviewing

@yuanmingyi

Copy link
Copy Markdown

I'll discard this PR and open a new PR with simpler changes (just one new zai coding plan provider added) at #34323 @teknium1 @alt-glitch

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

Labels

area/auth Authentication, OAuth, credential pools comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists 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