Create file source
POST/v2/agents/{agentId}/sources/files
Upload a PDF, DOCX, TXT or CSV file to an agent as a source with multipart form data and queue it for training.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
Uploads a file and creates a file source from it. Training starts at once. Call it to add manuals, policies or exports from a script, or to sync a folder of documents with an agent.
Unlike the other source calls, this one is not JSON. Send the file as multipart/form-data.
Request
POST /v2/agents/{agentId}/sources/files
Path parameters:
| Name | Type | Required | Description |
|---|---|---|---|
agentId |
string | Yes | The ID of the agent, starting with agt_. |
Form fields:
| Name | Type | Required | Description |
|---|---|---|---|
file |
file | Yes | A PDF, DOCX, TXT or CSV file. |
title |
string | No | The name of the source. Defaults to the file name. |
Set the Content-Type header to multipart/form-data with a boundary, which curl and fetch do for you when you pass a form. If you set the header by hand, the boundary is missing and the request fails. For websites, text and Q&A pairs use Create source.
Example request
curl -X POST https://api.askocto.co/v2/agents/agt_8f3k2m/sources/files \
-H "Authorization: Bearer $OCTO_API_KEY" \
-F "file=@./returns-policy.pdf" \
-F "title=Returns policy"
import { openAsBlob } from "node:fs"
const form = new FormData()
form.append("file", await openAsBlob("./returns-policy.pdf"), "returns-policy.pdf")
form.append("title", "Returns policy")
const response = await fetch("https://api.askocto.co/v2/agents/agt_8f3k2m/sources/files", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.OCTO_API_KEY}` },
body: form,
})
const source = await response.json()
console.log(source.id, source.status)
Example response
A successful call returns 201 Created. The upload is complete when you get this response, and the content is read during training.
{
"id": "src_4n7c2w",
"type": "file",
"title": "Returns policy",
"status": "queued",
"characters": 0,
"failureReason": null,
"createdAt": "2026-03-19T15:02:00Z"
}
Response fields
The response is a source object. Its fields are listed under Get source. characters is 0 until training reads the file. A scanned PDF with no text layer ends as failed, and failureReason says so. Follow the status with Get source.
Errors
| Status | Code | When |
|---|---|---|
| 400 | invalid_request |
The file part is missing or empty, the file type is not supported, or the request is not multipart/form-data. |
| 401 | unauthorized |
The API key is missing, malformed or deleted. |
| 404 | not_found |
No agent has this ID in your workspace. |
| 429 | rate_limited |
Too many requests. Wait for the number of seconds in the Retry-After header. |