> ## 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 - Web-enhanced AI responses

> Search the web and generate AI-powered answers using your chosen LLM model. Supports multiple search queries, custom prompts, and structured JSON output.



## OpenAPI

````yaml post /api/v2/answer
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:
    post:
      tags:
        - Answer API
      summary: Answer API - Web-enhanced AI responses
      description: >-
        Search the web and generate AI-powered answers using your chosen LLM
        model. Supports multiple search queries, custom prompts, and structured
        JSON output.
      operationId: answer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequest'
      responses:
        '200':
          description: Successful response with AI-generated answer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimitError'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '502':
          $ref: '#/components/responses/ProviderError'
      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.
    SearchResponse:
      type: object
      required:
        - answer
        - response_time
        - input_tokens
        - output_tokens
        - llmlayer_cost
      properties:
        answer:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
          description: >-
            The AI-generated answer. String for markdown/html, object for JSON
            responses.
        sources:
          type: array
          items:
            $ref: '#/components/schemas/Source'
          description: Source documents used (only when return_sources=true)
        images:
          type: array
          items:
            $ref: '#/components/schemas/Image'
          description: Relevant images (only when return_images=true)
        response_time:
          type: string
          description: Total processing time in seconds
          example: '2.34'
        input_tokens:
          type: integer
          description: >-
            Total input tokens processed (includes query generation + main LLM
            call + internal system prompts)
        output_tokens:
          type: integer
          description: >-
            Total output tokens generated (includes query generation + main LLM
            response)
        model_cost:
          type: number
          nullable: true
          description: Cost in USD for LLM usage. Null for fixed-price LLMLayer models.
        llmlayer_cost:
          type: number
          description: >-
            Cost in USD for LLMLayer search infrastructure. Base cost varies by
            max_queries and return_images.
    Source:
      type: object
      properties:
        title:
          type: string
          description: Title of the source document
        link:
          type: string
          format: uri
          description: URL of the source
        snippet:
          type: string
          description: Relevant excerpt from the source
      additionalProperties: true
    Image:
      type: object
      properties:
        title:
          type: string
          description: Image title or alt text
        imageUrl:
          type: string
          format: uri
          description: Direct URL to full-size image
        thumbnailUrl:
          type: string
          format: uri
          description: URL to thumbnail version
        source:
          type: string
          description: Source website domain
        link:
          type: string
          format: uri
          description: URL of page containing the image
      additionalProperties: true
    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>'''
    RateLimitError:
      description: Rate limit exceeded or insufficient credits
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            provider_rate_limit:
              value:
                detail:
                  error_type: provider_error
                  error_code: openai_rate_limit
                  message: Rate limit exceeded for openai. Please try again later
                  details:
                    provider: openai
    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
    ProviderError:
      description: >-
        LLM provider error (authentication, rate limit, or general provider
        failure)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            auth_error:
              value:
                detail:
                  error_type: provider_error
                  error_code: openai_auth_error
                  message: >-
                    Authentication failed for openai. Please check your provider
                    API key
                  details:
                    provider: openai
            provider_error:
              value:
                detail:
                  error_type: provider_error
                  error_code: openai_500
                  message: Error from openai provider
                  details:
                    provider: openai
                    status: 500
                    model: openai/gpt-4o-mini
  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

````