Create Knowledge Base
curl --request POST \
--url https://api.trugen.ai/v1/ext/kb \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-key: <api-key>' \
--form 'name=HR Policy' \
--form 'description=This knowledge base contains HR and compensation related information.' \
--form input='@example-file' \
--form 'text=As of 2025; we have increased the personal leaves to 15 per year.'import requests
url = "https://api.trugen.ai/v1/ext/kb"
files = { "input": ("example-file", open("example-file", "rb")) }
payload = {
"name": "HR Policy",
"description": "This knowledge base contains HR and compensation related information.",
"text": "As of 2025; we have increased the personal leaves to 15 per year."
}
headers = {"x-api-key": "<api-key>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('name', 'HR Policy');
form.append('description', 'This knowledge base contains HR and compensation related information.');
form.append('input', 'HR_Policy.docx');
form.append('text', 'As of 2025; we have increased the personal leaves to 15 per year.');
const options = {method: 'POST', headers: {'x-api-key': '<api-key>'}};
options.body = form;
fetch('https://api.trugen.ai/v1/ext/kb', 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.trugen.ai/v1/ext/kb",
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\nHR Policy\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nThis knowledge base contains HR and compensation related information.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\nHR_Policy.docx\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nAs of 2025; we have increased the personal leaves to 15 per year.\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data",
"x-api-key: <api-key>"
],
]);
$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.trugen.ai/v1/ext/kb"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nHR Policy\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nThis knowledge base contains HR and compensation related information.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\nHR_Policy.docx\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nAs of 2025; we have increased the personal leaves to 15 per year.\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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.trugen.ai/v1/ext/kb")
.header("x-api-key", "<api-key>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nHR Policy\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nThis knowledge base contains HR and compensation related information.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\nHR_Policy.docx\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nAs of 2025; we have increased the personal leaves to 15 per year.\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trugen.ai/v1/ext/kb")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nHR Policy\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nThis knowledge base contains HR and compensation related information.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\nHR_Policy.docx\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nAs of 2025; we have increased the personal leaves to 15 per year.\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"id": "5273e435-3cbb-4a11-9ea9-2c150ba19009",
"message": "Knowledge Base created successfully"
}{
"error": "Invalid request body"
}{
"error": "Unauthorized: not a valid authorization api key"
}{
"error": "Failed to retrieve knowledge base"
}Knowledge Base
Create Knowledge Base
Uploads a document or raw text to create a new Knowledge Base entry. Requires x-api-key authentication.
POST
/
ext
/
kb
Create Knowledge Base
curl --request POST \
--url https://api.trugen.ai/v1/ext/kb \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-key: <api-key>' \
--form 'name=HR Policy' \
--form 'description=This knowledge base contains HR and compensation related information.' \
--form input='@example-file' \
--form 'text=As of 2025; we have increased the personal leaves to 15 per year.'import requests
url = "https://api.trugen.ai/v1/ext/kb"
files = { "input": ("example-file", open("example-file", "rb")) }
payload = {
"name": "HR Policy",
"description": "This knowledge base contains HR and compensation related information.",
"text": "As of 2025; we have increased the personal leaves to 15 per year."
}
headers = {"x-api-key": "<api-key>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('name', 'HR Policy');
form.append('description', 'This knowledge base contains HR and compensation related information.');
form.append('input', 'HR_Policy.docx');
form.append('text', 'As of 2025; we have increased the personal leaves to 15 per year.');
const options = {method: 'POST', headers: {'x-api-key': '<api-key>'}};
options.body = form;
fetch('https://api.trugen.ai/v1/ext/kb', 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.trugen.ai/v1/ext/kb",
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\nHR Policy\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nThis knowledge base contains HR and compensation related information.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\nHR_Policy.docx\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nAs of 2025; we have increased the personal leaves to 15 per year.\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data",
"x-api-key: <api-key>"
],
]);
$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.trugen.ai/v1/ext/kb"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nHR Policy\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nThis knowledge base contains HR and compensation related information.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\nHR_Policy.docx\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nAs of 2025; we have increased the personal leaves to 15 per year.\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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.trugen.ai/v1/ext/kb")
.header("x-api-key", "<api-key>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nHR Policy\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nThis knowledge base contains HR and compensation related information.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\nHR_Policy.docx\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nAs of 2025; we have increased the personal leaves to 15 per year.\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trugen.ai/v1/ext/kb")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nHR Policy\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nThis knowledge base contains HR and compensation related information.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\nHR_Policy.docx\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nAs of 2025; we have increased the personal leaves to 15 per year.\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"id": "5273e435-3cbb-4a11-9ea9-2c150ba19009",
"message": "Knowledge Base created successfully"
}{
"error": "Invalid request body"
}{
"error": "Unauthorized: not a valid authorization api key"
}{
"error": "Failed to retrieve knowledge base"
}Authorizations
Body
multipart/form-data
Human readable name of the knowledge base.
Example:
"HR Policy"
Description of the knowledge base.
Example:
"This knowledge base contains HR and compensation related information."
Document file to upload (.pdf, .docx or .txt). Optional if text is provided.
As of 2025; we have increased the personal leaves to 15 per year.
Example:
"As of 2025; we have increased the personal leaves to 15 per year."
Was this page helpful?
⌘I