Mintplex-Labs/anything-llm · error · Error

Invalid response body returned from Minimax: ${JSON.stringif

Error message

Invalid response body returned from Minimax: ${JSON.stringify(result.output)}

What it means

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.

Source

Thrown at server/utils/AiProviders/minimax/index.js:104

      );

    const result = await LLMPerformanceMonitor.measureAsyncFunction(
      this.openai.chat.completions
        .create({
          model: this.model,
          messages,
          temperature,
        })
        .catch((e) => {
          throw new Error(e.message);
        })
    );

    if (
      !result?.output?.hasOwnProperty("choices") ||
      result?.output?.choices?.length === 0
    )
      throw new Error(
        `Invalid response body returned from Minimax: ${JSON.stringify(result.output)}`
      );

    return {
      textResponse: result.output.choices[0].message.content,
      metrics: {
        prompt_tokens: result.output.usage.prompt_tokens || 0,
        completion_tokens: result.output.usage.completion_tokens || 0,
        total_tokens: result.output.usage.total_tokens || 0,
        outputTps: result.output.usage.completion_tokens / result.duration,
        duration: result.duration,
        model: this.model,
        provider: this.className,
        timestamp: new Date(),
      },
    };
  }

View on GitHub (pinned to 526360e320)

Solutions

  1. Read the dumped JSON in the error message to see what Minimax actually returned.
  2. If it shows a moderation/content-policy object, adjust the prompt or disable filtering if supported.
  3. Confirm you are hitting the expected Minimax API version/baseURL.
  4. If the shape changed, pin the model and/or update the provider adapter's response parsing.

Example fix

// before
if (
  !result?.output?.hasOwnProperty("choices") ||
  result?.output?.choices?.length === 0
)
  throw new Error(`Invalid response body returned from Minimax: ${JSON.stringify(result.output)}`);

// after (safer own-property check + clearer branch)
const out = result?.output;
if (!out || !Object.prototype.hasOwnProperty.call(out, "choices") || !out.choices?.length) {
  throw new Error(`Minimax returned no choices: ${JSON.stringify(out)}`);
}
Defensive patterns

Strategy: try-catch

Type guard

function hasChoices(body) {
  return body != null
    && Object.prototype.hasOwnProperty.call(body, 'choices')
    && Array.isArray(body.choices)
    && body.choices.length > 0;
}

Try / catch

try {
  await llm.getChatCompletion(messages, { temperature });
} catch (e) {
  if (/Invalid response body returned from Minimax/i.test(e.message)) {
    // the JSON dump is in the message — log it, inspect for moderation/policy fields
    // do not retry the identical request
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/76a3858fdff9d780. Report an issue: GitHub.