> ## Documentation Index
> Fetch the complete documentation index at: https://docs.personal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Ingest File

> Add a document to an assistant's knowledge, or read it once

## Overview

Parses a file and either saves it to knowledge (`deep`, the default) so the assistant can recall it later, or returns its text without saving anything (`quick`).

Supported formats: txt, md, html, pdf, docx, pptx, eml, csv and xlsx. Send the file inline as base64 (up to about 24 MB), or [upload it first](https://docs.personal.ai/composer_apis/file-upload.md) and pass its `uri`.

> [!NOTE]
>
> Changes data, so it needs a key that isn't read-only.

Operation name: `ingest.file`.

## Authorization

**x-api-key** `string` *required*

Your Composer API key

## Headers

**Content-Type** `string` *required*

Must be set to application/json

## Body

**filename** `string` *required*

The original file name. Used to detect the format.

```json Example theme={null}
"filename": "menu.pdf"
```

**uri** `string`

The `object_uri` from [Upload a File](https://docs.personal.ai/composer_apis/file-upload.md). Send this or `content_b64`.

```json Example theme={null}
"uri": "<object_uri from Upload a File>"
```

**content\_b64** `string`

The file, base64-encoded. Send this or `uri`.

**mode** `string`

`deep` (default) saves it to knowledge. `quick` returns the text and saves nothing.

```json Example theme={null}
"mode": "deep"
```

**agent** `string`

The assistant this file is for (deep mode).

```json Example theme={null}
"agent": "my-assistant"
```

**collection** `string`

The knowledge collection to save into (deep mode). Default `semantic`.

**title** `string`

A title for the document.

```json Example theme={null}
"title": "Autumn menu"
```

**excerpt\_chars** `integer`

Deep mode: also return up to this many characters of the text as `excerpt`, to pass straight to Chat as an attachment.

```json Example theme={null}
"excerpt_chars": 4000
```

**max\_chars** `integer`

Quick mode: the most characters of text to return. Default 48,000.

**subject** `string`

Deep mode: the id of the person the file is about. Defaults to the caller.

**metadata** `object`

Extra details stored with the document (deep mode).

```json Example Request theme={null}
{
  "filename": "menu.pdf",
  "uri": "<object_uri from Upload a File>",
  "agent": "my-assistant",
  "title": "Autumn menu",
  "mode": "deep",
  "excerpt_chars": 4000
}
```

***

## Response

**documents** `array`

Deep mode: the documents saved, each with `document_id` and `kind`.

**chars** `integer`

How many characters were parsed.

**excerpt** `string`

Deep mode with `excerpt_chars`: the start of the text.

**excerpt\_truncated** `boolean`

True when the excerpt is shorter than the full text.

**content** `string`

Quick mode: the extracted text.

**truncated** `boolean`

Quick mode: true when `content` was cut to `max_chars`.

```json Example Success Response theme={null}
{
  "documents": [
    {
      "document_id": "c41d2e7a-6b5f-4a3e-8d9c-0b1a2f3e4d5c",
      "kind": "prose",
      "chunks": 6
    }
  ],
  "kind": "prose",
  "parse_ms": 412,
  "chars": 18240,
  "excerpt": "Autumn menu. Pumpkin soup 6.50 ...",
  "excerpt_truncated": true
}
```

***

## Example cURL

```bash cURL theme={null}
curl --request POST 'https://composer.personal.ai/lab/api/v1/op/ingest.file' \
--header 'Content-Type: application/json' \
--header 'x-api-key: <your-api-key>' \
--data '{"filename": "menu.pdf", "uri": "<object_uri from Upload a File>", "agent": "my-assistant", "title": "Autumn menu", "mode": "deep", "excerpt_chars": 4000}'
```

***

## Error Codes

| Code | Description |
| - | - |
| 400 | The body doesn't match the fields above, or the operation failed. The response body says why. |
| 401 | Missing or invalid API key |
| 403 | This key isn't allowed to call this operation (for example, a read-only key) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.