Manage documents within knowledge bases programmatically. Upload, update, retrieve metadata, and delete documents.
Required scope: knowledge-management
Prerequisite: Knowledge bases are created in the platform dashboard. See Knowledge Bases. This API manages documents within existing knowledge bases.
Document Upload Flow
Uploading a document requires three steps:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ 1. Request │ │ 2. Upload │ │ 3. Complete │ │ 4. Poll │
│ Upload Link │────▶│ File to S3 │────▶│ Upload │────▶│ Status │
└─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │ │
▼ ▼ ▼ ▼
POST /upload-link PUT to uploadUrl POST /upload-complete GET /documents
Returns: uploadUrl, Include headers Returns: status Check status
uploadId, s3Key from response "pending" until "ready"
Request upload link — Call /knowledge/documents/upload-link to get a pre-signed S3 URL
Upload file — PUT the file bytes to the returned uploadUrl with requiredHeaders
Complete upload — Call /knowledge/documents/upload-complete with the uploadId
Poll status — Query /knowledge/documents until status becomes ready or failed
Document Status Values
Status
Description
pending
Document uploaded, processing not yet started
processing
Document is being processed (text extraction, chunking, embedding)
ready
Document processed successfully and available for retrieval
failed
Processing failed; check error details
Document Identifiers
Documents can be referenced using two identifiers:
Identifier
Description
s3Key
System-generated path in format agents/<agentId>/<env>/<kbId>/<filename>. Returned by upload endpoints.
customDocumentId
Optional user-defined identifier. Use this to map documents to your external system IDs (e.g., CRM record ID, ticket ID). When provided during upload, you can use it instead of s3Key for update and delete operations.
Custom Metadata
The metadata field accepts arbitrary key-value pairs that you define. This is your custom metadata for filtering and organizing documents—not a predefined schema.
GET /knowledge/documents?agentId=your-agent-id&environment=production&knowledgeBaseId=kb-abc123&s3Key=agents/agent-id/production/kb-abc123/refund-policy.pdf