mem0ai/mem0 · error · Error
MiniMax API key is required
Error message
MiniMax API key is required
What it means
Thrown synchronously by the MiniMaxLLM constructor when no MiniMax API key is resolved. The provider falls back from config.apiKey to the MINIMAX_API_KEY environment variable and throws when both are empty — the standard fail-fast guard before building the OpenAI-compatible client for api.minimax.io.
Source
Thrown at mem0-ts/src/oss/src/llms/minimax.ts:9
import { OpenAILLM } from "./openai";
import { LLMConfig, Message } from "../types";
import { LLMResponse } from "./base";
export class MiniMaxLLM extends OpenAILLM {
constructor(config: LLMConfig) {
const apiKey = config.apiKey || process.env.MINIMAX_API_KEY;
if (!apiKey) {
throw new Error("MiniMax API key is required");
}
super({
...config,
apiKey,
baseURL:
config.baseURL ||
process.env.MINIMAX_API_BASE ||
"https://api.minimax.io/v1",
model: config.model || "MiniMax-M2.7",
});
}
async generateResponse(
messages: Message[],
responseFormat?: { type: string },
tools?: any[],
): Promise<string | LLMResponse> {
try {View on GitHub (pinned to 001c235229)
Solutions
- Export the env var: export MINIMAX_API_KEY=<key from the MiniMax console>.
- Or pass it in config: llm: { provider: 'minimax', config: { apiKey: process.env.MINIMAX_API_KEY } }.
- Ensure dotenv (or the platform's env injection) runs before creating the Memory instance.
- Add MINIMAX_API_KEY to CI/production secrets.
Example fix
// before
const mem = new Memory({ llm: { provider: 'minimax', config: {} } });
// throws: MiniMax API key is required
// after
import 'dotenv/config';
const mem = new Memory({
llm: { provider: 'minimax', config: { apiKey: process.env.MINIMAX_API_KEY! } },
}); Defensive patterns
Strategy: validation
Validate before calling
function assertMiniMaxKey(cfg: LLMConfig) {
if (!cfg.apiKey && !process.env.MINIMAX_API_KEY) {
throw new Error('MINIMAX_API_KEY not set — create a key in the MiniMax console');
}
} Type guard
const hasMiniMaxKey = (cfg: LLMConfig): boolean => Boolean(cfg.apiKey || process.env.MINIMAX_API_KEY);
Try / catch
try { new MiniMaxLLM(config); } catch (e) {
if ((e as Error).message === 'MiniMax API key is required') throw new StartupConfigError('MINIMAX_API_KEY missing');
throw e;
} Prevention
- Validate required env vars with a schema at process start.
- Load dotenv before Memory construction.
- Prefer passing apiKey explicitly over ambient env when running multiple providers.
When it happens
Trigger: Instantiating MiniMaxLLM (provider 'minimax') with apiKey absent and MINIMAX_API_KEY not set in the process environment at construction time.
Common situations: Key created on the MiniMax platform but never exported; env vars configured in one environment (local .env) but missing in the deployment target; dotenv imported after Memory construction; key name typo (e.g. MINIMAX_KEY).
Related errors
- DeepSeek API key is required
- Groq API key is required
- Sarvam API key is required
- Together API key is required
- MiniMax LLM failed: ${message}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/9a8e85dac8a7dd18.
Report an issue: GitHub.