Uploading knowledge files
Upload files to the chat agent's uploads area so you can promote them into your knowledge base.
Stage files for the Lightfield chat agent using the file upload lifecycle.
What the upload creates
Section titled “What the upload creates”A knowledge_user or knowledge_workspace upload stages a file for the agent. Completing the upload does not add it to Knowledge, and no API call promotes it. After completion, follow Files uploaded through the API to choose its audience and ask the agent to promote it.
Before you begin
Section titled “Before you begin”You will need:
- A valid API key whose caller resolves to a specific user
- The
files:createscope to create and complete uploads - The
files:readscope if you want to verify the uploaded file or fetch a signed download URL - For
knowledge_workspace: the caller must be an org admin
Choose a purpose
Section titled “Choose a purpose”Choose the purpose that matches who the file is for.
| Purpose | Where the file lands | Who can upload |
|---|---|---|
knowledge_user | The authenticated user’s personal uploads area | Any caller with a resolvable user identity |
knowledge_workspace | The organization’s shared uploads area | Org admins only |
Non-admin callers that request knowledge_workspace are rejected with 403.
Upload lifecycle
Section titled “Upload lifecycle”Knowledge uploads use the three-step upload lifecycle:
POST /v1/filesPUT <uploadUrl>POST /v1/files/{id}/complete
For knowledge uploads, set the purpose, keep the timestamped filename returned in the response, and send the if-none-match: * header from uploadHeaders. See Collision handling in the file upload guide for details.
Step 1: Create the upload session
Section titled “Step 1: Create the upload session”curl https://api.lightfield.app/v1/files \ -X POST \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01" \ -H "Content-Type: application/json" \ -d '{ "purpose": "knowledge_user", "filename": "playbook.md", "mimeType": "text/markdown", "sizeBytes": 4821 }'Replace sizeBytes with the byte count of your actual playbook.md file. This response excerpt shows the fields needed for the upload:
{ "id": "fil_abc123", "filename": "playbook_1713045600000.md", "status": "PENDING", "uploadUrl": "https://...", "uploadHeaders": { "content-type": "text/markdown", "if-none-match": "*" }, "expiresAt": "2026-04-08T12:00:00.000Z"}The server adds a timestamp to the stored filename. Use the returned filename when referring to the file in chat.
Step 2: Upload the raw bytes
Section titled “Step 2: Upload the raw bytes”Follow Upload the raw bytes using every header in uploadHeaders, including if-none-match: *. Do not replace those headers with your Lightfield API credentials.
Step 3: Complete the upload
Section titled “Step 3: Complete the upload”Follow Complete the upload. Once the file is COMPLETED, the agent can read it from the uploads area. Ask the agent to promote the file before using it as Knowledge.
Errors
Section titled “Errors”| Status | Code | Meaning |
|---|---|---|
400 | purpose_requires_user | The API key has no resolvable user identity. Use a key whose user or creator is still active in the workspace. |
403 | — | knowledge_workspace was requested by a non-admin caller. |
412 | (S3 response) | The presigned PUT’s if-none-match: * precondition failed. Create a new upload session to get a fresh timestamped key. |
See Errors for general error handling.
Next steps
Section titled “Next steps”- Uploading files: reference guide for the underlying file upload lifecycle.
- API keys: authenticate requests and handle invalid keys.
- API Reference: full endpoint reference for files and other resources.
Related documentation
Section titled “Related documentation”- In the app: Workspace and Personal knowledge explains the audience, editing permissions and promotion workflow.
- Endpoint contracts: create a file upload and complete it.