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

# Chat with documents

> Grounded question-answering over the indexed documents in your environment. Returns an answer plus structured citations back to the source files.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/chat
openapi: 3.1.0
info:
  title: Memic API
  description: >-
    Memic is a memory layer for AI applications. The Memic API lets you ingest
    documents, run semantic search and chat, and manage prompts — all scoped to
    an environment via a single API key.
  version: 1.0.0
servers:
  - url: https://api.memic.ai
    description: Production
security:
  - MemicApiKey: []
tags:
  - name: Endpoints
    description: All 10 Memic API endpoints.
paths:
  /api/v1/chat:
    post:
      tags:
        - Endpoints
      summary: Chat with documents
      description: >-
        Grounded question-answering over the indexed documents in your
        environment. Returns an answer plus structured citations back to the
        source files.
      operationId: chat
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - MemicApiKey: []
components:
  schemas:
    ChatRequest:
      properties:
        question:
          type: string
          maxLength: 1000
          minLength: 1
          title: Question
          description: User question
        project_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Project Id
          description: Optional project filter for semantic search
        file_ids:
          anyOf:
            - items:
                type: string
                format: uuid
              type: array
            - type: 'null'
          title: File Ids
          description: Optional file filter for semantic search
        connector_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Connector Id
          description: Optional connector ID for structured queries
        force_route:
          anyOf:
            - $ref: '#/components/schemas/QueryRouteEnum'
            - type: 'null'
          description: Force a specific route (structured/semantic/hybrid)
        top_k:
          type: integer
          maximum: 20
          minimum: 1
          title: Top K
          description: Number of chunks to retrieve
          default: 5
        min_score:
          type: number
          maximum: 1
          minimum: 0
          title: Min Score
          description: Minimum similarity score
          default: 0.2
      type: object
      required:
        - question
      title: ChatRequest
      description: Request for chat/answer generation with intelligent routing.
    ChatResponse:
      properties:
        question:
          type: string
          title: Question
        answer:
          type: string
          title: Answer
        citations:
          items:
            $ref: '#/components/schemas/Citation'
          type: array
          title: Citations
          default: []
        total_chunks_used:
          type: integer
          title: Total Chunks Used
          default: 0
        search_time_ms:
          type: number
          title: Search Time Ms
        generation_time_ms:
          type: number
          title: Generation Time Ms
        model:
          type: string
          title: Model
        routing:
          anyOf:
            - $ref: '#/components/schemas/RoutingInfo'
            - type: 'null'
          description: How the query was routed
        results:
          $ref: '#/components/schemas/SearchResults'
          description: >-
            Search results (semantic and/or structured) - same structure as
            SearchResponse
      type: object
      required:
        - question
        - answer
        - search_time_ms
        - generation_time_ms
        - model
      title: ChatResponse
      description: Response with LLM-generated answer, citations, and routing info.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    QueryRouteEnum:
      type: string
      enum:
        - structured
        - semantic
        - hybrid
      title: QueryRouteEnum
      description: Query routing options.
    Citation:
      properties:
        chunk_id:
          type: string
          format: uuid
          title: Chunk Id
        file_id:
          type: string
          format: uuid
          title: File Id
        file_name:
          type: string
          title: File Name
        chunk_index:
          type: integer
          title: Chunk Index
        page_number:
          anyOf:
            - type: integer
            - type: 'null'
          title: Page Number
        content_snippet:
          type: string
          title: Content Snippet
        score:
          type: number
          title: Score
        project_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Project Id
          description: Project ID for fetching file
        bounding_boxes:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Bounding Boxes
          description: >-
            Bounding boxes for highlighting: {content_id: {page: [x1, y1, x3,
            y3]}}
        blob_storage_path:
          anyOf:
            - type: string
            - type: 'null'
          title: Blob Storage Path
          description: Path to full chunk JSON in blob storage
      type: object
      required:
        - chunk_id
        - file_id
        - file_name
        - chunk_index
        - content_snippet
        - score
      title: Citation
      description: Citation linking answer to source chunk.
    RoutingInfo:
      properties:
        route:
          type: string
          title: Route
          description: 'Route used: structured, semantic, or hybrid'
        reasoning:
          anyOf:
            - type: string
            - type: 'null'
          title: Reasoning
          description: Why this route was chosen
        connector_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Connector Id
          description: Connector used for structured query
        connector_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Connector Name
          description: Name of connector used
        sql_generated:
          anyOf:
            - type: string
            - type: 'null'
          title: Sql Generated
          description: SQL query generated (if structured)
        sql_explanation:
          anyOf:
            - type: string
            - type: 'null'
          title: Sql Explanation
          description: Explanation of SQL query
      type: object
      required:
        - route
      title: RoutingInfo
      description: Information about how the query was routed.
    SearchResults:
      properties:
        semantic:
          items:
            $ref: '#/components/schemas/SearchResultChunk'
          type: array
          title: Semantic
          description: Semantic search results from vector store
          default: []
        structured:
          anyOf:
            - $ref: '#/components/schemas/StructuredResult'
            - type: 'null'
          description: Structured query results with schema
      type: object
      title: SearchResults
      description: Container for all result types.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    SearchResultChunk:
      properties:
        chunk_id:
          type: string
          format: uuid
          title: Chunk Id
          description: Database chunk ID
        file_id:
          type: string
          format: uuid
          title: File Id
          description: File ID the chunk belongs to
        file_name:
          type: string
          title: File Name
          description: Original filename
        project_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Project Id
          description: Project ID
        content:
          type: string
          title: Content
          description: Chunk text content
        score:
          type: number
          title: Score
          description: Similarity score (0.0 to 1.0)
        chunk_index:
          type: integer
          title: Chunk Index
          description: Index of chunk within file
        page_number:
          anyOf:
            - type: integer
            - type: 'null'
          title: Page Number
          description: Page number if available
        start_page:
          anyOf:
            - type: integer
            - type: 'null'
          title: Start Page
          description: Starting page number
        end_page:
          anyOf:
            - type: integer
            - type: 'null'
          title: End Page
          description: Ending page number
        token_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Token Count
          description: Number of tokens in chunk
        mime_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Mime Type
          description: File MIME type
        category:
          anyOf:
            - type: string
            - type: 'null'
          title: Category
          description: File category
        tags:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Tags
          description: File tags
        document_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Document Type
          description: Document type
        reference_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Reference Id
          description: Client-provided file reference ID
        blob_storage_path:
          anyOf:
            - type: string
            - type: 'null'
          title: Blob Storage Path
          description: Full chunk JSON path in blob storage
        bounding_boxes:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Bounding Boxes
          description: >-
            Bounding boxes for chunk highlighting: {content_id: {page: [x1, y1,
            x3, y3]}}
      type: object
      required:
        - chunk_id
        - file_id
        - file_name
        - content
        - score
        - chunk_index
      title: SearchResultChunk
      description: Individual search result chunk.
    StructuredResult:
      properties:
        columns:
          items:
            $ref: '#/components/schemas/ColumnInfo'
          type: array
          title: Columns
          description: Column metadata for the result set
          default: []
        rows:
          items:
            additionalProperties: true
            type: object
          type: array
          title: Rows
          description: Result rows as key-value objects
          default: []
      type: object
      title: StructuredResult
      description: Structured query results with schema metadata.
    ColumnInfo:
      properties:
        name:
          type: string
          title: Name
          description: Column name
        type:
          type: string
          title: Type
          description: Column data type (e.g., varchar, integer, timestamp)
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          description: Human-readable column description
      type: object
      required:
        - name
        - type
      title: ColumnInfo
      description: Column metadata for structured results.
  securitySchemes:
    MemicApiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        Memic API key. Every key is bound to exactly one environment — get one
        from the Memic dashboard under API Keys.

````