How to use the MiniMax M4 API
Call MiniMax-M4 from your own app using an API key from minimaxm4.net. This independent service supports OpenAI-compatible Chat Completions and shares your website credit balance with web chat.
How do I make my first request?
- Sign in, open API Keys, and create a key for your application.
- Store the key on your server as
M4_SITE_API_KEY. Set your client's base URL tohttps://minimaxm4.net/api/v1and its model toMiniMax-M4. - Run the example from a shell with access to the key. A successful response contains the answer in
choices[0].message.content.
curl -i https://minimaxm4.net/api/v1/chat/completions \
-H "Authorization: Bearer $M4_SITE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MiniMax-M4",
"messages": [{"role": "user", "content": "What is a token? Answer in one sentence."}],
"max_tokens": 128
}'To check your key before sending a prompt, use GET /api/v1/models with the same Authorization header. Listing models uses no chat credits.
Which features does the API support?
POST /api/v1/chat/completions returns a single JSON response by default. Set stream to true to receive server-sent events and read the text as it arrives. For a follow-up question, include the earlier messages in the next request.
For function calling, supply your own tool definitions in tools. When the model returns a function call, your app runs the function and sends the result in the next turn. For a hosted conversation where the assistant chooses when to search the web, or to generate an image, open web chat.
How much will an API call cost me?
Select your package on the pricing page to see the estimated price of a long-document answer in your billing currency. Your actual usage depends on the request and reply length.
After a JSON response, check X-Credits-Used or your credit history for the amount deducted from your balance.
What do API errors mean?
- 401 · Invalid API key
- Use an active key from this site's API Keys page and include the Bearer prefix.
- 402 · Insufficient credits
- Check the credit balance of the account that issued the key. Other requests can temporarily reserve credits.
- 400 · Invalid request
- Send a nonempty messages array and use the model ID from the example above.
- 429 · Rate limit
- Allow time between retries and reduce the number of concurrent requests.