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

# Agent - Query

### Streaming

##### When streaming is enabled, the endpoint will emit events "answer" (answer of the model) and "endpoint\_response" (full response of the endpoint)

```js theme={null}
import {
  EventStreamContentType,
  fetchEventSource,
} from '@microsoft/fetch-event-source';

let buffer = '';
let bufferEndpointResponse = '';
const ctrl = new AbortController();

await fetchEventSource(queryAgentURL, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        signal: ctrl.signal,
        body: JSON.stringify({
          streaming: true,
          query,
          conversationId,
          visitorId,
        }),

        async onopen(response) {
          if (response.status === 402) {
            throw new ApiError(ApiErrorType.USAGE_LIMIT);
          }
        },
        onmessage: (event) => {
          if (event.data === '[DONE]') {
            // End of stream
            ctrl.abort();

            try {
              const { sources, conversationId, visitorId } = JSON.parse(
                bufferEndpointResponse
              ) as ChatResponse;
            } catch {}
          } else if (event.data?.startsWith('[ERROR]')) {
            // ...
          } else if (event.event === "endpoint_response") {
            bufferEndpointResponse += event.data;
          } else if (event.event === "answer") {
            buffer += event.data;
            // ...
          }
       },
  });
```


## OpenAPI

````yaml POST /agents/query/{id}
openapi: 3.0.1
info:
  title: RapidAgent.ai - API OpenAPI specifications
  description: ''
  termsOfService: https://rapidagent.ai/terms
  contact:
    email: support@rapidagent.ai
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.0
servers:
  - url: https://api.chaindesk.ai
security:
  - bearerAuth: []
tags:
  - name: agents
  - name: datastores
  - name: datasources
paths:
  /agents/query/{id}:
    post:
      tags:
        - agents
      summary: This let you query your agent for a specific query.
      parameters:
        - in: path
          name: id
          schema:
            type: string
            description: ID of the agent
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                query:
                  type: string
                  description: This is the query you want to ask your agent.
                conversationId:
                  type: string
                  description: >-
                    ID of the conversation (If not provided a new conversation
                    is created)
                visitorId:
                  type: string
                  description: >-
                    ID of the participant that's sending the query (If not
                    provided a new ID is created)
                temperature:
                  type: number
                  description: Temperature of the model (min 0.0, max 1.0)
                streaming:
                  type: boolean
                  description: Enable streaming
                promptType:
                  description: Set the prompt type for this query
                  enum:
                    - raw
                    - customer_support
                promptTemplate:
                  type: string
                  description: Set the prompt template for this query
                filters:
                  type: object
                  properties:
                    custom_ids:
                      type: array
                      description: Filter by Custom IDs
                      items:
                        type: string
                    datasource_ids:
                      type: array
                      description: Filter by Datasource IDs
                      items:
                        type: string
              required:
                - query
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                properties:
                  answer:
                    type: string
                    description: The answer of the agent.
                  conversationId:
                    type: string
                    description: ID of the conversation
                  visitorId:
                    type: string
                    description: ID of the participant that's sending the query
                  sources:
                    type: array
                    items:
                      type: object
                      description: Datasource chunks that were used to generate the answer
        '400':
          description: Invalid body
        '403':
          description: Unauthorized
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````