Skip to main content
POST
/
v2
/
library
/
{library_id}
/
query
Create a query
curl --request POST \
  --url https://api.libraria.ai/v2/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/v2/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/v2/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/v2/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/v2/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/v2/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/v2/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"}

{"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":{
  "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":"done"}

Parameters

library_id
string
required
The ID of the library you are going to ask a question

Body

query
string
required
The question you will make to the library.
conversationId
string | null
Optional. Use this for a continuation of the conversation. You will receive a conversation id on the first query you send.
streaming
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 the streaming attribute.

Non-streamed response

When streaming is false, the response will be a JSON object containing the following fields
reply
string
required
The response from the library for the query provided in the request body
conversationId
string
required
Use this in follow-up requests for a continuation of the conversation. You will receive a conversation id on the first query you send.
metadata
json
required
A map containing data used to generate the query response. It provides additional sources of information to the reply.

Streamed response

When streaming is true, the response is sent as a series of chunks where each of them will be a JSON object. All chunks includes a type param the describes how the rest of the JSON will look like
type
string
required
Specifies the type of the chunk that is being sentPossible values are: initializing, token, response, done

type == initializing

The initial chunk when the stream has just be opened. Example:
{"type": "initializing"}

type == token

Each token represents a partial response sent from the library. When all chunks are concatenated together, you will have the final response. The body will include a value attribute the will include the current token sent.
value
string
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.
{"type": "token",
 "value": "Paris"}

type == response

It contains the final response and additional metadata that has been used to generate the response The body will include a data attribute the will include the final response and the metadata.
data
json
A json object containing the final response and additional metadata that has been used to generate the response.

done

The final chunk sent before the stream is closed. Example:
{"type": "done"}
{
  "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"}

{"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":{
  "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":"done"}