{"record":{"id":"fafb11d832547952","repo":"Mintplex-Labs/anything-llm","slug":"openrouter-chat-this-model-is-not-valid-for-ch","errorCode":null,"errorMessage":"OpenRouter chat: ${this.model} is not valid for chat completion!","messagePattern":"OpenRouter chat: (.+?) is not valid for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/openRouter/index.js","lineNumber":255,"sourceCode":"    attachments = [],\n  }) {\n    const prompt = {\n      role: \"system\",\n      content: `${systemPrompt}${this.#appendContext(contextTexts)}`,\n    };\n    return [\n      prompt,\n      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7, user = null }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `OpenRouter chat: ${this.model} is not valid for chat completion!`\n      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature,\n          // This is an OpenRouter specific option that allows us to get the reasoning text\n          // before the token text.\n          include_reasoning: true,\n          ...serviceTierParam(this.serviceTier, this.log.bind(this)),\n          user: user?.id ? `user_${user.id}` : \"\",\n        })\n        .catch((e) => {\n          throw new Error(e.message);\n        })","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/openRouter/index.js#L237-L273","documentation":"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.","triggerScenarios":"Thrown when the configured OpenRouter model is not a chat model.","commonSituations":"Model preference set to an invalid model id.","solutions":["Select an OpenRouter model valid for chat completion."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}