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

# Answer API - Stream responses in real-time

> Stream search results and AI responses in real-time using Server-Sent Events (SSE). Does not support JSON structured output.



## OpenAPI

````yaml post /api/v2/answer_stream
openapi: 3.0.0
info:
  title: LLMLayer API
  version: 2.0.0
  description: >-
    The Web API for AI Agents - Search, scrape, extract content, crawl websites,
    and generate AI-powered answers with multiple LLMs
servers:
  - url: https://api.llmlayer.dev
security: []
tags:
  - name: Answer API
    description: >-
      Web-enhanced AI responses combining search with multiple LLM models.
      Supports streaming, custom prompts, and structured JSON output.
  - name: Web Search
    description: >-
      Direct web search across multiple content types (general, news, shopping,
      videos, images, scholar) without AI processing.
  - name: Content Extraction
    description: >-
      Extract content from websites, PDFs, and YouTube videos in multiple
      formats.
  - name: Web Crawling
    description: >-
      Map websites and crawl multiple pages with depth control. Supports
      streaming with markdown output.
paths:
  /api/v2/answer_stream:
    post:
      tags:
        - Answer API
      summary: Answer API - Stream responses in real-time
      description: >-
        Stream search results and AI responses in real-time using Server-Sent
        Events (SSE). Does not support JSON structured output.
      operationId: answerStream
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequest'
      responses:
        '200':
          description: Server-Sent Events stream
          content:
            text/event-stream:
              schema:
                type: string
                description: >-
                  SSE stream with event types: sources, images, answer, usage,
                  done, error
              examples:
                sources_event:
                  value: >+
                    data: {"type":"sources","data":[{"title":"Y
                    Combinator","link":"https://www.ycombinator.com","snippet":"..."}]}

                images_event:
                  value: >+
                    data:
                    {"type":"images","data":[{"title":"Image","imageUrl":"https://..."}]}

                answer_event:
                  value: >+
                    data: {"type":"answer","content":"This is part of the
                    answer..."}

                usage_event:
                  value: >+
                    data:
                    {"type":"usage","input_tokens":1500,"output_tokens":800,"model_cost":0.0025,"llmlayer_cost":0.004}

                done_event:
                  value: |+
                    data: {"type":"done","response_time":"3.45"}

        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - BearerAuth: []
components:
  schemas:
    SearchRequest:
      type: object
      required:
        - query
        - model
      properties:
        query:
          type: string
          description: The search query or question to answer
          example: What are the latest developments in quantum computing?
        model:
          type: string
          description: >-
            LLM model to use (e.g., llmlayer-web, llmlayer-fast,
            openai/gpt-4o-mini, openai/gpt-5.1)
          example: llmlayer-web
        location:
          type: string
          default: us
          description: Country code for localized search results (us, uk, ca, etc.)
          example: us
        provider_key:
          type: string
          nullable: true
          description: >-
            Deprecated. Accepted for backward compatibility but currently
            ignored by the API.
        system_prompt:
          type: string
          nullable: true
          description: >-
            Custom system prompt to override default behavior. Use this to
            customize how the LLM processes the search results.
        response_language:
          type: string
          default: auto
          description: >-
            Language for the response. 'auto' detects from query, or specify
            language code (en, es, fr, etc.)
          example: auto
        answer_type:
          type: string
          enum:
            - markdown
            - html
            - json
          default: markdown
          description: >-
            Format of the response. Use 'json' with json_schema for structured
            output.
        search_type:
          type: string
          enum:
            - general
            - news
          default: general
          description: Type of web search to perform. 'news' provides recent news articles.
        json_schema:
          type: string
          nullable: true
          description: >-
            JSON schema as string for structured responses. Required when
            answer_type='json'. The LLM will format its response according to
            this schema.
          example: >-
            {"type":"object","properties":{"summary":{"type":"string"},"key_points":{"type":"array","items":{"type":"string"}}}}
        citations:
          type: boolean
          default: false
          description: Include inline citations [1], [2] in the response text
        return_sources:
          type: boolean
          default: false
          description: Return the source documents used for answer generation
        return_images:
          type: boolean
          default: false
          description: Return relevant images from image search. Adds $0.001 to cost.
        date_filter:
          type: string
          enum:
            - anytime
            - hour
            - day
            - week
            - month
            - year
          default: anytime
          description: Filter search results by recency. Useful for time-sensitive queries.
        max_tokens:
          type: integer
          default: 1500
          minimum: 1
          description: Maximum tokens in the LLM response. Affects cost.
        temperature:
          type: number
          default: 0.7
          minimum: 0
          maximum: 2
          description: >-
            Controls response randomness. 0=deterministic, 2=very creative. Not
            supported by all models.
        domain_filter:
          type: array
          items:
            type: string
          nullable: true
          description: >-
            Include or exclude specific domains. Use '-' prefix to exclude
            (e.g., ['-reddit.com', 'wikipedia.org'])
          example:
            - wikipedia.org
            - '-reddit.com'
        max_queries:
          type: integer
          default: 1
          minimum: 1
          maximum: 4
          description: >-
            Number of search queries to generate from the user query. More
            queries = broader search and higher LLMLayer fee. Token-priced
            models use $0.004 per query; fixed-price LLMLayer models use their
            model-specific per-query price.
          example: 3
        search_context_size:
          type: string
          enum:
            - low
            - medium
            - high
          default: medium
          description: >-
            Amount of search context to extract and pass to LLM. 'high' provides
            more context but uses more tokens.
    ErrorResponse:
      type: object
      required:
        - detail
      properties:
        detail:
          type: object
          required:
            - error_type
            - error_code
            - message
          properties:
            error_type:
              type: string
              enum:
                - validation_error
                - authentication_error
                - provider_error
                - rate_limit
                - internal_error
                - scraping_error
                - search_error
                - map_error
              description: Category of error
            error_code:
              type: string
              description: Specific error code for programmatic handling
              example: missing_query
            message:
              type: string
              description: Human-readable error message
            details:
              type: object
              additionalProperties: true
              nullable: true
              description: Additional error context and debugging information
  responses:
    BadRequest:
      description: Invalid request parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missing_query:
              value:
                detail:
                  error_type: validation_error
                  error_code: missing_query
                  message: Query parameter cannot be empty
            missing_json_schema:
              value:
                detail:
                  error_type: validation_error
                  error_code: missing_json_schema
                  message: JSON schema is required for JSON response type
            invalid_max_pages:
              value:
                detail:
                  error_type: validation_error
                  error_code: invalid_max_pages
                  message: max_pages must be between 1 and 100
    Unauthorized:
      description: Authentication error - missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            detail:
              error_type: authentication_error
              error_code: missing_llmlayer_api_key
              message: 'Provide LLMLayer API key via ''Authorization: Bearer <token>'''
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            unexpected_error:
              value:
                detail:
                  error_type: internal_error
                  error_code: unexpected_error
                  message: An unexpected error occurred. Please try again later
            scraping_error:
              value:
                detail:
                  error_type: scraping_error
                  error_code: url_scrape_failed
                  message: Failed to scrape content from the provided URL
                  details:
                    url: https://www.ycombinator.com
                    error: Connection timeout
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer token authentication using your LLMLayer API key. Include in
        Authorization header as: Bearer YOUR_LLMLAYER_API_KEY

````