Skip to content

feat(providers): split minimax zai into intl cn#398

Open
JochenYang wants to merge 1 commit into
Gitlawb:mainfrom
JochenYang:feat/china-providers
Open

feat(providers): split minimax zai into intl cn#398
JochenYang wants to merge 1 commit into
Gitlawb:mainfrom
JochenYang:feat/china-providers

Conversation

@JochenYang

@JochenYang JochenYang commented Jul 2, 2026

Copy link
Copy Markdown

Summary

  • Add minimaxi-cn (api.minimaxi.com) sharing the model catalog with minimax
  • Add zai-cn; zai now points at the international endpoint api.z.ai
  • Split env vars so the two sides don't share a key: ZAI_API_KEY vs ZHIPU_API_KEY for zai/zai-cn, MINIMAX_API_KEY vs MINIMAXI_API_KEY for minimax/minimaxi-cn
  • Map zai-cn and minimaxi-cn to the same models.dev providers as their international counterparts so the picker hydrates for both

Why

  1. Before this PR, catalog zai was hard-coded to the China endpoint open.bigmodel.cn. There was no built-in way to pick Z.ai's international host api.z.ai.
  2. zai and zai-cn both listed ZAI_API_KEY/ZHIPU_API_KEY as their env vars, so a key set for one side was silently picked up by the other. If the user had separate accounts (e.g. personal overseas vs. company China), the wrong key would 401.
  3. minimax/minimaxi-cn was already split this way for the same reasons; this PR brings zai/zai-cn to the same shape.

Test

go test ./internal/providercatalog/... ./internal/providermodelcatalog/... ./internal/config/...

All three packages pass. TUI smoke-tested: the picker shows the same model list (sourced from models.dev) for both endpoints, and the env vars stay scoped to their respective side.

- Add minimaxi-cn (api.minimaxi.com) sharing model catalog with minimax
- Add zai-cn (open.bigmodel.cn) splitting zai from china to intl
- Decouple env vars: ZAI_API_KEY vs ZHIPU_API_KEY for zai/zai-cn,
  MINIMAX_API_KEY vs MINIMAXI_API_KEY for minimax/minimaxi-cn
- Map zai-cn and minimaxi-cn to models.dev providers "zai" and "minimax"
  so the model catalog hydrates for both endpoints
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR adds provider catalog entries for MiniMax China (minimaxi-cn) and splits Z.ai into international (zai) and China (zai-cn) descriptors with distinct base URLs and API key env vars. Curated model lists are shared via new slices, provider ID mapping is updated, and tests cover resolver defaults, catalog ordering, and CN/international parity.

Changes

MiniMax CN and Zai CN Provider Support

Layer / File(s) Summary
Provider catalog descriptors
internal/providercatalog/catalog.go
Adds minimaxi-cn Anthropic-compatible descriptor and splits zai into zai (international, ZAI_API_KEY) and zai-cn (ZHIPU_API_KEY, bigmodel.cn base URL) OpenAI-compatible descriptors.
Curated model catalog sharing
internal/providermodelcatalog/catalog.go
Introduces shared minimaxCuratedModels and zaiCuratedModels slices, reused across minimax/minimaxi-cn and zai/zai-cn map entries instead of duplicated inline lists.
Remote provider ID mapping
internal/providermodelcatalog/remote.go, remote_test.go
ModelsDevProviderID maps zai-cnzai and minimaxi-cnminimax; alias test cases added.
Catalog ordering and scoping tests
internal/providercatalog/catalog_test.go, internal/providermodelcatalog/catalog_test.go
Extends expectedCatalogIDs, transport ordering, and provider-scoped model ID assertions to cover the two new provider IDs.
Catalog mirroring tests
internal/providermodelcatalog/catalog_test.go
Adds tests asserting CN provider model IDs and descriptions match their international counterparts.
Resolver default tests
internal/config/resolver_test.go
Adds tests verifying Resolve applies catalog defaults (kind, base URL, model, env-derived API key) for mini-cn, zai-cn, and zai.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • Gitlawb/zero#141: Builds on the provider-catalog descriptor/transport framework this PR extends with new entries.
  • Gitlawb/zero#385: Also extends internal/config/resolver_test.go coverage around Resolve catalog-default filling.

Suggested reviewers: Vasanthdev2004, anandh8x, kevincodex1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: splitting Minimax and Z.ai providers into international and China-specific variants.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
internal/config/resolver_test.go (2)

1146-1146: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Stale comment: default model isn't glm-5.2.

This comment says zai now resolves to "the glm-5.2 default," but the assertion two lines below (and the catalog descriptor) both use glm-4.5, with a separate comment clarifying glm-5.2 only comes via live discovery. The two comments contradict each other.

📝 Suggested fix
-	// "zai" now resolves to the international endpoint and the glm-5.2 default.
+	// "zai" now resolves to the international endpoint; the catalog default model
+	// stays glm-4.5, with live discovery upgrading to glm-5.2 at runtime.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/config/resolver_test.go` at line 1146, The comment in the resolver
test is stale and contradicts the actual `zai` expectation used by the nearby
assertion and catalog descriptor. Update the inline comment near the `zai` test
case so it matches the current default model (`glm-4.5`) and reserve any mention
of `glm-5.2` for the separate live-discovery comment, keeping the wording
consistent with the test setup in `resolver_test.go`.

1145-1174: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing ProviderKind/APIKeyEnv/APIKey assertions.

Unlike its two sibling tests, this one never asserts resolved.Provider.ProviderKind, APIKeyEnv, or APIKey — despite the test being specifically about ZAI_API_KEY routing correctly, which is the core behavior this PR changes. As written, this test would still pass even if ZAI_API_KEY resolution silently broke.

✅ Suggested additional assertions
 	if resolved.Provider.Model != "glm-4.5" {
 		t.Fatalf("Model = %q, want glm-4.5 (preserved default; live discovery upgrades to glm-5.2 at runtime)", resolved.Provider.Model)
 	}
+	if resolved.Provider.ProviderKind != ProviderKindOpenAICompatible {
+		t.Fatalf("ProviderKind = %q, want %q", resolved.Provider.ProviderKind, ProviderKindOpenAICompatible)
+	}
+	if resolved.Provider.APIKeyEnv != "ZAI_API_KEY" {
+		t.Fatalf("APIKeyEnv = %q, want ZAI_API_KEY", resolved.Provider.APIKeyEnv)
+	}
+	if resolved.Provider.APIKey != "sk-zai-intl" {
+		t.Fatalf("APIKey = %q, want env-resolved secret", resolved.Provider.APIKey)
+	}
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/config/resolver_test.go` around lines 1145 - 1174, Add the missing
assertions in TestResolveAppliesZaiInternationalCatalogDefaults so it also
verifies the Z.ai auth routing, not just BaseURL and Model. After Resolve
returns, assert resolved.Provider.ProviderKind, resolved.Provider.APIKeyEnv, and
resolved.Provider.APIKey match the expected zai-intl values, using the existing
Provider fields in the test alongside the current CatalogID checks to confirm
ZAI_API_KEY is wired correctly.
internal/providercatalog/catalog.go (1)

137-138: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Flag the base URL flip for existing zai configs.

Existing configs with catalog_id: "zai" and no explicit base_url previously resolved to the China endpoint; after this change they'll silently resolve to api.z.ai with a different required env var (ZAI_API_KEY vs the old key). Anyone with a bare zai config and only a Zhipu key set will start getting auth failures with no clear signal as to why. Worth a migration note (README/CHANGELOG) or a one-time warning when ZHIPU_API_KEY is set but ZAI_API_KEY isn't, given catalog_id=zai.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/providercatalog/catalog.go` around lines 137 - 138, The default
endpoint for the existing "zai" catalog_id is changing from the China base URL
to api.z.ai, which can break bare "zai" configs that only have ZHIPU_API_KEY
set. Update the catalog handling in internal/providercatalog/catalog.go around
openAICompat for "zai" and "zai-cn" so the transition is explicit, and add
either a migration note or a one-time warning when catalog_id is "zai" with
ZHIPU_API_KEY present but ZAI_API_KEY missing. Make sure the warning points
users to the new required env var and clarifies the endpoint selection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/config/resolver_test.go`:
- Line 1146: The comment in the resolver test is stale and contradicts the
actual `zai` expectation used by the nearby assertion and catalog descriptor.
Update the inline comment near the `zai` test case so it matches the current
default model (`glm-4.5`) and reserve any mention of `glm-5.2` for the separate
live-discovery comment, keeping the wording consistent with the test setup in
`resolver_test.go`.
- Around line 1145-1174: Add the missing assertions in
TestResolveAppliesZaiInternationalCatalogDefaults so it also verifies the Z.ai
auth routing, not just BaseURL and Model. After Resolve returns, assert
resolved.Provider.ProviderKind, resolved.Provider.APIKeyEnv, and
resolved.Provider.APIKey match the expected zai-intl values, using the existing
Provider fields in the test alongside the current CatalogID checks to confirm
ZAI_API_KEY is wired correctly.

In `@internal/providercatalog/catalog.go`:
- Around line 137-138: The default endpoint for the existing "zai" catalog_id is
changing from the China base URL to api.z.ai, which can break bare "zai" configs
that only have ZHIPU_API_KEY set. Update the catalog handling in
internal/providercatalog/catalog.go around openAICompat for "zai" and "zai-cn"
so the transition is explicit, and add either a migration note or a one-time
warning when catalog_id is "zai" with ZHIPU_API_KEY present but ZAI_API_KEY
missing. Make sure the warning points users to the new required env var and
clarifies the endpoint selection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 07fbd2ae-56cd-4f06-a96a-0c9e3cd1de87

📥 Commits

Reviewing files that changed from the base of the PR and between cdf9d83 and 8b6985b.

📒 Files selected for processing (7)
  • internal/config/resolver_test.go
  • internal/providercatalog/catalog.go
  • internal/providercatalog/catalog_test.go
  • internal/providermodelcatalog/catalog.go
  • internal/providermodelcatalog/catalog_test.go
  • internal/providermodelcatalog/remote.go
  • internal/providermodelcatalog/remote_test.go

@kevincodex1 kevincodex1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great to me. thnnks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants