Access MiniMax Using OpenAI-Compatible API
In this tutorial, you'll learn how to access MiniMax models using the OpenAI SDK through Puter's OpenAI-compatible endpoint. No MiniMax API key needed, just your Puter auth token.
Prerequisites
- A Puter account
- Your Puter auth token, go to puter.com/dashboard and click Copy to get your auth token
- Node.js installed on your machine
Setup
Install the OpenAI SDK:
npm install openai
Then configure the client with Puter's base URL and your auth token:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.puter.com/puterai/openai/v1/",
apiKey: "YOUR_PUTER_AUTH_TOKEN",
});
Replace YOUR_PUTER_AUTH_TOKEN with the auth token you copied from your Puter dashboard. That's all you need. No MiniMax API key required.
Basic Chat Completion
Here's a simple chat completion using MiniMax M2.5:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.puter.com/puterai/openai/v1/",
apiKey: "YOUR_PUTER_AUTH_TOKEN",
});
const response = await client.chat.completions.create({
model: "minimax/minimax-m2.5",
messages: [
{ role: "user", content: "What is the capital of France?" },
],
});
console.log(response.choices[0].message.content);
Sample output:
The capital of France is Paris.
The code is identical to what you'd write for OpenAI directly. The only difference is the base URL and the model string.
Streaming
For longer responses, enable streaming to get results in real-time:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.puter.com/puterai/openai/v1/",
apiKey: "YOUR_PUTER_AUTH_TOKEN",
});
const stream = await client.chat.completions.create({
model: "minimax/minimax-m2.5",
messages: [
{ role: "user", content: "Write a short story about a robot learning to paint." },
],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}
Set stream: true and iterate over the chunks as they arrive. Each chunk contains a piece of the response that you can display immediately.
Conclusion
That's it. You now have access to MiniMax through the OpenAI SDK via Puter, no MiniMax API key needed. Swap the model string to use any MiniMax model, from the efficient M1 to the powerful M2.5, or any of the hundreds of other AI models available through Puter.
Related
Free, Serverless AI and Cloud
Start creating powerful web applications with Puter.js in seconds!
Get Started Now