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

> Streams cited Markdown responses, sourced exclusively from corporate disclosures, as server-sent events in response to natural language queries. This endpoint provides real-time streaming of AI-generated answers, making it ideal for interactive chat interfaces where users can see responses as they're generated.
    
    **Server-Sent Events (SSE) Structure:**
    
    - **`data: {"type": "thinking", ...}`** - Agent's thinking process with stage information
      - `data: {"type": "thinking", "role": "assistant", "content": "...", "stage": "search"}`
    
    - **`data: {"type": "message", ...}`** - Response content chunks
      - `data: {"type": "message", "role": "assistant", "content": "..."}`
    
    - **`data: {"type": "warning", ...}`** - Warning when no documents found
      - `data: {"type": "warning", "message": "..."}`
    
    - **`data: {"type": "sources", ...}`** - Source document information
      - `data: {"type": "sources", "content": {"#ref_id": {"content": "...", "pageNumber": 123, "excerpt": "...", "documentMetadata": {"id": "...", "title": "...", "documentCategory": "...", "formType": "...", "tickers": ["..."], "companyName": "...", "date": "...", "fiscalQuarter": 1, "fiscalYear": 2025}}}}}` - Document sources and citations
      - `data: {"type": "sources", "content": {"#ref_id": {"content": "...", "pageNumber": 123, "excerpt": null, "documentMetadata": {"id": "...", "title": "...", "documentCategory": "...", "formType": "...", "tickers": ["..."], "companyName": "...", "date": "...", "fiscalQuarter": 1, "fiscalYear": 2025}}}}}` - Document sources and citations (with null excerpt, often given before agent response)
    
    - **`data: {"type": "done"}`** - Stream completion
      - `data: {"type": "done"}`
    
    This v2 endpoint supports newer document categories in source mappings (e.g., earnings-presentation, investor-event-presentation, shareholder-meeting-circular, etc.). Agent response quality is exactly the same compared to v1.



## 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.13
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 (v2)
      description: >-
        Streams cited Markdown responses, sourced exclusively from corporate
        disclosures, as server-sent events in response to natural language
        queries. This endpoint provides real-time streaming of AI-generated
        answers, making it ideal for interactive chat interfaces where users can
        see responses as they're generated.
            
            **Server-Sent Events (SSE) Structure:**
            
            - **`data: {"type": "thinking", ...}`** - Agent's thinking process with stage information
              - `data: {"type": "thinking", "role": "assistant", "content": "...", "stage": "search"}`
            
            - **`data: {"type": "message", ...}`** - Response content chunks
              - `data: {"type": "message", "role": "assistant", "content": "..."}`
            
            - **`data: {"type": "warning", ...}`** - Warning when no documents found
              - `data: {"type": "warning", "message": "..."}`
            
            - **`data: {"type": "sources", ...}`** - Source document information
              - `data: {"type": "sources", "content": {"#ref_id": {"content": "...", "pageNumber": 123, "excerpt": "...", "documentMetadata": {"id": "...", "title": "...", "documentCategory": "...", "formType": "...", "tickers": ["..."], "companyName": "...", "date": "...", "fiscalQuarter": 1, "fiscalYear": 2025}}}}}` - Document sources and citations
              - `data: {"type": "sources", "content": {"#ref_id": {"content": "...", "pageNumber": 123, "excerpt": null, "documentMetadata": {"id": "...", "title": "...", "documentCategory": "...", "formType": "...", "tickers": ["..."], "companyName": "...", "date": "...", "fiscalQuarter": 1, "fiscalYear": 2025}}}}}` - Document sources and citations (with null excerpt, often given before agent response)
            
            - **`data: {"type": "done"}`** - Stream completion
              - `data: {"type": "done"}`
            
            This v2 endpoint supports newer document categories in source mappings (e.g., earnings-presentation, investor-event-presentation, shareholder-meeting-circular, etc.). Agent response quality is exactly the same compared to v1.
      operationId: agent_response_stream_api_v2_rag_agent_response_stream_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentRequest'
        required: true
      responses:
        '200':
          description: Stream started successfully
          content:
            application/json:
              schema: {}
            text/event-stream:
              examples:
                with_sources:
                  summary: Stream with found documents
                  value: >+
                    data: {"type": "thinking", "role": "assistant", "content":
                    "I'm going to look through 3 documents from Apple Inc...",
                    "stage": "search"}


                    data: {"type": "thinking", "role": "assistant", "content":
                    "I found 13 relevant pages from Apple Inc", "stage":
                    "analyzing"}


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


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


                    data: {"type": "message", "role": "assistant", "content":
                    "'s revenue for the fiscal year 2024 was **$391.0
                    billion**."}


                    data: {"type": "sources", "content": {"#7bcd0078":
                    {"pageNumber": 79, "excerpt": "Total net sales $ 124,300",
                    "documentMetadata": {"id":
                    "7bcdbd06-6b2a-460d-9596-626b6bfded3a", "title": "Apple Q1
                    2025 Form 10-Q", "documentCategory":
                    "interim-financial-report", "formType": "10-Q", "tickers":
                    ["AAPL"], "companyName": "Apple Inc.", "date": "2025-01-31",
                    "fiscalQuarter": 1, "fiscalYear": 2025}}}}}}


                    data: {"type": "done"}

                no_sources:
                  summary: Stream when no documents found
                  value: >+
                    data: {"type": "thinking", "role": "assistant", "content":
                    "I'm going to look through 3 documents from Apple Inc.: Net
                    dollar retention (NDR) is a metric typically discussed in
                    the context of SaaS or subscription businesses, and may not
                    be a standard metric reported by Apple Inc. However, if
                    Apple does report or discuss NDR, it would most likely be
                    found in their most recent interim (10-Q) or annual (10-K)
                    reports, as these contain detailed financial and operational
                    metrics. The most recent 10-Qs and the latest 10-K are the
                    best sources to check for any mention or calculation of net
                    dollar retention or related metrics. If not explicitly
                    stated, these documents will provide the necessary revenue
                    and segment data to potentially calculate or estimate NDR if
                    applicable.", "stage": "search"}


                    data: {"type": "thinking", "role": "assistant", "content":
                    "I'm now analyzing 3 documents to find the most relevant
                    information...", "stage": "document_inspection"}


                    data: {"type": "warning", "message": "I couldn't find any
                    relevant information in the selected documents to answer
                    your question."}


                    data: {"type": "done"}

        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              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.
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key

````