Create a query
curl --request POST \
--url https://api.libraria.ai/library/{library_id}/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "<string>",
"conversationId": {},
"streaming": {}
}
'import requests
url = "https://api.libraria.ai/library/{library_id}/query"
payload = {
"query": "<string>",
"conversationId": {},
"streaming": {}
}
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({query: '<string>', conversationId: {}, streaming: {}})
};
fetch('https://api.libraria.ai/library/{library_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.libraria.ai/library/{library_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>',
'conversationId' => [
],
'streaming' => [
]
]),
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.libraria.ai/library/{library_id}/query"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"conversationId\": {},\n \"streaming\": {}\n}")
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.libraria.ai/library/{library_id}/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"conversationId\": {},\n \"streaming\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.libraria.ai/library/{library_id}/query")
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 = "{\n \"query\": \"<string>\",\n \"conversationId\": {},\n \"streaming\": {}\n}"
response = http.request(request)
puts response.read_body{
"reply": "The capital of France is Paris.",
"conversationId": "optional-unique-id",
"metadata": {
"documents": [
{
"id": "some-document-id",
"title": "The france capital",
"similarity": 0.966698234468654,
"extraFields": {
"learnMoreLink": {
"url": "https://france-capital",
"text": "The France Capital"
}
}
},
],
"images": [],
"helpArticles": [
{
"url": "https://france-capital",
"text": "The France Capital"
}
]
}
}
{"type":"initializing","gptQueryId":"some-gpt-query-id"}
{"type":"token","value":""}
{"type":"token","value":"Paris"}
{"type":"token","value":" is"}
{"type":"token","value":" the"}
{"type":"token","value":" capital"}
{"type":"token","value":" of"}
{"type":"token","value":" France"}
{"type":"token","value":"."}
{"type":"token","value":""}
{"type":"response","data":{"response":"Paris is the capital of France.","text":"Paris is the capital of France.","gptQuery":{"extraFields":{"images":[],"documents":[],"helpArticles":[]},"gptConversationId":"some-conversation-id"}}}
{"type":"done"}
Libraria API
Create a query
Given a query and an optional conversation id, get a response from your library
POST
/
library
/
{library_id}
/
query
Create a query
curl --request POST \
--url https://api.libraria.ai/library/{library_id}/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "<string>",
"conversationId": {},
"streaming": {}
}
'import requests
url = "https://api.libraria.ai/library/{library_id}/query"
payload = {
"query": "<string>",
"conversationId": {},
"streaming": {}
}
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({query: '<string>', conversationId: {}, streaming: {}})
};
fetch('https://api.libraria.ai/library/{library_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.libraria.ai/library/{library_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>',
'conversationId' => [
],
'streaming' => [
]
]),
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.libraria.ai/library/{library_id}/query"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"conversationId\": {},\n \"streaming\": {}\n}")
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.libraria.ai/library/{library_id}/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"conversationId\": {},\n \"streaming\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.libraria.ai/library/{library_id}/query")
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 = "{\n \"query\": \"<string>\",\n \"conversationId\": {},\n \"streaming\": {}\n}"
response = http.request(request)
puts response.read_body{
"reply": "The capital of France is Paris.",
"conversationId": "optional-unique-id",
"metadata": {
"documents": [
{
"id": "some-document-id",
"title": "The france capital",
"similarity": 0.966698234468654,
"extraFields": {
"learnMoreLink": {
"url": "https://france-capital",
"text": "The France Capital"
}
}
},
],
"images": [],
"helpArticles": [
{
"url": "https://france-capital",
"text": "The France Capital"
}
]
}
}
{"type":"initializing","gptQueryId":"some-gpt-query-id"}
{"type":"token","value":""}
{"type":"token","value":"Paris"}
{"type":"token","value":" is"}
{"type":"token","value":" the"}
{"type":"token","value":" capital"}
{"type":"token","value":" of"}
{"type":"token","value":" France"}
{"type":"token","value":"."}
{"type":"token","value":""}
{"type":"response","data":{"response":"Paris is the capital of France.","text":"Paris is the capital of France.","gptQuery":{"extraFields":{"images":[],"documents":[],"helpArticles":[]},"gptConversationId":"some-conversation-id"}}}
{"type":"done"}
Parameters
string
required
The ID of the library you are going to ask a question
Body
string
required
The question you will make to the library.
string | null
Optional. Use this for a continuation of the conversation. You will receive a conversation id on the first query you send.
boolean | null
Optional. Whether or not you want to receive a streamed response. Default value is False.
Response
The response will vary according to the value of thestreaming attribute.
Non-streamed response
Whenstreaming is equal to false the response will be a JSON object containing the following fields
string
required
The response from the library for the query provided in the request body
string
required
Optional. Use this in follow-up requests for a continuation of the conversation. You will receive a conversation id on the first query you send.
json
required
Streamed response
Whenstreaming is equal to true the response is sent as a series of chunk where each of them will be a JSON object.
string
required
Specifies the type of the chunk that is being sentPossible values are: initializing, token, response, done
string | null
It only appears when
type == token.It represents the token that is currently being sent as part of a partial response.
If you concatenate all tokens you will have the complete response.json | null
It only appears when
type == response.A json object containing the final response and metadata for the gptQuery.{
"reply": "The capital of France is Paris.",
"conversationId": "optional-unique-id",
"metadata": {
"documents": [
{
"id": "some-document-id",
"title": "The france capital",
"similarity": 0.966698234468654,
"extraFields": {
"learnMoreLink": {
"url": "https://france-capital",
"text": "The France Capital"
}
}
},
],
"images": [],
"helpArticles": [
{
"url": "https://france-capital",
"text": "The France Capital"
}
]
}
}
{"type":"initializing","gptQueryId":"some-gpt-query-id"}
{"type":"token","value":""}
{"type":"token","value":"Paris"}
{"type":"token","value":" is"}
{"type":"token","value":" the"}
{"type":"token","value":" capital"}
{"type":"token","value":" of"}
{"type":"token","value":" France"}
{"type":"token","value":"."}
{"type":"token","value":""}
{"type":"response","data":{"response":"Paris is the capital of France.","text":"Paris is the capital of France.","gptQuery":{"extraFields":{"images":[],"documents":[],"helpArticles":[]},"gptConversationId":"some-conversation-id"}}}
{"type":"done"}

