Mintplex-Labs/anything-llm · error · Error
OpenRouter chat: is not valid for chat completion!
Error message
OpenRouter chat: ${this.model} is not valid for chat completion! What it means
Pre-flight guard in OpenRouterLLM.getChatCompletion: the selected model is not in OpenRouter's valid model list (fetched/cached at construction), so a completion call would target an unavailable model and is rejected up front.
Solutions
- Select an OpenRouter model valid for chat completion.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown when the configured OpenRouter model is not a chat model.
Common situations: Model preference set to an invalid model id.
AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-08-18).
Data as JSON: /api/errors/fafb11d832547952.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/openRouter/index.js:255
attachments = [],
}) {
const prompt = {
role: "system",
content: `${systemPrompt}${this.#appendContext(contextTexts)}`,
};
return [
prompt,
...formatChatHistory(chatHistory, this.#generateContent),
{
role: "user",
content: this.#generateContent({ userPrompt, attachments }),
},
];
}
async getChatCompletion(messages = null, { temperature = 0.7, user = null }) {
if (!(await this.isValidChatCompletionModel(this.model)))
throw new Error(
`OpenRouter chat: ${this.model} is not valid for chat completion!`
);
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.chat.completions
.create({
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);
})View on GitHub (pinned to f92433b4ea)