{"record":{"id":"4b2b7f4560cc0f80","repo":"mem0ai/mem0","slug":"aws-bedrock-llm-failed-message","errorCode":null,"errorMessage":"AWS Bedrock LLM failed: ${message}","messagePattern":"AWS Bedrock LLM failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/aws_bedrock.ts","lineNumber":292,"sourceCode":"    _responseFormat?: { type: string },\n    tools?: any[],\n  ): Promise<string | LLMResponse> {\n    try {\n      const response = await this.converse(messages, tools);\n      if (tools && tools.length) {\n        const toolCalls = this.parseToolCalls(response);\n        if (toolCalls.length) {\n          return {\n            content: this.parseText(response),\n            role: \"assistant\",\n            toolCalls,\n          };\n        }\n      }\n      return this.parseText(response);\n    } catch (err) {\n      const message = err instanceof Error ? err.message : String(err);\n      throw new Error(`AWS Bedrock LLM failed: ${message}`);\n    }\n  }\n\n  async generateChat(messages: Message[]): Promise<LLMResponse> {\n    try {\n      const response = await this.converse(messages);\n      return { content: this.parseText(response), role: \"assistant\" };\n    } catch (err) {\n      const message = err instanceof Error ? err.message : String(err);\n      throw new Error(`AWS Bedrock LLM failed: ${message}`);\n    }\n  }\n}\n","sourceCodeStart":274,"sourceCodeEnd":306,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/aws_bedrock.ts#L274-L306","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the suffix of the message: it contains the AWS SDK error (e.g. AccessDeniedException, ThrottlingException) which names the fix","Verify credentials (aws sts get-caller-identity) and that the principal has bedrock:InvokeModel for the model ARN","Align the region: ensure awsRegion in config matches where the model is available","Add retry with backoff for throttling, and trim history to fit the model context window","Confirm the model id exists in your account/region (aws bedrock list-foundation-models --region <region>)"],"exampleFix":"// before\nconst llm = new AWSBedrockLLM({ model: \"anthropic.claude-3-sonnet-20240229-v1:0\" }); // default region\n\n// after\nconst llm = new AWSBedrockLLM({\n  model: \"anthropic.claude-3-sonnet-20240229-v1:0\",\n  awsRegion: \"us-east-1\",\n  awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,\n  awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,\n});","handlingStrategy":"retry","validationCode":"import { execSync } from \"node:child_process\";\nfunction assertBedrockReady(modelId: string, region: string): void {\n  execSync(`aws sts get-caller-identity`, { stdio: \"pipe\" }); // fails fast on bad credentials\n  const models = JSON.parse(execSync(`aws bedrock list-foundation-models --region ${region} --query 'modelSummaries[].modelId' --output json`, { stdio: \"pipe\" }).toString());\n  if (!models.some((m: string) => modelId.startsWith(m) || m.startsWith(modelId))) {\n    throw new Error(`Model '${modelId}' not available in ${region}`);\n  }\n}","typeGuard":"function isBedrockLLMError(err: unknown): boolean {\n  return err instanceof Error && err.message.startsWith(\"AWS Bedrock LLM failed:\");\n}\nfunction bedrockCause(err: unknown): string {\n  return err instanceof Error ? err.message.replace(/^AWS Bedrock LLM failed:\\s*/, \"\") : \"\";\n}","tryCatchPattern":"for (let attempt = 0; ; attempt++) {\n  try { return await llm.generateChat(messages); }\n  catch (err) {\n    const cause = bedrockCause(err);\n    const retryable = /Throttling|TooManyRequests|ServiceUnavailable|timeout/i.test(cause);\n    if (retryable && attempt < 3) {\n      await new Promise((r) => setTimeout(r, 2 ** attempt * 500));\n      continue;\n    }\n    if (/AccessDenied/i.test(cause)) throw new Error(\"IAM: grant bedrock:InvokeModel for this model\");\n    if (/validation/i.test(cause) && /context|token/i.test(cause)) throw new Error(\"Trim conversation history - context window exceeded\");\n    throw err;\n  }\n}","preventionTips":["Verify credentials and bedrock:InvokeModel permissions at deploy time","Match awsRegion to where the model is actually available","Wrap calls in exponential-backoff retry for throttling and trim long histories","Always parse the suffix after 'AWS Bedrock LLM failed:' - it carries the AWS SDK error name"],"tags":["aws-bedrock","llm","wrapper","aws","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}