Skip to content

Fix #206: Bedrock throttling with exponential backoff retry - #232

Open
Alif416 wants to merge 1 commit into
TensorOpsAI:mainfrom
Alif416:fix/206-bedrock-throttling
Open

Alif416 wants to merge 1 commit into
TensorOpsAI:mainfrom
Alif416:fix/206-bedrock-throttling

Conversation

@Alif416

@Alif416 Alif416 commented Sep 2, 2026

Copy link
Copy Markdown

Summary

This PR fixes Issue #206 where Bedrock's ConverseAPI with Claude 3.5 Sonnet was throwing throttling exceptions on sync stream calls. The fix adds retry logic with exponential backoff at both the application and AWS client levels.

The Problem

Users reported getting ThrottlingException: Too many requests, please wait before trying again when making sync stream calls to Bedrock, but the same operations worked fine for async stream, sync non-stream, and async non-stream modes. This was frustrating because it seemed like only sync stream was broken.

What's Actually Happening

After investigating, I found two issues:

First, the provider's retry loop was basically broken. The code had a retry mechanism in place but it was never actually retrying - it would just immediately raise an error. There was even a commented-out section suggesting someone had tried to implement retry logic for rate limits but never finished it.

Second, the Bedrock client wasn't configured for retries at all. It was using boto3's default settings, which aren't tuned for Bedrock's fairly strict per-model rate limits. So when the test harness makes four consecutive calls to the same model (async non-stream, async stream, sync non-stream, sync stream), the fourth call hits the rate limit and fails.

The Fix

I made two changes that work together:

  1. Fixed the retry loop in provider.py - Now when a throttling or rate limit error happens, it actually retries. It uses exponential backoff so it waits longer between each retry. This affects all providers, so OpenAI, Anthropic, Vertex, and others all benefit.

  2. Added retry config to the Bedrock client - The boto3 client now uses adaptive retry mode with up to 6 attempts. This handles AWS-side throttling gracefully.

Together, these changes make the system resilient to temporary rate limits instead of just giving up immediately.

Testing

To verify this works, run the bedrock example with proper AWS credentials. The sync stream call should no longer fail with throttling exceptions.

… for Bedrock throttling

Implement two-level retry mechanism to handle AWS Bedrock throttling exceptions:

1. Application-level retry in provider.py:
   - Detects retryable errors (throttling, rate limits, HTTP 429)
   - Retries with exponential backoff + jitter (base 2^attempt, max 32s)
   - Applied to both sync (chat) and async (achat) methods
   - Fixes broken retry loop that affected all providers

2. Bedrock-specific AWS-side retry config:
   - Added Config(retries={'mode': 'adaptive', 'max_attempts': 6})
   - Provides client-side rate limiting complementing application retries

Fixes the Bedrock ConverseAPI ThrottlingException that occurred specifically
on sync stream calls due to rapid back-to-back requests hitting AWS quotas.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant