{"record":{"id":"9a8e85dac8a7dd18","repo":"mem0ai/mem0","slug":"minimax-api-key-is-required","errorCode":null,"errorMessage":"MiniMax API key is required","messagePattern":"MiniMax API key is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/minimax.ts","lineNumber":9,"sourceCode":"import { OpenAILLM } from \"./openai\";\nimport { LLMConfig, Message } from \"../types\";\nimport { LLMResponse } from \"./base\";\n\nexport class MiniMaxLLM extends OpenAILLM {\n  constructor(config: LLMConfig) {\n    const apiKey = config.apiKey || process.env.MINIMAX_API_KEY;\n    if (!apiKey) {\n      throw new Error(\"MiniMax API key is required\");\n    }\n    super({\n      ...config,\n      apiKey,\n      baseURL:\n        config.baseURL ||\n        process.env.MINIMAX_API_BASE ||\n        \"https://api.minimax.io/v1\",\n      model: config.model || \"MiniMax-M2.7\",\n    });\n  }\n\n  async generateResponse(\n    messages: Message[],\n    responseFormat?: { type: string },\n    tools?: any[],\n  ): Promise<string | LLMResponse> {\n    try {","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/minimax.ts#L1-L27","documentation":"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.","triggerScenarios":"Instantiating MiniMaxLLM (provider 'minimax') with apiKey absent and MINIMAX_API_KEY not set in the process environment at construction time.","commonSituations":"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).","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."],"exampleFix":"// before\nconst mem = new Memory({ llm: { provider: 'minimax', config: {} } });\n// throws: MiniMax API key is required\n\n// after\nimport 'dotenv/config';\nconst mem = new Memory({\n  llm: { provider: 'minimax', config: { apiKey: process.env.MINIMAX_API_KEY! } },\n});","handlingStrategy":"validation","validationCode":"function assertMiniMaxKey(cfg: LLMConfig) {\n  if (!cfg.apiKey && !process.env.MINIMAX_API_KEY) {\n    throw new Error('MINIMAX_API_KEY not set — create a key in the MiniMax console');\n  }\n}","typeGuard":"const hasMiniMaxKey = (cfg: LLMConfig): boolean => Boolean(cfg.apiKey || process.env.MINIMAX_API_KEY);","tryCatchPattern":"try { new MiniMaxLLM(config); } catch (e) {\n  if ((e as Error).message === 'MiniMax API key is required') throw new StartupConfigError('MINIMAX_API_KEY missing');\n  throw e;\n}","preventionTips":["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."],"tags":["minimax","llm","api-key","config","env","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}