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

# Replace file

> Upload a new version of a ready file. Assistants keep using the old one until the new one is ready, then switch at once.

Uploads a new version of a ready file in one `multipart/form-data` request. The new file is a file of its own, with `replaces_id` naming the old one. Assistants keep searching the old file until the new one is `ready`; then the two swap at once and the old file is deleted. If the new one fails, the old one stays.

The new file may have another name and type. It counts as the same file toward your plan's files per knowledge base.

## Path parameters

**fileId** `string` *required*

UUID of the ready file to replace.

## Body

**files** `file` *required*

The new version: exactly one file, up to 25 MB.

## Request

```bash cURL theme={null}
curl -X POST "https://api.verbeo.ai/v1/knowledge-base/files/c4ff0c9c-4b3b-4a94-a86e-3d3b64088ae0/replace" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "files=@prices-2027.pdf"
```

```python Python theme={null}
import os, requests

file_id = "c4ff0c9c-4b3b-4a94-a86e-3d3b64088ae0"
res = requests.post(
    f"https://api.verbeo.ai/v1/knowledge-base/files/{file_id}/replace",
    headers={"Authorization": f"Bearer {os.environ['VERBEO_API_KEY']}"},
    files=[("files", open("prices-2027.pdf", "rb"))],
)
new_file = res.json()["data"]
```

## Response

`201 Created` with the new [file object](https://docs.verbeo.ai/api-reference/knowledge-bases/overview.md#the-file-object), `processing`, its `replaces_id` the old file's id. Read it until it is `ready`: the old file is then gone.

```json theme={null}
{
  "success": true,
  "data": {
    "id": "e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b",
    "store_id": "5df09066-0842-4c92-8ef0-6cf2ff6d7455",
    "display_name": "prices-2027.pdf",
    "status": "processing",
    "replaces_id": "c4ff0c9c-4b3b-4a94-a86e-3d3b64088ae0",
    "…": "every field of the file object"
  }
}
```

## Errors

| Code | Status | When |
| - | - | - |
| `KB_FILE_NOT_READY` | 409 | `prices-2027.pdf: Only a ready file can be replaced.` |
| `KB_FILE_BEING_REPLACED` | 409 | `prices-2027.pdf: This file is already being replaced. Delete or retry its replacement first.` |
| `KB_DUPLICATE_FILE` | 409 | The new version's bytes are already a file of this knowledge base, the one it replaces included. |
| `KB_*` | 409 | Another of your [plan's limits](https://docs.verbeo.ai/api-reference/knowledge-bases/overview.md#errors). |
| `VALIDATION_FAILED` | 422 | `files: must be one file`, or one of [the upload's](https://docs.verbeo.ai/api-reference/knowledge-bases/upload-files.md#errors) form rules. |
| `PAYLOAD_TOO_LARGE` | 413 | A file over 25 MB. |
| `NOT_FOUND` | 404 | No such file: `File not found`. |


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