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

> Given a query and an optional conversation id, get a response from your 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 equal to 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}>
  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.
</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 equal to **true** the response is sent as a series of chunk where each of them will be a JSON object.

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

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

<ResponseField name="data" type="json | null">
  It only appears when `type == response`.

  A json object containing the final response and metadata for the gptQuery.

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

    <ResponseField name="text" type="string">
      The final response, it represents all tokens previously sent concatenated
    </ResponseField>

    <ResponseField name="gptQuery" type="json">
      <Expandable title="content">
        <ResponseField name="response" type="string" />

        <ResponseField name="text" type="string" />

        <ResponseField name="gptQuery" type="json" />
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<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","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"}
  ```
</ResponseExample>
