Skip to main content
Requesty supports sending PDF documents to AI models for analysis, summarization, and question answering. This feature works with both the Chat Completions and Messages API endpoints.

How It Works

PDF documents are sent as part of the message content using base64 encoding. The AI model can then analyze the document and respond to questions about its contents.

Chat Completions API

Send PDFs using the file_input content type:
curl https://router.requesty.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_REQUESTY_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4-20250514",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Summarize this PDF"
          },
          {
            "type": "file_input",
            "filename": "document.pdf",
            "file_data": "JVBERi0=..."
          }
        ]
      }
    ]
  }'

Parameters

  • type: Must be "file_input"
  • filename: The name of the PDF file (e.g., "document.pdf")
  • file_data: Base64-encoded PDF content
See the Chat Completions API documentation for more details.

Messages API

Send PDFs using the document content type:
curl https://router.requesty.ai/v1/messages \
  -H "x-api-key: YOUR_REQUESTY_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What is in this PDF?"
          },
          {
            "type": "document",
            "source": {
              "type": "base64",
              "media_type": "application/pdf",
              "data": "JVBERi0=..."
            }
          }
        ]
      }
    ]
  }'

Parameters

  • type: Must be "document"
  • source.type: Must be "base64"
  • source.media_type: Must be "application/pdf"
  • source.data: Base64-encoded PDF content
See the Messages API documentation for more details.

Working with PDFs

Python Example (Chat Completions)

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",
)

# Read and encode PDF
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": "file_input",
                    "filename": "document.pdf",
                    "file_data": pdf_data
                }
            ]
        }
    ]
)

print(response.choices[0].message.content)

Python Example (Messages API)

import base64
from anthropic import Anthropic

requesty_api_key = "YOUR_REQUESTY_API_KEY"

client = Anthropic(
    api_key=requesty_api_key,
    base_url="https://router.requesty.ai/v1",
)

# Read and encode PDF
with open("document.pdf", "rb") as pdf_file:
    pdf_data = base64.b64encode(pdf_file.read()).decode('utf-8')

response = client.messages.create(
    model="anthropic/claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "What is in this PDF?"
                },
                {
                    "type": "document",
                    "source": {
                        "type": "base64",
                        "media_type": "application/pdf",
                        "data": pdf_data
                    }
                }
            ]
        }
    ]
)

print(response.content[0].text)

JavaScript/TypeScript Example (Chat Completions)

import OpenAI from 'openai';
import fs from 'fs';

const client = new OpenAI({
  apiKey: 'YOUR_REQUESTY_API_KEY',
  baseURL: 'https://router.requesty.ai/v1',
});

// Read and encode PDF
const pdfBuffer = fs.readFileSync('document.pdf');
const pdfData = pdfBuffer.toString('base64');

const response = await client.chat.completions.create({
  model: 'anthropic/claude-sonnet-4-20250514',
  messages: [
    {
      role: 'user',
      content: [
        {
          type: 'text',
          text: 'Summarize this PDF'
        },
        {
          type: 'file_input',
          filename: 'document.pdf',
          file_data: pdfData
        }
      ]
    }
  ]
});

console.log(response.choices[0].message.content);