Description
AsyncAnthropicBedrock performs AWS credential resolution and SigV4 signing synchronously on the event-loop thread.
Expected: AsyncAnthropicBedrock should not execute potentially blocking credential resolution or refresh on the event-loop thread.
Reproduction
import asyncio
import time
from unittest.mock import patch
from anthropic import AsyncAnthropicBedrock
async def heartbeat():
while True:
await asyncio.sleep(0.5)
print("heartbeat")
def slow_get_credentials(*args, **kwargs):
time.sleep(5)
raise RuntimeError()
async def main():
client = AsyncAnthropicBedrock(aws_region="us-east-1")
with patch(
"botocore.session.Session.get_credentials",
side_effect=slow_get_credentials,
):
await asyncio.gather(
heartbeat(),
client.messages.create(
model="anthropic.claude-3-haiku-20240307-v1:0",
max_tokens=1,
messages=[{"role": "user", "content": "hi"}],
),
)
asyncio.run(main())
No heartbeat output appears during the five-second credential call.
Cause: AsyncAnthropicBedrock._prepare_request() calls the synchronous credential/signing path directly.
Description
AsyncAnthropicBedrockperforms AWS credential resolution and SigV4 signing synchronously on the event-loop thread.Expected:
AsyncAnthropicBedrockshould not execute potentially blocking credential resolution or refresh on the event-loop thread.Reproduction
No heartbeat output appears during the five-second credential call.
Cause:
AsyncAnthropicBedrock._prepare_request()calls the synchronous credential/signing path directly.