File Attachments
Send images and PDF documents as part of your message request.
import os
import base64
import anthropic
client = anthropic.Anthropic(
api_key="<API_KEY>",,
base_url='https://llm.onerouter.pro'
)
# Read files as base64
with open('./document.pdf', 'rb') as f:
pdf_base64 = base64.b64encode(f.read()).decode('utf-8')
with open('./image.png', 'rb') as f:
image_base64 = base64.b64encode(f.read()).decode('utf-8')
message = client.messages.create(
model='claude-sonnet-4-5@20250929',
max_tokens=1024,
messages=[
{
'role': 'user',
'content': [
{
'type': 'document',
'source': {
'type': 'base64',
'media_type': 'application/pdf',
'data': pdf_base64,
},
},
{
'type': 'image',
'source': {
'type': 'base64',
'media_type': 'image/png',
'data': image_base64,
},
},
{
'type': 'text',
'text': 'Please summarize the PDF and describe the image.',
},
],
}
],
)
print('Response:', message.content[0].text)Supported file types
Last updated