Mintplex-Labs/anything-llm · error · Error
Invalid response body returned from OpenRouter
Error message
Invalid response body returned from OpenRouter: ${result.output?.error?.message || "Unknown error"} ${result.output?.error?.code || "Unknown code"} What it means
Response-shape guard in OpenRouterLLM.getChatCompletion: the call resolved but the payload has no non-empty choices array, so OpenRouter returned an error body or malformed response; the embedded error message and code are surfaced for diagnosis.
Solutions
- Check the OpenRouter error message and code in the response.
- Verify the model id and credits/quota on OpenRouter.
- Retry with a valid model.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown when OpenRouter returns an error body.
Common situations: Invalid model, insufficient credits, or provider error.
AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-08-18).
Data as JSON: /api/errors/5ad39777a0959d6a.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/openRouter/index.js:280
model: this.model,
messages,
temperature,
// This is an OpenRouter specific option that allows us to get the reasoning text
// before the token text.
include_reasoning: true,
...serviceTierParam(this.serviceTier, this.log.bind(this)),
user: user?.id ? `user_${user.id}` : "",
})
.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 OpenRouter: ${result.output?.error?.message || "Unknown error"} ${result.output?.error?.code || "Unknown code"}`
);
return {
textResponse: this.#parseReasoningFromResponse(result.output.choices[0]),
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 f92433b4ea)