- Newest
- Most votes
- Most comments
Hello,
I understand that you are experiencing an intermittent issue where some AWS Bedrock Runtime API calls fail to complete on the first attempt and must wait for the full configured read_timeout duration (currently 45 seconds) before boto3 automatically retries and succeeds immediately (in 1–5 seconds).
The issue you're experiencing with AWS Bedrock Runtime API calls appears to be related to how the boto3 client handles timeouts and retries when working with large language models. This is a known behavior pattern with Bedrock and other LLM services.
Additionally, please note that Bedrock is an on-demand service[1], and some variation in response times can occur based on overall service load, routing decisions, and customer demand for the given model at that timeframe.
As a potential workaround, you might experiment with different read_timeout values. For Lambda functions, it's recommended to set the boto3 read_timeout to a lower value than the function execution timeout, giving you time to take additional action.
To investigate it further, please reach out to AWS Support [2] with your detailed query and following details, and we will be happy to assist you further.
- Please mention some specific timestamps when you observed this issue for the mentioned models
- Please share the model invocation logs [3].
- Request IDs for a few specific incidents:
- The original request ID that timed out
- The successful retry request ID
—References—
[1] https://aws.amazon.com/bedrock/sla/
[2] Creating support cases and case management: https://docs.aws.amazon.com/awssupport/latest/user/case-management.html#creating-a-support-case
[3] https://docs.aws.amazon.com/bedrock/latest/userguide/model-invocation-logging.html
The issue you're experiencing with AWS Bedrock Runtime API calls appears to be related to how the boto3 client handles timeouts and retries when working with large language models. This is a known behavior pattern with Bedrock and other LLM services.
What's happening is that occasionally (in your case about 5-10% of the time), the Bedrock service accepts your request but doesn't process or respond within the expected timeframe. This forces your boto3 client to wait for the full read_timeout period (45 seconds) before automatically retrying the request, at which point it succeeds quickly (1-5 seconds).
This behavior is consistent with how the AWS SDK handles timeouts. When a read timeout occurs, the SDK's retry mechanism comes into play. Even with your configuration of max_attempts=2, the SDK will perform a single retry after the initial attempt times out. This explains why you see a pattern of waiting for the full timeout period followed by a quick successful response.
Some potential approaches to address this issue:
-
Implement streaming responses: Amazon Bedrock provides the ability to stream responses using InvokeModelWithResponseStream, which allows you to process and consume generated text in chunks as it becomes available. This enables faster response to the client and allows at least partial responses even if timeouts occur.
-
Adjust timeout configuration: While you've already set reasonable timeouts, you might experiment with different read_timeout values. For Lambda functions, it's recommended to set the boto3 read_timeout to a lower value than the function execution timeout, giving you time to take additional action.
-
Implement custom retry logic: Instead of relying solely on boto3's built-in retry mechanism, you could implement your own retry logic with exponential backoff for specific error conditions.
-
Monitor and optimize: Use CloudWatch Metrics to track your API call patterns and set up alerts for when you're approaching rate limits. This might help identify if the issue is related to service quotas.
-
Consider cross-region inference: If the issue persists, you might want to implement load balancing to another region with cross-region inference capabilities.
The non-deterministic nature of the issue is typical for LLM services, which can experience variable processing times based on model complexity, service load, and other factors. Since your application is already using async patterns with FastAPI and LangChain, you're on the right track for handling these types of intermittent delays.
Sources
Designing Serverless Integration Patterns for Large Language Models (LLMs) | AWS Compute Blog
Unexpected Delay in Amazon Bedrock Response | AWS re:Post
504 Gateway Time-out nginx - only using EB to call Bedrock, not using local Flask server | AWS re:Post
Solving 'Read Timed Out' Error and High Latencies in Amazon Bedrock with AWS Java SDK Client | AWS re:Post
answered a year ago
Relevant content
- AWS OFFICIALUpdated 2 months ago
