From 507b89e33d8bb8c2438eabcc23311eb1f520effa Mon Sep 17 00:00:00 2001 From: quangdang46 Date: Fri, 22 May 2026 00:15:17 +0700 Subject: [PATCH] docs(provider): clarify MiniMax dual-endpoint auto-switch + regression test Issue #141 (upstream PR #188) reports that MiniMax China Token Plan users get 401 authorized_error because the international endpoint is hit with a Token Plan key. Upstream's fix flips the default `api_base` from `api.minimax.io` to `api.minimaxi.com`. Our fork already handles this differently and better: the resolver (`apply_profile_key_based_endpoint_overrides`) auto-routes any `sk-cp-*` API key to the China base URL (`MINIMAX_CHINA_API_BASE`) without changing the default for international users. Mechanically porting upstream's flip would regress everyone whose key does not start with `sk-cp-`. This change: - Updates OAUTH.md MiniMax section to document the dual-endpoint behavior so users see exactly which base URL their key resolves to, and explicitly calls out that `sk-cp-...` keys auto-route to `api.minimaxi.com`. - Adds a regression test `minimax_token_plan_keys_route_to_china_even_when_openai_api_key_env_is_international` that pins down the exact 401 scenario from the issue: an unrelated international `OPENAI_API_KEY` exported in env must NOT pull the resolution back to `.io` when a real `sk-cp-*` key is the one actually being used. Defaults in `MINIMAX_PROFILE` are intentionally left unchanged. Refs #141 --- OAUTH.md | 14 ++++++++++++-- src/provider_catalog_tests.rs | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/OAUTH.md b/OAUTH.md index d29cb62c6..89a52aa09 100644 --- a/OAUTH.md +++ b/OAUTH.md @@ -266,9 +266,19 @@ Two notable presets are: - Login: `jcode login --provider minimax` - Stored env file: `~/.config/jcode/minimax.env` - API key env var: `OPENAI_API_KEY` -- Base URL: `https://api.minimax.io/v1` +- Endpoint auto-selection by API key: + - **International** (default): `https://api.minimax.io/v1` + - Docs: + - **China Token Plan** (auto-selected when the key starts with `sk-cp-`): + `https://api.minimaxi.com/v1` + - Docs: - Default model hint: `MiniMax-M2.7` -- Docs: + +> jcode resolves the MiniMax base URL from the API key prefix. China +> Token Plan keys (`sk-cp-...`) automatically route to +> `api.minimaxi.com`, so users on the China platform should not see +> the upstream `401 / authorized_error` reported when the international +> endpoint is hit with a Token Plan key. These are first-class jcode provider presets, not just manual custom endpoint examples. You can still use `openai-compatible` for arbitrary custom providers when there is not a built-in preset. diff --git a/src/provider_catalog_tests.rs b/src/provider_catalog_tests.rs index d6a48a9d9..bd88f3be3 100644 --- a/src/provider_catalog_tests.rs +++ b/src/provider_catalog_tests.rs @@ -129,6 +129,31 @@ fn minimax_token_plan_keys_resolve_to_china_endpoint_without_changing_internatio assert_eq!(china.setup_url, MINIMAX_CHINA_SETUP_URL); } +#[test] +fn minimax_token_plan_keys_route_to_china_even_when_openai_api_key_env_is_international() { + // Regression for issue #141 (upstream PR #188): users on the MiniMax + // China Token Plan reported a `401 authorized_error` because their + // `sk-cp-...` keys were being sent to `api.minimax.io`. Our fork + // resolves the base URL from the *hint* (the actual key being used to + // call the API), not from a stale `OPENAI_API_KEY` env value, so the + // auto-switch must still kick in even when an unrelated international + // OpenAI key is exported in the shell. + let _lock = crate::storage::lock_test_env(); + let _guard = EnvGuard::save(&["OPENAI_API_KEY"]); + crate::env::set_var("OPENAI_API_KEY", "sk-international-not-china"); + + let resolved = resolve_openai_compatible_profile_with_api_key_hint( + MINIMAX_PROFILE, + Some("sk-cp-real-china-token"), + ); + assert_eq!( + resolved.api_base, MINIMAX_CHINA_API_BASE, + "sk-cp-* keys must route to api.minimaxi.com regardless of an \ + unrelated international OPENAI_API_KEY in env" + ); + assert_eq!(resolved.setup_url, MINIMAX_CHINA_SETUP_URL); +} + #[test] fn auth_issue_lan_openai_compatible_bases_are_valid_for_local_model_servers() { assert_eq!(