Skip to content

PDF Support for AnthropicBedrock #921

Open
@akshit0201

Description

@akshit0201

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions