Upload a Document
POST /v1/knowledge-bases/{knowledge_base_id}/documents
| Property | Value |
|---|---|
| Operation | upload_knowledge_document |
| Group | Knowledge bases |
| Scope | knowledge:write |
| Route class | control |
| Idempotency | Idempotency-Key accepted: a retry with the same key replays the first answer |
| Audit | Audited knowledge.document.upload (mutation) |
| Released in | 1.53.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Uploads a file to an upload Source as multipart/form-data (1.53.0). The api checks the parts (KnowledgeDocumentIssueCode), encrypts the file under the data key of the Organization, stores it under the knowledge/ prefix, creates or revises the Document pending and starts an Ingestion run with cause manual, all before it answers. A new external_ref answers 201 with the new Document; one the Source holds answers 200 with the Document, revised, or unchanged when the content is the same. From 1.54.0: a cell with no object storage refuses every upload with 422 capability_not_available.
Request
Set VOCAL_API to the base URL of your API and VOCAL_API_KEY to an API key with the knowledge:write scope (Authentication and keys). Replace each placeholder, such as agt_... or <name>, with your own value.
curl -X POST "$VOCAL_API/v1/knowledge-bases/kb_.../documents" \
-H "Authorization: Bearer $VOCAL_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-F "source_id=ksrc_..." \
-F "file=@<file>"import { readFile } from 'node:fs/promises';
const form = new FormData();
form.append('source_id', 'ksrc_...');
form.append(
'file',
new Blob([await readFile('<file>')]),
'<file>',
);
const response = await fetch(`${process.env.VOCAL_API}/v1/knowledge-bases/kb_.../documents`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VOCAL_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
},
body: form,
});
console.log(response.status, await response.text());import os
import uuid
import requests
response = requests.post(
f"{os.environ['VOCAL_API']}/v1/knowledge-bases/kb_.../documents",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
data={
"source_id": "ksrc_...",
},
files={
"file": ("<file>", open("<file>", "rb")),
},
)
print(response.status_code, response.text)Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
knowledge_base_id | path | KnowledgeBaseId | yes | The id of a Knowledge base: kb_ and the row's UUIDv7 in 26 Crockford base32 characters. Opaque and safe to log. |
idempotency-key | header | string | no | A client-chosen key, kept 24 hours per Organization, environment and route. A replay returns the stored response. |
Request body
Content type multipart/form-data, required: KnowledgeDocumentUploadRequest.
| Field | Type | Required | Description |
|---|---|---|---|
external_ref | string | no | The reference to revise; the file name when omitted. |
file | string (binary) | yes | The file part: its bytes, at most 25 MiB (a target), with a filename and a Content-Type among KnowledgeMediaType. |
source_id | KnowledgeSourceId | yes | |
tags | array of DocumentTag | no | Sent as repeated tags parts. |
title | string | no |
Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
200 | application/json | KnowledgeDocument | |
201 | application/json | KnowledgeDocument | |
400 | application/json | ErrorEnvelope | invalid_request |
401 | application/json | ErrorEnvelope | unauthenticated |
403 | application/json | ErrorEnvelope | forbidden, org_suspended |
404 | application/json | ErrorEnvelope | not_found |
409 | application/json | ErrorEnvelope | knowledge_base_archived, idempotency_in_progress, idempotency_key_reused |
422 | application/json | ErrorEnvelope | validation_failed, capability_not_available |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 200 answer
The shape is KnowledgeDocument.
| Field | Type | Required | Description |
|---|---|---|---|
byte_size | integer or null | yes | |
chunk_count | integer | yes | |
chunker_version | string or null | yes | |
classification | KnowledgeClassification or null | yes | |
created_at | Timestamp | yes | |
embedding_space | EmbeddingSpace or null | yes | |
entity_counts | array of KnowledgeEntityCount | yes | |
error_code | IngestionErrorCode or null | yes | Set when failed. |
external_ref | string or null | yes | The file name, URL or vendor reference the Source knows the Document by. The content class names: null unless the read names include=names, and null in the answer of a write (1.53.0, second part). |
id | KnowledgeDocumentId | yes | |
indexed_at | Timestamp or null | yes | |
knowledge_base_id | KnowledgeBaseId | yes | |
last_ingestion_run_id | IngestionRunId or null | yes | |
media_type | KnowledgeMediaType or null | yes | |
object | "knowledge_document" | yes | |
page_count | integer or null | yes | |
parser_version | string or null | yes | |
purged_at | Timestamp or null | yes | |
quarantine_expires_at | Timestamp or null | yes | When the parsed text held for review is deleted, 14 days after the quarantine (a target); null otherwise. |
quarantined_at | Timestamp or null | yes | |
review_status | KnowledgeReviewStatus | yes | |
revision | integer | yes | Counts writes to the Document; returned as the ETag and required in If-Match. Not the number of content revisions. |
source_id | KnowledgeSourceId | yes | |
status | KnowledgeDocumentStatus | yes | |
tags | array of DocumentTag | yes | |
title | string or null | yes | The title the upload or the parse stage gave, or null when it has none. The content class names: null unless the read names include=names, and null in the answer of a write (1.53.0, second part). |
updated_at | Timestamp | yes |