Skip to main content
PUT
/
api
/
v2
/
agents
/
{agentId}
/
sources
/
{sourceId}
Update file source
curl --request PUT \
  --url https://files.chatbase.co/api/v2/agents/{agentId}/sources/{sourceId} \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: multipart/form-data' \
  --form 'name=Employee Handbook v2' \
  --form file='@example-file'
import requests

url = "https://files.chatbase.co/api/v2/agents/{agentId}/sources/{sourceId}"

files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "name": "Employee Handbook v2" }
headers = {"Authorization": "Bearer <token>"}

response = requests.put(url, data=payload, files=files, headers=headers)

print(response.text)
const form = new FormData();
form.append('name', 'Employee Handbook v2');
form.append('file', '<string>');

const options = {method: 'PUT', headers: {Authorization: 'Bearer <token>'}};

options.body = form;

fetch('https://files.chatbase.co/api/v2/agents/{agentId}/sources/{sourceId}', 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/{sourceId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook v2\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/{sourceId}"

payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook v2\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("PUT", 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.put("https://files.chatbase.co/api/v2/agents/{agentId}/sources/{sourceId}")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook v2\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/{sourceId}")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nEmployee Handbook v2\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 v2",
  "size": 261120,
  "createdAt": "2025-01-15T10:30:00.000Z",
  "status": "updated",
  "metadata": null
}
{
"error": {
"code": "VALIDATION_INVALID_BODY",
"message": "No fields provided 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": "SOURCE_NOT_FOUND",
"message": "Source not found."
}
}
{
"error": {
"code": "SOURCE_PENDING_DELETION",
"message": "Source is pending deletion. Restore it before editing."
}
}
{
"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

Authorization
string
header
required

API key from your account settings

Path Parameters

agentId
string
required

The agent ID

Minimum string length: 1
Example:

"5QHA6VB-DIAbBhxwqxfdi"

sourceId
string
required

The source ID

Minimum string length: 1
Example:

"a63a69a5-e7a9-4757-b73b-2041854d435d"

Body

multipart/form-data
name
string

New display name. If omitted, the existing name is preserved.

Minimum string length: 1
Example:

"Employee Handbook v2"

file
file

Replacement file. Same constraints as create. If omitted, existing content is preserved.

Response

Updated file source. If the file was replaced and previously trained, status becomes updated.

id
string
required

Source ID

type
enum<string>
required

Source type

Available options:
link,
file,
qna,
notionPage,
text
name
string | null
required

Source name or URL

size
number
required

Source size in bytes

createdAt
string
required

ISO 8601 creation timestamp

status
enum<string>
required

Training status of the source

Available options:
untrained,
trained,
toBeDeleted,
updated
metadata
object
required

Link-specific metadata. Present only for type="link".