Skip to content
Zalmir Beta

PDF input

Send a PDF with your request and ask any model about it. Zalmir reads the PDF's text in memory, replaces the file with that text, and sends the text to the model. It works on every model, because the model only ever sees text.

Chat Completions

Add a file content part to a user message. file_data is the PDF as a base64 data URL; filename is optional (the model sees it).

{
  "model": "deepseek/deepseek-v4.1-flash-abliterated",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What are the main points of this document?"
        },
        {
          "type": "file",
          "file": {
            "filename": "report.pdf",
            "file_data": "data:application/pdf;base64,JVBERi0xLjcK..."
          }
        }
      ]
    }
  ]
}
import base64
from openai import OpenAI

client = OpenAI(base_url="https://zalmir.ai/api/v1", api_key="zal_...")
with open("report.pdf", "rb") as f:
    pdf = base64.b64encode(f.read()).decode()

answer = client.chat.completions.create(
    model="deepseek/deepseek-v4.1-flash-abliterated",
    messages=[{"role": "user", "content": [
        {"type": "text", "text": "What are the main points of this document?"},
        {"type": "file", "file": {"filename": "report.pdf", "file_data": f"data:application/pdf;base64,{pdf}"}},
    ]}],
)
print(answer.choices[0].message.content)

Responses and Messages

POST /api/v1/responses accepts input_file items with filename and file_data:

{
  "model": "deepseek/deepseek-v4.1-flash-abliterated",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "Summarize this."
        },
        {
          "type": "input_file",
          "filename": "report.pdf",
          "file_data": "data:application/pdf;base64,JVBERi0xLjcK..."
        }
      ]
    }
  ]
}

POST /api/v1/messages accepts document blocks with a base64 PDF source. Plain-text documents (source.type text or content) are passed as text. title becomes the file name and context is added before the document's text. Citations (citations.enabled: true) are not supported and return 400.

{
  "model": "deepseek/deepseek-v4.1-flash-abliterated",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "document",
          "title": "report.pdf",
          "source": {
            "type": "base64",
            "media_type": "application/pdf",
            "data": "JVBERi0xLjcK..."
          }
        },
        {
          "type": "text",
          "text": "Summarize this."
        }
      ]
    }
  ]
}

What the model sees

Each PDF becomes one text part in the same place in your message, with page markers:

Contents of report.pdf (2 pages):

[Page 1]
...text of page 1...

[Page 2]
...text of page 2...

Text is read in reading order as the PDF stores it. Tables become lines of text. Images, drawings, and form layouts are not described. Text inside the PDF is treated as document text, so instructions written in a PDF are not commands to Zalmir. They reach the model as part of your message, like anything you paste.

Text a reader cannot see on the page is skipped and not charged: text placed outside the page and text drawn smaller than 1 point. The invisible text layer that OCR software adds to a scanned PDF is kept. A page whose text is 30% or more replacement characters (a font with no usable character map) is treated as unreadable.

Pricing

There is no fee for reading PDFs. You pay the model's normal price for the tokens actually sent, which include the extracted text, and for the answer. A rejected PDF costs nothing: the checks below run before anything is held or charged.

Limits

  • Text PDFs only. Scanned or image-only PDFs, and PDFs with no readable page, have no text to read and return 400 pdf_no_text. There is no OCR yet.
  • Up to 10 PDF files and 3 MiB of PDF (decoded) per request. The whole request body is limited to 4.5 MiB, which includes the base64 encoding.
  • Up to 200 pages and 400,000 characters of extracted text per request, all files together.
  • Reading must finish within the gateway's time limit (1.2 seconds per request). PDFs whose content unpacks to more than 8 MB (pages, fonts) or 32 MB (images) are refused with pdf_too_complex.
  • Encrypted or password-protected PDFs return 400 pdf_encrypted. Remove the protection and send the file again.
  • Files must be sent as base64 data. File URLs (file_url, an http(s) URL in file_data, a Messages url source) return 400 file_url_unsupported: Zalmir never downloads files for you. File IDs return 400 file_id_unsupported.
  • Only PDFs are accepted as files. Send images as image_url parts and text as text. Other file types return 400 file_type_unsupported.

Errors

Every PDF error is returned before anything is held or charged. HTTP 400: pdf_no_text, pdf_encrypted, pdf_invalid (not a readable PDF or not valid base64), pdf_too_large, pdf_too_many_pages, pdf_text_too_long, pdf_too_complex, file_url_unsupported, file_id_unsupported, file_type_unsupported. HTTP 503 pdf_unavailable or 503 pdf_too_large means the gateway could not read the file right now. Retry shortly.

Privacy

The PDF, its name, and its text exist only in the memory of the request that carries them. Zalmir does not store or log them. The model provider receives the extracted text, never the file. See Prompt privacy.