{"record":{"id":"0924fb64999bc43f","repo":"Mintplex-Labs/anything-llm","slug":"awsbedrock-getchatcompletion-failed-e-message","errorCode":null,"errorMessage":"AWSBedrock::getChatCompletion failed. ${e.message}","messagePattern":"AWSBedrock::getChatCompletion failed\\. (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/bedrock/index.js","lineNumber":201,"sourceCode":"    if (!messages?.length)\n      throw new Error(\n        \"AWSBedrock::getChatCompletion requires a non-empty messages array.\"\n      );\n\n    if (this.#isAnthropic) {\n      return this.#anthropicChatCompletion(messages, temperature);\n    }\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature: this.temperatureParam(temperature),\n        })\n        .catch((e) => {\n          this.#log(`Bedrock API Error (getChatCompletion): ${e.message}`, e);\n          throw new Error(`AWSBedrock::getChatCompletion failed. ${e.message}`);\n        })\n    );\n\n    const response = result.output;\n    if (!response?.choices?.[0]?.message) {\n      this.#log(\"Bedrock response missing expected structure.\", response);\n      return null;\n    }\n\n    return {\n      textResponse: response.choices[0].message.content,\n      metrics: this.#buildMetrics(response.usage, result.duration),\n    };\n  }\n\n  async streamGetChatCompletion(messages = null, { temperature }) {\n    if (!Array.isArray(messages) || messages.length === 0) {\n      throw new Error(","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/bedrock/index.js#L183-L219","documentation":"Re-thrown from the OpenAI-compatible Bedrock chat path (non-Anthropic models) inside AWSBedrockLLM.getChatCompletion. The .catch logs `Bedrock API Error (getChatCompletion): ...` then throws `AWSBedrock::getChatCompletion failed. <e.message>`. This path is taken for models like Titan/Cohere/Mistral served through Bedrock's OpenAI-compatible endpoint.","triggerScenarios":"Calling getChatCompletion on a non-Anthropic Bedrock model and the underlying `this.openai.chat.completions.create` rejects: 403 access denied to the model in that region, 400 from passing temperature to a noTemperatureModels entry (e.g. anthropic.* — though those route elsewhere), throttling (429), or transport errors.","commonSituations":"Model access not enabled in the AWS account/region; insufficient IAM/API-key permissions for the requested model; throttling under load; wrong region for the model; malformed messages payload.","solutions":["Read the logged inner `e.message` (the #log line) for the Bedrock status text and address it: enable model access in the AWS console, switch region, or fix the payload.","For 403, confirm the API key/role has `bedrock:InvokeModel` on the model ARN.","For throttling (429), reduce concurrency or request a quota increase.","Confirm AWS_BEDROCK_LLM_MODEL_PREFERENCE is a valid model id for the chosen region."],"exampleFix":"// before\nthis.openai.chat.completions.create({\n  model: this.model,\n  messages,\n  temperature,\n})\n\n// after - apply temperatureParam gating\nthis.openai.chat.completions.create({\n  model: this.model,\n  messages,\n  temperature: this.temperatureParam(temperature),\n})","handlingStrategy":"try-catch","validationCode":"// Pre-flight cheap checks\nif (!this.model) throw new Error(\"No Bedrock model selected.\");\nif (!Array.isArray(messages) || messages.length === 0)\n  throw new Error(\"Messages must be a non-empty array.\");\n// Permission/quota only detectable via the call itself.","typeGuard":"/** @param {unknown} e @returns {boolean} */\nfunction isBedrockInvokeError(e) {\n  return e != null && typeof e === \"object\" &&\n    typeof e.message === \"string\" &&\n    (typeof e.status === \"number\" || typeof e.response?.status === \"number\");\n}","tryCatchPattern":"try {\n  const res = await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  const status = e.status ?? e.response?.status;\n  if (status === 403) reportModelAccessMissing(this.model);\n  else if (status === 429) await backoffRetry(fn);\n  else if (status >= 500) await backoffRetry(fn);\n  else throw e;\n}","preventionTips":["Enable model access in the AWS Bedrock console for every model you intend to call.","Confirm the API key/role has bedrock:InvokeModel on the target model ARN.","Branch recovery on status: 403 (access), 429 (throttle), 5xx (transient).","Keep the noTemperatureModels gating in temperatureParam correct for each model family."],"tags":["network","api","bedrock","aws","try-catch","runtime"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}