import base64
from openai import OpenAI
requesty_api_key = "YOUR_REQUESTY_API_KEY"
client = OpenAI(
api_key=requesty_api_key,
base_url="https://router.requesty.ai/v1",
)
# Option 1: Using base64-encoded PDF from a file
with open("document.pdf", "rb") as pdf_file:
pdf_data = base64.b64encode(pdf_file.read()).decode('utf-8')
response = client.chat.completions.create(
model="anthropic/claude-sonnet-4-20250514",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Summarize this PDF"
},
{
"type": "input_file",
"filename": "document.pdf",
"file_data": f"data:application/pdf;base64,{pdf_data}"
}
]
}
]
)
print(response.choices[0].message.content)
# Option 2: Using PDF URL
response = client.chat.completions.create(
model="anthropic/claude-sonnet-4-20250514",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Summarize this PDF"
},
{
"type": "input_file",
"filename": "document.pdf",
"file_data": "https://example.com/document.pdf"
}
]
}
]
)
print(response.choices[0].message.content)