OpenAI 兼容 API
使用 OpenAI 兼容端点,通过标准 Chat Completions 格式与 MiMo 模型交互。
端点
POST https://api.mimo-v2.com/v1/chat/completions认证
使用以下任一请求头进行身份验证:
| 请求头 | 格式 |
|---|---|
api-key | <your-api-key> |
Authorization | Bearer <your-api-key> |
您可以在 Mimo 控制台的 设置 → API 密钥 中生成 API 密钥。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID。可选值:mimo-v2-pro、mimo-v2-omni、mimo-v2-flash |
messages | array | 是 | 消息对象数组,包含 role 和 content |
max_completion_tokens | integer | 否 | 最大生成 token 数(默认值因模型而异) |
temperature | number | 否 | 采样温度,0-2(默认:1.0) |
top_p | number | 否 | 核采样阈值,0-1(默认:0.95) |
stream | boolean | 否 | 启用流式输出(默认:false) |
stop | string/array | 否 | 停止序列 |
frequency_penalty | number | 否 | 频率惩罚,-2 到 2(默认:0) |
presence_penalty | number | 否 | 存在惩罚,-2 到 2(默认:0) |
tools | array | 否 | 工具/函数定义列表 |
tool_choice | string/object | 否 | 工具选择策略:auto、none 或指定工具 |
消息对象
| 字段 | 类型 | 说明 |
|---|---|---|
role | string | 可选值:system、user、assistant、tool |
content | string/array | 消息内容(文本或多模态内容数组) |
reasoning_content | string | (可选)模型的思考/推理内容 |
tool_calls | array | (可选)助手发起的工具调用 |
请求示例
curl https://api.mimo-v2.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "api-key: YOUR_API_KEY" \
-d '{
"model": "mimo-v2-pro",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "你好,你是谁?"}
],
"max_completion_tokens": 1024,
"temperature": 0.7
}'响应格式
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1711234567,
"model": "mimo-v2-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I am MiMo...",
"reasoning_content": "The user asked me to introduce myself..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 50,
"completion_tokens": 100,
"total_tokens": 150
}
}响应字段
| 字段 | 说明 |
|---|---|
id | 补全的唯一标识符 |
object | 固定为 chat.completion |
created | 响应创建的 Unix 时间戳 |
model | 用于补全的模型 |
choices | 补全选项数组 |
choices[].message.content | 生成的文本响应 |
choices[].message.reasoning_content | 模型的内部推理(可用时) |
choices[].finish_reason | 模型停止原因:stop、length 或 tool_calls |
usage | Token 使用统计 |
流式响应
当 stream 设为 true 时,API 返回 Server-Sent Events(SSE)。每个事件包含一个部分响应块。
流式请求示例
curl https://api.mimo-v2.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "api-key: YOUR_API_KEY" \
-d '{
"model": "mimo-v2-pro",
"messages": [
{"role": "user", "content": "你好!"}
],
"stream": true
}'流式事件格式
每个 SSE 事件以 data: 为前缀,包含一个 JSON 块。流以 data: [DONE] 事件结束。
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"好"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]在流式模式下,reasoning_content 可能出现在主 content 之前的早期 delta 块中。
MiMo API 文档