> ## Documentation Index
> Fetch the complete documentation index at: https://docs.libraria.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a query

> Make queries to a specific chatbot / library

## Parameters

<ParamField path="library_id" type="string" required={true}>
  The ID of the library you are going to ask a question
</ParamField>

## Body

<ParamField body="query" type="string" required={true}>
  The question you will make to the library.
</ParamField>

<ParamField body="conversationId" type="string | null">
  Optional. Use this for a continuation of the conversation. You will receive a conversation id on the first query you send.
</ParamField>

<ParamField body="streaming" type="boolean | null">
  Optional. Whether or not you want to receive a streamed response. Default value is False.
</ParamField>

## 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

<ResponseField name="reply" type="string" required={true}>
  The response from the library for the query provided in the request body
</ResponseField>

<ResponseField name="conversationId" type="string" required={true}>
  Use this in follow-up requests for a continuation of the conversation. You will receive a conversation id on the first query you send.
</ResponseField>

<ResponseField name="metadata" type="json" required={true}>
  A map containing data used to generate the query response. It provides additional sources of information to the reply.

  <Expandable title="content">
    <ResponseField name="documents" type="array" />

    <ResponseField name="images" type="array" />

    <ResponseField name="helpArticles" type="array" />
  </Expandable>
</ResponseField>

### 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

<ResponseField name="type" type="string" required={true}>
  Specifies the type of the chunk that is being sent

  Possible values are: **initializing**, **token**, **response**, **done**
</ResponseField>

#### `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.

<ResponseField name="value" type="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"}
  ```
</ResponseField>

#### `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.

<ResponseField name="data" type="json">
  A json object containing the final response and additional metadata that has been used to generate the response.

  <Expandable title="content">
    <ResponseField name="response" type="string" required={true}>
      The final response, it represents all tokens previously sent concatenated
    </ResponseField>

    <ResponseField name="conversationId" type="string" required={true}>
      Use this in follow-up requests for a continuation of the conversation. You will receive a conversation id on the first query you send.
    </ResponseField>

    <ResponseField name="metadata" type="json" required={true}>
      A map containing data used to generate the query response. It provides additional sources of information to the reply.

      <Expandable title="content">
        <ResponseField name="documents" type="array" />

        <ResponseField name="images" type="array" />

        <ResponseField name="helpArticles" type="array" />
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

#### done

The final chunk sent before the stream is closed.

Example:

```
{"type": "done"}
```

<ResponseExample>
  ```json Example Non-Streamed Response
  {
    "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"
    		}
        ]
    }
  }
  ```

  ```json Example Streamed Response
  {"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"}
  ```
</ResponseExample>
