跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://platform.minimaxi.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

为了满足开发者对 OpenAI API 生态的使用需求,我们的 API 新增了对 OpenAI API 格式的支持。通过简单的配置,即可将 MiniMax 的能力接入到 OpenAI API 生态中。

快速开始

1. 安装 OpenAI SDK

pip install openai

2. 配置环境变量

export OPENAI_BASE_URL=https://api.minimaxi.com/v1
export OPENAI_API_KEY=${YOUR_API_KEY}

3. 调用 API

Python
from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hi, how are you?"},
    ],
    # 设置 reasoning_split=True 将思考内容分离到 reasoning_details 字段
    extra_body={"reasoning_split": True},
)

print(f"Thinking:\n{response.choices[0].message.reasoning_details[0]['text']}\n")
print(f"Text:\n{response.choices[0].message.content}\n")

4. 特别注意

在多轮 Function Call 对话中,必须将完整的模型返回(即 assistant 消息)添加到对话历史,以保持思维链的连续性:
  • 将完整的 response_message 对象(包含 tool_calls 字段)添加到消息历史
    • 原生的OpenAI API 的 MiniMax-M2.7 MiniMax-M2.7-highspeed MiniMax-M2.5 MiniMax-M2.5-highspeed MiniMax-M2.1 MiniMax-M2.1-highspeed MiniMax-M2 模型 content 字段会包含 <think> 标签内容,需要完整保留
    • 在 Interleaved Thinking 友好格式中,通过启用额外的参数(reasoning_split=True),模型思考内容通过 reasoning_details 字段单独提供,同样需要完整保留

支持的模型

使用 OpenAI SDK 时,支持以下 MiniMax 模型:
模型名称上下文窗口模型介绍
MiniMax-M2.7204,800开启模型的自我迭代(输出速度约 60 TPS)
MiniMax-M2.7-highspeed204,800M2.7 极速版:效果不变,更快,更敏捷(输出速度约 100 TPS)
MiniMax-M2.5204,800顶尖性能与极致性价比,轻松驾驭复杂任务(输出速度约 60 TPS)
MiniMax-M2.5-highspeed204,800M2.5 极速版:效果不变,更快,更敏捷(输出速度约 100 TPS)
MiniMax-M2.1204,800强大多语言编程能力,全面升级编程体验(输出速度约 60 TPS)
MiniMax-M2.1-highspeed204,800M2.1 极速版:效果不变,更快,更敏捷(输出速度约 100 TPS)
MiniMax-M2204,800专为高效编码与 Agent 工作流而生
TPS(Tokens Per Second)的计算方式详见常见问题 > 接口相关
更多模型信息请参考标准的 MiniMax API 接口文档。

示例代码

流式响应

Python
from openai import OpenAI

client = OpenAI()

print("Starting stream response...\n")
print("=" * 60)
print("Thinking Process:")
print("=" * 60)

stream = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hi, how are you?"},
    ],
    # 设置 reasoning_split=True 将思考内容分离到 reasoning_details 字段
    extra_body={"reasoning_split": True},
    stream=True,
)

reasoning_buffer = ""
text_buffer = ""

for chunk in stream:
    if (
        hasattr(chunk.choices[0].delta, "reasoning_details")
        and chunk.choices[0].delta.reasoning_details
    ):
        for detail in chunk.choices[0].delta.reasoning_details:
            if "text" in detail:
                reasoning_text = detail["text"]
                new_reasoning = reasoning_text[len(reasoning_buffer) :]
                if new_reasoning:
                    print(new_reasoning, end="", flush=True)
                    reasoning_buffer = reasoning_text

    if chunk.choices[0].delta.content:
        content_text = chunk.choices[0].delta.content
        new_text = content_text[len(text_buffer) :] if text_buffer else content_text
        if new_text:
            print(new_text, end="", flush=True)
            text_buffer = content_text

print("\n" + "=" * 60)
print("Response Content:")
print("=" * 60)
print(f"{text_buffer}\n")

注意事项

如果在使用MiniMax模型过程中遇到任何问题:
  • 通过邮箱 Model@minimaxi.com 等官方渠道联系我们的技术支持团队
  • 在我们的 Github 仓库提交Issue
  1. temperature 参数取值范围为(0.0, 1.0],推荐使用 1.0,超出范围会返回错误
  2. 部分 OpenAI 参数(如presence_penaltyfrequency_penaltylogit_bias 等)会被忽略
  3. 当前不支持图像和音频类型的输入
  4. n 参数仅支持值为 1
  5. 旧版的function_call 已废弃,请使用 tools 参数