Skip to content

Commit 507b89e

Browse files
committed
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
1 parent e1886bb commit 507b89e

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

OAUTH.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,19 @@ Two notable presets are:
266266
- Login: `jcode login --provider minimax`
267267
- Stored env file: `~/.config/jcode/minimax.env`
268268
- API key env var: `OPENAI_API_KEY`
269-
- Base URL: `https://api.minimax.io/v1`
269+
- Endpoint auto-selection by API key:
270+
- **International** (default): `https://api.minimax.io/v1`
271+
- Docs: <https://platform.minimax.io/docs/guides/text-generation>
272+
- **China Token Plan** (auto-selected when the key starts with `sk-cp-`):
273+
`https://api.minimaxi.com/v1`
274+
- Docs: <https://platform.minimaxi.com/docs/llms.txt>
270275
- Default model hint: `MiniMax-M2.7`
271-
- Docs: <https://platform.minimax.io/docs/guides/text-generation>
276+
277+
> jcode resolves the MiniMax base URL from the API key prefix. China
278+
> Token Plan keys (`sk-cp-...`) automatically route to
279+
> `api.minimaxi.com`, so users on the China platform should not see
280+
> the upstream `401 / authorized_error` reported when the international
281+
> endpoint is hit with a Token Plan key.
272282
273283
These are first-class jcode provider presets, not just manual custom endpoint examples.
274284
You can still use `openai-compatible` for arbitrary custom providers when there is not a built-in preset.

src/provider_catalog_tests.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,31 @@ fn minimax_token_plan_keys_resolve_to_china_endpoint_without_changing_internatio
129129
assert_eq!(china.setup_url, MINIMAX_CHINA_SETUP_URL);
130130
}
131131

132+
#[test]
133+
fn minimax_token_plan_keys_route_to_china_even_when_openai_api_key_env_is_international() {
134+
// Regression for issue #141 (upstream PR #188): users on the MiniMax
135+
// China Token Plan reported a `401 authorized_error` because their
136+
// `sk-cp-...` keys were being sent to `api.minimax.io`. Our fork
137+
// resolves the base URL from the *hint* (the actual key being used to
138+
// call the API), not from a stale `OPENAI_API_KEY` env value, so the
139+
// auto-switch must still kick in even when an unrelated international
140+
// OpenAI key is exported in the shell.
141+
let _lock = crate::storage::lock_test_env();
142+
let _guard = EnvGuard::save(&["OPENAI_API_KEY"]);
143+
crate::env::set_var("OPENAI_API_KEY", "sk-international-not-china");
144+
145+
let resolved = resolve_openai_compatible_profile_with_api_key_hint(
146+
MINIMAX_PROFILE,
147+
Some("sk-cp-real-china-token"),
148+
);
149+
assert_eq!(
150+
resolved.api_base, MINIMAX_CHINA_API_BASE,
151+
"sk-cp-* keys must route to api.minimaxi.com regardless of an \
152+
unrelated international OPENAI_API_KEY in env"
153+
);
154+
assert_eq!(resolved.setup_url, MINIMAX_CHINA_SETUP_URL);
155+
}
156+
132157
#[test]
133158
fn auth_issue_lan_openai_compatible_bases_are_valid_for_local_model_servers() {
134159
assert_eq!(

0 commit comments

Comments
 (0)