Mintplex-Labs/anything-llm · error · Error

AWSBedrock::getChatCompletion failed. ${e.message}

Error message

AWSBedrock::getChatCompletion failed. ${e.message}

What it means

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.

Source

Thrown at server/utils/AiProviders/bedrock/index.js:201

    if (!messages?.length)
      throw new Error(
        "AWSBedrock::getChatCompletion requires a non-empty messages array."
      );

    if (this.#isAnthropic) {
      return this.#anthropicChatCompletion(messages, temperature);
    }

    const result = await LLMPerformanceMonitor.measureAsyncFunction(
      this.openai.chat.completions
        .create({
          model: this.model,
          messages,
          temperature: this.temperatureParam(temperature),
        })
        .catch((e) => {
          this.#log(`Bedrock API Error (getChatCompletion): ${e.message}`, e);
          throw new Error(`AWSBedrock::getChatCompletion failed. ${e.message}`);
        })
    );

    const response = result.output;
    if (!response?.choices?.[0]?.message) {
      this.#log("Bedrock response missing expected structure.", response);
      return null;
    }

    return {
      textResponse: response.choices[0].message.content,
      metrics: this.#buildMetrics(response.usage, result.duration),
    };
  }

  async streamGetChatCompletion(messages = null, { temperature }) {
    if (!Array.isArray(messages) || messages.length === 0) {
      throw new Error(

View on GitHub (pinned to 526360e320)

Solutions

  1. 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.
  2. For 403, confirm the API key/role has `bedrock:InvokeModel` on the model ARN.
  3. For throttling (429), reduce concurrency or request a quota increase.
  4. Confirm AWS_BEDROCK_LLM_MODEL_PREFERENCE is a valid model id for the chosen region.

Example fix

// before
this.openai.chat.completions.create({
  model: this.model,
  messages,
  temperature,
})

// after - apply temperatureParam gating
this.openai.chat.completions.create({
  model: this.model,
  messages,
  temperature: this.temperatureParam(temperature),
})
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight cheap checks
if (!this.model) throw new Error("No Bedrock model selected.");
if (!Array.isArray(messages) || messages.length === 0)
  throw new Error("Messages must be a non-empty array.");
// Permission/quota only detectable via the call itself.

Type guard

/** @param {unknown} e @returns {boolean} */
function isBedrockInvokeError(e) {
  return e != null && typeof e === "object" &&
    typeof e.message === "string" &&
    (typeof e.status === "number" || typeof e.response?.status === "number");
}

Try / catch

try {
  const res = await llm.getChatCompletion(messages, { temperature });
} catch (e) {
  const status = e.status ?? e.response?.status;
  if (status === 403) reportModelAccessMissing(this.model);
  else if (status === 429) await backoffRetry(fn);
  else if (status >= 500) await backoffRetry(fn);
  else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/0924fb64999bc43f. Report an issue: GitHub.