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

# Run AutoRAG agent with streaming response

> Uses the AutoRAG agent to answer a question about any data that the user can access.
Returns results as a Server-Sent Events (SSE) stream with incremental updates.

The stream emits the following event types in order:
- `plan`: The execution plan with a list of steps to be performed.
- `step`: One event per step, containing the instruction, query, and result data.
- `answer`: The final synthesized answer to the user's question.
- `error`: Emitted if an error occurs during processing (instead of answer).




## OpenAPI

````yaml /api-reference/openapi.yml post /query/ask
openapi: 3.0.3
info:
  title: DataLinks
  version: 2.2.3
servers:
  - url: https://api.datalinks.com/api/v1
    description: production server
security:
  - bearerAuth: []
  - openId:
      - implicit
paths:
  /query/ask:
    post:
      tags:
        - autorag
      summary: Run AutoRAG agent with streaming response
      description: >
        Uses the AutoRAG agent to answer a question about any data that the user
        can access.

        Returns results as a Server-Sent Events (SSE) stream with incremental
        updates.


        The stream emits the following event types in order:

        - `plan`: The execution plan with a list of steps to be performed.

        - `step`: One event per step, containing the instruction, query, and
        result data.

        - `answer`: The final synthesized answer to the user's question.

        - `error`: Emitted if an error occurs during processing (instead of
        answer).
      operationId: autoragStream
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AutoRagRequest'
        required: true
      responses:
        '200':
          $ref: '#/components/responses/AutoRagStreamResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    AutoRagRequest:
      required:
        - namespace
        - query
        - username
      type: object
      properties:
        username:
          type: string
        namespace:
          type: string
        query:
          type: string
          example: What do llamas drink to cool themselves down?
        helperPrompt:
          type: string
          example: You're a prophet of the alpacalypse. Your task is to spit the word!
        model:
          type: string
        provider:
          type: string
        conversationId:
          type: string
          description: >-
            Existing conversation to continue. Omit to start a new conversation;
            the id is returned on the run-started SSE event.
    AutoRagStreamEvent:
      oneOf:
        - $ref: '#/components/schemas/AutoRagPlanEvent'
        - $ref: '#/components/schemas/AutoRagStepEvent'
        - $ref: '#/components/schemas/AutoRagAnswerEvent'
        - $ref: '#/components/schemas/AutoRagErrorEvent'
        - $ref: '#/components/schemas/AutoRagPlanningStartedEvent'
        - $ref: '#/components/schemas/AutoRagStepStartedEvent'
        - $ref: '#/components/schemas/AutoRagQueryExecutingEvent'
        - $ref: '#/components/schemas/AutoRagAnswerStartedEvent'
    ErrorResponse:
      required:
        - error_code
        - message
      type: object
      properties:
        error_code:
          type: string
          example: UNAUTHORIZED
        error_message:
          type: string
          example: ''
        message:
          type: string
          example: Missing authentication token
        sub_errors:
          type: array
          items:
            required:
              - code
              - message
            type: object
            properties:
              code:
                type: string
              message:
                type: string
    AutoRagPlanEvent:
      required:
        - reasoning
        - steps
      type: object
      properties:
        steps:
          type: array
          description: List of step descriptions that will be executed.
          items:
            type: string
        reasoning:
          type: string
          description: The reasoning produced by the LLM when generating the plan.
      description: SSE event containing the execution plan. Event name is "plan".
    AutoRagStepEvent:
      required:
        - data
        - index
        - instruction
        - query
        - reasoning
      type: object
      properties:
        index:
          type: integer
          description: Zero-based index of this step in the plan.
        instruction:
          type: string
          description: The instruction generated and executed for this step.
        query:
          type: string
          description: The query derived from the instruction.
        reasoning:
          type: string
          description: >-
            The reasoning produced by the LLM when generating the query for this
            step.
        data:
          $ref: '#/components/schemas/DataArray'
      description: >-
        SSE event containing the result of a single execution step. Event name
        is "step".
    AutoRagAnswerEvent:
      required:
        - response
      type: object
      properties:
        response:
          type: string
          description: The final synthesized answer to the user's question.
      description: SSE event containing the final answer. Event name is "answer".
    AutoRagErrorEvent:
      required:
        - message
      type: object
      properties:
        message:
          type: string
          description: Error message describing what went wrong.
      description: SSE event emitted when an error occurs. Event name is "error".
    AutoRagPlanningStartedEvent:
      type: object
      description: >-
        SSE lifecycle event signalling that the agent has started planning.
        Event name is "planningStarted". The event name carries the meaning; the
        body is an empty object.
    AutoRagStepStartedEvent:
      required:
        - index
        - instruction
      type: object
      properties:
        index:
          type: integer
          description: Zero-based index of the step that just started.
        instruction:
          type: string
          description: The plan instruction for this step.
      description: >-
        SSE lifecycle event signalling that a plan step has started. Event name
        is "stepStarted".
    AutoRagQueryExecutingEvent:
      required:
        - index
      type: object
      properties:
        index:
          type: integer
          description: Zero-based index of the step whose query is executing.
      description: >-
        SSE lifecycle event signalling that the query for a step is now
        executing against the data. Event name is "queryExecuting".
    AutoRagAnswerStartedEvent:
      type: object
      description: >-
        SSE lifecycle event signalling that the agent has started generating the
        final answer. Event name is "answerStarted". The event name carries the
        meaning; the body is an empty object.
    DataArray:
      type: array
      description: Array of ontology data objects retrieved from queries.
      items:
        type: object
        additionalProperties: true
  responses:
    AutoRagStreamResponse:
      description: SSE stream of AutoRAG execution events.
      content:
        text/event-stream:
          schema:
            $ref: '#/components/schemas/AutoRagStreamEvent'
    Unauthorized:
      description: >-
        Unauthorized. This error occurs if the authentication token is missing
        or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      description: >
        Use a Bearer token for authentication. Submit the token using the
        `Authorization`

        header: `Authorization: Bearer <token>`.
      scheme: bearer
    openId:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: >-
            https://login.datalinks.com/realms/datalinks-realm/protocol/openid-connect/auth
          scopes:
            openid: openid

````