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

# Agent Response (Stream)

> Answer a natural-language question from corporate disclosures, streamed as Server-Sent Events, so you can show progress and the answer as it is written.

    Each event is a `data:` line holding a JSON object. Its `type` is one of:
    - `thinking`: a progress update, with a `stage`
    - `message`: the next piece of the answer
    - `content_final`: the complete answer; when present, it replaces the text built from `message` events
    - `sources`: the `sourceMap`, mapping each citation to its passage, page and excerpt
    - `warning`: a non-fatal issue, such as no relevant documents being found
    - `done`: the end of the stream



## OpenAPI

````yaml POST /api/v2/rag/agent-response-stream
openapi: 3.1.0
info:
  title: Captide REST API
  description: >-
    API for accessing financial disclosures and AI-powered financial document
    analysis.
  version: 0.3.14
servers:
  - url: https://rest-api.captide.co
    description: Prod server
security: []
paths:
  /api/v2/rag/agent-response-stream:
    post:
      tags:
        - Retrieval Augmented Generation
      summary: Stream agent response
      description: >-
        Answer a natural-language question from corporate disclosures, streamed
        as Server-Sent Events, so you can show progress and the answer as it is
        written.

            Each event is a `data:` line holding a JSON object. Its `type` is one of:
            - `thinking`: a progress update, with a `stage`
            - `message`: the next piece of the answer
            - `content_final`: the complete answer; when present, it replaces the text built from `message` events
            - `sources`: the `sourceMap`, mapping each citation to its passage, page and excerpt
            - `warning`: a non-fatal issue, such as no relevant documents being found
            - `done`: the end of the stream
      operationId: agent_response_stream_api_v2_rag_agent_response_stream_post
      parameters:
        - name: X-Langfuse-Trace-Id
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Langfuse-Trace-Id
        - name: X-Langfuse-Parent-Span-Id
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Langfuse-Parent-Span-Id
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentRequest'
        required: true
      responses:
        '200':
          description: >-
            Server-Sent Events: thinking, message, content_final, sources,
            warning, done
          content:
            text/event-stream:
              example: >+
                data: {"type": "thinking", "role": "assistant", "content":
                "Identifying companies from your query...", "stage": "search"}


                data: {"type": "thinking", "role": "assistant", "content":
                "Selecting documents for Zscaler, Inc....", "stage":
                "document_selection"}


                data: {"type": "thinking", "role": "assistant", "content":
                "Found 5 relevant pages.", "stage": "analyzing"}


                data: {"type": "message", "role": "assistant", "content": "Z"}


                data: {"type": "message", "role": "assistant", "content":
                "scaler"}


                ...


                data: {"type": "content_final", "role": "assistant", "content":
                "Zscaler’s net dollar retention was **115%** in Q4 FY2026
                [#43c00004]. …"}


                data: {"type": "sources", "content": {"#43c00004": {"content":
                "…", "pageNumber": 5, "excerpt": "115%", "documentMetadata":
                {"id": "a0dcd3e7-7985-4fbc-9c77-371b4232e242", "title":
                "Zscaler, Inc. Earnings Call Transcript Q4 2026 (2026-09-03)",
                …}}}}


                data: {"type": "done"}

        '401':
          description: Missing or invalid API key
          content:
            application/json:
              examples:
                missing_key:
                  summary: Missing API key
                  value:
                    detail: Missing API key
                invalid_key:
                  summary: Invalid or expired API key
                  value:
                    detail: Invalid or expired API key
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: Not enough API credits for this request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                insufficient_credits:
                  summary: 'Insufficient credits. Required: 10 cents, Available: 4 cents'
                  value:
                    detail: >-
                      Insufficient credits. Required: 10 cents, Available: 4
                      cents
        '403':
          description: Your organization doesn't have access to this endpoint
          content:
            application/json:
              examples:
                forbidden:
                  summary: Access to this endpoint is not allowed for your organization
                  value:
                    detail: >-
                      Access to this endpoint is not allowed for your
                      organization
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: >-
            Validation error: a parameter or body field is missing, has the
            wrong type or is out of range
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'
              example:
                detail:
                  - type: missing
                    loc:
                      - body
                    msg: Field required
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              examples:
                rate_limited:
                  summary: 'Rate limit exceeded: 100 requests per minute'
                  value:
                    detail: 'Rate limit exceeded: 100 requests per minute'
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              examples:
                database_error:
                  summary: Database error occurred
                  value:
                    detail: Database error occurred
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - APIKeyHeader: []
components:
  schemas:
    AgentRequest:
      properties:
        query:
          type: string
          minLength: 1
          title: Query
          description: The natural language query
        documentIds:
          anyOf:
            - type: string
            - type: 'null'
          title: Documentids
          description: >-
            Comma-separated string of document file IDs. If provided and
            non-empty, skips document and company selection and goes directly to
            retrieval.
      type: object
      required:
        - query
      title: AgentRequest
      description: Request model for agent queries.
    ErrorResponse:
      properties:
        detail:
          type: string
          title: Detail
      type: object
      required:
        - detail
      title: ErrorResponse
      description: Standard error response model for all API endpoints.
    ValidationErrorResponse:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
          type: array
          title: Detail
      type: object
      required:
        - detail
      title: ValidationErrorResponse
      description: '422 body: every invalid field of the request.'
    ValidationErrorItem:
      properties:
        type:
          type: string
          title: Type
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Loc
        msg:
          type: string
          title: Msg
        input:
          anyOf:
            - {}
            - type: 'null'
          title: Input
        ctx:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Ctx
      type: object
      required:
        - type
        - loc
        - msg
      title: ValidationErrorItem
      description: One invalid field, as FastAPI reports it.
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.