{"record":{"id":"76a3858fdff9d780","repo":"Mintplex-Labs/anything-llm","slug":"invalid-response-body-returned-from-minimax-jso","errorCode":null,"errorMessage":"Invalid response body returned from Minimax: ${JSON.stringify(result.output)}","messagePattern":"Invalid response body returned from Minimax: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/minimax/index.js","lineNumber":104,"sourceCode":"      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature,\n        })\n        .catch((e) => {\n          throw new Error(e.message);\n        })\n    );\n\n    if (\n      !result?.output?.hasOwnProperty(\"choices\") ||\n      result?.output?.choices?.length === 0\n    )\n      throw new Error(\n        `Invalid response body returned from Minimax: ${JSON.stringify(result.output)}`\n      );\n\n    return {\n      textResponse: result.output.choices[0].message.content,\n      metrics: {\n        prompt_tokens: result.output.usage.prompt_tokens || 0,\n        completion_tokens: result.output.usage.completion_tokens || 0,\n        total_tokens: result.output.usage.total_tokens || 0,\n        outputTps: result.output.usage.completion_tokens / result.duration,\n        duration: result.duration,\n        model: this.model,\n        provider: this.className,\n        timestamp: new Date(),\n      },\n    };\n  }\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/minimax/index.js#L86-L122","documentation":"After a successful HTTP round-trip, the provider verifies result.output has a non-empty choices array. If Minimax returns a 2xx body without choices (moderation block, content-policy refusal, or an unexpected envelope), it throws and dumps JSON.stringify(result.output) for diagnosis. Note it uses direct .hasOwnProperty rather than the safer Object.prototype.hasOwnProperty.call.","triggerScenarios":"Minimax returns a 2xx response whose body lacks a choices array or has choices:[] — e.g. content filtered by policy, a moderation flag, or an API-contract change where the envelope differs from the OpenAI shape.","commonSituations":"Content policy triggers on the prompt; Minimax API version returning a different response shape; an intermediate proxy stripping or reshaping the body; model returning an error object inside a 2xx envelope.","solutions":["Read the dumped JSON in the error message to see what Minimax actually returned.","If it shows a moderation/content-policy object, adjust the prompt or disable filtering if supported.","Confirm you are hitting the expected Minimax API version/baseURL.","If the shape changed, pin the model and/or update the provider adapter's response parsing."],"exampleFix":"// before\nif (\n  !result?.output?.hasOwnProperty(\"choices\") ||\n  result?.output?.choices?.length === 0\n)\n  throw new Error(`Invalid response body returned from Minimax: ${JSON.stringify(result.output)}`);\n\n// after (safer own-property check + clearer branch)\nconst out = result?.output;\nif (!out || !Object.prototype.hasOwnProperty.call(out, \"choices\") || !out.choices?.length) {\n  throw new Error(`Minimax returned no choices: ${JSON.stringify(out)}`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasChoices(body) {\n  return body != null\n    && Object.prototype.hasOwnProperty.call(body, 'choices')\n    && Array.isArray(body.choices)\n    && body.choices.length > 0;\n}","tryCatchPattern":"try {\n  await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  if (/Invalid response body returned from Minimax/i.test(e.message)) {\n    // the JSON dump is in the message — log it, inspect for moderation/policy fields\n    // do not retry the identical request\n  }\n}","preventionTips":["Log the full upstream body when choices are missing, to distinguish policy vs contract drift.","Pin the Minimax API version/model to avoid envelope changes.","Watch for content-policy fields in 2xx responses when testing edgy prompts."],"tags":["minimax","response-parsing","api-contract","content-policy"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}