MiniMax with LiteLLM, LangChain and the Vercel AI SDK
MiniMax-M2.7, MiniMax-M2.7-highspeed and MiniMax-M3 are served through the OpenAI-compatible endpoint at https://yiduochan.com/v1, so LiteLLM, LangChain and the Vercel AI SDK connect with their standard OpenAI providers and a changed base URL. This page gives the exact configuration for each framework, the current per-token prices, and fixes for the most common errors.
MiniMax text models on YiduoChan are served through a standard OpenAI-compatible endpoint at https://yiduochan.com/v1. LiteLLM, LangChain and the Vercel AI SDK each ship an OpenAI provider that accepts a custom base URL, so none of them needs a MiniMax-specific plugin: you point the OpenAI provider at YiduoChan, pass the API key from the console, and use the MiniMax model IDs as the model name. This page gives the exact configuration for each framework, then covers streaming, tool calling, cost control and the errors that come up most often.
Before you start
- Create an account at /register and add prepaid credits. Billing is pay-as-you-go in USD with no subscription; the minimum top-up is $5 and credits stay valid for 12 months.
- Generate an API key in the console. Every framework below sends it as
Authorization: Bearer <API key>; you never build that header by hand. - Use the base URL
https://yiduochan.com/v1. Chat requests go to/v1/chat/completions, and/v1/modelslists the models your key can call. - Model IDs are passed verbatim and are case-sensitive:
MiniMax-M2.7,MiniMax-M2.7-highspeedandMiniMax-M3.
Keep the key in an environment variable rather than in source. The examples below read YIDUOCHAN_API_KEY.
Verify the key with curl
Before touching any framework, confirm the key and base URL with one direct request. If this succeeds, any later failure is a framework configuration issue rather than an account issue.
curl https://yiduochan.com/v1/chat/completions \
-H "Authorization: Bearer $YIDUOCHAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "MiniMax-M2.7", "messages": [{"role": "user", "content": "ping"}]}'
Which integration to use
- LiteLLM when you want one call signature across many providers, or a proxy with its own keys and budgets in front of several applications.
- LangChain when you already build chains, agents or retrieval pipelines in Python and want
ChatOpenAIas a drop-in. - Vercel AI SDK for TypeScript and Next.js applications that stream responses to the browser.
All three send the same JSON to the same endpoint. The choice is about your existing stack, not about what the models can do.
Models and prices
All prices are USD per 1M tokens at MiniMax list-level rates. The MiniMax overview describes each model; the pricing page is the authoritative list.
| Model ID | Input | Output | Cache read | Notes |
|---|---|---|---|---|
MiniMax-M2.7 | $0.30 | $1.20 | $0.06 | Default choice for most workloads. Cache write $0.375. |
MiniMax-M2.7-highspeed | $0.60 | $2.40 | $0.06 | Same quality as M2.7, lower latency. Cache write $0.375. |
MiniMax-M3 (prompt up to 512K tokens) | $0.30 | $1.20 | $0.06 | 1,048,576-token (1M) context window. |
MiniMax-M3 (prompt 512K to 1M tokens) | $0.60 | $2.40 | $0.12 | Higher tier applies once the prompt exceeds 512K tokens. |
Per-model pages: MiniMax-M2.7 and MiniMax-M3. Failed requests are never charged.
LiteLLM
LiteLLM talks to any OpenAI-compatible server through its openai/ provider prefix. The prefix selects the OpenAI request format; api_base selects the destination. Everything after the slash is forwarded to YiduoChan unchanged as the model field, so the MiniMax model ID goes there exactly as listed above.
Python SDK
import os
from litellm import completion
response = completion(
model="openai/MiniMax-M2.7",
api_base="https://yiduochan.com/v1",
api_key=os.environ["YIDUOCHAN_API_KEY"],
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain idempotency keys in two sentences."},
],
temperature=0.2,
)
print(response.choices[0].message.content)
print(response.usage)
# Streaming: identical call with stream=True
for chunk in completion(
model="openai/MiniMax-M3",
api_base="https://yiduochan.com/v1",
api_key=os.environ["YIDUOCHAN_API_KEY"],
messages=[{"role": "user", "content": "List three uses of a message queue."}],
stream=True,
):
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
Do not set OPENAI_API_KEY to your YiduoChan key as a shortcut. Passing api_key and api_base explicitly keeps the MiniMax route independent from any OpenAI credentials already present in the same process.
LiteLLM proxy (config.yaml)
When several services share one gateway, run the LiteLLM proxy and declare each MiniMax model in model_list. model_name is the alias your applications call; litellm_params.model keeps the openai/ prefix. The os.environ/ syntax reads the key from the proxy's environment at startup.
model_list:
- model_name: minimax-m2.7
litellm_params:
model: openai/MiniMax-M2.7
api_base: https://yiduochan.com/v1
api_key: os.environ/YIDUOCHAN_API_KEY
- model_name: minimax-m2.7-highspeed
litellm_params:
model: openai/MiniMax-M2.7-highspeed
api_base: https://yiduochan.com/v1
api_key: os.environ/YIDUOCHAN_API_KEY
- model_name: minimax-m3
litellm_params:
model: openai/MiniMax-M3
api_base: https://yiduochan.com/v1
api_key: os.environ/YIDUOCHAN_API_KEY
Start it with litellm --config config.yaml and point clients at http://localhost:4000/v1 using the alias as the model name. The proxy layers its own virtual keys, spend logs and per-alias budgets on top of your YiduoChan prepaid balance, which is useful when multiple teams share one account.
LangChain: ChatOpenAI with base_url
LangChain's ChatOpenAI class (package langchain-openai) accepts base_url and api_key directly. Set model to the MiniMax model ID and the rest of the LangChain surface (invoke, stream, chains, bind_tools, structured output helpers) works without changes.
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://yiduochan.com/v1",
api_key=os.environ["YIDUOCHAN_API_KEY"],
model="MiniMax-M2.7",
temperature=0.2,
max_tokens=1024,
)
# Single response
result = llm.invoke("Write a one-line commit message for a null-check fix.")
print(result.content)
print(result.response_metadata.get("token_usage"))
# Token-by-token streaming
for chunk in llm.stream("Summarize the CAP theorem."):
print(chunk.content, end="", flush=True)
Older tutorials use openai_api_base and openai_api_key; both still work as aliases, but base_url and api_key are the current parameter names.
Tool calling in LangChain
Tools are attached with bind_tools. LangChain converts the Python signature and docstring into the OpenAI tools schema and sends it in the request body.
from langchain_core.tools import tool
@tool
def get_order_status(order_id: str) -> str:
"""Look up the shipping status of an order by its ID."""
return f"Order {order_id} shipped"
llm_with_tools = llm.bind_tools([get_order_status])
msg = llm_with_tools.invoke("Where is order A-1042?")
for call in msg.tool_calls:
print(call["name"], call["args"])
For long-document pipelines swap model="MiniMax-M3" and keep the same code; the 1M context window removes most chunking steps for retrieval over large files.
Vercel AI SDK
The Vercel AI SDK uses the @ai-sdk/openai provider. createOpenAI takes baseURL and apiKey and returns a provider instance; call its .chat() method so requests use /v1/chat/completions. Install with npm i ai @ai-sdk/openai.
import { createOpenAI } from "@ai-sdk/openai";
import { generateText, streamText } from "ai";
const yiduochan = createOpenAI({
baseURL: "https://yiduochan.com/v1",
apiKey: process.env.YIDUOCHAN_API_KEY,
});
// One-shot completion
const { text, usage } = await generateText({
model: yiduochan.chat("MiniMax-M2.7"),
prompt: "Explain optimistic locking in three sentences.",
});
console.log(text, usage);
// Streaming, e.g. inside a Next.js route handler
const result = streamText({
model: yiduochan.chat("MiniMax-M3"),
system: "You are a precise technical writer.",
prompt: "Describe the tradeoffs of server-sent events.",
});
for await (const delta of result.textStream) {
process.stdout.write(delta);
}
// In a route handler: return result.toTextStreamResponse();
On AI SDK 5, calling the provider directly as yiduochan("MiniMax-M2.7") targets the OpenAI Responses API rather than Chat Completions. Use yiduochan.chat(...) so the request goes to the endpoint YiduoChan serves.
Tools with generateText
import { generateText, tool } from "ai";
import { z } from "zod";
const { text, toolResults } = await generateText({
model: yiduochan.chat("MiniMax-M2.7"),
tools: {
getOrderStatus: tool({
description: "Look up the shipping status of an order",
inputSchema: z.object({ orderId: z.string() }),
execute: async ({ orderId }) => ({ orderId, status: "shipped" }),
}),
},
prompt: "Where is order A-1042?",
});
console.log(toolResults, text);
AI SDK 4 names the schema field parameters instead of inputSchema; everything else is the same.
Streaming and tool calling notes
- Streaming uses the standard OpenAI server-sent-events format. Each framework sets
stream: truefor you when you callstream(),streamTextor passstream=True. - Tool definitions are sent in the OpenAI
toolsarray and tool calls come back intool_calls. Because the frameworks emit the same JSON they would send to OpenAI, no MiniMax-specific mapping is required. - Run a short end-to-end test with your own tool schemas before shipping. Models differ in how strictly they follow argument formats, and a five-line smoke test is cheaper than debugging in production.
- Token usage is returned in the
usageobject on non-streaming responses. For streaming, request usage in the final chunk through the framework's stream options if you log spend per request. - Prompt caching is reflected in billing rather than in the request: tokens served from the prompt cache are charged at the cache read rate shown in the table, and the framework code does not change.
Cost tips
- Default to
MiniMax-M2.7. Switch toMiniMax-M2.7-highspeedonly for the specific routes where latency matters, since its input and output rates are twice those of M2.7 for the same output quality. - Keep repeated system prompts and few-shot examples byte-identical across calls, which is the precondition for any cache hit. Cache reads are billed at $0.06 per 1M tokens against the $0.30 input rate.
- With
MiniMax-M3, watch the 512K boundary. A prompt above 512K tokens moves the whole request to the $0.60 input and $2.40 output tier, so trim retrieval context where you can. - Set
max_tokens(LangChain, LiteLLM) ormaxOutputTokens(AI SDK) on user-facing routes. Output is roughly four times the price of input, so uncapped generations dominate the bill. - If you run the LiteLLM proxy, set per-key budgets there. Combined with prepaid credits, this gives two independent spend limits.
Troubleshooting
401 Unauthorized
The key is missing, truncated or belongs to a different account. Confirm the environment variable is populated in the process that runs the request (a common miss in serverless functions and Docker containers) and that no stray OPENAI_API_KEY is being picked up instead.
404 on /v1/responses or /v1/embeddings
The OpenAI-compatible surface on this base URL is /v1/chat/completions, /v1/audio/speech and /v1/models. Paths such as /v1/responses or /v1/embeddings are not part of it. In the AI SDK use .chat(); in LiteLLM call completion() with the openai/ prefix rather than the Responses API helpers; in LangChain do not point OpenAIEmbeddings at this base URL.
Model not found
Check the ID against /v1/models. minimax-m2.7 in lower case, MiniMax-M2 or MiniMax-M2.7-fast will be rejected; the exact strings are MiniMax-M2.7, MiniMax-M2.7-highspeed and MiniMax-M3. If you use a LiteLLM alias, make sure the alias maps to one of these.
Base URL ends with a trailing path
Use https://yiduochan.com/v1, not https://yiduochan.com or https://yiduochan.com/v1/chat/completions. The frameworks append /chat/completions themselves, so an extra or missing /v1 produces a 404.
Insufficient balance
Credits are prepaid. Top up from the console; presets are $5, $10, $20, $50, $100, $200 and $500, or any custom amount. Requests that fail for any reason, including balance, are not charged.
Anthropic-format clients
If a tool speaks the Anthropic Messages API instead of OpenAI's, set ANTHROPIC_BASE_URL=https://yiduochan.com and ANTHROPIC_AUTH_TOKEN=<API key> with ANTHROPIC_MODEL=MiniMax-M2.7 or MiniMax-M3. The Claude Code guide covers that path, including the fact that count_tokens is not available.
Related endpoints
The same key and base URL also serve text-to-speech at /v1/audio/speech with speech-2.8-hd and speech-2.8-turbo, billed per input character at MiniMax's published rates; see MiniMax Speech 2.8. A video model, MiniMax-H3, is coming but temporarily unavailable. Questions about integration go to [email protected].
FAQ
Does LiteLLM support MiniMax through YiduoChan?
Yes. Use the openai/ prefix, for example model="openai/MiniMax-M2.7", with api_base="https://yiduochan.com/v1" and your YiduoChan API key; no MiniMax-specific LiteLLM provider is needed, and the same settings work in the proxy config.yaml.
How do I use MiniMax with LangChain's ChatOpenAI?
Create ChatOpenAI(base_url="https://yiduochan.com/v1", api_key=<your key>, model="MiniMax-M2.7") from the langchain-openai package. invoke, stream and bind_tools then work unchanged, and you can switch to MiniMax-M3 for 1M-token prompts.
Which Vercel AI SDK provider works with MiniMax?
The standard @ai-sdk/openai provider: call createOpenAI({ baseURL: "https://yiduochan.com/v1", apiKey }) and pass provider.chat("MiniMax-M2.7") as the model so requests go to /v1/chat/completions rather than the Responses API.
Do streaming and tool calling work with MiniMax through these frameworks?
Requests use the OpenAI Chat Completions format, so the stream and tools fields are sent exactly as they would be to OpenAI and tool calls come back in tool_calls. Run a short test with your own tool schemas before relying on them in production.
What does MiniMax cost through YiduoChan?
MiniMax-M2.7 is $0.30 per 1M input tokens and $1.20 per 1M output tokens; MiniMax-M3 has the same rates for prompts up to 512K tokens and $0.60 input / $2.40 output from 512K to 1M. See /pricing for the full list.
Is there a free tier or trial for MiniMax on YiduoChan?
No. Credits are prepaid in USD with a $5 minimum top-up, valid for 12 months, with no subscription; failed requests are never charged. Sign up at /register.