Skip to main content
POST
/
knowledge
/
{knowledge_base_id}
/
upload
Python
import os
import requests

# Upload a file directly to a knowledge base
knowledge_base_id = "your-knowledge-base-id"
api_key = os.getenv("OPPER_API_KEY")

# Simple upload with just the file
with open("document.pdf", "rb") as f:
    response = requests.post(
        f"https://api.opper.ai/v2/knowledge/{knowledge_base_id}/upload",
        headers={"Authorization": f"Bearer {api_key}"},
        files={"file": ("document.pdf", f, "application/pdf")},
    )

print(response.json())
# {"id": "...", "key": "...", "original_filename": "document.pdf", "document_id": 123, "metadata": {}}

# Upload with metadata and custom chunk settings
with open("contract.pdf", "rb") as f:
    response = requests.post(
        f"https://api.opper.ai/v2/knowledge/{knowledge_base_id}/upload",
        headers={"Authorization": f"Bearer {api_key}"},
        files={"file": ("contract.pdf", f, "application/pdf")},
        data={
            "text_processing.chunk_size": 1000,
            "text_processing.chunk_overlap": 100,
            "metadata": '{"category": "legal", "client": "acme"}',
        },
    )

print(response.json())
{
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "key": "<string>",
  "original_filename": "<string>",
  "document_id": 123,
  "metadata": {}
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

knowledge_base_id
string<uuid>
required

The id of the knowledge base to upload the file to

Body

multipart/form-data
file
file
required

The file to upload

chunk_size
integer
default:2000

The chunk size to use for the document (number of characters)

chunk_overlap
integer
default:200

The chunk overlap to use for the document (number of characters)

metadata
string | null

Optional JSON object metadata to attach to the file

Example:

"{\"category\": \"legal\", \"client\": \"acme\"}"

Response

Successful Response

id
string<uuid>
required
key
string
required
original_filename
string
required
document_id
integer
required
metadata
Metadata · object