# 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.

A 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:

**cURL**

```bash
# 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" } }
      ]
    }
  ]
}
JSON
```

**Python**

```python
import 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)
```

**TypeScript**

```typescript
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);
```

- `type` (string) — `file`.
- `file.filename` (string) — The file's name. Some providers show it to the model as the document's title.
- `file.file_data` (string) — The 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 as `image_url` parts, 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 (`413` beyond it). Large documents also count against the model's context window.
- **Models:** the model must list `file` (for PDFs) or `image` (for images) in its `input_modalities` in [`GET /models`](https://www.getlykia.com/en/docs/api-reference/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](https://www.getlykia.com/en/docs/guides/credits-and-billing#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](https://www.getlykia.com/en/docs/guides/privacy-and-logging).

## Next steps

- [Reasoning and prompt caching](https://www.getlykia.com/en/docs/guides/reasoning-and-caching): cache a long document you send with every request.
- [Compatibility](https://www.getlykia.com/en/docs/guides/compatibility): which provider family supports what.
- [`POST /chat/completions`](https://www.getlykia.com/en/docs/api-reference/chat-completions): every request field.
