MiniMax M4, hands-on: call the 2.74T flagship from your own code
MiniMax M4 is a 2.74T-parameter flagship with 66B active per token and a 1M-token context — and until its weights land, the API is the only way in. Here is the complete setup: both protocols, thinking-depth control, tool calling, image input, streaming, and the real cost math, every snippet verified.
- 2.74T total, 66B active per token: 1,000,000-token context, natively multimodal (text, image, video); weights to follow after a safety review.
- Two protocols, one model: OpenAI-compatible at
https://api.minimax.io/v1(reasoning_effort) and Anthropic-compatible athttps://api.minimax.io/anthropic(output_config.effort) — the recommended path. Model ID on the platform isMiniMax-M4. - Thinking is always on: five effort levels
low/medium/high/xhigh/max(defaultmax); disabling it returns HTTP 400; thinking tokens are billed as output at $3.10 per million. - Pricing: $0.80 input / $3.10 output / $0.05 cached input per million tokens. M3.1-Flash is roughly a fifth of the price for high-volume simple calls.
- Verified: every snippet was executed against a local stand-in returning MiniMax's documented response shapes (openai 3.63.0, anthropic 2.17.0); the live calls need your own key.

On December 3, MiniMax released M4, its new flagship: 2.74 trillion total parameters with 66 billion active per token, a 1-million-token context window, and native text, image, and video input. It is described as open-weight, but the weights are not downloadable yet — the official repository says they will be released after a safety review. Until then, the API is the only way to use it.
That is actually good news for getting started. You do not need a GPU, a download, or a local setup. You need an API key and about fifteen minutes. This tutorial wires up both of MiniMax's protocols, shows you how to control the model's thinking depth (the one setting that decides most of your bill), gives it a tool to call, feeds it an image, and streams the answer — with the exact request and response shapes, verified against the official documentation.
A note on verification: every snippet below was executed end to end against a local stand-in server returning MiniMax's documented response shapes, using openai 3.63.0 and anthropic 2.17.0. The only step that needs your own key is the live call itself, and the first curl in Step 2 is that call.
What you'll need#
- A MiniMax platform account and an API key. Sign up at platform.minimax.io and create a key in the console. The platform separates a pay-as-you-go API key from the Subscription Key used by Token Plan (M Plan) quota — use the key that matches how you intend to pay.
- Python 3.10+ and
pip install openai anthropicfor the SDK steps. Everything before that iscurl. - A few cents of credit. Every call in this tutorial costs a fraction of a cent at list prices; the whole thing lands well under a dollar.
- No GPU, no download, no local model. M4 runs on MiniMax's infrastructure. Your machine only sends HTTP requests.
1. Get your key#
Create the key in the MiniMax Open Platform console and put it in an environment variable. Never paste a key into a file you might commit, and never print it in a log.
export MINIMAX_API_KEY="your-key-here"
Check it stuck:
echo ${#MINIMAX_API_KEY} # expect a two-digit number, not 0
Everything below reads the key from this variable. If a call returns 401, the key is wrong or belongs to the wrong billing resource — regenerate it in the console rather than debugging the request body.
2. First call: curl on the OpenAI-compatible endpoint#
MiniMax exposes two protocols for the same model. The OpenAI-compatible one lives at https://api.minimax.io/v1, so any client already pointed at OpenAI works with a base-URL swap. The model ID on the platform is MiniMax-M4 — exact casing matters.
curl https://api.minimax.io/v1/chat/completions \
-H "Authorization: Bearer $MINIMAX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MiniMax-M4",
"reasoning_effort": "max",
"messages": [{"role": "user", "content": "Which is bigger, 9.11 or 9.9?"}]
}'
The response is a standard Chat Completions object with one MiniMax-specific field. The answer is in choices[0].message.content; the model's thinking is in choices[0].message.reasoning_content, kept separate from the answer so you never have to strip <think> tags out of it yourself:
{
"id": "chatcmpl-...",
"model": "MiniMax-M4",
"choices": [{
"message": {
"role": "assistant",
"content": "9.9 is bigger than 9.11...",
"reasoning_content": "The user asks which is bigger, 9.11 or 9.9..."
},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 18, "completion_tokens": 142, "total_tokens": 160}
}
Two things to notice. First, reasoning_effort is set to max — that is also the default if you omit it, and Step 5 explains why you will usually want to lower it. Second, completion_tokens includes the thinking tokens: the reasoning is billed as output, at the output price. That is the single most important fact about M4's cost.
3. The same call in Python#
If you already use the OpenAI SDK, the only changes are the base URL and the model name:
# pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MINIMAX_API_KEY"],
base_url="https://api.minimax.io/v1",
)
resp = client.chat.completions.create(
model="MiniMax-M4",
reasoning_effort="max",
messages=[{"role": "user", "content": "Which is bigger, 9.11 or 9.9?"}],
)
print(resp.choices[0].message.content)
print("--- thinking ---")
print(resp.choices[0].message.reasoning_content)
print("--- usage ---")
print(resp.usage)
Expected output: the answer, then the thinking, then a usage object like CompletionUsage(completion_tokens=142, prompt_tokens=18, total_tokens=160). The reasoning_content attribute is present on the message object in openai 3.x; if you use a much older SDK version and it comes back empty, upgrade rather than parsing the answer text.
4. The recommended path: Anthropic-compatible#
MiniMax calls its Anthropic-compatible endpoint the recommended path: https://api.minimax.io/anthropic. It supports thinking blocks and interleaved thinking, which the OpenAI-compatible path does not expose. The model ID is the same, the key is the same, and the thinking-depth setting moves to a different field: output_config.effort.
curl https://api.minimax.io/anthropic/v1/messages \
-H "Authorization: Bearer $MINIMAX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MiniMax-M4",
"thinking": {"type": "adaptive"},
"output_config": {"effort": "max"},
"max_tokens": 4096,
"messages": [{"role": "user", "content": "Which is bigger, 9.11 or 9.9?"}]
}'
The thinking field is optional — M4 always thinks, and if you send it, it must be adaptive; sending disabled returns HTTP 400. max_tokens, by contrast, is required on this endpoint. The response carries thinking and text as separate content blocks:
{
"id": "msg_...",
"type": "message",
"model": "MiniMax-M4",
"content": [
{"type": "thinking", "thinking": "The user asks which is bigger..."},
{"type": "text", "text": "**9.9 is bigger than 9.11.**..."}
],
"stop_reason": "end_turn",
"usage": {"input_tokens": 18, "output_tokens": 142}
}
The same call with the Anthropic SDK:
# pip install anthropic
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.minimax.io/anthropic",
api_key=os.environ["MINIMAX_API_KEY"],
)
message = client.messages.create(
model="MiniMax-M4",
output_config={"effort": "max"},
max_tokens=4096,
messages=[
{"role": "user", "content": "Which is bigger, 9.11 or 9.9?"}
],
)
for block in message.content:
if block.type == "thinking":
print(f"Thinking:
{block.thinking}
")
elif block.type == "text":
print(f"Text:
{block.text}
")
One sizing rule for this endpoint: max_tokens caps everything the model generates, thinking included. MiniMax recommends 131,072 for M4, with a maximum of 262,144. The 4,096 above is fine for a one-line question; for a long coding task, set it in six figures or the model will stop mid-thought with stop_reason: "max_tokens" and you will mistake a truncated answer for a wrong one.

5. Tune the thinking depth — this is where the money goes#
M4 reasons before it answers, and it cannot be switched off. What you can control is how deeply it thinks, with five effort levels:
| Effort | OpenAI-compatible field | Anthropic-compatible field | Use it for |
|---|---|---|---|
low | reasoning_effort: "low" | output_config.effort: "low" | Short answers, classification, formatting |
medium | reasoning_effort: "medium" | output_config.effort: "medium" | Everyday questions, short summaries |
high | reasoning_effort: "high" | output_config.effort: "high" | Multi-step reasoning, careful code review |
xhigh | reasoning_effort: "xhigh" | output_config.effort: "xhigh" | Hard problems, long-horizon agent work |
max (default) | reasoning_effort: "max" | output_config.effort: "max" | The hardest tasks, when accuracy matters most |
Higher levels think more thoroughly and produce more output tokens at higher latency. Because thinking is billed as output at $3.10 per million tokens, the default max is the most expensive way to ask a simple question. The rule: start at low for anything with a short, checkable answer, and raise the effort only when the answer is wrong or shallow. Sending effort: "none" or thinking: {"type": "disabled"} returns HTTP 400 — lowering the level is the only off-ramp.
The pricing, per million tokens, from MiniMax's pricing page:
| Model | Input / 1M | Output / 1M | Cached input / 1M |
|---|---|---|---|
| MiniMax-M4 | $0.80 | $3.10 | $0.05 |
| MiniMax-M3.1-Flash | $0.15 | $0.60 | $0.015 |
| MiniMax-M3 | $0.30 | $1.20 | — |
M3's list prices are $0.60 / $2.40 with a permanent 50% discount applied. Run the math yourself before you build anything on top of this:
INPUT_PRICE = 0.80 # $ per 1M input tokens
OUTPUT_PRICE = 3.10 # $ per 1M output tokens
CACHE_PRICE = 0.05 # $ per 1M cached input tokens
def cost(input_tokens, output_tokens, cached_tokens=0):
return ((input_tokens - cached_tokens) * INPUT_PRICE / 1_000_000
+ cached_tokens * CACHE_PRICE / 1_000_000
+ output_tokens * OUTPUT_PRICE / 1_000_000)
print(f"100k fresh in + 5k out: ${cost(100_000, 5_000):.4f}")
print(f"1M cached in + 10k out: ${cost(1_000_000, 10_000, cached_tokens=1_000_000):.4f}")
print(f"1M fresh in + 100k out: ${cost(1_000_000, 100_000):.4f}")
That prints $0.0955, $0.0810, and $1.1100. The lesson in the second line: a million cached input tokens plus a short answer costs eight cents, while the same million tokens fresh plus a long answer costs $1.11. Long context is cheap to re-read and expensive to think about — keep prompts cached where you can, and keep effort low where you can.

6. Give it tools#
M4 is built for agentic work, and tool calling works on the OpenAI-compatible endpoint with the standard tools parameter. The loop has two turns: the model asks for a tool, you run it, you send the result back, and the model answers. Here the tool is a stub returning fixed weather — swap in a real weather API call in production.
import json
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MINIMAX_API_KEY"],
base_url="https://api.minimax.io/v1",
)
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City, e.g. 'Montreal, QC'"}
},
"required": ["location"],
},
},
}]
messages = [{"role": "user", "content": "What is the weather like in Montreal right now?"}]
resp = client.chat.completions.create(
model="MiniMax-M4",
reasoning_effort="low",
messages=messages,
tools=tools,
)
msg = resp.choices[0].message
messages.append(msg)
for call in msg.tool_calls or []:
args = json.loads(call.function.arguments)
# Your real function would call a weather API here.
result = {"location": args["location"], "temperature_c": -4,
"conditions": "snowing", "wind_chill_c": -9}
messages.append({"role": "tool", "tool_call_id": call.id,
"content": json.dumps(result)})
resp = client.chat.completions.create(
model="MiniMax-M4",
reasoning_effort="low",
messages=messages,
tools=tools,
)
print(resp.choices[0].message.content)
Two details matter. First, the assistant message from turn one goes back into messages verbatim — including its tool_calls — so the model sees its own request when it reads the result. Second, the tool result's tool_call_id must match the id of the call it answers, or the API rejects the request. On the Anthropic-compatible endpoint the same flow uses tools and tool_use / tool_result blocks, and tool_choice only supports auto — the model decides whether to call a tool; you cannot force or forbid a specific one.
7. Send it an image#
M4 is natively multimodal, so the same endpoint accepts images alongside text. Send the image as an image_url content part — a public URL or a base64 data URL:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MINIMAX_API_KEY"],
base_url="https://api.minimax.io/v1",
)
resp = client.chat.completions.create(
model="MiniMax-M4",
reasoning_effort="low",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image? Answer in one sentence."},
{"type": "image_url", "image_url": {
"url": "https://aifrontierpost.com/articles/qwen4-35b-a3b-run-locally-tutorial/cover.webp"
}},
],
}],
)
print(resp.choices[0].message.content)
The model fetches the URL server-side, so the image must be publicly reachable — a localhost path or a signed URL that expires will fail. The Anthropic-compatible endpoint accepts image (and video) content blocks in messages the same way. Image input is billed as input tokens, at the $0.80 rate; the exact token count depends on the image size, so check usage.prompt_tokens on your first few calls before you budget a pipeline around it.
8. Stream the answer#
For anything user-facing, stream. Flip stream to true and the response arrives as server-sent events. One SDK quirk to know: on openai 3.x, a chunk's delta only carries reasoning_content when that chunk actually contains thinking, so read it defensively — a bare delta.reasoning_content raises AttributeError on text-only chunks:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MINIMAX_API_KEY"],
base_url="https://api.minimax.io/v1",
)
stream = client.chat.completions.create(
model="MiniMax-M4",
reasoning_effort="low",
messages=[{"role": "user", "content": "Which is bigger, 9.11 or 9.9?"}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta
if getattr(delta, "reasoning_content", None):
print(getattr(delta, "reasoning_content", ""), end="", flush=True)
if delta.content:
print(delta.content, end="", flush=True)
print()
Stream the thinking to your own logs, not to the user's screen — it is long, it arrives first, and it is the part of the response most likely to contain half-formed reasoning the model later corrects. Show the user content as it arrives; keep reasoning_content for debugging.
Which approach should you use?#
| Situation | Use | Why |
|---|---|---|
| You already use the OpenAI SDK | OpenAI-compatible, https://api.minimax.io/v1 | Zero migration: swap the base URL and model ID |
| You want thinking blocks and interleaved thinking | Anthropic-compatible, https://api.minimax.io/anthropic | MiniMax's recommended path; the richest response shape |
| You already have an OpenRouter key | OpenRouter, model minimax/minimax-m4 | No new account; note the model ID has a slash prefix here |
| Long-horizon coding or agent work | M4 at high or xhigh | That is the workload MiniMax built M4 for |
| High-volume, simple calls | M3.1-Flash at low | $0.15 / $0.60 per million tokens — roughly a fifth of M4 |
| You need weights on your own hardware | Wait | M4's weights are not released yet; nothing to download today |
The most common mistake is the model ID. On MiniMax's own platform it is MiniMax-M4; on OpenRouter and the Vercel AI Gateway it is minimax/minimax-m4. Send the slashed form to the platform and you will get a 404; send the bare form to a gateway and you will get the same. Match the ID to the base URL, every time.
Mistakes that waste your money#
- Leaving effort at
max. It is the default, and it is the most expensive setting. A one-line factual question does not need maximum thinking. - Trying to disable thinking. It returns HTTP 400. Lower the effort level instead.
- Setting
max_tokenstoo small on the Anthropic path. Thinking counts toward the limit. A 4,096 cap on a hard task truncates the answer mid-thought; MiniMax recommends 131,072 for M4. - Forgetting the thinking is billed as output. A long reasoning trace at $3.10 per million tokens is where M4 bills add up — not the input.
- Assuming the weights are available. They are not, as of December 4. Any tutorial telling you to download M4 is describing a different model or a future release.
The takeaway#
MiniMax M4 is a frontier-class model you can call from a fifteen-line script, and the whole integration is three decisions: which protocol, which effort level, and how much output you are willing to pay for. Pick the Anthropic-compatible endpoint if you want the thinking blocks, the OpenAI-compatible one if you already live in that SDK, and low effort for anything with a short, checkable answer. The weights will come — the repository says so — but the API is here now, it costs cents to learn, and the code above is everything you need to start.