Skip to content
Docs

Guides

Files

Send a PDF, a Word, Excel or PowerPoint document, its LibreOffice version or a text file inside the request, in any of the three API formats. The model gets the text where there is text, and the pictures and charts as images, in their place.

Which models read files

Every model reads the text of a file. The images that come out of a file (photos, charts, scanned pages) reach the model as images when it takes images: it has image in architecture.input_modalities (Vision). A model that doesn't take images gets the text, with [image not included: this model doesn't read images] where each image was, so it knows something is missing. A file with no text at all, such as a scanned PDF, returns 400 invalid_request with that model.

Send a file

Put the file in the message as a base64 data URL (data:application/pdf;base64,...), next to the text that asks about it.

# base64 -w0 on Linux; on macOS, base64 -i report.pdf
PDF=$(base64 -w0 report.pdf)

curl https://api.libremodel.ai/v1/chat/completions \
  -H "Authorization: Bearer $LIBREMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF
{
  "model": "deepseek-v4.1-flash-1017",
  "messages": [{"role": "user", "content": [
    {"type": "text", "text": "Summarize this report in five bullet points."},
    {"type": "file", "file": {"filename": "report.pdf", "file_data": "data:application/pdf;base64,$PDF"}}
  ]}]
}
EOF

Each format has its own part for it:

FormatFile part
Chat Completions{"type": "file", "file": {"filename": "report.pdf", "file_data": "data:application/pdf;base64,..."}}
Responses{"type": "input_file", "filename": "report.pdf", "file_data": "data:application/pdf;base64,..."}
Anthropic Messages{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "..."}}, or a text source for plain text
  • A file also works inside a tool result: in a tool_result in Messages, or a function_call_output in Responses.
  • The type comes from the file's content, not from its name or its media_type.
  • The model sees each part labeled with the file and its place, such as [report.pdf, page 3], [deck.pptx, slide 2] or [sales.xlsx, sheet January].
  • There is no /v1/files: a file by file_id or by URL (file_url, a url source) returns 400 invalid_request. Send it in base64. Only images can go by URL (Vision).

Formats

FormatFilesWhat the model gets
TextMarkdown, TXT, CSV, TSV, JSON, JSONL, XML, YAML, TOML, HTML, logs and source code, in UTF-8The text as is
PDF.pdfThe text of each page. Embedded pictures and charts, as images in their place. A page with no text (a scan), as an image of the whole page
Word and Writer.docx, .odtParagraphs and tables (cells split by |), with their images in place. From Word, also headers and footers at the start of their section, and footnotes and endnotes at the end, numbered as in the document
PowerPoint and Impress.pptx, .odpThe text of each slide and its notes, with their images in place
Excel and Calc.xlsx, .odsEach sheet as CSV, with its name and the calculated value of each cell. Dates and times in ISO format, such as 2025-12-01 or 2025-12-01 14:30
  • Hidden text is left out: invisible or off-page text in a PDF, text marked as hidden in Word and Writer, and hidden sheets and slides. A scanned page with a hidden text layer still goes as an image, so the model reads it.
  • An image that repeats (the same logo on every page) goes once, tiny icons are skipped, and each image is scaled to 1,600 px on its longest side at most.
  • EMF, WMF, SVG and TIFF images inside a document go as a mark, such as [image not included: EMF chart], followed by the text they contain.
  • Comments, and charts built in Word, PowerPoint or Excel, are left out. For a chart's numbers, send the spreadsheet that holds them.

These return 400 invalid_request, and the message says why:

FileWhat to do
Old Office formats (.doc, .xls, .ppt) and RTFSave it in the newer format: .docx, .xlsx or .pptx
A PDF or Office file with a passwordRemove the password and send it again
Any other formatConvert it to one of the formats above. The message lists them

Limits

  • A request can carry up to 10 files. Past that, it returns 400 invalid_request.
  • Each file can be up to 32 MB, with up to 150 pages or slides and 50 images. Past that, it returns 400 invalid_request.
  • A request can carry up to 50 images, counting the ones you send and the ones that come out of files. Past that, it returns 400 invalid_request: send fewer images, or split the file.
  • A whole request, files included, can be up to 40 MB. Base64 makes a file about a third bigger, and that counts. Past that, it returns 413 request_too_large.

Cost

  • The text of a file is billed as input tokens, at the model's input price.
  • Each image that comes out of a file, pages sent as images included, is billed at the model's price per image (pricing.image in GET /v1/models), on top of its tokens, like any image.
  • A file sent again with the history is billed again. What each request cost comes in usage.cost.

Same file, same input

The same file always becomes exactly the same input for the model, every time you send it. An agent that sends the file again on every turn gets prompt cache hits on it, as long as the file and what comes before it don't change.

Long files

A file is read whole. If what it becomes doesn't fit in the model's context, the request returns 400 context_length_exceeded: the file is never cut short.

To work with a long file, send it in parts: a range of pages, one sheet, one section. Coding agents such as Claude Code and Codex already read long files in parts with their own tools, and send the model only the part it asks for.