feat(ai): switch xiaomi default to api billing, add per-region token plan providers (#4112)

Built-in `xiaomi` provider now targets the API billing endpoint (https://api.xiaomimimo.com/anthropic) — a single stable URL for keys issued at platform.xiaomimimo.com. The Token Plan endpoints are exposed as three sibling providers, each with its own env var:

- xiaomi-token-plan-cn: XIAOMI_TOKEN_PLAN_CN_API_KEY
- xiaomi-token-plan-ams: XIAOMI_TOKEN_PLAN_AMS_API_KEY
- xiaomi-token-plan-sgp: XIAOMI_TOKEN_PLAN_SGP_API_KEY

BREAKING CHANGE: users who previously set XIAOMI_API_KEY against the Token Plan AMS endpoint must move to xiaomi-token-plan-ams and set XIAOMI_TOKEN_PLAN_AMS_API_KEY. This also resolves the 401 reported by on #4005, where a platform.xiaomimimo.com key fails against the Token Plan endpoint.

closes #4082
This commit is contained in:
Jake Jia
2026-05-03 18:57:11 +08:00
committed by GitHub
parent 7c5ef0b70e
commit 693888ac47
22 changed files with 859 additions and 46 deletions

View File

@@ -994,7 +994,7 @@ describe("Generate E2E Tests", () => {
);
describe.skipIf(!process.env.XIAOMI_API_KEY)(
"Xiaomi MiMo Token Plan Provider (Xiaomi MiMo-V2.5-Pro via Anthropic Messages)",
"Xiaomi MiMo (API billing) Provider (Xiaomi MiMo-V2.5-Pro via Anthropic Messages)",
() => {
const llm = getModel("xiaomi", "mimo-v2.5-pro");
const thinkingOptions = {
@@ -1023,6 +1023,100 @@ describe("Generate E2E Tests", () => {
});
},
);
describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_CN_API_KEY)(
"Xiaomi MiMo Token Plan Provider (Xiaomi MiMo-V2.5-Pro via Anthropic Messages, CN region)",
() => {
const llm = getModel("xiaomi-token-plan-cn", "mimo-v2.5-pro");
const thinkingOptions = {
thinkingEnabled: true,
reasoningEffort: "high",
} satisfies StreamOptionsWithExtras;
it("should complete basic text generation", { retry: 3 }, async () => {
await basicTextGeneration(llm);
});
it("should handle tool calling", { retry: 3 }, async () => {
await handleToolCall(llm);
});
it("should handle streaming", { retry: 3 }, async () => {
await handleStreaming(llm);
});
it("should handle thinking mode", { retry: 3 }, async () => {
await handleThinking(llm, thinkingOptions);
});
it("should handle multi-turn with thinking and tools", { retry: 3 }, async () => {
await multiTurn(llm, thinkingOptions);
});
},
);
describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_AMS_API_KEY)(
"Xiaomi MiMo Token Plan Provider (Xiaomi MiMo-V2.5-Pro via Anthropic Messages, AMS region)",
() => {
const llm = getModel("xiaomi-token-plan-ams", "mimo-v2.5-pro");
const thinkingOptions = {
thinkingEnabled: true,
reasoningEffort: "high",
} satisfies StreamOptionsWithExtras;
it("should complete basic text generation", { retry: 3 }, async () => {
await basicTextGeneration(llm);
});
it("should handle tool calling", { retry: 3 }, async () => {
await handleToolCall(llm);
});
it("should handle streaming", { retry: 3 }, async () => {
await handleStreaming(llm);
});
it("should handle thinking mode", { retry: 3 }, async () => {
await handleThinking(llm, thinkingOptions);
});
it("should handle multi-turn with thinking and tools", { retry: 3 }, async () => {
await multiTurn(llm, thinkingOptions);
});
},
);
describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_SGP_API_KEY)(
"Xiaomi MiMo Token Plan Provider (Xiaomi MiMo-V2.5-Pro via Anthropic Messages, SGP region)",
() => {
const llm = getModel("xiaomi-token-plan-sgp", "mimo-v2.5-pro");
const thinkingOptions = {
thinkingEnabled: true,
reasoningEffort: "high",
} satisfies StreamOptionsWithExtras;
it("should complete basic text generation", { retry: 3 }, async () => {
await basicTextGeneration(llm);
});
it("should handle tool calling", { retry: 3 }, async () => {
await handleToolCall(llm);
});
it("should handle streaming", { retry: 3 }, async () => {
await handleStreaming(llm);
});
it("should handle thinking mode", { retry: 3 }, async () => {
await handleThinking(llm, thinkingOptions);
});
it("should handle multi-turn with thinking and tools", { retry: 3 }, async () => {
await multiTurn(llm, thinkingOptions);
});
},
);
// =========================================================================
// OAuth-based providers (credentials from ~/.pi/agent/oauth.json)
// Tokens are resolved at module level (see oauthTokens above)