Skip to main content
Anannas supports PDF file processing through the /chat/completions API.
PDFs can be sent as direct URLs or base64-encoded data URLs in the messages array, using the file content type. This works on all models, even if the model doesn’t natively support PDFs.
URLs are preferred for large files since they avoid payload bloat.Use base64 encoding when working with local or private files.

Using PDF URLs

For publicly accessible PDFs, send the file URL directly:
import requests

url = "https://api.anannas.ai/v1/chat/completions"
headers = {
    "Authorization": f"Bearer {API_KEY_REF}",
    "Content-Type": "application/json",
}

messages = [
    {
        "role": "user",
        "content": [
            { "type": "text", "text": "Summarize this PDF." },
            {
                "type": "file",
                "file": {
                    "filename": "sample.pdf",
                    "file_data": "https://example.com/sample.pdf",
                },
            },
        ],
    }
]

payload = { "model": "openai/gpt-5-mini", "messages": messages }

response = requests.post(url, headers=headers, json=payload)
print(response.json())
const response = await fetch("https://api.anannas.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY_REF}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "openai/gpt-5-mini",
    messages: [
      {
        role: "user",
        content: [
          { type: "text", text: "Summarize this PDF." },
          {
            type: "file",
            file: {
              filename: "sample.pdf",
              file_data: "https://example.com/sample.pdf",
            },
          },
        ],
      },
    ],
  }),
});

const data = await response.json();
console.log(data);

Using Base64-Encoded PDFs

For local or private PDFs, encode to base64 and send as a data URL:
import base64
import requests

def encode_file_to_base64(file_path):
    with open(file_path, "rb") as f:
        return base64.b64encode(f.read()).decode("utf-8")

pdf_path = "document.pdf"
base64_pdf = encode_file_to_base64(pdf_path)
data_url = f"data:application/pdf;base64,{base64_pdf}"

url = "https://api.anannas.ai/v1/chat/completions"
headers = {
    "Authorization": f"Bearer {API_KEY_REF}",
    "Content-Type": "application/json",
}

messages = [
    {
        "role": "user",
        "content": [
            { "type": "text", "text": "Extract key points from this PDF." },
            {
                "type": "file",
                "file": {
                    "filename": "document.pdf",
                    "file_data": data_url,
                },
            },
        ],
    }
]

payload = { "model": "anthropic/claude-3-5-sonnet-20241022", "messages": messages }

response = requests.post(url, headers=headers, json=payload)
print(response.json())
import fs from "fs";

async function encodeFileToBase64(filePath: string): Promise<string> {
  const buffer = await fs.promises.readFile(filePath);
  return `data:application/pdf;base64,${buffer.toString("base64")}`;
}

const base64File = await encodeFileToBase64("document.pdf");

const response = await fetch("https://api.anannas.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY_REF}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "anthropic/claude-3-5-sonnet-20241022",
    messages: [
      {
        role: "user",
        content: [
          { type: "text", text: "Extract key points from this PDF." },
          {
            type: "file",
            file: {
              filename: "document.pdf",
              file_data: base64File,
            },
          },
        ],
      },
    ],
  }),
});

const data = await response.json();
console.log(data);
Was this page helpful?