feat(providers): add MiniMax (global + China) via Anthropic Messages

Providers 21-22 (24th & 25th registry variants), sourced from Pi
(earendil-works/pi). Pi drives MiniMax through its Anthropic-COMPATIBLE
surface (baseUrl .../anthropic), so Kigi reuses the existing Anthropic
Messages machinery (wire_api=Messages, listing=Anthropic, key_header=XApiKey
x-api-key+anthropic-version) rather than the OpenAI path. Global:
api.minimax.io/anthropic, MINIMAX_API_KEY, models.dev minimax. China:
api.minimaxi.com/anthropic, MINIMAX_CN_API_KEY, models.dev minimax-cn.

The base carries the /v1 suffix (.../anthropic/v1) since Kigi appends bare
paths → listing .../anthropic/v1/models?limit=1000, inference
.../anthropic/v1/messages (matches the live-probed x-api-key-gated endpoint).
restrict_to_enriched=FALSE: the 7 MiniMax-M* models are clean (no pollution)
and restrict would drop launch-day models not yet in models.dev.

Also HARDENS parse_anthropic_listing to tolerate a bare array in addition to
the {data:[...]} envelope (mirrors parse_openai_listing's sniff that Together
taught us) — so MiniMax's Anthropic-compatible /models can't silently empty
the catalog if it serves a bare array. A bare object without data still errors.

Review found no defects (5 areas CONFIRMED incl. the /v1 non-doubling, the
additive parser change, restrict=false rationale). Residual (logged): the live
200 body / anthropic-version acceptance is unverifiable without a key; the
bare-array tolerance + restrict=false hedge most shapes.

Tests: e2e mocks the x-api-key-gated Anthropic listing (proves the auth header
+ enrichment + keying under minimax/); both validation tests reject 401 with
the per-variant console host; new parser test covers envelope + bare array +
bare-object-errors. Registry at 25; picker 26 rows.
This commit is contained in:
2026-07-21 20:21:26 -04:00
parent 347311bfe5
commit bc4e76db96
4 changed files with 269 additions and 19 deletions
@@ -627,7 +627,9 @@ mod tests {
"zai",
"zai-coding-cn",
"xiaomi",
"xiaomi-token-plan-cn"
"xiaomi-token-plan-cn",
"minimax",
"minimax-cn"
]
);
assert_eq!(default_id(&built), Some(XAI_API_KEY_METHOD_ID));
@@ -673,7 +675,9 @@ mod tests {
"zai",
"zai-coding-cn",
"xiaomi",
"xiaomi-token-plan-cn"
"xiaomi-token-plan-cn",
"minimax",
"minimax-cn"
]
);
assert_eq!(default_id(&built), Some(CACHED_TOKEN_AUTH_METHOD_ID));
@@ -712,7 +716,9 @@ mod tests {
"zai",
"zai-coding-cn",
"xiaomi",
"xiaomi-token-plan-cn"
"xiaomi-token-plan-cn",
"minimax",
"minimax-cn"
]
);
assert_eq!(default_id(&built), Some(CACHED_TOKEN_AUTH_METHOD_ID));
@@ -754,7 +760,9 @@ mod tests {
"zai",
"zai-coding-cn",
"xiaomi",
"xiaomi-token-plan-cn"
"xiaomi-token-plan-cn",
"minimax",
"minimax-cn"
]
);
assert_eq!(default_id(&built), None);
@@ -1205,4 +1213,51 @@ mod tests {
"Invalid API key for xiaomi-token-plan-cn \u{2014} check your key on xiaomimimo.com"
);
}
/// MiniMax (global): Anthropic-compatible /models is x-api-key-gated (401
/// for a bad key) → validator. Confirms the XApiKey header path is used.
#[tokio::test]
#[serial]
async fn minimax_validates_against_models_and_rejects_bad_key() {
use wiremock::matchers::{header, method, path};
let server = wiremock::MockServer::start().await;
wiremock::Mock::given(method("GET"))
.and(path("/models"))
.and(header("x-api-key", "mm-bad"))
.respond_with(wiremock::ResponseTemplate::new(401))
.expect(1)
.mount(&server)
.await;
let _base = EnvGuard::set(kigi_models::MINIMAX_BASE_URL_ENV, &server.uri());
let err = authenticate_platform_api_key(kigi_models::PlatformId::Minimax, Some("mm-bad"))
.await
.expect_err("a 401 from /models must reject the key");
assert_eq!(
err.message,
"Invalid API key for minimax \u{2014} check your key on platform.minimax.io"
);
}
/// MiniMax (China): distinct base URL + console host.
#[tokio::test]
#[serial]
async fn minimax_cn_validates_against_models_and_rejects_bad_key() {
use wiremock::matchers::{method, path};
let server = wiremock::MockServer::start().await;
wiremock::Mock::given(method("GET"))
.and(path("/models"))
.respond_with(wiremock::ResponseTemplate::new(401))
.expect(1)
.mount(&server)
.await;
let _base = EnvGuard::set(kigi_models::MINIMAX_CN_BASE_URL_ENV, &server.uri());
let err =
authenticate_platform_api_key(kigi_models::PlatformId::MinimaxCn, Some("mm-cn-bad"))
.await
.expect_err("a 401 from /models must reject the key");
assert_eq!(
err.message,
"Invalid API key for minimax-cn \u{2014} check your key on platform.minimaxi.com"
);
}
}
@@ -2438,6 +2438,89 @@ mod tests {
);
}
/// MiniMax e2e: Pi drives MiniMax through its Anthropic-compatible surface,
/// so Kigi uses the Anthropic listing (x-api-key + anthropic-version,
/// ?limit=1000) + Messages wire. /anthropic/v1/models is minimal, so
/// enrichment supplies context; restrict=false keeps the clean MiniMax-M*
/// catalog; id round-trips under the minimax key.
#[tokio::test(flavor = "multi_thread")]
#[serial_test::serial]
async fn minimax_anthropic_listing_enriches_and_keys_under_platform() {
let platform_server = wiremock::MockServer::start().await;
wiremock::Mock::given(wiremock::matchers::method("GET"))
.and(wiremock::matchers::path("/models"))
// x-api-key auth (Anthropic key header) must be present.
.and(wiremock::matchers::header("x-api-key", "mm-1"))
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(
// Anthropic listing envelope; minimal (id only) → enrichment fills.
serde_json::json!({ "data": [
{ "id": "MiniMax-M2.5", "type": "model" }
], "has_more": false }),
))
.expect(1)
.mount(&platform_server)
.await;
let modelsdev_server = wiremock::MockServer::start().await;
wiremock::Mock::given(wiremock::matchers::method("GET"))
.and(wiremock::matchers::path("/api.json"))
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(
serde_json::json!({ "minimax": { "models": {
"MiniMax-M2.5": {
"limit": {"context": 204800, "output": 131072},
"tool_call": true
}
}}}),
))
.expect(1)
.mount(&modelsdev_server)
.await;
let cache_dir = tempfile::tempdir().unwrap();
let _base = kigi_test_support::EnvGuard::set(
kigi_models::MINIMAX_BASE_URL_ENV,
platform_server.uri(),
);
let _mdev = kigi_test_support::EnvGuard::set(
crate::agent::enrichment_fetch::MODELS_DEV_URL_ENV,
format!("{}/api.json", modelsdev_server.uri()),
);
let _mdev_cache = kigi_test_support::EnvGuard::set(
crate::agent::enrichment_fetch::MODELS_DEV_CACHE_DIR_ENV,
cache_dir.path(),
);
let endpoints = crate::agent::config::EndpointsConfig::default();
let keys = crate::agent::models::PlatformApiKeys::test_single(
kigi_models::PlatformId::Minimax,
"mm-1",
);
let result = tokio::task::spawn_blocking(move || {
fetch_platform_models_blocking(&endpoints, None, &keys)
})
.await
.unwrap()
.expect("fetch must succeed");
assert_eq!(
result
.models
.iter()
.map(|m| m.id.as_deref().unwrap_or_default())
.collect::<Vec<_>>(),
vec!["minimax/MiniMax-M2.5"],
"the Anthropic-listed model is keyed under the minimax platform"
);
let entry = &result.models[0];
assert_eq!(
entry.context_window.get(),
204_800,
"context comes from enrichment (the wire listing carries none)"
);
assert_eq!(entry.max_completion_tokens, Some(131_072));
assert_eq!(entry.model, "MiniMax-M2.5");
assert_eq!(
kigi_models::parse_managed_model_key(entry.id.as_deref().unwrap()),
Some((kigi_models::PlatformId::Minimax, "MiniMax-M2.5")),
);
}
#[test]
fn get_env_keys_parses_strings_and_rejects_non_strings() {
use crate::agent::config::EnvKeys;