Skip to content

Connecting AWS Bedrock models to new Claude Agent SDK #224

@arindam-giri

Description

@arindam-giri

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

  1. Set up AWS credentials with a profile in ~/.aws/credentials:
[arindam_linux]
aws_access_key_id = AKIA...
aws_secret_access_key = ...
  1. Install required packages:
pip install anthropic[bedrock] claude-agent-sdk
  1. 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:

  1. Receive the init SystemMessage
  2. Send the prompt to AWS Bedrock
  3. Receive and yield the assistant's response
  4. Complete successfully

Actual Behavior

The SDK:

  1. ✅ Receives the init SystemMessage correctly
  2. ❌ Hangs indefinitely after that
  3. ❌ Never receives any AssistantMessage or response
  4. ❌ 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.

Image

Happy to provide any additional information or testing needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions