File inputs
Send PDFs and images inside a chat request as file parts. Which models read them, the size and count limits, and the errors to expect.
MarkdownA model that reads documents can answer questions about a PDF you send with the request: an invoice, a contract, a report. Lykia accepts the file in OpenAI's file-part format and converts it to each provider's own document format.
Send a file
Add a file part to a user message's content array, with the file as a base64 data: URI:
# Send a PDF from disk as a data: URI (base64 without line breaks).
FILE_DATA="data:application/pdf;base64,$(base64 < report.pdf | tr -d '\n')"
curl https://api.getlykia.com/v1/chat/completions \
-H "Authorization: Bearer $LYKIA_API_KEY" \
-H "Content-Type: application/json" \
-d @- <<JSON
{
"model": "anthropic/claude-sonnet-4.5",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "List the totals in this report." },
{ "type": "file", "file": { "filename": "report.pdf", "file_data": "$FILE_DATA" } }
]
}
]
}
JSONimport base64
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.getlykia.com/v1", api_key=os.environ["LYKIA_API_KEY"])
with open("report.pdf", "rb") as f:
file_data = "data:application/pdf;base64," + base64.b64encode(f.read()).decode()
completion = client.chat.completions.create(
model="anthropic/claude-sonnet-4.5",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "List the totals in this report."},
{"type": "file", "file": {"filename": "report.pdf", "file_data": file_data}},
],
}
],
)
print(completion.choices[0].message.content)import { readFile } from "node:fs/promises";
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.getlykia.com/v1", apiKey: process.env.LYKIA_API_KEY });
const fileData = `data:application/pdf;base64,${(await readFile("report.pdf")).toString("base64")}`;
const completion = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4.5",
messages: [
{
role: "user",
content: [
{ type: "text", text: "List the totals in this report." },
{ type: "file", file: { filename: "report.pdf", file_data: fileData } },
],
},
],
});
console.log(completion.choices[0].message.content);typestringfile.
file.filenamestringThe file's name. Some providers show it to the model as the document's title.
file.file_datastringThe file as data:<media type>;base64,<data>, without line breaks.
What is accepted
- Types: PDF (
application/pdf) and images (image/png,image/jpeg,image/gif,image/webp). Images can also be sent asimage_urlparts, as before. - Count: at most eight files per request (
400,too_many_files). - Size: the whole request body, files included, must fit Lykia's body size limit (
413beyond it). Large documents also count against the model's context window. - Models: the model must list
file(for PDFs) orimage(for images) in itsinput_modalitiesinGET /models. When the request has fallback models or several providers, candidates that cannot read the file are skipped.
A file of another type, or a request where no candidate can read the file, gets 400 with the code unsupported_input.
| Provider family | How the file is sent |
|---|---|
| Anthropic | PDF as a document block (the file name becomes its title), images as image blocks |
| Google AI Studio | Inline data with the file's media type |
| OpenAI-compatible | The file part as it is, for providers whose models read files |
Cost and privacy
File content is billed as input tokens, counted by the provider; a PDF's pages usually cost more tokens than their text alone. Before sending, Lykia reserves the request's maximum cost, estimating the file's size in tokens from its bytes, so a large file needs enough available balance (see Reservations).
Files are passed to the provider with the request and not stored by Lykia. With prompt logging on, the request body, files included, is stored in the record up to the size cap; see Privacy and logging.
Next steps
- Reasoning and prompt caching: cache a long document you send with every request.
- Compatibility: which provider family supports what.
POST /chat/completions: every request field.