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

# Query document(s) with an AI agent (synchronous)

> Run the full document agent against one or more indexed PDFs or documents. The agent uses tools (search, read sections, read pages) to research the document(s) and produce a comprehensive answer with citations. Supports optional structured output via json_schema.

**This endpoint is synchronous and holds the HTTP connection for the entire agent run (typically 1-10 minutes).** For production workloads or anything that may run longer, use POST /document/agent/jobs instead — it returns a job_id immediately and lets you poll or stream results without an HTTP connection limit.



## OpenAPI

````yaml /openapi-docs.yaml post /document/agent
openapi: 3.1.0
info:
  title: Nia AI API
  version: 1.1.0
  description: >-
    Nia AI API provides a single, consistent `sources` resource for all indexed
    content.


    ## Core Resources


    **Sources** (`/sources`)

    - `repository`

    - `documentation`

    - `research_paper`

    - `huggingface_dataset`

    - `local_folder`


    **Search** (`/search`)

    - `mode`: query | web | deep | universal


    Legacy endpoints are deprecated and will be removed in a future version.
    Prefer `/sources` and `/search` for new integrations.
servers:
  - url: https://apigcp.trynia.ai/v2
    description: Production API
  - url: http://localhost:8000/v2
    description: Local development
security:
  - ApiKeyAuth: []
tags:
  - name: Auth
    description: API-first signup, login, and API key bootstrapping
  - name: Sources
    description: >-
      Unified source management (repositories, documentation, papers, datasets,
      local folders)
  - name: Search
    description: Unified search endpoint with mode discriminator
  - name: Context Sharing
    description: Cross-agent context management and retrieval
  - name: Categories
    description: Category management for organizing indexed sources
  - name: GitHub Search
    description: Live GitHub search and repository exploration
  - name: Advisor
    description: Context-aware code advisor against indexed documentation
  - name: Dependencies
    description: Dependency analysis and documentation subscription
  - name: Usage
    description: Usage tracking and bulk operations
paths:
  /document/agent:
    post:
      tags:
        - Usage
      summary: Query document(s) with an AI agent (synchronous)
      description: >-
        Run the full document agent against one or more indexed PDFs or
        documents. The agent uses tools (search, read sections, read pages) to
        research the document(s) and produce a comprehensive answer with
        citations. Supports optional structured output via json_schema.


        **This endpoint is synchronous and holds the HTTP connection for the
        entire agent run (typically 1-10 minutes).** For production workloads or
        anything that may run longer, use POST /document/agent/jobs instead — it
        returns a job_id immediately and lets you poll or stream results without
        an HTTP connection limit.
      operationId: document_query_v2_document_agent_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DocumentQueryRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentQueryResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    DocumentQueryRequest:
      properties:
        source_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Source Id
          description: Data source ID of a single indexed document
        source_ids:
          anyOf:
            - items:
                type: string
              type: array
              maxItems: 50
            - type: 'null'
          title: Source Ids
          description: List of data source IDs for multi-document queries (max 50)
        query:
          type: string
          maxLength: 10000
          minLength: 1
          title: Query
          description: Question to ask about the document(s)
        json_schema:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Json Schema
          description: JSON Schema for structured output
        model:
          type: string
          title: Model
          description: Model to use (claude-opus-4-7, claude-sonnet-4-5-20250929, etc.)
          default: claude-opus-4-7
        thinking_enabled:
          type: boolean
          title: Thinking Enabled
          description: Enable extended thinking
          default: true
        thinking_budget:
          type: integer
          maximum: 50000
          minimum: 1000
          title: Thinking Budget
          description: >-
            Token budget for thinking (ignored for adaptive models like Opus
            4.7)
          default: 10000
        stream:
          type: boolean
          title: Stream
          description: Stream response as SSE events
          default: false
      type: object
      required:
        - query
      title: DocumentQueryRequest
      description: Request for the v2 document/agent endpoint.
    DocumentQueryResponse:
      properties:
        answer:
          type: string
          title: Answer
        citations:
          items:
            $ref: '#/components/schemas/DocumentCitation'
          type: array
          title: Citations
        structured_output:
          anyOf:
            - {}
            - type: 'null'
          title: Structured Output
        model:
          type: string
          title: Model
        usage:
          anyOf:
            - additionalProperties:
                type: integer
              type: object
            - type: 'null'
          title: Usage
      type: object
      required:
        - answer
        - model
      title: DocumentQueryResponse
      description: Response from the v2 document/agent endpoint.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    DocumentCitation:
      properties:
        content:
          type: string
          title: Content
        page_number:
          anyOf:
            - type: integer
            - type: 'null'
          title: Page Number
        section_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Section Id
        section_title:
          anyOf:
            - type: string
            - type: 'null'
          title: Section Title
        section_path:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Section Path
        tool_source:
          type: string
          title: Tool Source
        source_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Source Id
        source_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Source Name
      type: object
      required:
        - content
        - tool_source
      title: DocumentCitation
      description: A citation from the document agent with full location metadata.
    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
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key must be provided in the Authorization header

````