Skip to main content
To meet developers’ needs for the OpenAI API ecosystem, our API now supports the OpenAI API format. With simple configuration, you can integrate MiniMax capabilities into the OpenAI API ecosystem.

Quick Start

1. Install OpenAI SDK

pip install openai

2. Configure Environment Variables

export OPENAI_BASE_URL=https://api.minimax.io/v1
export OPENAI_API_KEY=${YOUR_API_KEY}

3. Call API

from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="MiniMax-M2",
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "Hi, how are you?"
        }
    ]
)
print(response.choices[0].message.content)

Supported Models

When using the OpenAI SDK, the following MiniMax models are supported:
Model NameDescription
MiniMax-M2MiniMax-M2 launching on October 27th, stay tuned
For more model information, please refer to the standard MiniMax API documentation.

Examples

Basic Conversation

from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="MiniMax-M2",
    messages=[
        {
            "role": "user",
            "content": "Explain machine learning in simple terms"
        }
    ]
)

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

Streaming Response

from openai import OpenAI

client = OpenAI()

stream = client.chat.completions.create(
    model="MiniMax-M2",
    messages=[
        {
            "role": "user",
            "content": "Write a poem about spring"
        }
    ],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Tool Calling (Function Calling)

For more details, see MiniMax-M2 Function Calling Guide
from openai import OpenAI

client = OpenAI()

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get weather information for a specified city",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {
                        "type": "string",
                        "description": "City name"
                    }
                },
                "required": ["city"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="MiniMax-M2",
    messages=[
        {
            "role": "user",
            "content": "What's the weather like in Beijing today?"
        }
    ],
    tools=tools
)

print(response.choices[0].message)

Important Notes

  1. Set OPENAI_BASE_URL to https://api.minimax.io/v1 when using
  2. Set OPENAI_API_KEY to your MiniMax API Key
  3. The temperature parameter range is (0.0, 1.0], recommended value: 1.0, values outside this range will return an error
  4. Some OpenAI parameters (such as presence_penalty, frequency_penalty, logit_bias, etc.) will be ignored
  5. Image and audio type inputs are not currently supported
  6. The n parameter only supports value 1
  7. The deprecated function_call is not supported, please use the tools parameter