Skip to content

Chat Completions API 完整指南

MiniMax 支持 OpenAI 兼容 Chat Completions。Xikapi 示例统一使用:

text
https://xikapi.com/v1/chat/completions

基础调用

bash
curl https://xikapi.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XIKAPI_API_KEY" \
  -d '{
    "model": "MiniMax-M2.8",
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": "Explain in three sentences what MiniMax is best suited for" }
    ]
  }'

JavaScript

javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.XIKAPI_API_KEY,
  baseURL: "https://xikapi.com/v1",
});

const completion = await client.chat.completions.create({
  model: "MiniMax-M2.8",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Introduce the MiniMax-compatible calling method" },
  ],
});

console.log(completion.choices[0].message.content);

Python

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_XIKAPI_API_KEY",
    base_url="https://xikapi.com/v1",
)

completion = client.chat.completions.create(
    model="MiniMax-M2.8",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Introduce the MiniMax-compatible calling method"},
    ],
)

print(completion.choices[0].message.content)

流式输出

json
{
  "model": "MiniMax-M2.8",
  "stream": true,
  "messages": [
    { "role": "user", "content": "Write a short article about API integration" }
  ]
}

扩展参数

部分模型支持思考内容分离等扩展参数。通过 OpenAI 兼容接口时,通常放在 extra_body 中。

javascript
const stream = await client.chat.completions.create({
  model: "MiniMax-M2.8",
  stream: true,
  messages: [
    { role: "user", content: "Analyze a complex code refactoring plan" }
  ],
  extra_body: {
    reasoning_split: true
  }
});

接入建议

  • API Key 只放在服务端
  • 高速版本和标准版本要分别压测
  • 长上下文任务设置更长超时
  • 扩展参数要逐模型验证