-
Notifications
You must be signed in to change notification settings - Fork 518
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Claude Agent SDK hangs when using AWS Bedrock backend
Description
When using the Claude Agent SDK with AWS Bedrock (via CLAUDE_CODE_USE_BEDROCK=1), the SDK hangs after receiving the initial SystemMessage with subtype='init' and never proceeds to get a response from the model. The process times out and no assistant messages are received.
Environment
- Python Version: 3.12
- claude-agent-sdk Version: 0.1.1
- anthropic Version: 0.69.0
- OS: macOS
- AWS Region: us-east-1
- Bedrock Model:
us.anthropic.claude-sonnet-4-20250514-v1:0(Claude Sonnet 4)
Steps to Reproduce
- Set up AWS credentials with a profile in
~/.aws/credentials:
[arindam_linux]
aws_access_key_id = AKIA...
aws_secret_access_key = ...- Install required packages:
pip install anthropic[bedrock] claude-agent-sdk- Run the following code:
import asyncio
import boto3
import os
from claude_agent_sdk import query, ClaudeAgentOptions
async def main():
# Enable Bedrock mode
os.environ["CLAUDE_CODE_USE_BEDROCK"] = "1"
# Set up AWS
boto3.setup_default_session(profile_name="arindam_linux")
os.environ["AWS_REGION"] = "us-east-1"
# Configure options
options = ClaudeAgentOptions(
model="us.anthropic.claude-sonnet-4-20250514-v1:0",
permission_mode='bypassPermissions',
max_turns=1,
allowed_tools=[]
)
# Query
async for message in query(prompt="Say hello", options=options):
print(f"Message type: {type(message).__name__}")
if hasattr(message, 'subtype'):
print(f"Subtype: {message.subtype}")
asyncio.run(main())Expected Behavior
The SDK should:
- Receive the
initSystemMessage - Send the prompt to AWS Bedrock
- Receive and yield the assistant's response
- Complete successfully
Actual Behavior
The SDK:
- ✅ Receives the
initSystemMessage correctly - ❌ Hangs indefinitely after that
- ❌ Never receives any AssistantMessage or response
- ❌ Times out after 30+ seconds with no further messages
Output:
[Message 1]
Type: SystemMessage
Subtype: init
------------------------------------------------------------
<hangs here indefinitely>
Verification that Bedrock Works
Direct Bedrock API calls work perfectly with the same credentials and model:
import boto3
import json
boto3.setup_default_session(profile_name="arindam_linux")
client = boto3.client("bedrock-runtime", region_name="us-east-1")
native_request = {
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 100,
"messages": [{"role": "user", "content": [{"type": "text", "text": "Say hello"}]}],
}
response = client.invoke_model(
modelId="us.anthropic.claude-sonnet-4-20250514-v1:0",
body=json.dumps(native_request)
)
model_response = json.loads(response["body"].read())
print(model_response['content'][0]['text'])
# Output: Hello! It's nice to meet you. How are you doing today?This confirms:
- ✅ AWS credentials are correct
- ✅ Bedrock access is enabled
- ✅ Model is accessible
- ✅ IAM permissions are sufficient
Additional Context
I do not have ANTHROPIC_API_KEY setup since I do not want to use that key. I want to use the Bedrock model instead.
Thanks.
Happy to provide any additional information or testing needed.
jakoberpf, alejandroBallesterosC and alechewitt
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working