{"record":{"id":"5ad39777a0959d6a","repo":"Mintplex-Labs/anything-llm","slug":"invalid-response-body-returned-from-openrouter","errorCode":null,"errorMessage":"Invalid response body returned from OpenRouter: ${result.output?.error?.message || \"Unknown error\"} ${result.output?.error?.code || \"Unknown code\"}","messagePattern":"Invalid response body returned from OpenRouter: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/openRouter/index.js","lineNumber":280,"sourceCode":"          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        })\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 OpenRouter: ${result.output?.error?.message || \"Unknown error\"} ${result.output?.error?.code || \"Unknown code\"}`\n      );\n\n    return {\n      textResponse: this.#parseReasoningFromResponse(result.output.choices[0]),\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":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/openRouter/index.js#L262-L298","documentation":"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.","triggerScenarios":"Thrown when OpenRouter returns an error body.","commonSituations":"Invalid model, insufficient credits, or provider error.","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."],"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"}