---
title: Sending files
description: Send documents inline as base64, or upload once and reference them by file_id on Chat Completions or Responses.
---

> Status: Early access

Send a small, one-off file inline with Chat Completions. Upload first when you
use Responses, reuse a file, or need the larger upload limit.

## Choose a method

|               | Inline base64                                                                 | Uploaded file                          |
| ------------- | ----------------------------------------------------------------------------- | -------------------------------------- |
| Available on  | Chat Completions                                                              | Chat Completions and Responses         |
| Request field | `file_data`                                                                   | `file_id` returned by `POST /v1/files` |
| Best for      | One-off files                                                                 | Reuse, Responses, and larger files     |
| Size          | 25 MiB for the whole request, base64 included (about 18 MiB of file bytes)    | 50 MiB per file; 10 MiB per image      |
| Retention     | Follows the request policy; inline PDF and Word persist unless `store: false` | Kept until you delete the file         |

See [Data retention](/using-the-api/data-retention/) for storage details.

### Format support

| Format                                         | Inline Chat | Uploaded Chat | Uploaded Responses |
| ---------------------------------------------- | ----------- | ------------- | ------------------ |
| PDF, Word, text, Markdown, CSV, TSV, JSON, XML | Yes         | Yes           | Yes                |
| PNG, JPEG, WebP                                | Yes         | Yes           | No                 |
| JSONL                                          | No          | Yes           | Yes                |

- **Responses images:** an uploaded image returns `400`
  `unsupported_file_type`; use Chat Completions.
- **Word:** keep a `.doc` or `.docx` filename so SubQ can detect the format.
- **Uploaded non-text files:** wait for `status: "processed"` before using the
  ID.

## Inline base64

Inline `file_data` is Chat Completions only. Pass raw base64 with no line
wrapping or `data:` prefix.

```bash title="cURL"
curl --request POST \
  --url https://api.subq.ai/v1/chat/completions \
  --header "Authorization: Bearer $SUBQ_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "subq-savant-1.4",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Summarize this report."
        },
        {
          "type": "file",
          "filename": "report.pdf",
          "file_data": "JVBERi0xLjcKJdDUxdgK..."
        }
      ]
    }
  ]
}
'
```

```ts title="TypeScript"
import { readFileSync } from "node:fs";
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.SUBQ_API_KEY,
  baseURL: "https://api.subq.ai/v1",
});

const report = readFileSync("./report.pdf").toString("base64");

const completion = await client.chat.completions.create({
  model: "subq-savant-1.4",
  messages: [
    {
      role: "user",
      content: [
        { type: "text", text: "Summarize this report." },
        {
          type: "file",
          filename: "report.pdf",
          file_data: report,
        },
      ],
    },
  ],
});

console.log(completion.choices[0].message.content);
```

```py title="Python"
import base64
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SUBQ_API_KEY"],
    base_url="https://api.subq.ai/v1",
)

with open("./report.pdf", "rb") as handle:
    report = base64.b64encode(handle.read()).decode("ascii")

completion = client.chat.completions.create(
    model="subq-savant-1.4",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Summarize this report."},
                {
                    "type": "file",
                    "filename": "report.pdf",
                    "file_data": report,
                },
            ],
        }
    ],
)

print(completion.choices[0].message.content)
```

Use the flat file part shown above for every supported inline format:

```json
{ "type": "file", "filename": "report.pdf", "file_data": "<base64>" }
```

For OpenAI compatibility, PDFs also accept a nested `file` object. Nested file
parts are PDF-only and accept raw base64 or a
`data:application/pdf;base64,` URI.

```json
{ "type": "file", "file": { "filename": "report.pdf", "file_data": "<base64>" } }
```

| Field       | Required    | Description                                                    |
| ----------- | ----------- | -------------------------------------------------------------- |
| `filename`  | Recommended | Required for Word; use a `.doc` or `.docx` extension.          |
| `mime_type` | No          | If omitted, SubQ detects the type from the bytes and filename. |
| `file_data` | Yes         | Base64-encoded file bytes.                                     |

Use exactly one source per file part: `file_data` or `file_id`.

## Uploaded files

Upload through the [Files API](/endpoints/files-api/) with purpose
`assistants`, then use the returned ID. The example IDs below represent values
returned by `POST /v1/files`.

```bash title="cURL"
curl --request POST \
  --url https://api.subq.ai/v1/responses \
  --header "Authorization: Bearer $SUBQ_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "subq-savant-1.4",
  "input": [
    {
      "type": "input_file",
      "file_id": "file_abc123"
    },
    {
      "type": "input_file",
      "file_id": "file_def456"
    },
    {
      "type": "input_text",
      "text": "Summarize these documents."
    }
  ]
}
'
```

```ts title="TypeScript"
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.SUBQ_API_KEY,
  baseURL: "https://api.subq.ai/v1",
});

const fileId1 = process.env.SUBQ_FILE_ID ?? "file_abc123";
const fileId2 = process.env.SUBQ_FILE_ID_2 ?? "file_def456";

const response = await client.responses.create({
  model: "subq-savant-1.4",
  input: [
    { type: "input_file", file_id: fileId1 },
    { type: "input_file", file_id: fileId2 },
    { type: "input_text", text: "Summarize these documents." },
  ],
});

const message = response.output.find((item) => item.type === "message");
const text = message?.content
  ?.filter((part) => part.type === "output_text")
  .map((part) => part.text)
  .join("");

console.log(text);
```

```py title="Python"
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SUBQ_API_KEY"],
    base_url="https://api.subq.ai/v1",
)

file_id_1 = os.getenv("SUBQ_FILE_ID", "file_abc123")
file_id_2 = os.getenv("SUBQ_FILE_ID_2", "file_def456")

response = client.responses.create(
    model="subq-savant-1.4",
    input=[
        {"type": "input_file", "file_id": file_id_1},
        {"type": "input_file", "file_id": file_id_2},
        {"type": "input_text", "text": "Summarize these documents."},
    ],
)

message = next((item for item in response.output if item.type == "message"), None)
text = "".join(
    part.text for part in (message.content if message else []) if part.type == "output_text"
)

print(text)
```

```bash title="cURL"
curl --request POST \
  --url https://api.subq.ai/v1/chat/completions \
  --header "Authorization: Bearer $SUBQ_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "subq-savant-1.4",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Summarize these documents."
        },
        {
          "type": "file",
          "file_id": "file_abc123"
        },
        {
          "type": "file",
          "file_id": "file_def456"
        }
      ]
    }
  ]
}
'
```

```ts title="TypeScript"
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.SUBQ_API_KEY,
  baseURL: "https://api.subq.ai/v1",
});

const fileId1 = process.env.SUBQ_FILE_ID ?? "file_abc123";
const fileId2 = process.env.SUBQ_FILE_ID_2 ?? "file_def456";

const completion = await client.chat.completions.create({
  model: "subq-savant-1.4",
  messages: [
    {
      role: "user",
      content: [
        { type: "text", text: "Summarize these documents." },
        { type: "file", file_id: fileId1 },
        { type: "file", file_id: fileId2 },
      ],
    },
  ],
});

console.log(completion.choices[0].message.content);
```

```py title="Python"
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SUBQ_API_KEY"],
    base_url="https://api.subq.ai/v1",
)

file_id_1 = os.getenv("SUBQ_FILE_ID", "file_abc123")
file_id_2 = os.getenv("SUBQ_FILE_ID_2", "file_def456")

completion = client.chat.completions.create(
    model="subq-savant-1.4",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Summarize these documents."},
                {"type": "file", "file_id": file_id_1},
                {"type": "file", "file_id": file_id_2},
            ],
        }
    ],
)

print(completion.choices[0].message.content)
```

Chat Completions accepts the flat `file_id` part shown in the Chat tab for
every supported format. PDFs also accept the nested OpenAI shape:
`{ "type": "file", "file": { "file_id": "file_abc123" } }`. Responses uses
`{ "type": "input_file", "file_id": "file_abc123" }`.

## Common errors

| Error                       | Cause                                                               |
| --------------------------- | ------------------------------------------------------------------- |
| `400 validation_error`      | Malformed part, more than one source, or invalid declared MIME type |
| `400 unsupported_file_type` | Unsupported bytes, or an image sent to Responses                    |
| `409 file_not_ready`        | Uploaded file has not reached `processed`                           |
| `413`                       | File or inline request exceeds its size limit                       |

See the [Files API](/endpoints/files-api/) for upload mechanics and
[Structured outputs](/using-the-api/structured-outputs/) to extract fields
instead of a free-text summary.
