Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions OAUTH.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://platform.minimax.io/docs/guides/text-generation>
- **China Token Plan** (auto-selected when the key starts with `sk-cp-`):
`https://api.minimaxi.com/v1`
- Docs: <https://platform.minimaxi.com/docs/llms.txt>
- Default model hint: `MiniMax-M2.7`
- Docs: <https://platform.minimax.io/docs/guides/text-generation>

> 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.
Expand Down
25 changes: 25 additions & 0 deletions src/provider_catalog_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down