Query a Knowledge Base
curl --request POST \
--url https://api.example.com/kb/{kb_id}/query \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"query": "<string>"
}
'import requests
url = "https://api.example.com/kb/{kb_id}/query"
payload = { "query": "<string>" }
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({query: '<string>'})
};
fetch('https://api.example.com/kb/{kb_id}/query', 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.example.com/kb/{kb_id}/query",
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([
'query' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$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.example.com/kb/{kb_id}/query"
payload := strings.NewReader("{\n \"query\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
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.example.com/kb/{kb_id}/query")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"query\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/kb/{kb_id}/query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"query\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"answer": "<string>",
"citations": [
{
"document_id": "<string>",
"title": "<string>",
"excerpt": "<string>",
"page": 123
}
],
"tokens_used": 123
}Endpoints
Query a Knowledge Base
Send questions and receive answers with citations
POST
/
kb
/
{kb_id}
/
query
Query a Knowledge Base
curl --request POST \
--url https://api.example.com/kb/{kb_id}/query \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"query": "<string>"
}
'import requests
url = "https://api.example.com/kb/{kb_id}/query"
payload = { "query": "<string>" }
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({query: '<string>'})
};
fetch('https://api.example.com/kb/{kb_id}/query', 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.example.com/kb/{kb_id}/query",
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([
'query' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$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.example.com/kb/{kb_id}/query"
payload := strings.NewReader("{\n \"query\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
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.example.com/kb/{kb_id}/query")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"query\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/kb/{kb_id}/query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"query\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"answer": "<string>",
"citations": [
{
"document_id": "<string>",
"title": "<string>",
"excerpt": "<string>",
"page": 123
}
],
"tokens_used": 123
}Endpoint
POST https://api.ardie.ai/kb/{kb_id}/query
Path Parameters
string
required
The unique identifier of the knowledge base to query.
Request Headers
string
required
Bearer token with your API key:
Bearer YOUR_API_KEYstring
required
Must be
application/jsonRequest Body
string
required
The question or search query to send to the knowledge base.
Example Request
curl -X POST https://api.ardie.ai/kb/kb_edu_123/query \
-H "Authorization: Bearer ardie_sk_live_abc123" \
-H "Content-Type: application/json" \
-d '{
"query": "What are the key curriculum standards for grade 5 math?"
}'
import requests
response = requests.post(
"https://api.ardie.ai/kb/kb_edu_123/query",
headers={
"Authorization": "Bearer ardie_sk_live_abc123",
"Content-Type": "application/json"
},
json={
"query": "What are the key curriculum standards for grade 5 math?"
}
)
data = response.json()
print(data["answer"])
const response = await fetch('https://api.ardie.ai/kb/kb_edu_123/query', {
method: 'POST',
headers: {
'Authorization': 'Bearer ardie_sk_live_abc123',
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: 'What are the key curriculum standards for grade 5 math?'
})
});
const data = await response.json();
console.log(data.answer);
Response
string
The generated answer to your query based on the knowledge base content.
array
integer
Number of tokens consumed by this query.
Example Response
{
"answer": "The key curriculum standards for grade 5 math include operations with fractions, understanding of place value to the thousandths, and introduction to coordinate geometry. Students should be able to add and subtract fractions with unlike denominators, multiply and divide fractions, and understand the relationship between fractions and decimals.",
"citations": [
{
"document_id": "doc_123",
"title": "Common Core Math Standards",
"excerpt": "Students should be able to add and subtract fractions with unlike denominators (including mixed numbers) by replacing given fractions with equivalent fractions...",
"page": 42
},
{
"document_id": "doc_456",
"title": "Grade 5 Mathematics Framework",
"excerpt": "Place value understanding extends to the thousandths place, with students reading, writing, and comparing decimals...",
"page": 15
}
],
"tokens_used": 150
}
Error Responses
| Status | Error | Description |
|---|---|---|
400 | invalid_query | Query is empty or malformed |
401 | unauthorized | Missing or invalid API key |
403 | forbidden | Key doesn’t have access to this KB |
429 | query_cap_exceeded | Monthly query limit reached |
429 | rate_limit_exceeded | Too many requests per minute |
500 | internal_error | Server error, retry later |
Next Steps
Rate Limits
Understand usage caps
Error Handling
Handle errors gracefully
⌘I
(7).png?fit=max&auto=format&n=6FZsVQ5mPkveKHn2&q=85&s=46e497b52f808bab8589207e29abb2e1)
(6).png?fit=max&auto=format&n=3Dv90z8s7pwEMiZV&q=85&s=5b1b766bf867af4abce636e36c001b97)