# minimax-m4 (https://reapi.ai/docs/minimax-m4)

MiniMax M4 uses `POST https://api.reapi.ai/v1/chat/completions` (OpenAI Chat Completions, primary) and also accepts `POST https://api.reapi.ai/v1/messages` (Anthropic Messages, for Anthropic SDKs and Claude Code) with the exact case-sensitive model ID `MiniMax-M4`. Each request returns a synchronous JSON response or an SSE stream, rather than an asynchronous task ID. [Current pricing and playground](/models/minimax-m4).

The request contract follows MiniMax's official OpenAI-compatible Chat API. Unknown fields pass through; request acceptance does not guarantee that every upstream field alters the output. The dated checks below separate verified behavior from passthrough fields.

## Quickstart

Create a key in [API keys](/settings/apikeys). Keep it on your server. These examples send a single request with retries disabled where the SDK otherwise retries automatically.

### cURL

    ```bash
    curl https://api.reapi.ai/v1/chat/completions \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "MiniMax-M4",
        "messages": [{"role": "user", "content": "Audit this retry loop for race conditions."}],
        "reasoning_effort": "low"
      }'
    ```

### Python

    ```python
    from openai import OpenAI

    client = OpenAI(
        api_key="YOUR_API_KEY",
        base_url="https://api.reapi.ai/v1",
        max_retries=0,
    )
    response = client.chat.completions.create(
        model="MiniMax-M4",
        messages=[{"role": "user", "content": "Audit this retry loop for race conditions."}],
        reasoning_effort="low",
    )
    print(response.choices[0].message.content)
    # Preserve the complete assistant message (including reasoning_content and tool_calls) for follow-up turns.
    assistant_message = response.choices[0].message.model_dump(exclude_none=True)
    ```

### Node.js

    ```js
    import OpenAI from 'openai';

    const client = new OpenAI({
      apiKey: 'YOUR_API_KEY',
      baseURL: 'https://api.reapi.ai/v1',
      maxRetries: 0,
    });
    const response = await client.chat.completions.create({
      model: 'MiniMax-M4',
      messages: [{ role: 'user', content: 'Audit this retry loop for race conditions.' }],
      reasoning_effort: 'low',
    });
    console.log(response.choices[0].message.content);
    const assistantMessage = response.choices[0].message;
    ```

### Go

    ```go
    package main

    import (
        "bytes"
        "io"
        "net/http"
        "os"
        "time"
    )

    func main() {
        body := []byte(`{"model":"MiniMax-M4","messages":[{"role":"user","content":"Audit this retry loop for race conditions."}],"reasoning_effort":"low"}`)
        req, err := http.NewRequest("POST", "https://api.reapi.ai/v1/chat/completions", bytes.NewReader(body))
        if err != nil { panic(err) }
        req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
        req.Header.Set("Content-Type", "application/json")
        client := &http.Client{Timeout: 120 * time.Second,
            CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }}
        res, err := client.Do(req)
        if err != nil { panic(err) }
        defer res.Body.Close()
        if _, err := io.Copy(os.Stdout, res.Body); err != nil { panic(err) }
        if res.StatusCode >= 400 { os.Exit(1) }
    }
    ```

## Endpoint

* **OpenAI Chat Completions (primary)**: `POST https://api.reapi.ai/v1/chat/completions` with `Authorization: Bearer YOUR_API_KEY` and `Content-Type: application/json`.
* **Anthropic Messages (compatible)**: `POST https://api.reapi.ai/v1/messages` with `x-api-key: YOUR_API_KEY`, `anthropic-version: 2023-06-01`, and `Content-Type: application/json`.

Responses use `application/json`, or `text/event-stream` when `stream: true`. Use the exact model ID `MiniMax-M4` (the lowercase form is not recognized). There is no task-polling endpoint.

## Official input parameters

The table below lists all 10 active top-level parameters in MiniMax's OpenAI-compatible Chat OpenAPI 3.1.0 schema for `MiniMax-M4`, checked December 4, 2026. Omitted fields keep MiniMax's defaults. Both token-cap spellings are forwarded verbatim without silent substitution.

| Parameter               | Type    | Required / default        | Meaning                                                                                                                                                                              |
| ----------------------- | ------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `model`                 | string  | Required                  | Case-sensitive model ID: `MiniMax-M4`.                                                                                                                                               |
| `messages`              | array   | Required                  | Conversation history with roles `system`, `user`, `assistant`, and `tool`. Content may be a string or structured parts (`text`, `image_url`, `video_url`).                           |
| `thinking`              | object  | `{"type":"adaptive"}`     | Controls thinking mode. `MiniMax-M4` requires `{"type":"adaptive"}`; `{"type":"disabled"}` is rejected upstream.                                                                     |
| `reasoning_effort`      | string  | `"max"`                   | Adaptive reasoning depth: `low`, `medium`, `high`, `xhigh`, or `max`. `"none"` is rejected upstream. Set `low` or `medium` on routine prompts to avoid unnecessary reasoning tokens. |
| `reasoning_split`       | boolean | `true`                    | Separates thinking output into `message.reasoning_content` (or `delta.reasoning_content`). `false` is rejected on `MiniMax-M4`.                                                      |
| `max_completion_tokens` | integer | `131072` (recommended)    | Upper bound on generated tokens (reasoning plus visible text). Verified hard ceiling is `262144`; values above `262144` are rejected.                                                |
| `max_tokens`            | integer | Omitted                   | Legacy alias for `max_completion_tokens`. Forwarded verbatim; verified to enforce the same cap and `262144` ceiling.                                                                 |
| `stream`                | boolean | `false`                   | Set `true` for Server-Sent Events (SSE).                                                                                                                                             |
| `stream_options`        | object  | `{"include_usage":false}` | Optional streaming settings. reAPI requests `include_usage: true` upstream for accurate streaming settlement.                                                                        |
| `tools`                 | array   | Omitted                   | Function tool definitions (`type: "function"`, `function.name`, `function.parameters`, optional `function.description`).                                                             |

### Sampling, stop, and passthrough parameters

MiniMax documents fixed internal sampling for `MiniMax-M4` and excludes `temperature`, `top_p`, `n`, `seed`, `logprobs`, `frequency_penalty`, `presence_penalty`, and `stop` from its active M4 controls:

* `temperature`, `top_p`, `seed`, `frequency_penalty`, and `presence_penalty`: forwarded as supplied without HTTP error, but MiniMax keeps sampling fixed internally.
* `stop`: accepted with HTTP 200 in our December 4, 2026 probe, yet ignored in generation (`stop: ["3"]` still returned `"1 2 3 4 5"`).
* `n`: values greater than `1` are rejected upstream (`base_resp.status_code: 2013`).
* `response_format`: not listed as an active M4 OpenAPI control, yet `json_object` and `json_schema` passed through and returned valid JSON in our December 4, 2026 probe. Validate parsed output in application code.

The context window is **1,000,000 tokens** shared by input, tool history, reasoning, and visible output. No full 1M-token stress test was run during integration checks.

## Preserved thinking and tool calls

Keep the full assistant message returned on every turn, including `reasoning_content` and `tool_calls`. Supply one `role: "tool"` message for each requested `tool_call_id`. Tool execution runs in your application, never inside the reAPI endpoint or playground.

```python
messages = [{"role": "user", "content": "Check the deployment status for service-api."}]
tools = [{
    "type": "function",
    "function": {
        "name": "get_deploy_status",
        "description": "Return the latest deployment status for a service.",
        "parameters": {
            "type": "object",
            "properties": {"service": {"type": "string"}},
            "required": ["service"],
        },
    },
}]
first = client.chat.completions.create(
    model="MiniMax-M4",
    messages=messages,
    tools=tools,
    reasoning_effort="low",
)
assistant = first.choices[0].message.model_dump(exclude_none=True)
messages.append(assistant)
for call in assistant.get("tool_calls", []):
    messages.append({
        "role": "tool",
        "tool_call_id": call["id"],
        "content": '{"service":"service-api","status":"healthy","sha":"9a4c1d2"}',
    })
second = client.chat.completions.create(
    model="MiniMax-M4",
    messages=messages,
    tools=tools,
    reasoning_effort="low",
)
print(second.choices[0].message.content)
```

Preserving the unmodified prefix across tool turns also enables automatic prompt caching on MiniMax's MFlashKV layer.

## Images and video

`MiniMax-M4` natively accepts `text`, `image_url`, and `video_url` content parts inside `messages`. **Audio input is not supported.**

Supply publicly reachable `https://` or `http://` URLs. Do not send base64 `data:` URIs or vendor `mm_file://` handles to reAPI.

* **Images (`image_url`)**: JPEG, PNG, GIF, or WebP up to 10 MB each; up to 200 images across all messages. Optional `detail`: `"low"`, `"default"`, or `"high"`.
* **Video (`video_url`)**: MP4, AVI, MOV, or MKV up to 50 MB via URL and up to 30 minutes; up to 20 videos across all messages. Files must contain a video stream (audio-only containers are unsupported). Optional `detail` (`"low"`, `"default"`, `"high"`), `fps` (`0.2`–`5`, default `2`), and `max_long_side_pixel`. Total sampled video pixels across a request must not exceed `301,056,000`.

```json
{
  "model": "MiniMax-M4",
  "reasoning_effort": "low",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "Summarize what changes between the screenshot and the clip."},
        {"type": "image_url", "image_url": {"url": "https://example.com/frame.png", "detail": "low"}},
        {"type": "video_url", "video_url": {"url": "https://example.com/demo.mp4", "detail": "low", "fps": 0.5}}
      ]
    }
  ]
}
```

Replace the example URLs with publicly accessible media of your own.

## Streaming

Set `stream: true` for SSE output — **strongly recommended** whenever using `reasoning_effort` above `low`, because long adaptive thinking chains (especially at `high`, `xhigh`, or `max`) can exceed 100-second non-streaming proxy timeouts (`HTTP 524`) before headers return. Accumulate `delta.reasoning_content`, `delta.content`, and indexed `delta.tool_calls` fragments. The final usage chunk may contain an empty `choices` array before `[DONE]`. Treat any connection drop before `[DONE]` as an incomplete response.

## Capability observations — December 4, 2026

These checks verified live integration behavior through the upstream gateway; they are not an independent quality benchmark.

| Capability                          | Observation                                                                                                                                                                                                                |
| ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Non-stream text & billing receipt   | HTTP 200; returned answer, `usage`, and exact gateway credit receipt.                                                                                                                                                      |
| Streaming SSE                       | HTTP 200 `text/event-stream`; streamed `delta.reasoning_content` and `delta.content`, emitted final `usage` and `[DONE]`.                                                                                                  |
| Adaptive `reasoning_effort`         | `low`, `medium`, `high`, `xhigh`, `max` all succeeded. Trivial arithmetic skipped reasoning at `low`/`medium`/`high` and emitted reasoning tokens at `xhigh`/`max`.                                                        |
| Disabling thinking                  | `reasoning_effort: "none"`, `thinking: {"type":"disabled"}`, and `reasoning_split: false` returned HTTP 200 with `choices: null` and `base_resp.status_code: 2013`. reAPI settles empty-choice responses with no charge.   |
| Output caps                         | `max_completion_tokens: 30` and `max_tokens: 30` both enforced a 30-token stop (`finish_reason: "length"`). `262144` succeeded; `262145` failed with `base_resp.status_code: 2013`.                                        |
| Tool loop & prompt cache            | Two-turn function call with preserved assistant message succeeded and reported 468 cached prompt tokens out of 489 on turn 2.                                                                                              |
| Public `image_url`                  | HTTP 200 (`detail: "low"`); accurately described a public portrait image.                                                                                                                                                  |
| Public `video_url`                  | HTTP 200 (`detail: "low"`, `fps: 0.5`); accurately described a public video clip.                                                                                                                                          |
| Structured output                   | `response_format` (`json_object` and `json_schema`) returned valid JSON; keep application-side schema validation.                                                                                                          |
| Unsupported / fixed controls        | `n: 2` failed with `base_resp.status_code: 2013`; `stop: ["3"]` was accepted but ignored; `temperature`, `top_p`, `seed`, and penalties were accepted without error.                                                       |
| Anthropic Messages (`/v1/messages`) | Non-stream JSON, SSE streaming (`message_start` → `content_block_delta` → `message_delta` → `message_stop`), `output_config.effort`, and `thinking: {"type":"adaptive"}` all returned HTTP 200 with exact credit receipts. |

## Anthropic Messages compatibility

If your client uses an Anthropic SDK or Claude Code, you can also send `MiniMax-M4` to `POST https://api.reapi.ai/v1/messages` with `x-api-key` and `anthropic-version: 2023-06-01`:

```bash
curl -N https://api.reapi.ai/v1/messages \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniMax-M4",
    "max_tokens": 4096,
    "stream": true,
    "output_config": {"effort": "medium"},
    "messages": [{"role": "user", "content": "Audit this retry loop for race conditions."}]
  }'
```

Use `/v1/chat/completions` when you need MiniMax OpenAI-compatible fields such as `video_url` sampling options (`fps`, `max_long_side_pixel`) or `reasoning_split`.

## Groups

See the [model page's live group prices](/models/minimax-m4#pricing). Copy the model ID for the group you want into the `model` field. One reAPI key works across all available groups.

The bare `MiniMax-M4` ID routes to the default `minimax` group. If additional groups appear in the price table, select them with the `MiniMax-M4:<group>` syntax documented in [LLM groups](/docs/api/llm-groups).

## Pricing and billing

Input tokens, output tokens (including adaptive reasoning tokens), cache reads, and cache writes are metered separately. Check [current rates on the MiniMax M4 page](/models/minimax-m4); no numeric SKU prices are embedded in this reference.

Accounting uses integer micro-USD: `microUSD = ceil(settled_USD_charge × 1,000,000)` and `credits = microUSD / 1,000`. One credit equals $0.001.

reAPI sends one upstream inference request per accepted submission and never retries failed calls or executes tools. Postpaid settlement requires usable delivery and valid usage evidence; upstream failures or empty `choices: null` soft-errors (`base_resp`) are settled with no charge.

## Output schema

A non-streaming response uses the standard Chat Completions shape (illustrative token counts):

```json
{
  "id": "063195467387f9ef857d3e0d78123456",
  "object": "chat.completion",
  "model": "MiniMax-M4",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Two race conditions stand out in the retry loop...",
        "reasoning_content": "Inspecting shared state across concurrent retries..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 124,
    "completion_tokens": 86,
    "total_tokens": 210,
    "prompt_tokens_details": {
      "cached_tokens": 0
    }
  }
}
```

## Errors

reAPI errors return `error.code`, `error.message`, `error.request_id`, and Chat-compatible `error.type`:

| HTTP / code                              | Meaning                                                                                                       |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| 401 / `10001`–`10005`                    | Missing, invalid, or revoked API key.                                                                         |
| 400 / `20001`, `20002`, `20003`, `20004` | Invalid JSON, missing fields, invalid parameter value, or unknown model ID (check exact casing `MiniMax-M4`). |
| 413 / `20008`                            | Request payload exceeds limit.                                                                                |
| 402 / `30001`                            | Insufficient balance.                                                                                         |
| 429 / `50001`                            | Rate or in-flight concurrency limit reached.                                                                  |
| 502–503 / `70001`                        | Upstream inference or pricing service unavailable.                                                            |

**MiniMax `base_resp` soft-errors**: When an invalid MiniMax-specific value passes HTTP admission (for example `reasoning_effort: "none"`, `reasoning_split: false`, `n > 1`, or `max_completion_tokens > 262144`), upstream may return HTTP 200 with `choices: null` and `base_resp.status_code: 2013`. Check `choices` before parsing message content; reAPI does not bill empty-choice responses. See the [error-code catalog](/docs/api/errors).

## Tips

* Enable `stream: true` on coding, reasoning, or multi-step prompts so tokens start arriving within a few seconds and long thinking chains do not hit proxy read timeouts.
* Set `reasoning_effort: "low"` or `"medium"` on routine prompts; leaving `"max"` on complex prompts can generate 10K+ thinking tokens and add significant latency.
* Keep static system instructions and long code/document prefixes identical at the start of `messages` to maximize cache reads on multi-turn agent loops.
* Always check `choices?.length` and `base_resp?.status_msg` in client code so upstream parameter rejections surface immediately.

## Related

Compare the [MiniMax M3 documentation](/docs/minimax-m3) and [Kimi K3.1 Pro documentation](/docs/kimi-k3-1-pro), or read the [MiniMax M4 pricing, benchmarks, and integration guide](/resources/minimax-m4-pricing-benchmarks-api-guide).

## Official references

* [MiniMax M4 launch announcement](https://www.minimax.io/blog/m4)
* [MiniMax OpenAI-compatible Chat API](https://platform.minimax.io/docs/api-reference/text-openai-api) and [OpenAPI 3.1.0 schema](https://platform.minimax.io/docs/api-reference/text/api/openapi-chat-openai.json)
* [MiniMax pricing overview](https://platform.minimax.io/docs/pricing/overview)
* [MiniMax M4 GitHub repository](https://github.com/MiniMax-AI/MiniMax-M4)