anthropic-sdk-python icon indicating copy to clipboard operation
anthropic-sdk-python copied to clipboard

PDF Support for AnthropicBedrock

Open akshit0201 opened this issue 9 months ago • 1 comments

I use bedrock to access Claude.

I'm trying to upload a pdf using Anthropic Bedrock

result = make_anthropic_call_with_fallback(
        context=[{
            'role': 'user',
            'content': [
                {
                    'type': 'document',
                    'source': {
                        'type': 'base64',
                        "media_type": "application/pdf",
                        "data": pdf_base64
                    }
                },
                {
                    'type': 'text',
                    'text': 'Pls explain the content of this file'
                }
            ]
        }]

Here is my helper function

def make_anthropic_call_with_fallback(context, print_prompt=False, system='', temperature=1,thinking=True,budget=10000):

    anthropic_backup_client = AnthropicBedrock(
    aws_access_key=userdata.get('AWS_ACCESS_KEY_ID'),
    aws_secret_key=userdata.get('AWS_SECRET_ACCESS_KEY'),
    aws_region='us-east-1',
    max_retries=0
)
    # Common parameters for all API calls
    params = {
        "max_tokens": 8192,
        "temperature": temperature,
        "system": system,
        "messages": context
    }

    if thinking:
        params['thinking'] = {
       "type": "enabled",
       "budget_tokens": budget
   }
        params['max_tokens'] += budget
        params['temperature'] = 1


    response = anthropic_backup_client.messages.create(
          model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
          **params
      )
   
    return response

Here is the error I'm getting

BadRequestError: Error code: 400 - {'message': "messages.0.content.0: Input tag 'document' found using 'type' does not match any of the expected tags: 'image', 'redacted_thinking', 'text', 'thinking', 'tool_result', 'tool_use'"}

Pls add PDF support for anthropic bedrock

akshit0201 avatar Apr 02 '25 07:04 akshit0201

+1 Waiting for this for the past 3-4 months. Can we get the support/feature soon?

OmiWakode avatar Apr 16 '25 21:04 OmiWakode

This is now supported: https://aws.amazon.com/about-aws/whats-new/2025/06/citations-api-pdf-claude-models-amazon-bedrock/

pjuhos avatar Jul 23 '25 20:07 pjuhos