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

# Get context

> Retrieve relevant context from a context workspace based on a prompt. Use includeSources parameter to choose response format.

<Tip>This endpoint retrieves relevant context from the workspace context based on a textual prompt. Understanding how the system processes your prompt is critical to achieving best-in-class results.</Tip>

1. Hybrid search: The file index is first searched to find files that are most relevant to the prompt. This ensures that only the most relevant information is considered for retrieval.
2. The retrieved files are read and returned as sources with their content.


## OpenAPI

````yaml https://api.qontext.ai/docs-json post /v1/retrieval
openapi: 3.0.0
info:
  title: Qontext API
  description: API to ingest and retrieve data to enable contextualised AI.
  version: '1.0'
  contact: {}
servers:
  - url: https://api.qontext.ai
    description: Production
security: []
tags: []
paths:
  /v1/retrieval:
    post:
      tags:
        - Retrieval
      summary: Get context
      description: >-
        Retrieve relevant context from a context workspace based on a prompt.
        Use includeSources parameter to choose response format.
      operationId: RetrievalController_getContext
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContextRequestDto'
      responses:
        '201':
          description: Context successfully retrieved
          content:
            application/json:
              schema:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - $ref: '#/components/schemas/RetrievalResponseDto'
              examples:
                legacy:
                  summary: Legacy format (default, includeSources=false)
                  value:
                    - >-
                      *Harry Potter*: Harry Potter is a contact with email
                      harry@gryffindor.com...
                    - >-
                      *Harry Potter -> Gryffindor Inc. (works_at)*: Harry Potter
                      works at Gryffindor Inc. as Project Lead.
                withSources:
                  summary: With sources (includeSources=true)
                  value:
                    data:
                      - text: >-
                          *Harry Potter*: Harry Potter is a contact with email
                          harry@gryffindor.com...
                        sources:
                          - source_integration: HubSpot
                            source_data_type: Contact
                            source_id: '123'
                            source_url: https://...
                      - text: >-
                          *Harry Potter -> Gryffindor Inc. (works_at)*: Harry
                          Potter works at Gryffindor Inc. as Project Lead.
                        sources:
                          - source_integration: HubSpot
                            source_data_type: Deal
                            source_id: '456'
                            source_url: https://...
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestDto'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorDto'
      security:
        - bearer: []
        - X-API-Key:
            - X-API-Key
components:
  schemas:
    ContextRequestDto:
      type: object
      properties:
        prompt:
          type: string
          description: The prompt to retrieve context for.
          example: >-
            Give me the following information regarding Harry Potter. 1) Who is
            he?, 2) What is his relationship with Gryffindor Inc., Weasleys
            Wizard Wheezes, and Ollivanders?
        limit:
          type: number
          description: Maximum number of files to return in the context response.
          example: 5
      required:
        - prompt
        - limit
    RetrievalResponseDto:
      type: object
      properties:
        data:
          description: The retrieved and relevant context with source information.
          example:
            - text: >-
                *Harry Potter -> Gryffindor Inc. (works_at)*: Harry Potter works
                at Gryffindor Inc. as Project Lead.
              sources:
                - source_integration: HubSpot
                  source_data_type: Deal
                  source_id: deal-123
                  source_url: https://app.hubspot.com/contacts/deals/deal-123
            - text: >-
                *Harry Potter*: Harry Potter is a contact with email
                harry@gryffindor.com; he entered the system on 2025-09-01...
              sources:
                - source_integration: GoogleDrive
                  source_data_type: Doc
                  source_id: doc-456
                  source_url: https://docs.google.com/document/d/doc-456
                - source_integration: HubSpot
                  source_data_type: Contact
                  source_id: contact-123
                  source_url: https://app.hubspot.com/contacts/contacts/contact-123
          type: array
          items:
            $ref: '#/components/schemas/RetrievalItemDto'
      required:
        - data
    BadRequestDto:
      type: object
      properties:
        message:
          description: Array of specific error messages
          example:
            - <error message>
            - <error message>
          type: array
          items:
            type: string
        error:
          type: string
          description: Error Message
          example: Bad Request
        statusCode:
          type: number
          description: Status Code
          example: 400
          default: 400
      required:
        - message
        - error
        - statusCode
    InternalServerErrorDto:
      type: object
      properties:
        error:
          type: string
          description: Error Message
          example: Internal Server Error
        statusCode:
          type: number
          description: Status Code
          example: 500
          default: 500
      required:
        - error
        - statusCode
    RetrievalItemDto:
      type: object
      properties:
        text:
          type: string
          description: Formatted text describing the node or relationship
          example: >-
            *Harry Potter*: Harry Potter is a contact with email
            harry@gryffindor.com...
        sources:
          description: Array of source objects with source, type, ID, and URL
          example:
            - source_integration: GoogleDrive
              source_data_type: Doc
              source_id: 1BxaRkXYZ...FZo
              source_url: https://docs.google.com/document/d/1BxaRkXYZ...FZo
            - source_integration: HubSpot
              source_data_type: Contact
              source_id: contact-123
              source_url: https://app.hubspot.com/contacts/contacts/contact-123
          type: array
          items:
            $ref: '#/components/schemas/SourceInfoDto'
      required:
        - text
        - sources
    SourceInfoDto:
      type: object
      properties:
        source_integration:
          type: string
          description: Source name
          example: GoogleDrive
        source_data_type:
          type: string
          description: Data type
          example: Doc
        source_id:
          type: string
          description: Source identifier
          example: 1BxaRkXYZ...FZo
        source_url:
          type: string
          description: Clickable URL
          example: https://docs.google.com/document/d/1BxaRkXYZ...FZo
      required:
        - source_integration
        - source_data_type
        - source_id
  securitySchemes:
    X-API-Key:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key for the Qontext API

````