Create file source
curl --request POST \
--url https://files.chatbase.co/api/v2/agents/{agentId}/sources \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form 'name=Employee Handbook' \
--form file='@example-file'import requests
url = "https://files.chatbase.co/api/v2/agents/{agentId}/sources"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "name": "Employee Handbook" }
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('name', 'Employee Handbook');
form.append('file', '<string>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://files.chatbase.co/api/v2/agents/{agentId}/sources', 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://files.chatbase.co/api/v2/agents/{agentId}/sources",
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=\"name\"\r\n\r\nEmployee Handbook\r\n-----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--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$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://files.chatbase.co/api/v2/agents/{agentId}/sources"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook\r\n-----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--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://files.chatbase.co/api/v2/agents/{agentId}/sources")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook\r\n-----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--")
.asString();require 'uri'
require 'net/http'
url = URI("https://files.chatbase.co/api/v2/agents/{agentId}/sources")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook\r\n-----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--"
response = http.request(request)
puts response.read_body{
"id": "a63a69a5-e7a9-4757-b73b-2041854d435d",
"type": "file",
"name": "Employee Handbook",
"size": 245760,
"createdAt": "2025-01-15T10:30:00.000Z",
"status": "untrained",
"metadata": null
}{
"error": {
"code": "VALIDATION_INVALID_BODY",
"message": "Missing required field or unsupported file type."
}
}{
"error": {
"code": "AUTH_MISSING_API_KEY",
"message": "No Authorization header present."
}
}{
"error": {
"code": "SUBSCRIPTION_API_RESTRICTED_PLAN",
"message": "Standard plan or higher required."
}
}{
"error": {
"code": "AGENT_NOT_FOUND",
"message": "Agent not found."
}
}{
"error": {
"code": "SOURCE_SIZE_LIMIT_EXCEEDED",
"message": "File would exceed the plan storage limit."
}
}{
"error": {
"code": "RATE_LIMIT_TOO_MANY_REQUESTS",
"message": "Rate limit exceeded."
}
}{
"error": {
"code": "INTERNAL_SERVER_ERROR",
"message": "Unhandled server error."
}
}Sources
Create file source
Upload a file as a knowledge source for an agent. Accepts PDF, DOC, DOCX, and TXT files up to 20 MB.
Base URL: https://files.chatbase.co/api/v2 — this endpoint uses a different host from all other Sources endpoints.
POST
/
api
/
v2
/
agents
/
{agentId}
/
sources
Create file source
curl --request POST \
--url https://files.chatbase.co/api/v2/agents/{agentId}/sources \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form 'name=Employee Handbook' \
--form file='@example-file'import requests
url = "https://files.chatbase.co/api/v2/agents/{agentId}/sources"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "name": "Employee Handbook" }
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('name', 'Employee Handbook');
form.append('file', '<string>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://files.chatbase.co/api/v2/agents/{agentId}/sources', 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://files.chatbase.co/api/v2/agents/{agentId}/sources",
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=\"name\"\r\n\r\nEmployee Handbook\r\n-----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--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$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://files.chatbase.co/api/v2/agents/{agentId}/sources"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook\r\n-----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--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://files.chatbase.co/api/v2/agents/{agentId}/sources")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook\r\n-----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--")
.asString();require 'uri'
require 'net/http'
url = URI("https://files.chatbase.co/api/v2/agents/{agentId}/sources")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook\r\n-----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--"
response = http.request(request)
puts response.read_body{
"id": "a63a69a5-e7a9-4757-b73b-2041854d435d",
"type": "file",
"name": "Employee Handbook",
"size": 245760,
"createdAt": "2025-01-15T10:30:00.000Z",
"status": "untrained",
"metadata": null
}{
"error": {
"code": "VALIDATION_INVALID_BODY",
"message": "Missing required field or unsupported file type."
}
}{
"error": {
"code": "AUTH_MISSING_API_KEY",
"message": "No Authorization header present."
}
}{
"error": {
"code": "SUBSCRIPTION_API_RESTRICTED_PLAN",
"message": "Standard plan or higher required."
}
}{
"error": {
"code": "AGENT_NOT_FOUND",
"message": "Agent not found."
}
}{
"error": {
"code": "SOURCE_SIZE_LIMIT_EXCEEDED",
"message": "File would exceed the plan storage limit."
}
}{
"error": {
"code": "RATE_LIMIT_TOO_MANY_REQUESTS",
"message": "Rate limit exceeded."
}
}{
"error": {
"code": "INTERNAL_SERVER_ERROR",
"message": "Unhandled server error."
}
}Authorizations
API key from your account settings
Path Parameters
The agent ID
Minimum string length:
1Example:
"5QHA6VB-DIAbBhxwqxfdi"
Body
multipart/form-data
Response
File source created. Status is untrained until the agent is retrained.
Source ID
Source type
Available options:
link, file, qna, notionPage, text Source name or URL
Source size in bytes
ISO 8601 creation timestamp
Training status of the source
Available options:
untrained, trained, toBeDeleted, updated Link-specific metadata. Present only for type="link".
- Option 1
- Option 2
Show child attributes
Show child attributes
⌘I