fix(ai): use Xiaomi Token Plan Anthropic endpoint

closes #3912
This commit is contained in:
Mario Zechner
2026-05-02 01:36:34 +02:00
parent 80f06d3636
commit c0e046990e
11 changed files with 42 additions and 25 deletions

View File

@@ -16,6 +16,7 @@
- Always ask before removing functionality or code that appears to be intentional
- Do not preserve backward compatibility unless the user explicitly asks for it
- Never hardcode key checks with, eg. `matchesKey(keyData, "ctrl+x")`. All keybindings must be configurable. Add default to matching object (`DEFAULT_EDITOR_KEYBINDINGS` or `DEFAULT_APP_KEYBINDINGS`)
- NEVER modify `packages/ai/src/models.generated.ts` directly. Update `packages/ai/scripts/generate-models.ts` instead.
## Commands

View File

@@ -16,7 +16,7 @@
### Added
- Added Xiaomi MiMo provider (openai-completions compatible) with `XIAOMI_API_KEY` authentication.
- Added Xiaomi MiMo Token Plan provider (Anthropic-compatible) with `XIAOMI_API_KEY` authentication ([#4005](https://github.com/badlogic/pi-mono/pull/4005) by [@Phoen1xCode](https://github.com/Phoen1xCode)).
- Added `Model.thinkingLevelMap`, `getSupportedThinkingLevels()`, and `clampThinkingLevel()` so model metadata can describe supported thinking levels and provider-specific level values ([#3208](https://github.com/badlogic/pi-mono/issues/3208)).
## [0.71.1] - 2026-05-01

View File

@@ -69,7 +69,7 @@ Unified LLM API with automatic model discovery, provider configuration, token an
- **OpenCode Go**
- **Fireworks** (uses Anthropic-compatible API)
- **Kimi For Coding** (Moonshot AI, uses Anthropic-compatible API)
- **Xiaomi MiMo** (uses OpenAI-compatible API)
- **Xiaomi MiMo Token Plan** (uses Anthropic-compatible API)
- **Any OpenAI-compatible API**: Ollama, vLLM, LM Studio, etc.
## Installation
@@ -1047,6 +1047,7 @@ In Node.js environments, you can set environment variables to avoid passing API
| MiniMax | `MINIMAX_API_KEY` |
| OpenCode Zen / OpenCode Go | `OPENCODE_API_KEY` |
| Kimi For Coding | `KIMI_API_KEY` |
| Xiaomi MiMo Token Plan | `XIAOMI_API_KEY` |
| GitHub Copilot | `COPILOT_GITHUB_TOKEN` or `GH_TOKEN` or `GITHUB_TOKEN` |
When set, the library automatically uses these keys:

View File

@@ -919,9 +919,9 @@ async function loadModelsDevData(): Promise<Model<any>[]> {
models.push({
id: modelId,
name: m.name || modelId,
api: "openai-completions",
api: "anthropic-messages",
provider: "xiaomi",
baseUrl: "https://api.xiaomimimo.com/v1",
baseUrl: "https://token-plan-ams.xiaomimimo.com/anthropic",
reasoning: m.reasoning === true,
input: m.modalities?.input?.includes("image") ? ["text", "image"] : ["text"],
cost: {

View File

@@ -9316,7 +9316,7 @@ export const MODELS = {
cacheRead: 0.024999999999999998,
cacheWrite: 0.08333333333333334,
},
contextWindow: 1000000,
contextWindow: 1048576,
maxTokens: 8192,
} satisfies Model<"openai-completions">,
"google/gemini-2.0-flash-lite-001": {
@@ -16392,9 +16392,9 @@ export const MODELS = {
"mimo-v2-flash": {
id: "mimo-v2-flash",
name: "MiMo-V2-Flash",
api: "openai-completions",
api: "anthropic-messages",
provider: "xiaomi",
baseUrl: "https://api.xiaomimimo.com/v1",
baseUrl: "https://token-plan-ams.xiaomimimo.com/anthropic",
reasoning: true,
input: ["text"],
cost: {
@@ -16405,13 +16405,13 @@ export const MODELS = {
},
contextWindow: 256000,
maxTokens: 64000,
} satisfies Model<"openai-completions">,
} satisfies Model<"anthropic-messages">,
"mimo-v2-omni": {
id: "mimo-v2-omni",
name: "MiMo-V2-Omni",
api: "openai-completions",
api: "anthropic-messages",
provider: "xiaomi",
baseUrl: "https://api.xiaomimimo.com/v1",
baseUrl: "https://token-plan-ams.xiaomimimo.com/anthropic",
reasoning: true,
input: ["text", "image"],
cost: {
@@ -16422,13 +16422,13 @@ export const MODELS = {
},
contextWindow: 256000,
maxTokens: 128000,
} satisfies Model<"openai-completions">,
} satisfies Model<"anthropic-messages">,
"mimo-v2-pro": {
id: "mimo-v2-pro",
name: "MiMo-V2-Pro",
api: "openai-completions",
api: "anthropic-messages",
provider: "xiaomi",
baseUrl: "https://api.xiaomimimo.com/v1",
baseUrl: "https://token-plan-ams.xiaomimimo.com/anthropic",
reasoning: true,
input: ["text"],
cost: {
@@ -16439,13 +16439,13 @@ export const MODELS = {
},
contextWindow: 1000000,
maxTokens: 128000,
} satisfies Model<"openai-completions">,
} satisfies Model<"anthropic-messages">,
"mimo-v2.5": {
id: "mimo-v2.5",
name: "MiMo-V2.5",
api: "openai-completions",
api: "anthropic-messages",
provider: "xiaomi",
baseUrl: "https://api.xiaomimimo.com/v1",
baseUrl: "https://token-plan-ams.xiaomimimo.com/anthropic",
reasoning: true,
input: ["text"],
cost: {
@@ -16456,13 +16456,13 @@ export const MODELS = {
},
contextWindow: 1048576,
maxTokens: 131072,
} satisfies Model<"openai-completions">,
} satisfies Model<"anthropic-messages">,
"mimo-v2.5-pro": {
id: "mimo-v2.5-pro",
name: "MiMo-V2.5-Pro",
api: "openai-completions",
api: "anthropic-messages",
provider: "xiaomi",
baseUrl: "https://api.xiaomimimo.com/v1",
baseUrl: "https://token-plan-ams.xiaomimimo.com/anthropic",
reasoning: true,
input: ["text", "image"],
cost: {
@@ -16473,7 +16473,7 @@ export const MODELS = {
},
contextWindow: 1048576,
maxTokens: 131072,
} satisfies Model<"openai-completions">,
} satisfies Model<"anthropic-messages">,
},
"zai": {
"glm-4.5-air": {

View File

@@ -994,9 +994,13 @@ describe("Generate E2E Tests", () => {
);
describe.skipIf(!process.env.XIAOMI_API_KEY)(
"Xiaomi MiMo Provider (Xiaomi MiMo-V2.5-Pro via OpenAI Completions)",
"Xiaomi MiMo Token Plan Provider (Xiaomi MiMo-V2.5-Pro via Anthropic Messages)",
() => {
const llm = getModel("xiaomi", "mimo-v2.5-pro");
const thinkingOptions = {
thinkingEnabled: true,
reasoningEffort: "high",
} satisfies StreamOptionsWithExtras;
it("should complete basic text generation", { retry: 3 }, async () => {
await basicTextGeneration(llm);
@@ -1009,6 +1013,14 @@ describe("Generate E2E Tests", () => {
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);
});
},
);
// =========================================================================

View File

@@ -8,6 +8,7 @@
### Added
- Added Xiaomi MiMo Token Plan provider support with `XIAOMI_API_KEY`, default model resolution, `/login` display support, and provider documentation ([#4005](https://github.com/badlogic/pi-mono/pull/4005) by [@Phoen1xCode](https://github.com/Phoen1xCode)).
- Added model-level `thinkingLevelMap` support in `models.json` and `pi.registerProvider()`, allowing models to expose only the thinking levels they actually support ([#3208](https://github.com/badlogic/pi-mono/issues/3208)).
### Fixed

View File

@@ -128,7 +128,7 @@ For each built-in provider, pi maintains a list of tool-capable models, updated
- Fireworks
- Kimi For Coding
- MiniMax
- Xiaomi MiMo
- Xiaomi MiMo Token Plan
See [docs/providers.md](docs/providers.md) for detailed setup instructions.

View File

@@ -69,7 +69,9 @@ pi
| Kimi For Coding | `KIMI_API_KEY` | `kimi-coding` |
| MiniMax | `MINIMAX_API_KEY` | `minimax` |
| MiniMax (China) | `MINIMAX_CN_API_KEY` | `minimax-cn` |
| Xiaomi MiMo | `XIAOMI_API_KEY` | `xiaomi` |
| Xiaomi MiMo Token Plan | `XIAOMI_API_KEY` | `xiaomi` |
The Xiaomi MiMo provider targets the Xiaomi MiMo Token Plan Anthropic-compatible endpoint.
Reference for environment variables and `auth.json` keys: [`const envMap`](https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/env-api-keys.ts) in [`packages/ai/src/env-api-keys.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/env-api-keys.ts).

View File

@@ -320,7 +320,7 @@ ${chalk.bold("Environment Variables:")}
CLOUDFLARE_API_KEY - Cloudflare API token (Workers AI and AI Gateway)
CLOUDFLARE_ACCOUNT_ID - Cloudflare account id (required for both)
CLOUDFLARE_GATEWAY_ID - Cloudflare AI Gateway slug (required for AI Gateway)
XIAOMI_API_KEY - Xiaomi MiMo API key
XIAOMI_API_KEY - Xiaomi MiMo Token Plan API key
AWS_PROFILE - AWS profile for Amazon Bedrock
AWS_ACCESS_KEY_ID - AWS access key for Amazon Bedrock
AWS_SECRET_ACCESS_KEY - AWS secret key for Amazon Bedrock

View File

@@ -24,5 +24,5 @@ export const BUILT_IN_PROVIDER_DISPLAY_NAMES: Record<string, string> = {
"vercel-ai-gateway": "Vercel AI Gateway",
xai: "xAI",
zai: "ZAI",
xiaomi: "Xiaomi MiMo",
xiaomi: "Xiaomi MiMo Token Plan",
};