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!(