> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anannas.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# PDF Inputs

> Send PDF files to any model on Anannas

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.

<Note>
  URLs are preferred for large files since they avoid payload bloat.

  Use base64 encoding when working with local or private files.
</Note>

### Using PDF URLs

For publicly accessible PDFs, send the file URL directly:

<CodeGroup>
  ```json JSON theme={null}
  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())
  ```

  ```python Python theme={null}
  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);
  ```
</CodeGroup>

### Using Base64-Encoded PDFs

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

<CodeGroup>
  ```python Python theme={null}
  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())
  ```

  ```Typescript theme={null}
  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);
  ```
</CodeGroup>

<div
  style={{ 
marginTop: '2rem',
display: 'flex',
alignItems: 'center',
gap: '0.75rem',
fontSize: '14px',
color: '#6b7280'
}}
>
  <span>Was this page helpful?</span>

  <button
    id="feedback-yes-btn"
    onClick={() => {
  console.log('Positive feedback');
  document.getElementById('feedback-yes-btn').style.background = 'rgba(156, 163, 175, 0.1)';
  document.getElementById('feedback-yes-btn').style.backdropFilter = 'blur(10px)';
  document.getElementById('feedback-yes-btn').style.border = '1px solid rgba(156, 163, 175, 0.2)';
  document.getElementById('feedback-no-btn').style.background = 'transparent';
  document.getElementById('feedback-no-btn').style.backdropFilter = 'none';
  document.getElementById('feedback-no-btn').style.border = 'none';
}}
    style={{
  background: 'transparent',
  border: 'none',
  cursor: 'pointer',
  padding: '6px 12px',
  fontSize: '14px',
  borderRadius: '8px',
  transition: 'all 0.2s ease',
  display: 'flex',
  alignItems: 'center',
  gap: '6px',
  color: '#6b7280'
}}
  >
    <span style={{ fontSize: '16px' }}>👍</span>
    Yes
  </button>

  <button
    id="feedback-no-btn"
    onClick={() => {
  console.log('Negative feedback');
  document.getElementById('feedback-no-btn').style.background = 'rgba(156, 163, 175, 0.1)';
  document.getElementById('feedback-no-btn').style.backdropFilter = 'blur(10px)';
  document.getElementById('feedback-no-btn').style.border = '1px solid rgba(156, 163, 175, 0.2)';
  document.getElementById('feedback-yes-btn').style.background = 'transparent';
  document.getElementById('feedback-yes-btn').style.backdropFilter = 'none';
  document.getElementById('feedback-yes-btn').style.border = 'none';
}}
    style={{
  background: 'transparent',
  border: 'none',
  cursor: 'pointer',
  padding: '6px 12px',
  fontSize: '14px',
  borderRadius: '8px',
  transition: 'all 0.2s ease',
  display: 'flex',
  alignItems: 'center',
  gap: '6px',
  color: '#6b7280'
}}
  >
    <span style={{ fontSize: '16px' }}>👎</span>
    No
  </button>
</div>
