curl --request POST \
--url https://api.chatling.ai/v3/knowledge-base/uploads \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"agent_id": "3132353852",
"filename": "Handbook.pdf",
"size": 482133
}
'import requests
url = "https://api.chatling.ai/v3/knowledge-base/uploads"
payload = {
"agent_id": "3132353852",
"filename": "Handbook.pdf",
"size": 482133
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({agent_id: '3132353852', filename: 'Handbook.pdf', size: 482133})
};
fetch('https://api.chatling.ai/v3/knowledge-base/uploads', 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.chatling.ai/v3/knowledge-base/uploads",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '3132353852',
'filename' => 'Handbook.pdf',
'size' => 482133
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.chatling.ai/v3/knowledge-base/uploads"
payload := strings.NewReader("{\n \"agent_id\": \"3132353852\",\n \"filename\": \"Handbook.pdf\",\n \"size\": 482133\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
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.chatling.ai/v3/knowledge-base/uploads")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"3132353852\",\n \"filename\": \"Handbook.pdf\",\n \"size\": 482133\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.chatling.ai/v3/knowledge-base/uploads")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"3132353852\",\n \"filename\": \"Handbook.pdf\",\n \"size\": 482133\n}"
response = http.request(request)
puts response.read_body{
"object": "knowledge_base_upload",
"id": "9b2e7c41-8d3a-4f6e-a1b5-2c7d9e0f3a64",
"agent": {
"id": "3132353852",
"type": "ai_agent",
"name": "Support"
},
"filename": "Handbook.pdf",
"size": 482133,
"content_type": "application/pdf",
"upload": {
"method": "POST",
"url": "https://chatling-documents-data-source.s3.us-east-2.amazonaws.com",
"fields": {
"key": "9b2e7c41-8d3a-4f6e-a1b5-2c7d9e0f3a64.pdf",
"Content-Type": "application/pdf",
"X-Amz-Credential": "…",
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Date": "20261123T101500Z",
"Policy": "…",
"X-Amz-Signature": "…"
}
},
"expires_at": "2026-11-23T10:20:00Z"
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is invalid or has been revoked.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "not_found_error",
"code": "resource_not_found",
"message": "No agent with this ID exists, or this API key can't access it.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}Create a document upload
Adding a document to a knowledge base takes three requests: create an upload with this endpoint, upload the file to the storage URL it returns, then add the document as a source. The file goes straight to storage, so the API’s request size limit doesn’t apply.
1. Create an upload
Pass the file’s name, with its extension, and its exact size in bytes.
curl https://api.chatling.ai/v3/knowledge-base/uploads \
-H "Authorization: Bearer $CHATLING_API_KEY" \
-H "Content-Type: application/json" \
-d '{"agent_id": "3132353852", "filename": "Handbook.pdf", "size": 482133}'
The response includes the upload’s id and a signed form in upload:
{
"object": "knowledge_base_upload",
"id": "9b2e7c41-8d3a-4f6e-a1b5-2c7d9e0f3a64",
"filename": "Handbook.pdf",
"size": 482133,
"content_type": "application/pdf",
"upload": {
"method": "POST",
"url": "https://chatling-documents-data-source.s3.us-east-2.amazonaws.com",
"fields": {
"key": "9b2e7c41-8d3a-4f6e-a1b5-2c7d9e0f3a64.pdf",
"Content-Type": "application/pdf",
"X-Amz-Credential": "…",
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Date": "20261123T101500Z",
"Policy": "…",
"X-Amz-Signature": "…"
}
},
"expires_at": "2026-11-23T10:20:00Z"
}
2. Upload the file
Before expires_at (5 minutes after you create the upload), send a multipart/form-data POST to upload.url. Include every field in upload.fields unchanged, then the file as the last field, named file. Don’t send your API key to this URL. A successful upload returns 204 No Content.
curl -i -X POST "https://chatling-documents-data-source.s3.us-east-2.amazonaws.com" \
-F "key=9b2e7c41-8d3a-4f6e-a1b5-2c7d9e0f3a64.pdf" \
-F "Content-Type=application/pdf" \
-F "X-Amz-Credential=…" \
-F "X-Amz-Algorithm=AWS4-HMAC-SHA256" \
-F "X-Amz-Date=20261123T101500Z" \
-F "Policy=…" \
-F "X-Amz-Signature=…" \
-F "[email protected]"
In JavaScript (Node.js 18 or later), where upload is the response from step 1:
import { readFile } from "node:fs/promises";
const form = new FormData();
for (const [name, value] of Object.entries(upload.upload.fields)) {
form.append(name, value);
}
const file = await readFile("Handbook.pdf");
form.append("file", new Blob([file], { type: upload.content_type }), upload.filename);
const response = await fetch(upload.upload.url, { method: "POST", body: form });
if (response.status !== 204) {
throw new Error(await response.text());
}
In Python, with requests:
import requests
with open("Handbook.pdf", "rb") as file:
response = requests.post(
upload["upload"]["url"],
data=upload["upload"]["fields"],
files={"file": (upload["filename"], file, upload["content_type"])},
)
if response.status_code != 204:
raise RuntimeError(response.text)
Storage returns errors as XML. EntityTooLarge or EntityTooSmall means the file doesn’t match the size from step 1. AccessDenied with “Policy expired” means the upload expired. In either case, create a new upload and try again.
3. Add the document
Within 24 hours of creating the upload, add a source with type: document and the upload’s id:
curl https://api.chatling.ai/v3/knowledge-base/sources \
-H "Authorization: Bearer $CHATLING_API_KEY" \
-H "Content-Type: application/json" \
-d '{"agent_id": "3132353852", "type": "document", "document": {"upload_id": "9b2e7c41-8d3a-4f6e-a1b5-2c7d9e0f3a64"}}'
The source starts as pending and trains in the background. Retrieve it until its status is processed, when the agent can use it, or failed, with the reason in error. To add several documents, create one upload per file, then add them together with Add knowledge base sources in bulk.
Limits
- PDF, TXT, DOC, and DOCX files, up to the plan’s document size limit.
- Up to 5 million characters per document, within the plan’s remaining knowledge base characters. Both limits are checked when the document trains, and a document over either limit fails.
- 30 uploads per minute per project.
- Each upload adds one source. To add the same file again, create a new upload.
- Documents can’t be updated or resynced. Delete the source and add the new file instead.
curl --request POST \
--url https://api.chatling.ai/v3/knowledge-base/uploads \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"agent_id": "3132353852",
"filename": "Handbook.pdf",
"size": 482133
}
'import requests
url = "https://api.chatling.ai/v3/knowledge-base/uploads"
payload = {
"agent_id": "3132353852",
"filename": "Handbook.pdf",
"size": 482133
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({agent_id: '3132353852', filename: 'Handbook.pdf', size: 482133})
};
fetch('https://api.chatling.ai/v3/knowledge-base/uploads', 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.chatling.ai/v3/knowledge-base/uploads",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '3132353852',
'filename' => 'Handbook.pdf',
'size' => 482133
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.chatling.ai/v3/knowledge-base/uploads"
payload := strings.NewReader("{\n \"agent_id\": \"3132353852\",\n \"filename\": \"Handbook.pdf\",\n \"size\": 482133\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
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.chatling.ai/v3/knowledge-base/uploads")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"3132353852\",\n \"filename\": \"Handbook.pdf\",\n \"size\": 482133\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.chatling.ai/v3/knowledge-base/uploads")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"3132353852\",\n \"filename\": \"Handbook.pdf\",\n \"size\": 482133\n}"
response = http.request(request)
puts response.read_body{
"object": "knowledge_base_upload",
"id": "9b2e7c41-8d3a-4f6e-a1b5-2c7d9e0f3a64",
"agent": {
"id": "3132353852",
"type": "ai_agent",
"name": "Support"
},
"filename": "Handbook.pdf",
"size": 482133,
"content_type": "application/pdf",
"upload": {
"method": "POST",
"url": "https://chatling-documents-data-source.s3.us-east-2.amazonaws.com",
"fields": {
"key": "9b2e7c41-8d3a-4f6e-a1b5-2c7d9e0f3a64.pdf",
"Content-Type": "application/pdf",
"X-Amz-Credential": "…",
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Date": "20261123T101500Z",
"Policy": "…",
"X-Amz-Signature": "…"
}
},
"expires_at": "2026-11-23T10:20:00Z"
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is invalid or has been revoked.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "not_found_error",
"code": "resource_not_found",
"message": "No agent with this ID exists, or this API key can't access it.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}Headers
Body
Response
The upload, with the form for uploading the file.