curl --request POST \
--url https://api.example.com/knowledge_bases/{knowledge_base_id}/documents \
--header 'Content-Type: multipart/form-data' \
--header 'x-user-id: <x-user-id>' \
--form file='@example-file' \
--form 'content_type=<string>'import requests
url = "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "content_type": "<string>" }
headers = {"x-user-id": "<x-user-id>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('content_type', '<string>');
const options = {method: 'POST', headers: {'x-user-id': '<x-user-id>'}};
options.body = form;
fetch('https://api.example.com/knowledge_bases/{knowledge_base_id}/documents', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content_type\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data",
"x-user-id: <x-user-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content_type\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-user-id", "<x-user-id>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/knowledge_bases/{knowledge_base_id}/documents")
.header("x-user-id", "<x-user-id>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content_type\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/knowledge_bases/{knowledge_base_id}/documents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-user-id"] = '<x-user-id>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content_type\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"document_id": "<string>",
"filename": "<string>",
"status": "pending"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Upload a document into a knowledge base
Register an uploaded document and dispatch it for indexing.
The HTTP connection covers only the upload phase: the request body
is streamed into the blob store, a pending document record is
persisted, the indexing task is dispatched, and the response is
returned. Parsing / chunking / embedding happen asynchronously in
a worker; the client tracks progress via
:func:list_knowledge_document_status.
Args:
knowledge_base_id (str):
The knowledge base to receive the document.
file (UploadFile):
The uploaded file (multipart/form-data).
content_type (str | None, optional):
Override the IANA media type used to route the upload.
user_id (str):
Injected authenticated user ID.
service (KnowledgeBaseService):
Injected knowledge base service.
Returns:
UploadKnowledgeDocumentResponse:
The server-assigned document id, filename, and the
initial lifecycle state (always "pending").
curl --request POST \
--url https://api.example.com/knowledge_bases/{knowledge_base_id}/documents \
--header 'Content-Type: multipart/form-data' \
--header 'x-user-id: <x-user-id>' \
--form file='@example-file' \
--form 'content_type=<string>'import requests
url = "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "content_type": "<string>" }
headers = {"x-user-id": "<x-user-id>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('content_type', '<string>');
const options = {method: 'POST', headers: {'x-user-id': '<x-user-id>'}};
options.body = form;
fetch('https://api.example.com/knowledge_bases/{knowledge_base_id}/documents', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content_type\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data",
"x-user-id: <x-user-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content_type\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-user-id", "<x-user-id>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/knowledge_bases/{knowledge_base_id}/documents")
.header("x-user-id", "<x-user-id>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content_type\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/knowledge_bases/{knowledge_base_id}/documents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-user-id"] = '<x-user-id>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content_type\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"document_id": "<string>",
"filename": "<string>",
"status": "pending"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Headers
Caller's user ID. Temporary header-based identity; will be replaced by JWT auth.
Path Parameters
The knowledge base id.
Body
Response
Successful Response
Response body after uploading a document into a knowledge base.
Server-assigned document identifier.
The original filename of the uploaded document.
Lifecycle state immediately after upload — always 'pending' in the happy path; surfaced so the client can seed its progress tracker without an extra round-trip.
pending, parsing, chunking, indexing, ready, error