跳转到主要内容

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.

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

快速开始

1. 安装 Anthropic SDK

pip install anthropic

2. 配置环境变量

export ANTHROPIC_BASE_URL=https://api.minimaxi.com/anthropic
export ANTHROPIC_API_KEY=${YOUR_API_KEY}

3. 调用 API

Python
import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="MiniMax-M2.7",
    max_tokens=1000,
    system="You are a helpful assistant.",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Hi, how are you?"
                }
            ]
        }
    ]
)

for block in message.content:
    if block.type == "thinking":
        print(f"Thinking:\n{block.thinking}\n")
    elif block.type == "text":
        print(f"Text:\n{block.text}\n")

4. 特别注意

在多轮 Function Call 对话中,必须将完整的模型返回(即 assistant 消息)添加到对话历史,以保持思维链的连续性:
  • 将完整的 response.content(包含 thinking/text/tool_use 等所有块)添加到消息历史
  • response.content 是一个列表,包含多种类型的内容块,必须完整回传

支持的模型

使用 Anthropic SDK 时,支持 MiniMax-M2.7 MiniMax-M2.7-highspeed MiniMax-M2.5 MiniMax-M2.5-highspeed MiniMax-M2.1 MiniMax-M2.1-highspeed MiniMax-M2 模型:
模型名称上下文窗口模型介绍
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)的计算方式详见常见问题 > 接口相关
Anthropic API 兼容接口支持 MiniMax-M2.7 MiniMax-M2.7-highspeed MiniMax-M2.5 MiniMax-M2.5-highspeed MiniMax-M2.1 MiniMax-M2.1-highspeed MiniMax-M2 模型。如需使用其他模型,请使用标准的 MiniMax API 接口。

兼容性说明

支持的参数

在使用 Anthropic SDK 接入时,我们支持以下输入参数:
参数支持状态说明
model完全支持支持 MiniMax-M2.7 MiniMax-M2.7-highspeed MiniMax-M2.5 MiniMax-M2.5-highspeed MiniMax-M2.1 MiniMax-M2.1-highspeed MiniMax-M2 模型
messages部分支持支持文本和工具调用,不支持图像和文档输入
max_tokens完全支持最大生成 token 数
stream完全支持流式响应
system完全支持系统提示词
temperature完全支持取值范围 (0.0, 1.0],控制输出随机性,建议取值 1
tool_choice完全支持工具选择策略
tools完全支持工具定义
top_p完全支持核采样参数
thinking完全支持推理内容
metadata完全支持元信息
top_k忽略该参数会被忽略
stop_sequences忽略该参数会被忽略
service_tier忽略该参数会被忽略
mcp_servers忽略该参数会被忽略
context_management忽略该参数会被忽略
container忽略该参数会被忽略

Messages 字段支持

字段类型支持状态说明
type="text"完全支持文本消息
type="tool_use"完全支持工具调用
type="tool_result"完全支持工具调用结果
type="thinking"完全支持推理的内容
type="image"不支持暂不支持图像输入
type="document"不支持暂不支持文档输入

示例代码

流式响应

Python
import anthropic

client = anthropic.Anthropic()

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

stream = client.messages.create(
    model="MiniMax-M2.7",
    max_tokens=1000,
    system="You are a helpful assistant.",
    messages=[
        {"role": "user", "content": [{"type": "text", "text": "Hi, how are you?"}]}
    ],
    stream=True,
)

reasoning_buffer = ""
text_buffer = ""

for chunk in stream:
    if chunk.type == "content_block_start":
        if hasattr(chunk, "content_block") and chunk.content_block:
            if chunk.content_block.type == "text":
                print("\n" + "=" * 60)
                print("Response Content:")
                print("=" * 60)

    elif chunk.type == "content_block_delta":
        if hasattr(chunk, "delta") and chunk.delta:
            if chunk.delta.type == "thinking_delta":
                # 流式输出 thinking 过程
                new_thinking = chunk.delta.thinking
                if new_thinking:
                    print(new_thinking, end="", flush=True)
                    reasoning_buffer += new_thinking
            elif chunk.delta.type == "text_delta":
                # 流式输出文本内容
                new_text = chunk.delta.text
                if new_text:
                    print(new_text, end="", flush=True)
                    text_buffer += new_text

print("\n")

注意事项

如果在使用模型过程中遇到任何问题:
  • 通过邮箱 Model@minimaxi.com 等官方渠道联系我们的技术支持团队
  • 在我们的 Github 仓库提交Issue
  1. Anthropic API 兼容接口目前支持 MiniMax-M2.7 MiniMax-M2.7-highspeed MiniMax-M2.5 MiniMax-M2.5-highspeed MiniMax-M2.1 MiniMax-M2.1-highspeed MiniMax-M2 模型
  2. temperature 参数取值范围为 (0.0, 1.0],推荐使用1.0,超出范围会返回错误
  3. 部分 Anthropic 参数(如 thinkingtop_kstop_sequencesservice_tiermcp_serverscontext_managementcontainer)会被忽略
  4. 当前不支持图像和文档类型的输入