Tutorials

Access MiniMax Using Vercel AI SDK

On this page

In this tutorial, you'll learn how to use MiniMax models with the Vercel AI SDK through Puter's OpenAI-compatible endpoint. No MiniMax API key needed, just your Puter auth token.

Prerequisites

Puter copy auth token
  • Node.js installed on your machine

Setup

Install the Vercel AI SDK and the OpenAI provider:

npm install ai @ai-sdk/openai

Then configure the provider with Puter's base URL and your auth token:

import { createOpenAI } from '@ai-sdk/openai';

const puter = createOpenAI({
  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 Text Generation

Here's a simple text generation call using MiniMax M2.5:

import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';

const puter = createOpenAI({
  baseURL: 'https://api.puter.com/puterai/openai/v1/',
  apiKey: 'YOUR_PUTER_AUTH_TOKEN',
});

const { text } = await generateText({
  model: puter.chat('minimax/minimax-m2.5'),
  prompt: 'What is the capital of France?',
});

console.log(text);

The code is identical to what you'd write for any OpenAI provider. The only difference is the base URL and the model string.

Streaming

For longer responses, use streamText to get results in real-time:

import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';

const puter = createOpenAI({
  baseURL: 'https://api.puter.com/puterai/openai/v1/',
  apiKey: 'YOUR_PUTER_AUTH_TOKEN',
});

const result = streamText({
  model: puter.chat('minimax/minimax-m2.5'),
  prompt: 'Write a short story about a robot learning to paint.',
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Use streamText instead of generateText and iterate over result.textStream to get text chunks as they arrive.

Conclusion

That's it. You now have access to MiniMax through the Vercel AI 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.

Free, Serverless AI and Cloud

Start creating powerful web applications with Puter.js in seconds!

Get Started Now

Read the Docs Try the Playground