mem0ai/mem0 · error · Error

AWS Bedrock LLM failed: ${message}

Error message

AWS Bedrock LLM failed: ${message}

What it means

Both generateResponse() and generateChat() wrap their entire Bedrock converse() call in a try-catch and rethrow any failure (SDK errors, throttling, auth, model access, response-parsing issues) prefixed with 'AWS Bedrock LLM failed:'. The suffix carries the original message, which is where the real diagnosis lives.

Source

Thrown at mem0-ts/src/oss/src/llms/aws_bedrock.ts:292

    _responseFormat?: { type: string },
    tools?: any[],
  ): Promise<string | LLMResponse> {
    try {
      const response = await this.converse(messages, tools);
      if (tools && tools.length) {
        const toolCalls = this.parseToolCalls(response);
        if (toolCalls.length) {
          return {
            content: this.parseText(response),
            role: "assistant",
            toolCalls,
          };
        }
      }
      return this.parseText(response);
    } catch (err) {
      const message = err instanceof Error ? err.message : String(err);
      throw new Error(`AWS Bedrock LLM failed: ${message}`);
    }
  }

  async generateChat(messages: Message[]): Promise<LLMResponse> {
    try {
      const response = await this.converse(messages);
      return { content: this.parseText(response), role: "assistant" };
    } catch (err) {
      const message = err instanceof Error ? err.message : String(err);
      throw new Error(`AWS Bedrock LLM failed: ${message}`);
    }
  }
}

View on GitHub (pinned to 001c235229)

Solutions

  1. Read the suffix of the message: it contains the AWS SDK error (e.g. AccessDeniedException, ThrottlingException) which names the fix
  2. Verify credentials (aws sts get-caller-identity) and that the principal has bedrock:InvokeModel for the model ARN
  3. Align the region: ensure awsRegion in config matches where the model is available
  4. Add retry with backoff for throttling, and trim history to fit the model context window
  5. Confirm the model id exists in your account/region (aws bedrock list-foundation-models --region <region>)

Example fix

// before
const llm = new AWSBedrockLLM({ model: "anthropic.claude-3-sonnet-20240229-v1:0" }); // default region

// after
const llm = new AWSBedrockLLM({
  model: "anthropic.claude-3-sonnet-20240229-v1:0",
  awsRegion: "us-east-1",
  awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,
  awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});
Defensive patterns

Strategy: retry

Validate before calling

import { execSync } from "node:child_process";
function assertBedrockReady(modelId: string, region: string): void {
  execSync(`aws sts get-caller-identity`, { stdio: "pipe" }); // fails fast on bad credentials
  const models = JSON.parse(execSync(`aws bedrock list-foundation-models --region ${region} --query 'modelSummaries[].modelId' --output json`, { stdio: "pipe" }).toString());
  if (!models.some((m: string) => modelId.startsWith(m) || m.startsWith(modelId))) {
    throw new Error(`Model '${modelId}' not available in ${region}`);
  }
}

Type guard

function isBedrockLLMError(err: unknown): boolean {
  return err instanceof Error && err.message.startsWith("AWS Bedrock LLM failed:");
}
function bedrockCause(err: unknown): string {
  return err instanceof Error ? err.message.replace(/^AWS Bedrock LLM failed:\s*/, "") : "";
}

Try / catch

for (let attempt = 0; ; attempt++) {
  try { return await llm.generateChat(messages); }
  catch (err) {
    const cause = bedrockCause(err);
    const retryable = /Throttling|TooManyRequests|ServiceUnavailable|timeout/i.test(cause);
    if (retryable && attempt < 3) {
      await new Promise((r) => setTimeout(r, 2 ** attempt * 500));
      continue;
    }
    if (/AccessDenied/i.test(cause)) throw new Error("IAM: grant bedrock:InvokeModel for this model");
    if (/validation/i.test(cause) && /context|token/i.test(cause)) throw new Error("Trim conversation history - context window exceeded");
    throw err;
  }
}

Prevention

When it happens

Trigger: Missing/invalid AWS credentials or no permission to invoke the model (AccessDeniedException); wrong region or model not available in it; throttling (TooManyRequestsException) during memory-heavy workloads; context length exceeded for the conversation payload; tool-use responses that fail parseText/parseToolCalls.

Common situations: IAM role/policy without bedrock:InvokeModel; model id enabled in us-east-1 but the client is in another region; expired session tokens; bursty Memory.add() loops exceeding Bedrock limits; very long histories blowing the model context window.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/4b2b7f4560cc0f80. Report an issue: GitHub.