Files
Replace file
Upload a new version of a ready file. Assistants keep using the old one until the new one is ready, then switch at once.
POST
/
knowledge-base
/
files
/
{fileId}
/
replace
Replace file
curl --request POST \
--url https://api.verbeo.ai/v1/knowledge-base/files/{fileId}/replace \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'import requests
url = "https://api.verbeo.ai/v1/knowledge-base/files/{fileId}/replace"
payload = {}
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({})
};
fetch('https://api.verbeo.ai/v1/knowledge-base/files/{fileId}/replace', 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.verbeo.ai/v1/knowledge-base/files/{fileId}/replace",
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([
]),
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.verbeo.ai/v1/knowledge-base/files/{fileId}/replace"
payload := strings.NewReader("{}")
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.verbeo.ai/v1/knowledge-base/files/{fileId}/replace")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.verbeo.ai/v1/knowledge-base/files/{fileId}/replace")
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 = "{}"
response = http.request(request)
puts response.read_bodyUploads a new version of a ready file in one
multipart/form-data request. The new file is a file of its own, with replaces_id naming the old one. Assistants keep searching the old file until the new one is ready; then the two swap at once and the old file is deleted. If the new one fails, the old one stays.
The new file may have another name and type. It counts as the same file toward your plan’s files per knowledge base.
Path parameters
Body
Request
curl -X POST "https://api.verbeo.ai/v1/knowledge-base/files/c4ff0c9c-4b3b-4a94-a86e-3d3b64088ae0/replace" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "files=@prices-2027.pdf"
import os, requests
file_id = "c4ff0c9c-4b3b-4a94-a86e-3d3b64088ae0"
res = requests.post(
f"https://api.verbeo.ai/v1/knowledge-base/files/{file_id}/replace",
headers={"Authorization": f"Bearer {os.environ['VERBEO_API_KEY']}"},
files=[("files", open("prices-2027.pdf", "rb"))],
)
new_file = res.json()["data"]
Response
201 Created with the new file object, processing, its replaces_id the old file’s id. Read it until it is ready: the old file is then gone.
{
"success": true,
"data": {
"id": "e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b",
"store_id": "5df09066-0842-4c92-8ef0-6cf2ff6d7455",
"display_name": "prices-2027.pdf",
"status": "processing",
"replaces_id": "c4ff0c9c-4b3b-4a94-a86e-3d3b64088ae0",
"…": "every field of the file object"
}
}
Errors
| Code | Status | When |
|---|---|---|
KB_FILE_NOT_READY | 409 | prices-2027.pdf: Only a ready file can be replaced. |
KB_FILE_BEING_REPLACED | 409 | prices-2027.pdf: This file is already being replaced. Delete or retry its replacement first. |
KB_DUPLICATE_FILE | 409 | The new version’s bytes are already a file of this knowledge base, the one it replaces included. |
KB_* | 409 | Another of your plan’s limits. |
VALIDATION_FAILED | 422 | files: must be one file, or one of the upload’s form rules. |
PAYLOAD_TOO_LARGE | 413 | A file over 25 MB. |
NOT_FOUND | 404 | No such file: File not found. |
Was this page helpful?
⌘I
Replace file
curl --request POST \
--url https://api.verbeo.ai/v1/knowledge-base/files/{fileId}/replace \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'import requests
url = "https://api.verbeo.ai/v1/knowledge-base/files/{fileId}/replace"
payload = {}
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({})
};
fetch('https://api.verbeo.ai/v1/knowledge-base/files/{fileId}/replace', 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.verbeo.ai/v1/knowledge-base/files/{fileId}/replace",
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([
]),
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.verbeo.ai/v1/knowledge-base/files/{fileId}/replace"
payload := strings.NewReader("{}")
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.verbeo.ai/v1/knowledge-base/files/{fileId}/replace")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.verbeo.ai/v1/knowledge-base/files/{fileId}/replace")
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 = "{}"
response = http.request(request)
puts response.read_body