Call MiniMax models on Alibaba Cloud Model Studio.
The features described in this document are available only in the China (Beijing) region. To use the model, get an API key in the China (Beijing) region.
Getting started
Prerequisites: Create an API key and set it as an environment variable. If you call the model using a SDK, install the OpenAI or DashScope SDK.- OpenAI compatible
- DashScope
- Anthropic compatible
- Python
- Node.js
- HTTP
Sample code
Copy
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
# China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="MiniMax-M2.5",
messages=[{"role": "user", "content": "Who are you?"}],
stream=True,
)
reasoning_content = "" # Full chain-of-thought
answer_content = "" # Full response
is_answering = False # Whether response has started
print("\n" + "=" * 20 + "Chain of thought" + "=" * 20 + "\n")
for chunk in completion:
if chunk.choices:
delta = chunk.choices[0].delta
# Collect only chain-of-thought content
if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
if not is_answering:
print(delta.reasoning_content, end="", flush=True)
reasoning_content += delta.reasoning_content
# Start response when content arrives
if hasattr(delta, "content") and delta.content:
if not is_answering:
print("\n" + "=" * 20 + "Full response" + "=" * 20 + "\n")
is_answering = True
print(delta.content, end="", flush=True)
answer_content += delta.content
Response
Copy
====================Chain of thought====================
The user asked "Who are you?".
I should reply and introduce myself as an AI assistant.
====================Full response====================
Hello! I am MiniMax-M2.5, an AI assistant. I can help you answer questions, provide information, hold conversations, and more. How can I help you?
Sample code
Copy
import OpenAI from "openai";
import process from 'process';
// Initialize the OpenAI client
const openai = new OpenAI({
// If you have not set the environment variable, replace this with your Alibaba Cloud Model Studio API key: apiKey: "sk-xxx"
apiKey: process.env.DASHSCOPE_API_KEY,
// China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
baseURL: 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1'
});
let reasoningContent = ''; // Full chain-of-thought
let answerContent = ''; // Full response
let isAnswering = false; // Whether response has started
async function main() {
const messages = [{ role: 'user', content: 'Who are you?' }];
const stream = await openai.chat.completions.create({
model: 'MiniMax-M2.5',
messages,
stream: true,
});
console.log('\n' + '='.repeat(20) + 'Chain of thought' + '='.repeat(20) + '\n');
for await (const chunk of stream) {
if (chunk.choices?.length) {
const delta = chunk.choices[0].delta;
// Collect only chain-of-thought content
if (delta.reasoning_content !== undefined && delta.reasoning_content !== null) {
if (!isAnswering) {
process.stdout.write(delta.reasoning_content);
}
reasoningContent += delta.reasoning_content;
}
// Start response when content arrives
if (delta.content !== undefined && delta.content) {
if (!isAnswering) {
console.log('\n' + '='.repeat(20) + 'Full response' + '='.repeat(20) + '\n');
isAnswering = true;
}
process.stdout.write(delta.content);
answerContent += delta.content;
}
}
}
}
main();
Response
Copy
====================Chain of thought====================
The user asked "Who are you?".
I should reply and introduce myself as an AI assistant.
====================Full response====================
Hello! I am MiniMax-M2.5, an AI assistant. I can help you answer questions, provide information, hold conversations, and more. How can I help you?
Sample code
- curl
Copy
# China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MiniMax-M2.5",
"messages": [
{
"role": "user",
"content": "Who are you?"
}
]
}'
Response
Copy
{
"choices": [
{
"message": {
"content": "Hello! I am MiniMax-M2.5, an AI assistant developed by MiniMax. I can help you answer questions, provide information, hold conversations, and complete various text-related tasks. How can I help you?",
"reasoning_content": "The user asked \"Who are you?\".\n\nI should reply and introduce myself.",
"role": "assistant"
},
"finish_reason": "stop",
"index": 0,
"logprobs": null
}
],
"object": "chat.completion",
"usage": {
"prompt_tokens": 40,
"completion_tokens": 72,
"total_tokens": 112,
"completion_tokens_details": {
"reasoning_tokens": 26
},
"prompt_tokens_details": {
"cached_tokens": 0
}
},
"created": 1771944590,
"system_fingerprint": null,
"model": "MiniMax-M2.5",
"id": "chatcmpl-b1277a9c-52da-9de7-988a-d5c063d83xxx"
}
- Python
- Java
- HTTP
Sample code
Copy
import os
import dashscope
# The following is the configuration for the China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. The region value varies by region.
client = dashscope.Client(
# If you have not set the environment variable, replace this with your Alibaba Cloud Model Studio API key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="cn-beijing",
)
# Initialize request parameters
messages = [{"role": "user", "content": "Who are you?"}]
completion = client.chat.completions.create(
model="MiniMax-M2.5",
messages=messages,
stream=True, # Enable streaming output
)
reasoning_content = "" # Full chain-of-thought
answer_content = "" # Full response
is_answering = False # Whether response has started
print("\n" + "=" * 20 + "Chain of thought" + "=" * 20 + "\n")
for chunk in completion:
message = chunk.choices[0].delta
# Collect only chain-of-thought content
if message.reasoning_content:
if not is_answering:
print(message.reasoning_content, end="", flush=True)
reasoning_content += message.reasoning_content
# Start response when content arrives
if message.content:
if not is_answering:
print("\n" + "=" * 20 + "Full response" + "=" * 20 + "\n")
is_answering = True
print(message.content, end="", flush=True)
answer_content += message.content
# After the loop ends, reasoning_content and answer_content contain the full content
# You can process them further as needed
# print(f"\n\nFull chain of thought:\n{reasoning_content}")
# print(f"\nFull response:\n{answer_content}")
Response
Copy
====================Chain of thought====================
The user asked "Who are you?".
I should reply and introduce myself as an AI assistant.
====================Full response====================
Hello! I am MiniMax-M2.5, an AI assistant. I can help you answer questions, provide information, hold conversations, and more. How can I help you?
Sample code
Copy
// DashScope SDK version >= 2.19.4
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main {
static {
// China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID. The configuration varies by region.
Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
}
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static StringBuilder reasoningContent = new StringBuilder();
private static StringBuilder finalContent = new StringBuilder();
private static boolean isFirstPrint = true;
private static void handleGenerationResult(GenerationResult message) {
String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
String content = message.getOutput().getChoices().get(0).getMessage().getContent();
if (reasoning != null && !reasoning.isEmpty()) {
reasoningContent.append(reasoning);
if (isFirstPrint) {
System.out.println("====================Chain of thought====================");
isFirstPrint = false;
}
System.out.print(reasoning);
}
if (content != null && !content.isEmpty()) {
finalContent.append(content);
if (!isFirstPrint) {
System.out.println("\n====================Full response====================");
isFirstPrint = true;
}
System.out.print(content);
}
}
private static GenerationParam buildGenerationParam(Message userMsg) {
return GenerationParam.builder()
// If you have not set the environment variable, replace this line with: .apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("MiniMax-M2.5")
.incrementalOutput(true)
.resultFormat("message")
.messages(Arrays.asList(userMsg))
.build();
}
public static void streamCallWithMessage(Generation gen, Message userMsg)
throws NoApiKeyException, ApiException, InputRequiredException {
GenerationParam param = buildGenerationParam(userMsg);
Flowable<GenerationResult> result = gen.streamCall(param);
result.blockingForEach(message -> handleGenerationResult(message));
}
public static void main(String[] args) {
try {
Generation gen = new Generation();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("Who are you?").build();
streamCallWithMessage(gen, userMsg);
// Print final results
// if (reasoningContent.length() > 0) {
// System.out.println("\n====================Full response====================");
// System.out.println(finalContent.toString());
// }
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
logger.error("An exception occurred: {}", e.getMessage());
}
System.exit(0);
}
}
Response
Copy
====================Chain of thought====================
The user asked "Who are you?".
I should reply and introduce myself as an AI assistant.
====================Full response====================
Hello! I am MiniMax-M2.5, an AI assistant. I can help you answer questions, provide information, hold conversations, and more. How can I help you?
Sample code
- curl
Copy
# China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MiniMax-M2.5",
"input":{
"messages":[
{
"role": "user",
"content": "Who are you?"
}
]
},
"parameters": {
"result_format": "message"
}
}'
Response
Copy
{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": "Hello! I am MiniMax-M2.5, an AI assistant developed by MiniMax. I can help you answer questions, provide information, hold conversations, and complete various text-related tasks. How can I help you?",
"reasoning_content": "The user asked \"Who are you?\".\n\nI should reply and introduce myself. I should state that I am MiniMax-M2.5, an AI assistant developed by MiniMax.",
"role": "assistant"
}
}
]
},
"usage": {
"input_tokens": 41,
"output_tokens": 79,
"output_tokens_details": {
"reasoning_tokens": 39
},
"prompt_tokens_details": {
"cached_tokens": 0
},
"total_tokens": 120
},
"request_id": "1bbd770e-564a-4601-83fc-3bf639423xxx"
}
- Python
- HTTP
Sample code
Copy
import anthropic
import os
client = anthropic.Anthropic(
# If you have not set the environment variable, replace this with your Alibaba Cloud Model Studio API key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
# China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic",
)
message = client.messages.create(
model="MiniMax-M2.5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Who are you?"}
],
stream=True,
)
for event in message:
if event.type == "content_block_delta":
if hasattr(event.delta, "thinking"):
print(event.delta.thinking, end="", flush=True)
if hasattr(event.delta, "text"):
print(event.delta.text, end="", flush=True)
Sample code
- curl
Copy
# China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic/v1/messages \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "MiniMax-M2.5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Who are you?"
}
]
}'
Other features
| Model | Multi-turn conversation | Deep thinking | Function calling | Structured output | Web search | Partial mode | Context Cache |
|---|---|---|---|---|---|---|---|
| MiniMax-M2.5 | Supported | Supported | Supported | Not supported | Supported | Not supported | SupportedImplicit cache only. |
Default parameter values
Model | temperature | top_p | presence_penalty |
|---|---|---|---|
MiniMax-M2.5 | 1.0 | 0.95 | 0.0 |