新增 MiMo (小米) LLM Provider 适配器,支持 mimo-v2.5-pro 和 mimo-v2.5 两个文本模型,复用 OpenAI 兼容 SSE 流式解析,支持 Thinking 模式和 Function Calling。同步校准全量 docs 文档与 README 使其与实际代码一致。 主要变更: - 新增 mimo.adapter.ts 适配器(SSE + thinking.type + max_completion_tokens) - 修复 thinking 逻辑 bug:禁用思考时未传 temperature/top_p - 补全 sse-stream.ts 的 MiMo 缓存字段映射(prompt_tokens_details.cached_tokens) - 补全 sse-stream.ts 的 finish_reason 映射(repetition_truncation) - 注册 MiMo 适配器到 adapters/index.ts、main.ts 工厂 - handlers.ts 添加 mimo.contextWindow 热重载触发 - database.service.ts seed 添加 mimo 默认配置 - SettingsModal/OnboardingWizard/Header 添加 MiMo Provider UI - constants.ts PROVIDER_LABELS 添加 mimo - .env.example 添加 MIMO_API_KEY/MIMO_BASE_URL - 反向修改 4 个 docs HTML 设计文档(工具数量/版本日期/适配器列表/数据库表) - 反向修改 Agent网络工具通用设计-v2.md 附录 B 文件索引 - 完全重写 README.md(v0.3.4、27 工具、4 适配器、9 表)
793 lines
44 KiB
HTML
793 lines
44 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>MiMo Chat Completions API 接口文档</title>
|
||
<style>
|
||
:root {
|
||
--primary: #ff6900;
|
||
--primary-light: #fff4eb;
|
||
--text: #1a1a2e;
|
||
--text-secondary: #555;
|
||
--border: #e0e0e0;
|
||
--bg: #ffffff;
|
||
--code-bg: #f6f8fa;
|
||
--accent-blue: #2563eb;
|
||
--accent-green: #16a34a;
|
||
--accent-red: #dc2626;
|
||
--accent-purple: #7c3aed;
|
||
--shadow: 0 2px 8px rgba(0,0,0,0.08);
|
||
--radius: 8px;
|
||
}
|
||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif; color: var(--text); line-height: 1.7; background: var(--bg); }
|
||
|
||
/* Header */
|
||
.hero { background: linear-gradient(135deg, #ff6900 0%, #ff8533 50%, #ffa366 100%); color: #fff; padding: 48px 24px 40px; text-align: center; }
|
||
.hero h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 12px; }
|
||
.hero p { opacity: 0.92; font-size: 1.05rem; max-width: 700px; margin: 0 auto; }
|
||
.hero .badge { display: inline-block; background: rgba(255,255,255,0.22); padding: 4px 14px; border-radius: 20px; font-size: 0.82rem; margin-top: 16px; backdrop-filter: blur(4px); }
|
||
|
||
/* Container */
|
||
.container { max-width: 960px; margin: 0 auto; padding: 0 24px; }
|
||
|
||
/* TOC */
|
||
.toc { background: var(--primary-light); border: 1px solid #ffd9b3; border-radius: var(--radius); padding: 28px 32px; margin: -30px auto 36px; position: relative; z-index: 10; box-shadow: var(--shadow); }
|
||
.toc h2 { font-size: 1.15rem; color: var(--primary); margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
|
||
.toc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 20px; }
|
||
.toc a { color: var(--text); text-decoration: none; font-size: 0.92rem; padding: 3px 0; display: flex; align-items: center; gap: 6px; transition: color .15s; }
|
||
.toc a:hover { color: var(--primary); }
|
||
|
||
/* Sections */
|
||
section { margin-bottom: 48px; scroll-margin-top: 24px; }
|
||
section h2 { font-size: 1.55rem; font-weight: 700; margin-bottom: 18px; padding-bottom: 10px; border-bottom: 2px solid var(--primary); display: flex; align-items: center; gap: 10px; }
|
||
section h3 { font-size: 1.2rem; font-weight: 600; margin: 26px 0 12px; color: var(--text); }
|
||
section h4 { font-size: 1.02rem; font-weight: 600; margin: 18px 0 8px; color: var(--text-secondary); }
|
||
|
||
/* Method badge */
|
||
.method-badge { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 10px; }
|
||
.method-tag { padding: 4px 12px; border-radius: 5px; font-size: 0.82rem; font-weight: 700; letter-spacing: 0.5px; color: #fff; }
|
||
.method-post { background: var(--accent-green); }
|
||
.url-box { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.88rem; background: var(--code-bg); padding: 10px 16px; border-radius: 6px; border: 1px solid var(--border); word-break: break-all; color: var(--accent-blue); }
|
||
|
||
/* Tables */
|
||
table { width: 100%; border-collapse: collapse; margin: 14px 0 20px; font-size: 0.9rem; }
|
||
th { background: #f0f0f0; text-align: left; padding: 10px 14px; font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap; }
|
||
td { padding: 9px 14px; border-bottom: 1px solid #eee; vertical-align: top; }
|
||
tr:hover td { background: #fafafa; }
|
||
.type-tag { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.83rem; color: var(--accent-purple); background: #f3effa; padding: 1px 7px; border-radius: 4px; }
|
||
.required-tag { font-size: 0.78rem; font-weight: 600; padding: 1px 7px; border-radius: 4px; }
|
||
.req-yes { background: #fef2f2; color: var(--accent-red); }
|
||
.req-no { background: #f0fdf4; color: var(--accent-green); }
|
||
.req-default { background: #eff6ff; color: var(--accent-blue); }
|
||
|
||
/* Code blocks */
|
||
pre { background: #1e1e2e; color: #cdd6f4; padding: 20px 24px; border-radius: var(--radius); overflow-x: auto; font-size: 0.85rem; line-height: 1.6; margin: 14px 0 20px; position: relative; }
|
||
pre code { font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace; background: none; padding: 0; }
|
||
.code-lang { position: absolute; top: 0; right: 12px; font-size: 0.72rem; color: rgba(255,255,255,0.35); text-transform: uppercase; letter-spacing: 1px; }
|
||
|
||
/* Inline code */
|
||
code:not(pre code) { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.84em; background: var(--code-bg); padding: 2px 7px; border-radius: 4px; color: #d63384; }
|
||
|
||
/* Info / Warning boxes */
|
||
.info-box { background: #eff6ff; border-left: 4px solid var(--accent-blue); padding: 14px 18px; border-radius: 0 var(--radius) var(--radius) 0; margin: 16px 0; font-size: 0.92rem; }
|
||
.info-box strong { color: var(--accent-blue); }
|
||
.warn-box { background: #fffbeb; border-left: 4px solid #d97706; padding: 14px 18px; border-radius: 0 var(--radius) var(--radius) 0; margin: 16px 0; font-size: 0.92rem; }
|
||
.warn-box strong { color: #b45309; }
|
||
.tip-box { background: #f0fdf4; border-left: 4px solid var(--accent-green); padding: 14px 18px; border-radius: 0 var(--radius) var(--radius) 0; margin: 16px 0; font-size: 0.92rem; }
|
||
.tip-box strong { color: var(--accent-green); }
|
||
|
||
/* Tabs */
|
||
.tabs { display: flex; gap: 0; margin: 16px 0 0; border-bottom: 2px solid var(--border); }
|
||
.tab-btn { padding: 8px 18px; cursor: pointer; border: none; background: none; font-size: 0.88rem; font-weight: 500; color: var(--text-secondary); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
|
||
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
|
||
.tab-content { display: none; }
|
||
.tab-content.active { display: block; }
|
||
|
||
/* Feature cards */
|
||
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 18px 0; }
|
||
.feature-card { background: #fafafa; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; transition: box-shadow .15s; }
|
||
.feature-card:hover { box-shadow: var(--shadow); }
|
||
.feature-card .icon { font-size: 1.5rem; margin-bottom: 8px; }
|
||
.feature-card h4 { margin: 0 0 6px; font-size: 0.95rem; }
|
||
.feature-card p { font-size: 0.84rem; color: var(--text-secondary); margin: 0; }
|
||
|
||
/* Footer */
|
||
footer { background: #1a1a2e; color: rgba(255,255,255,0.65); text-align: center; padding: 32px 24px; margin-top: 56px; font-size: 0.86rem; }
|
||
footer a { color: var(--primary); text-decoration: none; }
|
||
|
||
/* Responsive */
|
||
@media (max-width: 640px) {
|
||
.hero h1 { font-size: 1.6rem; }
|
||
.toc { padding: 20px; margin-top: -20px; }
|
||
table { font-size: 0.82rem; }
|
||
th, td { padding: 7px 10px; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<!-- ===== HERO ===== -->
|
||
<div class="hero">
|
||
<h1>🔮 MiMo Chat Completions API</h1>
|
||
<p>Xiaomi MiMo V2.5 系列 OpenAI 兼容对话补全接口完整文档。支持多轮对话、深度思考、工具调用、联网搜索、语音合成、图像/视频输入等全功能。</p>
|
||
<div class="badge">支持模型:mimo-v2.5-pro · mimo-v2.5 · mimo-v2.5-tts · mimo-v2.5-tts-voicedesign · mimo-v2.5-tts-voiceclone</div>
|
||
</div>
|
||
|
||
<div class="container">
|
||
|
||
<!-- ===== TOC ===== -->
|
||
<nav class="toc">
|
||
<h2>📋 目录导航</h2>
|
||
<div class="toc-grid">
|
||
<a href="#overview">📌 概述 & 基本信息</a>
|
||
<a href="#quickstart">⚡ 快速开始</a>
|
||
<a href="#models">💰 可用模型</a>
|
||
<a href="#request-auth">🔐 认证方式</a>
|
||
<a href="#request-body">📥 请求参数详解</a>
|
||
<a href="#response">📤 响应对象(非流式)</a>
|
||
<a href="#response-stream">📤 响应 Chunk(流式)</a>
|
||
<a href="#thinking">🧠 深度思考模式</a>
|
||
<a href="#tools">🔧 工具调用 (Function Calling)</a>
|
||
<a href="#websearch">🌐 联网搜索</a>
|
||
<a href="#tts">🎙️ 语音合成 (TTS)</a>
|
||
<a href="#examples">💻 代码示例</a>
|
||
<a href="#errors">⚠️ 错误码说明</a>
|
||
</div>
|
||
</nav>
|
||
|
||
<!-- ===== OVERVIEW ===== -->
|
||
<section id="overview">
|
||
<h2>📌 概述 & 基本信息</h2>
|
||
<p>MiMo Chat Completions API 是小米大语言模型提供的 OpenAI 兼容对话补全接口,支持 RESTful HTTP 协议,所有请求与响应均使用 JSON 格式。流式响应采用 SSE(Server-Sent Events)。</p>
|
||
|
||
<div style="margin-top:18px;">
|
||
<table>
|
||
<tr><th width="140">项目</th><th>值</th></tr>
|
||
<tr><td>Base URL</td><td><code>https://api.xiaomimimo.com/v1/chat/completions</code></td></tr>
|
||
<tr><td>协议</td><td>HTTPS (POST)</td></tr>
|
||
<tr><td>认证方式</td><td>api-key Header 或 Authorization Bearer</td></tr>
|
||
<tr><td>内容类型</td><td>application/json</td></tr>
|
||
<tr><td>SDK 兼容</td><td>OpenAI Python / Node.js SDK(修改 base_url 即可)</td></tr>
|
||
<tr><td>文档日期</td><td>2026-07-15</td></tr>
|
||
<tr><td>更新时间</td><td>2026-06-29(官方)</td></tr>
|
||
</table>
|
||
</div>
|
||
|
||
<div class="info-box" style="margin-top:18px;">
|
||
<strong>⚠️ 版本提醒:</strong>MiMo-V2 系列模型已于 <strong>2026.6.30 00:00</strong> 正式下线,原模型名称已失效。请使用 V2.5 系列模型。
|
||
</div>
|
||
|
||
<h3>核心能力一览</h3>
|
||
<div class="feature-grid">
|
||
<div class="feature-card"><div class="icon">💬</div><h4>多轮对话</h4><p>支持 system/user/assistant/developer/tool 多角色消息</p></div>
|
||
<div class="feature-card"><div class="icon">🧠</div><h4>深度思考</h4><p>思维链推理,返回 reasoning_content</p></div>
|
||
<div class="feature-card"><div class="icon">🔧</div><h4>工具调用</h4><p>Function Calling + Web Search 工具</p></div>
|
||
<div class="feature-card"><div class="icon">🌐</div><h4>联网搜索</h4><p>自动联网检索并返回引用注释</p></div>
|
||
<div class="feature-card"><div class="icon">🖼️</div><h4>多模态输入</h4><p>支持图像、音频、视频输入</p></div>
|
||
<div class="feature-card"><div class="icon">🎙️</div><h4>语音合成</h4><p>TTS / Voice Design / Voice Clone</p></div>
|
||
<div class="feature-card"><div class="icon">📡</div><h4>SSE 流式</h4><p>流式输出,降低首字延迟</p></div>
|
||
<div class="feature-card"><div class="icon">📊</div><h4>用量明细</h4><td>缓存命中/推理 token 等详细统计</td></div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ===== QUICK START ===== -->
|
||
<section id="quickstart">
|
||
<h2>⚡ 快速开始</h2>
|
||
<p>获取 API Key 后即可开始调用。支持 OpenAI SDK 兼容格式,也可直接使用 HTTP 请求。</p>
|
||
|
||
<div class="tabs">
|
||
<button class="tab-btn active" onclick="switchTab(event,'tab-q-curl')">curl</button>
|
||
<button class="tab-btn" onclick="switchTab(event,'tab-q-python')">Python (OpenAI SDK)</button>
|
||
</div>
|
||
|
||
<div id="tab-q-curl" class="tab-content active">
|
||
<pre><span class="code-lang">bash</span>curl --location --request POST 'https://api.xiaomimimo.com/v1/chat/completions' \
|
||
--header "api-key: $MIMO_API_KEY" \
|
||
--header "Content-Type: application/json" \
|
||
--data-raw '{
|
||
"model": "mimo-v2.5-pro",
|
||
"messages": [
|
||
{
|
||
"role": "system",
|
||
"content": "You are MiMo, an AI assistant developed by Xiaomi."
|
||
},
|
||
{
|
||
"role": "user",
|
||
"content": "你好,请介绍一下自己"
|
||
}
|
||
],
|
||
"max_completion_tokens": 1024,
|
||
"temperature": 1.0,
|
||
"top_p": 0.95,
|
||
"stream": false,
|
||
"thinking": {
|
||
"type": "disabled"
|
||
}
|
||
}'</pre>
|
||
</div>
|
||
|
||
<div id="tab-q-python" class="tab-content">
|
||
<pre><span class="code-lang">python</span>from openai import OpenAI
|
||
|
||
client = OpenAI(
|
||
api_key="$MIMO_API_KEY",
|
||
base_url="https://api.xiaomimimo.com/v1"
|
||
)
|
||
|
||
response = client.chat.completions.create(
|
||
model="mimo-v2.5-pro",
|
||
messages=[
|
||
{"role": "system", "content": "You are MiMo, an AI assistant developed by Xiaomi."},
|
||
{"role": "user", "content": "你好,请介绍一下自己"}
|
||
],
|
||
max_completion_tokens=1024,
|
||
temperature=1.0,
|
||
thinking={"type": "disabled"}
|
||
)
|
||
|
||
print(response.choices[0].message.content)</pre>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ===== MODELS ===== -->
|
||
<section id="models">
|
||
<h2>💰 可用模型</h2>
|
||
<table>
|
||
<tr><th>模型 ID</th><th>类型</th><th>默认 max_tokens</th><th>深度思考</th><th>工具调用</th><th>语音合成</th><th>联网搜索</th></tr>
|
||
<tr><td><code>mimo-v2.5-pro</code></td><td>旗舰文本</td><td>131072</td><td>✅ 支持</td><td>✅ 支持</td><td>❌</td><td>✅ 支持</td></tr>
|
||
<tr><td><code>mimo-v2.5</code></td><td>标准文本</td><td>32768</td><td>✅ 支持</td><td>✅ 支持</td><td>❌</td><td>✅ 支持</td></tr>
|
||
<tr><td><code>mimo-v2.5-tts</code></td><td>语音合成</td><td>8192</td><td>❌</td><td>❌</td><td>✅ 预置音色</td><td>❌</td></tr>
|
||
<tr><td><code>mimo-v2.5-tts-voicedesign</code></td><td>音色设计</td><td>8192</td><td>❌</td><td>❌</td><td>✅ 音色设计</td><td>❌</td></tr>
|
||
<tr><td><code>mimo-v2.5-tts-voiceclone</code></td><td>声音克隆</td><td>8192</td><td>❌</td><td>❌</td><td>✅ 声音克隆</td><td>❌</td></tr>
|
||
</table>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 temperature 默认值:</strong>mimo-v2.5-pro / mimo-v2.5 默认 <code>1.0</code>;TTS 系列默认 <code>0.6</code>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ===== AUTH ===== -->
|
||
<section id="request-auth">
|
||
<h2>🔐 认证方式</h2>
|
||
<p>接口支持以下两种认证方式,<strong>选择其中一种</strong>添加到请求头中:</p>
|
||
|
||
<h3>方式一:api-key 字段认证</h3>
|
||
<pre><span class="code-lang">http</span>api-key: $MIMO_API_KEY
|
||
Content-Type: application/json</pre>
|
||
|
||
<h3>方式二:Authorization Bearer 认证</h3>
|
||
<pre><span class="code-lang">http</span>Authorization: Bearer $MIMO_API_KEY
|
||
Content-Type: application/json</pre>
|
||
</section>
|
||
|
||
<!-- ===== REQUEST BODY ===== -->
|
||
<section id="request-body">
|
||
<h2>📥 请求参数详解</h2>
|
||
|
||
<div class="method-badge">
|
||
<span class="method-tag method-post">POST</span>
|
||
<span class="url-box">https://api.xiaomimimo.com/v1/chat/completions</span>
|
||
</div>
|
||
|
||
<h3>核心参数</h3>
|
||
<table>
|
||
<tr><th width="160">参数名</th><th width="90">类型</th><th width="70">必填</th><th>描述</th></tr>
|
||
<tr><td><code>model</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-yes">必选</span></td><td>模型 ID。可选值:<code>mimo-v2.5-pro</code>, <code>mimo-v2.5</code>, <code>mimo-v2.5-tts</code>, <code>mimo-v2.5-tts-voicedesign</code>, <code>mimo-v2.5-tts-voiceclone</code></td></tr>
|
||
<tr><td><code>messages</code></td><td><span class="type-tag">array</span></td><td><span class="required-tag req-yes">必选</span></td><td>对话消息列表。支持 role: system / user / assistant / developer / tool</td></tr>
|
||
<tr><td><code>messages[].role</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-yes">必选</span></td><td>角色:<code>system</code> / <code>user</code> / <code>assistant</code> / <code>developer</code> / <code>tool</code></td></tr>
|
||
<tr><td><code>messages[].content</code></td><td><span class="type-tag">string | array</span></td><td><span class="required-tag req-yes">必选</span></td><td>消息内容。支持纯文本或多模态 content parts 数组</td></tr>
|
||
<tr><td><code>messages[].name</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-no">可选</span></td><td>参与者名称,用于区分相同角色的不同参与者</td></tr>
|
||
</table>
|
||
|
||
<h3>生成控制参数</h3>
|
||
<table>
|
||
<tr><th width="160">参数名</th><th width="90">类型</th><th width="70">必填</th><th>描述</th></tr>
|
||
<tr><td><code>max_completion_tokens</code></td><td><span class="type-tag">integer | null</span></td><td><span class="required-tag req-default">可选</span></td><td>生成 token 上限(含推理 token)。pro 默认 131072;标准版 32768;TTS 系列 8192。范围 [1, 131072]</td></tr>
|
||
<tr><td><code>temperature</code></td><td><span class="type-tag">number</span></td><td><span class="required-tag req-default">可选</span></td><td>采样温度 [0, 1.5]。pro/标准默认 1.0;TTS 默认 0.6。思考模式下不可自定义</td></tr>
|
||
<tr><td><code>top_p</code></td><td><span class="type-tag">number</span></td><td><span class="required-tag req-default">可选</span></td><td>核采样概率 [0.01, 1.0],默认 0.95。建议仅与 temperature 二选一。思考模式下不可自定义</td></tr>
|
||
<tr><td><code>frequency_penalty</code></td><td><span class="type-tag">number | null</span></td><td><span class="required-tag req-default">可选</span></td><td>频率惩罚 [-2.0, 2.0],默认 0</td></tr>
|
||
<tr><td><code>presence_penalty</code></td><td><span class="type-tag">number | null</span></td><td><span class="required-tag req-default">可选</span></td><td>存在惩罚 [-2.0, 2.0],默认 0</td></tr>
|
||
<tr><td><code>stop</code></td><td><span class="type-tag">string | array | null</span></td><td><span class="required-tag req-default">可选</span></td><td>停止序列(最多 4 个)。TTS 系列不支持</td></tr>
|
||
<tr><td><code>stream</code></td><td><span class="type-tag">boolean | null</span></td><td><span class="required-tag req-default">可选</span></td><td>是否 SSE 流式传输,默认 false</td></tr>
|
||
<tr><td><code>response_format</code></td><td><span class="type-tag">object</span></td><td><span class="required-tag req-default">可选</span></td><td>指定输出格式。TTS 系列不支持</td></tr>
|
||
</table>
|
||
|
||
<h3>深度思考参数</h3>
|
||
<table>
|
||
<tr><th width="160">参数名</th><th width="90">类型</th><th width="70">必填</th><th>描述</th></tr>
|
||
<tr><td><code>thinking</code></td><td><span class="type-tag">object</span></td><td><span class="required-tag req-default">可选</span></td><td>思维链控制。TTS 系列不支持</td></tr>
|
||
<tr><td><code>thinking.type</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-default">可选</span></td><td><code>"enabled"</code>(默认)或 <code>"disabled"</code></td></tr>
|
||
</table>
|
||
|
||
<div class="warn-box">
|
||
<strong>⚠️ 思考模式限制:</strong>在思考模式下,mimo-v2.5-pro / mimo-v2.5 不支持自定义 temperature 和 top_p,强制使用推荐默认值 1.0 和 0.95。多轮工具调用中建议保留历史 reasoning_content。
|
||
</div>
|
||
|
||
<h3>工具调用参数</h3>
|
||
<table>
|
||
<tr><th width="160">参数名</th><th width="90">类型</th><th width="70">必填</th><th>描述</th></tr>
|
||
<tr><td><code>tools</code></td><td><span class="type-tag">array</span></td><td><span class="required-tag req-default">可选</span></td><td>工具列表。支持 function 和 web_search 两种类型。TTS 系列不支持</td></tr>
|
||
<tr><td><code>tools[].type</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-yes">必选</span></td><td>工具类型:<code>"function"</code> 或 <code>"web_search"</code></td></tr>
|
||
<tr><td><code>tools[].function.name</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-yes">必选</span></td><td>函数名(a-z, A-Z, 0-9, _, -),最大 64 字符</td></tr>
|
||
<tr><td><code>tools[].function.description</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-default">可选</span></td><td>功能描述</td></tr>
|
||
<tr><td><code>tools[].function.parameters</code></td><td><span class="type-tag">object</span></td><td><span class="required-tag req-default">可选</span></td><td>JSON Schema 格式的参数定义</td></tr>
|
||
<tr><td><code>tools[].function.strict</code></td><td><span class="type-tag">boolean</span></td><td><span class="required-tag req-default">可选</span></td><td>是否严格遵循 schema,默认 false</td></tr>
|
||
<tr><td><code>tool_choice</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-default">可选</span></td><td>仅支持 <code>"auto"</code>。传入其他值会被后端移除。TTS 系列不支持</td></tr>
|
||
</table>
|
||
|
||
<h3>语音合成参数 (audio)</h3>
|
||
<table>
|
||
<tr><th width="160">参数名</th><th width="90">类型</th><th width="70">必填</th><th>描述</th></tr>
|
||
<tr><td><code>audio</code></td><td><span class="type-tag">object</span></td><td><span class="required-tag req-default">可选</span></td><td>音频输出参数。仅 TTS 系列模型支持</td></tr>
|
||
<tr><td><code>audio.format</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-default">可选</span></td><td>输出格式:<code>wav</code>(默认) / <code>mp3</code> / <code>pcm</code> / <code>pcm16</code>。stream:true 时默认 pcm</td></tr>
|
||
<tr><td><code>audio.voice</code></td><td><span class="type-tag">string</span></td><td><span class="required-tag req-default">可选</span></td><td>预置音色 ID 或 base64 音频样本。TTS 预置:<code>mimo_default</code>, <code>冰糖</code>, <code>茉莉</code>, <code>苏打</code>, <code>白桦</code>, <code>Mia</code>, <code>Chloe</code>, <code>Milo</code>, <code>Dean</code></td></tr>
|
||
<tr><td><code>audio.optimize_text_preview</code></td><td><span class="type-tag">boolean</span></td><td><span class="required-tag req-default">可选</span></td><td>智能润色播报文本,默认 false。仅 voicedesign 模型支持</td></tr>
|
||
</table>
|
||
|
||
<div class="tip-box">
|
||
<strong>💡 TTS 提示:</strong>要生成音频时,必须添加一条 <code>role: "assistant"</code> 的消息指定合成文本。使用 voicedesign + optimize_text_preview=true 时可省略 assistant 消息。
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ===== RESPONSE ===== -->
|
||
<section id="response">
|
||
<h2>📤 响应对象(非流式输出)</h2>
|
||
<p>当 <code>stream: false</code> 时,API 返回完整的 <code>chat.completion</code> 对象。</p>
|
||
|
||
<h3>顶层字段</h3>
|
||
<table>
|
||
<tr><th width="180">字段名</th><th width="90">类型</th><th>描述</th></tr>
|
||
<tr><td><code>id</code></td><td><span class="type-tag">string</span></td><td>响应的唯一标识符</td></tr>
|
||
<tr><td><code>object</code></td><td><span class="type-tag">string</span></td><td>固定值 <code>"chat.completion"</code></td></tr>
|
||
<tr><td><code>created</code></td><td><span class="type-tag">integer</span></td><td>Unix 时间戳(秒)</td></tr>
|
||
<tr><td><code>model</code></td><td><span class="type-tag">string</span></td><td>实际使用的模型 ID</td></tr>
|
||
</table>
|
||
|
||
<h3>choices[] 字段</h3>
|
||
<table>
|
||
<tr><th width="200">字段名</th><th width="80">类型</th><th>描述</th></tr>
|
||
<tr><td><code>choices[].index</code></td><td><span class="type-tag">integer</span></td><td>选项索引</td></tr>
|
||
<tr><td><code>choices[].finish_reason</code></td><td><span class="type-tag">string</span></td><td>停止原因:<code>stop</code> / <code>length</code> / <code>tool_calls</code> / <code>content_filter</code> / <code>repetition_truncation</code></td></tr>
|
||
<tr><td><code>choices[].message.content</code></td><td><span class="type-tag">string</span></td><td>回复内容</td></tr>
|
||
<tr><td><code>choices[].message.reasoning_content</code></td><td><span class="type-tag">string</span></td><td>思维链推理内容(思考模式)</td></tr>
|
||
<tr><td><code>choices[].message.role</code></td><td><span class="type-tag">string</span></td><td>固定为 <code>"assistant"</code></td></tr>
|
||
<tr><td><code>choices[].message.tool_calls</code></td><td><span class="type-tag">array</span></td><td>工具调用列表(如有)</td></tr>
|
||
<tr><td><code>choices[].message.tool_calls[].id</code></td><td><span class="type-tag">string</span></td><td>工具调用 ID</td></tr>
|
||
<tr><td><code>choices[].message.tool_calls[].type</code></td><td><span class="type-tag">string</span></td><td>固定为 <code>"function"</code></td></tr>
|
||
<tr><td><code>choices[].message.tool_calls[].function.name</code></td><td><span class="type-tag">string</span></td><td>被调用的函数名</td></tr>
|
||
<tr><td><code>choices[].message.tool_calls[].function.arguments</code></td><td><span class="type-tag">string</span></td><td>JSON 格式的调用参数</td></tr>
|
||
<tr><td><code>choices[].message.annotations</code></td><td><span class="type-tag">array</span></td><td>联网搜索引用注释(如有)</td></tr>
|
||
<tr><td><code>choices[].message.audio</code></td><td><span class="type-tag">object</span></td><td>音频响应数据(TTS 请求时)</td></tr>
|
||
<tr><td><code>choices[].message.audio.id</code></td><td><span class="type-tag">string</span></td><td>音频唯一标识</td></tr>
|
||
<tr><td><code>choices[].message.audio.data</code></td><td><span class="type-tag">string</span></td><td>Base64 编码的音频数据</td></tr>
|
||
<tr><td><code>choices[].final_text_preview</code></td><td><span class="type-tag">string</span></td><td>优化后的播报文本(optimize_text_preview 时返回)</td></tr>
|
||
</table>
|
||
|
||
<h3>usage 用量信息</h3>
|
||
<table>
|
||
<tr><th width="220">字段名</th><th width="80">类型</th><th>描述</th></tr>
|
||
<tr><td><code>usage.prompt_tokens</code></td><td><span class="type-tag">integer</span></td><td>提示词 token 数</td></tr>
|
||
<tr><td><code>usage.completion_tokens</code></td><td><span class="type-tag">integer</span></td><td>输出 token 数</td></tr>
|
||
<tr><td><code>usage.total_tokens</code></td><td><span class="type-tag">integer</span></td><td>总 token 数</td></tr>
|
||
<tr><td><code>usage.completion_tokens_details.reasoning_tokens</code></td><td><span class="type-tag">integer</span></td><td>推理 token 数</td></tr>
|
||
<tr><td><code>usage.prompt_tokens_details.cached_tokens</code></td><td><span class="type-tag">integer</span></td><td>缓存命中的 token 数</td></tr>
|
||
<tr><td><code>usage.prompt_tokens_details.audio_tokens</code></td><td><span class="type-tag">integer</span></td><td>音频输入 token 数</td></tr>
|
||
<tr><td><code>usage.prompt_tokens_details.image_tokens</code></td><td><span class="type-tag">integer</span></td><td>图像输入 token 数</td></tr>
|
||
<tr><td><code>usage.prompt_tokens_details.video_tokens</code></td><td><span class="type-tag">integer</span></td><td>视频输入 token 数</td></tr>
|
||
<tr><td><code>usage.web_search_usage.tool_usage</code></td><td><span class="type-tag">integer</span></td><td>联网搜索 API 调用次数</td></tr>
|
||
<tr><td><code>usage.web_search_usage.page_usage</code></td><td><span class="type-tag">integer</span></td><td>联网搜索返回网页数</td></tr>
|
||
</table>
|
||
|
||
<h3>响应示例</h3>
|
||
<pre><span class="code-lang">json</span>{
|
||
"id": "8b51f9e0515949cb8207fbd35ea6ea5c",
|
||
"object": "chat.completion",
|
||
"created": 1776848906,
|
||
"model": "mimo-v2.5-pro",
|
||
"choices": [
|
||
{
|
||
"finish_reason": "stop",
|
||
"index": 0,
|
||
"message": {
|
||
"content": "Hello! I'm MiMo, Xiaomi's AI assistant created by the Xiaomi LLM-Core team...",
|
||
"role": "assistant",
|
||
"tool_calls": null
|
||
}
|
||
}
|
||
],
|
||
"usage": {
|
||
"completion_tokens": 72,
|
||
"prompt_tokens": 57,
|
||
"total_tokens": 129,
|
||
"completion_tokens_details": {
|
||
"reasoning_tokens": 0
|
||
},
|
||
"prompt_tokens_details": null
|
||
}
|
||
}</pre>
|
||
</section>
|
||
|
||
<!-- ===== STREAM RESPONSE ===== -->
|
||
<section id="response-stream">
|
||
<h2>📤 响应 Chunk 对象(流式输出)</h2>
|
||
<p>当 <code>stream: true</code> 时,API 通过 SSE 以 <code>chat.completion.chunk</code> 格式增量返回数据。</p>
|
||
|
||
<div class="info-box">
|
||
<strong>SSE 格式说明:</strong>每个 chunk 以 <code>data: {...}</code> 行发送,结束标记为 <code>data: [DONE]</code>。
|
||
</div>
|
||
|
||
<h3>Chunk 特有字段(vs 非流式差异)</h3>
|
||
<table>
|
||
<tr><th width="220">字段名</th><th width="80">类型</th><th>描述</th></tr>
|
||
<tr><td><code>object</code></td><td><span class="type-tag">string</span></td><td>固定值 <code>"chat.completion.chunk"</code></td></tr>
|
||
<tr><td><code>choices[].delta</code></td><td><span class="type-tag">object</span></td><td>增量数据(替代 message)</td></tr>
|
||
<tr><td><code>choices[].delta.content</code></td><td><span class="type-tag">string</span></td><td>本 chunk 的文本增量</td></tr>
|
||
<tr><td><code>choices[].delta.reasoning_content</code></td><td><span class="type-tag">string</span></td><td>本 chunk 的推理增量</td></tr>
|
||
<tr><td><code>choices[].delta.role</code></td><td><span class="type-tag">string</span></td><td>首个 chunk 中的角色(通常为 "assistant")</td></tr>
|
||
<tr><td><code>choices[].delta.tool_calls</code></td><td><span class="type-tag">array</span></td><td>增量工具调用(含 index 定位)</td></tr>
|
||
<tr><td><code>choices[].delta.tool_calls[].index</code></td><td><span class="type-tag">integer</span></td><td>工具调用在列表中的索引(从 0 开始)</td></tr>
|
||
<tr><td><code>choices[].delta.audio</code></td><td><span class="type-tag">object | null</span></td><td>音频增量数据</td></tr>
|
||
<tr><td><code>choices[].finish_reason</code></td><td><span class="type-tag">string | null</span></td><td>最后一个 chunk 的停止原因</td></tr>
|
||
</table>
|
||
|
||
<p>其余字段(id, created, model, usage, annotations 等)与非流式相同,通常仅在最后一个 chunk 中返回 usage。</p>
|
||
</section>
|
||
|
||
<!-- ===== THINKING ===== -->
|
||
<section id="thinking">
|
||
<h2>🧠 深度思考模式</h2>
|
||
<p>MiMo V2.5 Pro 和标准版支持思维链(Chain-of-Thought)推理,让模型在回答前进行深度推理。适用于数学、逻辑、编程、复杂分析等场景。</p>
|
||
|
||
<h3>核心参数</h3>
|
||
<table>
|
||
<tr><th width="160">参数名</th><th width="90">类型</th><th>描述</th></tr>
|
||
<tr><td><code>thinking.type</code></td><td><span class="type-tag">string</span></td><td><code>"enabled"</code>(默认)启用 / <code>"disabled"</code> 关闭</td></tr>
|
||
</table>
|
||
|
||
<h3>行为说明</h3>
|
||
<ul style="padding-left:20px;margin:12px 0;font-size:0.93rem;">
|
||
<li>启用后,响应中 <code>reasoning_content</code> 字段包含模型的推理过程,<code>content</code> 为最终回答</li>
|
||
<li>思考模式下 <code>temperature</code> 强制为 <code>1.0</code>,<code>top_p</code> 强制为 <code>0.95</code>,自定义无效</li>
|
||
<li>多轮工具调用中,模型同时返回 <code>tool_calls</code> 和 <code>reasoning_content</code></li>
|
||
<li><strong>建议</strong>:后续每次请求的 messages 中保留所有历史 reasoning_content,以获得最佳表现</li>
|
||
</ul>
|
||
|
||
<div class="warn-box">
|
||
<strong>不支持范围:</strong>mimo-v2.5-tts / mimo-v2.5-tts-voicedesign / mimo-v2.5-tts-voiceclone 不支持思考模式。
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ===== TOOLS ===== -->
|
||
<section id="tools">
|
||
<h2>🔧 工具调用 (Function Calling)</h2>
|
||
<p>MiMo 支持 Function Calling,允许模型调用外部函数获取信息或执行操作。同时内置 <strong>Web Search</strong> 联网搜索工具。</p>
|
||
|
||
<h3>核心要点</h3>
|
||
<table>
|
||
<tr><th width="180">特性</th><th>描述</th></tr>
|
||
<tr><td>工具类型</td><td><code>function</code>(函数工具)+ <code>web_search</code>(联网搜索)</td></tr>
|
||
<tr><td>tool_choice</td><td>仅支持 <code>"auto"</code>。传入其他值会被后端移除</td></tr>
|
||
<tr><td>strict 模式</td><td>支持 <code>strict: true</code>,严格遵循 JSON Schema(子集)</td></tr>
|
||
<tr><td>思考模式兼容</td><td>V2.5 Pro/标准版支持思考模式下的工具调用</td></tr>
|
||
</table>
|
||
|
||
<h3>Function Tool 结构</h3>
|
||
<pre><span class="code-lang">json</span>{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_weather",
|
||
"description": "获取指定城市的当前天气信息",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"location": { "type": "string", "description": "城市名称" }
|
||
},
|
||
"required": ["location"]
|
||
},
|
||
"strict": false
|
||
}
|
||
}</pre>
|
||
|
||
<div class="tip-box">
|
||
<strong>💡 多轮工具调用提示:</strong>思考模式下工具调用会同时返回 reasoning_content,务必在后续轮次中保留以维持上下文连贯性。
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ===== WEB SEARCH ===== -->
|
||
<section id="websearch">
|
||
<h2>🌐 联网搜索</h2>
|
||
<p>MiMo 内置 Web Search 工具,模型可自动联网检索最新信息并在回答中引用来源。</p>
|
||
|
||
<h3>启用方式</h3>
|
||
<p>在 <code>tools</code> 数组中添加 web search 类型的工具:</p>
|
||
<pre><span class="code-lang">json</span>{
|
||
"tools": [
|
||
{ "type": "web_search" }
|
||
]
|
||
}</pre>
|
||
|
||
<h3>返回的引用注释 (annotations)</h3>
|
||
<table>
|
||
<tr><th width="200">字段名</th><th width="80">类型</th><th>描述</th></tr>
|
||
<tr><td><code>annotations[].title</code></td><td><span class="type-tag">string</span></td><td>引用页面标题</td></tr>
|
||
<tr><td><code>annotations[].url</code></td><td><span class="type-tag">string</span></td><td>引用网址</td></tr>
|
||
<tr><td><code>annotations[].site_name</code></td><td><span class="type-tag">string</span></td><td>网站名称</td></tr>
|
||
<tr><td><code>annotations[].summary</code></td><td><span class="type-tag">string</span></td><td>内容摘要</td></tr>
|
||
<tr><td><code>annotations[].publish_time</code></td><td><span class="type-tag">string</span></td><td>发布时间</td></tr>
|
||
<tr><td><code>annotations[].logo_url</code></td><td><span class="type-tag">string</span></td><td>网站 Logo 地址</td></tr>
|
||
<tr><td><code>annotations[].type</code></td><td><span class="type-tag">string</span></td><td>类型</td></tr>
|
||
<tr><td><code>error_message</code></td><td><span class="type-tag">string</span></td><td>联网搜索错误信息(如有)</td></tr>
|
||
</table>
|
||
</section>
|
||
|
||
<!-- ===== TTS ===== -->
|
||
<section id="tts">
|
||
<h2>🎙️ 语音合成 (TTS)</h2>
|
||
<p>MiMo 提供三种 TTS 能力,通过不同的模型和 audio 参数组合实现。</p>
|
||
|
||
<h3>三种模式对比</h3>
|
||
<table>
|
||
<tr><th>能力</th><th>模型</th><th>audio.voice</th><th>特点</th></tr>
|
||
<tr><td>预置音色 TTS</td><td><code>mimo-v2.5-tts</code></td><td>可选,预置音色名</td><td>9 种预置音色,默认 mimo_default</td></tr>
|
||
<tr><td>音色设计</td><td><code>mimo-v2.5-tts-voicedesign</code></td><td>不支持</td><td>通过文字描述设计音色</td></tr>
|
||
<tr><td>声音克隆</td><td><code>mimo-v2.5-tts-voiceclone</code></td><td>必填,base64 音频</td><td>上传 3~10 秒音频样本克隆声音</td></tr>
|
||
</table>
|
||
|
||
<h3>预置音色列表 (mimo-v2.5-tts)</h3>
|
||
<table>
|
||
<tr><th>音色 ID</th><th>说明</th></tr>
|
||
<tr><td><code>mimo_default</code></td><td>默认音色</td></tr>
|
||
<tr><td><code>冰糖</code></td><td>甜美女声</td></tr>
|
||
<tr><td><code>茉莉</code></td><td>温柔女声</td></tr>
|
||
<tr><td><code>苏打</code></td><td>清爽男声</td></tr>
|
||
<tr><td><code>白桦</code></td><td>沉稳男声</td></tr>
|
||
<tr><td><code>Mia</code></td><td>英文女声</td></tr>
|
||
<tr><td><code>Chloe</code></td><td>英文女声</td></tr>
|
||
<tr><td><code>Milo</code></td><td>英文男声</td></tr>
|
||
<tr><td><code>Dean</code></td><td>英文男声</td></tr>
|
||
</table>
|
||
|
||
<h3>音频格式</h3>
|
||
<table>
|
||
<tr><th>format 值</th><th>说明</th></tr>
|
||
<tr><td><code>wav</code></td><td>WAV 格式(默认)</td></tr>
|
||
<tr><td><code>mp3</code></td><td>MP3 格式</td></tr>
|
||
<tr><td><code>pcm</code> / <code>pcm16</code></td><td>PCM16 格式(stream 模式下默认)</td></tr>
|
||
</table>
|
||
|
||
<div class="warn-box">
|
||
<strong>⚠️ TTS 限制:</strong>TTS 系列模型 max_completion_tokens 范围为 [1, 8192];不支持 thinking、tools、response_format、stop 参数。
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ===== EXAMPLES ===== -->
|
||
<section id="examples">
|
||
<h2>💻 代码示例</h2>
|
||
|
||
<h3>基础调用(非流式)</h3>
|
||
<div class="tabs">
|
||
<button class="tab-btn active" onclick="switchTab(event,'tab-ex1-py')">Python SDK</button>
|
||
<button class="tab-btn" onclick="switchTab(event,'tab-ex1-curl')">curl</button>
|
||
</div>
|
||
<div id="tab-ex1-py" class="tab-content active">
|
||
<pre><span class="code-lang">python</span>from openai import OpenAI
|
||
|
||
client = OpenAI(api_key="$MIMO_API_KEY", base_url="https://api.xiaomimimo.com/v1")
|
||
|
||
response = client.chat.completions.create(
|
||
model="mimo-v2.5-pro",
|
||
messages=[
|
||
{"role": "system", "content": "You are MiMo, an AI assistant developed by Xiaomi."},
|
||
{"role": "user", "content": "你好,请介绍一下自己"}
|
||
],
|
||
max_completion_tokens=1024,
|
||
temperature=1.0,
|
||
thinking={"type": "disabled"}
|
||
)
|
||
|
||
print(response.choices[0].message.content)
|
||
print(f"输入: {response.usage.prompt_tokens}, 输出: {response.usage.completion_tokens}")</pre>
|
||
</div>
|
||
<div id="tab-ex1-curl" class="tab-content">
|
||
<pre><span class="code-lang">bash</span>curl --location --request POST 'https://api.xiaomimimo.com/v1/chat/completions' \
|
||
--header "api-key: $MIMO_API_KEY" \
|
||
--header "Content-Type: application/json" \
|
||
--data-raw '{"model":"mimo-v2.5-pro","messages":[{"role":"system","content":"You are MiMo."},{"role":"user","content":"你好"}],"max_completion_tokens":1024,"thinking":{"type":"disabled"}}'</pre>
|
||
</div>
|
||
|
||
<h3>流式响应</h3>
|
||
<div class="tabs">
|
||
<button class="tab-btn active" onclick="switchTab(event,'tab-ex2-py')">Python SDK</button>
|
||
<button class="tab-btn" onclick="switchTab(event,'tab-ex2-js')">JavaScript</button>
|
||
</div>
|
||
<div id="tab-ex2-py" class="tab-content active">
|
||
<pre><span class="code-lang">python</span>from openai import OpenAI
|
||
|
||
client = OpenAI(api_key="$MIMO_API_KEY", base_url="https://api.xiaomimimo.com/v1")
|
||
|
||
response = client.chat.completions.create(
|
||
model="mimo-v2.5-pro",
|
||
messages=[
|
||
{"role": "system", "content": "你是一个专业的编程助手。"},
|
||
{"role": "user", "content": "解释 JavaScript 的事件循环机制"}
|
||
],
|
||
stream=True
|
||
)
|
||
|
||
full_reply = ""
|
||
for chunk in response:
|
||
content = chunk.choices[0].delta.content
|
||
if content:
|
||
full_reply += content
|
||
print(content, end="", flush=True)
|
||
|
||
# 继续对话
|
||
messages.append({"role": "assistant", "content": full_reply})
|
||
messages.append({"role": "user", "content": "能给一个 async/await 的代码示例吗?"})</pre>
|
||
</div>
|
||
<div id="tab-ex2-js" class="tab-content">
|
||
<pre><span class="code-lang">javascript</span>const response = await fetch('https://api.xiaomimimo.com/v1/chat/completions', {
|
||
method: 'POST',
|
||
headers: {
|
||
'api-key': MIMO_API_KEY,
|
||
'Content-Type': 'application/json'
|
||
},
|
||
body: JSON.stringify({
|
||
model: 'mimo-v2.5-pro',
|
||
messages: [
|
||
{ role: 'system', content: '你是一个专业的编程助手。' },
|
||
{ role: 'user', content: '解释 JavaScript 的事件循环机制' }
|
||
],
|
||
stream: true
|
||
})
|
||
});
|
||
|
||
const reader = response.body.getReader();
|
||
const decoder = new TextDecoder();
|
||
let buffer = '';
|
||
|
||
while (true) {
|
||
const { done, value } = await reader.read();
|
||
if (done) break;
|
||
buffer += decoder.decode(value, { stream: true });
|
||
const lines = buffer.split('\n');
|
||
buffer = lines.pop();
|
||
for (const line of lines) {
|
||
if (!line.startsWith('data: ') || line === 'data: [DONE]') continue;
|
||
const chunk = JSON.parse(line.slice(6));
|
||
const content = chunk.choices[0]?.delta?.content;
|
||
if (content) process.stdout.write(content);
|
||
}
|
||
}</pre>
|
||
</div>
|
||
|
||
<h3>深度思考模式</h3>
|
||
<pre><span class="code-lang">python</span>from openai import OpenAI
|
||
|
||
client = OpenAI(api_key="$MIMO_API_KEY", base_url="https://api.xiaomimimo.com/v1")
|
||
|
||
response = client.chat.completions.create(
|
||
model="mimo-v2.5-pro",
|
||
messages=[{"role": "user", "content": "9.11 和 9.8 哪个更大?"}],
|
||
extra_body={"thinking": {"type": "enabled"}}
|
||
)
|
||
|
||
msg = response.choices[0].message
|
||
print(f"[思考过程]\n{msg.reasoning_content}")
|
||
print(f"\n[最终回答]\n{msg.content}")</pre>
|
||
|
||
<h3>函数调用 (Function Calling)</h3>
|
||
<pre><span class="code-lang">python</span>from openai import OpenAI
|
||
|
||
client = OpenAI(api_key="$MIMO_API_KEY", base_url="https://api.xiaomimimo.com/v1")
|
||
|
||
response = client.chat.completions.create(
|
||
model="mimo-v2.5-pro",
|
||
messages=[{"role": "user", "content": "杭州今天天气怎么样?"}],
|
||
tools=[{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_weather",
|
||
"description": "获取指定城市的当前天气信息",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"location": {"type": "string", "description": "城市名称"}
|
||
},
|
||
"required": ["location"]
|
||
}
|
||
}
|
||
}]
|
||
)
|
||
|
||
tool_calls = response.choices[0].message.tool_calls
|
||
print("工具调用:", tool_calls)</pre>
|
||
|
||
<h3>联网搜索</h3>
|
||
<pre><span class="code-lang">python</span>from openai import OpenAI
|
||
|
||
client = OpenAI(api_key="$MIMO_API_KEY", base_url="https://api.xiaomimimo.com/v1")
|
||
|
||
response = client.chat.completions.create(
|
||
model="mimo-v2.5-pro",
|
||
messages=[{"role": "user", "content": "今天有什么科技新闻?"}],
|
||
tools=[{"type": "web_search"}]
|
||
)
|
||
|
||
msg = response.choices[0].message
|
||
print("回答:", msg.content)
|
||
if msg.annotations:
|
||
print("\n引用来源:")
|
||
for ann in msg.annotations:
|
||
print(f" - [{ann.title}]({ann.url})")</pre>
|
||
|
||
<h3>语音合成 (TTS)</h3>
|
||
<pre><span class="code-lang">python</span>from openai import OpenAI
|
||
import base64
|
||
|
||
client = OpenAI(api_key="$MIMO_API_KEY", base_url="https://api.xiaomimimo.com/v1")
|
||
|
||
response = client.chat.completions.create(
|
||
model="mimo-v2.5-tts",
|
||
messages=[
|
||
{"role": "user", "content": "用甜美的声音为大家念一首诗"},
|
||
{"role": "assistant", "content": "床前明月光,疑是地上霜。举头望明月,低头思故乡。"}
|
||
],
|
||
audio={
|
||
"format": "wav",
|
||
"voice": "茉莉"
|
||
}
|
||
)
|
||
|
||
audio_data = response.choices[0].message.audio.data
|
||
audio_bytes = base64.b64decode(audio_data)
|
||
with output("output.wav", "wb") as f:
|
||
f.write(audio_bytes)
|
||
print("音频已保存到 output.wav")</pre>
|
||
</section>
|
||
|
||
<!-- ===== ERRORS ===== -->
|
||
<section id="errors">
|
||
<h2>⚠️ 错误码说明</h2>
|
||
<table>
|
||
<tr><th width="120">错误码</th><th>HTTP 状态</th><th>描述</th></tr>
|
||
<tr><td><code>invalid_api_key</code></td><td>401</td><td>API Key 无效或未提供</td></tr>
|
||
<tr><td><code>rate_limit_exceeded</code></td><td>429</td><td>请求频率超限,请稍后重试</td></tr>
|
||
<tr><td><code>invalid_request</code></td><td>400</td><td>请求参数错误(如缺少必填字段、模型不存在等)</td></tr>
|
||
<tr><td><code>context_length_exceeded</code></td><td>400</td><td>输入内容超出模型上下文长度限制</td></tr>
|
||
<tr><td><code>content_filter</code></td><td>400</td><td>内容触发安全过滤策略</td></tr>
|
||
<tr><td><code>server_error</code></td><td>500</td><td>服务器内部错误</td></tr>
|
||
<tr><td><code>model_not_found</code></td><td>404</td><td>请求的模型不存在或已下线</td></tr>
|
||
</table>
|
||
|
||
<div class="info-box">
|
||
<strong>📌 finish_reason 含义参考:</strong><br>
|
||
• <code>stop</code> — 自然结束 · <code>length</code> — 达到最大 token · <code>tool_calls</code> — 模型调用了工具<br>
|
||
• <code>content_filter</code> — 内容被过滤 · <code>repetition_truncation</code> — 检测到复读截断
|
||
</div>
|
||
</section>
|
||
|
||
</div><!-- /.container -->
|
||
|
||
<!-- ===== FOOTER ===== -->
|
||
<footer>
|
||
<p>本文档基于 <a href="https://mimo.mi.com/docs/zh-CN/api/chat/openai-api" target="_blank">MiMo 官方 API 文档</a> 整理</p>
|
||
<p style="margin-top:8px;">支持模型:<strong>mimo-v2.5-pro · mimo-v2.5 · mimo-v2.5-tts · mimo-v2.5-tts-voicedesign · mimo-v2.5-tts-voiceclone</strong></p>
|
||
<p style="margin-top:8px;opacity:0.5;">Generated with ❤️ · 文档日期 2026-07-15 · 参考 DeepSeek API 文档风格</p>
|
||
</footer>
|
||
|
||
<script>
|
||
function switchTab(evt, tabId) {
|
||
const tabBtns = evt.target.parentElement.querySelectorAll('.tab-btn');
|
||
tabBtns.forEach(b => b.classList.remove('active'));
|
||
evt.target.classList.add('active');
|
||
const parent = evt.target.parentElement.parentElement;
|
||
parent.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
||
document.getElementById(tabId).classList.add('active');
|
||
}
|
||
</script>
|
||
|
||
</body>
|
||
</html> |