Associate file with knowledge base
Associate an uploaded file with a knowledge base and trigger processing.
This is Step 2 of the file upload flow (after uploading to the presigned URL).
What this endpoint does:
- Creates a database record for the file
- Triggers content extraction (text, images)
- Triggers chunking and embedding generation
- For PDFs, generates page images for preview
The orgId is automatically extracted from your JWT token - you don’t need to include it in the request body.
Complete upload flow:
1. POST /upload/presigned → Get signed URL + file metadata
2. PUT to signed URL → Upload file to storage
3. POST /kb/files → Associate with KB & trigger processing
Authorizations
JWT token from Clerk authentication.
Must be from a user with org:admin role.
Body
The ID of the knowledge base to associate the file with
123
The file UUID returned from the presigned upload endpoint
"550e8400-e29b-41d4-a716-446655440000"
Original filename
"quarterly-report.pdf"
The storage key returned from the presigned upload endpoint
"org_xxx/uploads/550e8400-e29b-41d4-a716-446655440000/quarterly-report.pdf"
The content key returned from the presigned upload endpoint
"org_xxx/contents/550e8400-e29b-41d4-a716-446655440000.md"
MIME type of the file
"application/pdf"
File size in bytes (optional but recommended)
1048576
Optional metadata to attach to the file record. For inbound email files, this includes emailId, emailSubject, emailFrom, emailDate, and emailMessageId to link files from the same email.
{
"source": "inbound-email",
"emailId": "7ef4b7eb-4345-4f3f-ab95-ab76f7bd9634",
"emailSubject": "Updated contract",
"emailFrom": "user@example.com"
}