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

# Files

> List, inspect, download, resume, and delete files an agent holds in v2, and understand citations and attached images.

A **file** is any document or image stored on an agent:

* A **document** uploaded with multipart [POST`/v2/agents/{agent_id}/threads/{thread_id}/observe`](https://www.sapientpriors.com/docs/api-reference/v2/threads/learn-messages-or-files) (PDF, Office, OpenDocument, Markdown, CSV, plain text, code, or an image read as a one-page document).
* A **picture cut from a document** (carries `parent_file_id` pointing to its parent document).
* An **image** sent in `files` on `observe-and-respond` or `respond` for the agent to inspect while answering.

Files belong to the agent. Once a document reaches `committed`, every thread of the agent can retrieve memories from it and cite it.

## List, inspect, and download files

| Call | What it does |
| - | - |
| [GET`/v2/agents/{agent_id}/files`](https://www.sapientpriors.com/docs/api-reference/v2/files/list-files) | Lists files on the agent. Optional query params: `thread_id`, `type`, `limit`, `cursor`. Returns `items` and `next_cursor`. |
| [GET`/v2/agents/{agent_id}/files/{file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/files/get-file) | Returns one `File` object with size, media type, `memory_state`, upload progress, and download `href`. |
| [GET`/v2/agents/{agent_id}/files/{file_id}/download`](https://www.sapientpriors.com/docs/api-reference/v2/files/download-file) | Downloads the original file bytes with your same API key headers. |

```bash theme={null}
curl "https://app.sapientpriors.com/api/v2/agents/agent_01J.../files?limit=20" \
  -H "Authorization: Bearer $SP_API_KEY"
```

```json theme={null}
{
  "items": [
    {
      "file_id": "src_01J...",
      "thread_id": "thread_01J...",
      "filename": "employee-handbook.pdf",
      "media_type": "application/pdf",
      "size_bytes": 482910,
      "created_at": "2026-09-17T10:15:00Z",
      "memory_state": "learned",
      "upload_state": null,
      "turns_done": null,
      "turns_total": null,
      "stop_reason": null,
      "figures_unread": null,
      "figures_retry": null,
      "can_finish": null,
      "finish_blocked": null,
      "parent_file_id": null,
      "href": "/api/v2/agents/agent_01J.../files/src_01J.../download"
    }
  ],
  "next_cursor": null
}
```

### Understanding upload status fields

When a document finished cleanly, `memory_state` is `learned` and the unfinished fields are `null`. When something is still running or stopped partway, `File` reports:

| Field | Meaning |
| - | - |
| `memory_state` | `learned` when the agent has learned from the file; `available` when stored but not yet learned. |
| `upload_state` | `learning` (running), `resuming` (continuing automatically after a restart), `partial` (stopped partway), or `failed`. |
| `stop_reason` | `cancelled`, `learning_stopped` (resuming usually finishes it), or `unreadable` (try another export or format). |
| `turns_done`, `turns_total` | Pieces learned so far out of the total pieces. |
| `can_finish`, `finish_blocked` | Whether you can resume in its original thread (`finish_blocked` is `not_yours` or `conversation_gone` when `false`). |
| `figures_unread`, `figures_retry` | Count of document figures that could not be read; `figures_retry` is `available` when you can trigger a picture retry, or `running` while it runs. |
| `parent_file_id` | For a picture cut from a document, the parent document's `file_id`; `null` for standalone uploads. |

## Resume a stopped upload or unread pictures

If an upload stopped partway (`upload_state` is `partial` or `failed`), Priors keeps the stored file. Call [POST`/v2/agents/{agent_id}/files/{file_id}/resume`](https://www.sapientpriors.com/docs/api-reference/v2/files/resume-a-file) to finish learning only the remaining pieces without re-uploading or paying for pieces already learned:

```bash theme={null}
curl -X POST https://app.sapientpriors.com/api/v2/agents/agent_01J.../files/src_01J.../resume \
  -H "Authorization: Bearer $SP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Success:** status `202` with the updated `File` object and a `Location` header pointing to [GET`/v2/agents/{agent_id}/files/{file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/files/get-file). Poll [GET`.../files/{file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/files/get-file) until `upload_state` clears and `memory_state` is `learned`.

Optional request fields:

* `{"only": "pictures"}`: when a document's text finished learning but `figures_unread > 0` and `figures_retry` is `available`, re-reads only the unread figures (charging only for the newly read figure descriptions).
* `{"thread_id": "thread_01J..."}`: when you cannot open the original thread (`can_finish: false`), reads the full file again in the specified thread (charged in full).

**Errors:** `409 conflict` (nothing to resume or caller cannot open the upload thread), `409 duplicate_upload_in_progress` (already running), `413` (exceeds current document limits), `429 rate_limit_exceeded`.

## Delete a file and its memories

Call [DELETE`/v2/agents/{agent_id}/files/{file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/files/delete-file) as the agent's owner:

```bash theme={null}
curl -X DELETE https://app.sapientpriors.com/api/v2/agents/agent_01J.../files/src_01J... \
  -H "Authorization: Bearer $SP_API_KEY"
```

**Success:** status `202` with no body and a `Location` header pointing to [GET`/v2/agents/{agent_id}/memories?file_id={file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/memories/list-memories).

What happens immediately vs in the background:

1. **Before `202` returns:** Priors deletes the file bytes, any pictures cut from it, and its upload ledger rows. The file disappears from [GET`.../files`](https://www.sapientpriors.com/docs/api-reference/v2/files/list-files) and returns `404` on download.
2. **In the background:** a deletion job erases the file's pieces and deletes every memory made from any turn citing that file. Poll the `Location` URL until every turn listed there has `state: "forgotten"`.

### Errors on `DELETE /v2/agents/{agent_id}/files/{file_id}`

| Status | `code` | Cause | What to do |
| - | - | - | - |
| `404` | `agent_not_found` or `not_found` | Caller is not the agent's owner, or the file does not exist. | Call as the owner and verify `file_id`. |
| `409` | `conflict` | The file is still learning or queued in the upload queue, a picture retry is running, or `file_id` is a picture cut from a document (`parent_file_id` is set). | Wait until learning finishes before deleting; for an extracted picture, delete the parent document instead. |
| `409` | `agent_not_ready` | Agent is still initializing. | Wait until `status` is `ready`. |

> [!WARNING]
>
> Deleting a file forgets every turn that cites that file, but it does not touch unrelated chat turns where a user manually pasted or paraphrased text from the document. See [C2. Remove a document](https://www.sapientpriors.com/docs/how-to-use/remove-a-document.md) and [B4. A policy changes](https://www.sapientpriors.com/docs/how-to-use/policy-changes.md).

## Citations on answers

`observe-and-respond` and `respond` return a `citations` list naming the files the answer drew on:

```json theme={null}
{
  "file_id": "src_01J...",
  "label": "employee-handbook.pdf",
  "media_type": "application/pdf",
  "href": "/api/v2/agents/agent_01J.../files/src_01J.../download",
  "verified": false
}
```

* `href` downloads the file using your same bearer token.
* `verified` is `true` when the answering model looked directly at an attached image on that turn, and `false` when the answer drew on memories learned earlier from a document (the normal case for PDFs and handbooks).

## Attaching images to answering calls

In v2, you do not need a separate upload endpoint to show an image to the agent while answering. Pass images directly in the `files` array of `observe-and-respond` or `respond`:

* **New image:** `{"type": "image", "data": "<base64>", "media_type": "image/png", "filename": "error.png"}`
* **Existing image on this agent:** `{"type": "image", "file_id": "img_9f2c4e7a1b3d5f8091a2b3c4d5e6f708"}`

Up to 10 images per message, 10 MiB per image (PNG, JPEG, or WebP), up to 20 MiB total base64 image payload per v2 request. To teach an agent the text inside a screenshot or receipt as a permanent document, upload it with multipart `observe` instead.


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