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

# Generate a context document

> Generate an LLM-synthesized context document from the app's synced data.

This endpoint is async — it creates a ContextDocument record with status
PROCESSING, starts a Temporal workflow, and returns immediately. The actual
synthesis (which can take 1-15 minutes depending on data volume) happens
in the background via GenerateContextDocumentWorkflow.

The pipeline automatically chooses single-pass or multi-pass mode based
on the total number of resources. See tasks/context_documents.py for
the full pipeline architecture.



## OpenAPI

````yaml https://app.stainlessapi.com/api/spec/documented/hyperspell.yaml post /context-documents/generate
openapi: 3.1.0
info:
  title: Hyperspell API
  summary: >-
    Hyperspell is the memory layer for AI apps and agents. Through the API, you
    can add memories, connect data sources to index them in real-time, and
    search memories with our natural language query engine.
  termsOfService: https://hyperspell.com/blog/tos
  contact:
    name: Hyperspell
    url: https://hyperspell.com/
    email: hello@hyperspell.com
  version: 0.32.1
servers:
  - url: https://api.hyperspell.com
    description: Production
security:
  - APIKey: []
    AsUser: []
paths:
  /context-documents/generate:
    post:
      tags:
        - Context Documents
      summary: Generate a context document
      description: >-
        Generate an LLM-synthesized context document from the app's synced data.


        This endpoint is async — it creates a ContextDocument record with status

        PROCESSING, starts a Temporal workflow, and returns immediately. The
        actual

        synthesis (which can take 1-15 minutes depending on data volume) happens

        in the background via GenerateContextDocumentWorkflow.


        The pipeline automatically chooses single-pass or multi-pass mode based

        on the total number of resources. See tasks/context_documents.py for

        the full pipeline architecture.
      operationId: generate_context_documents_generate_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKey: []
        - AsUser: []
components:
  schemas:
    GenerateRequest:
      properties:
        sources:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Sources
          description: >-
            Integration sources to include (e.g., ['gmail', 'slack']). Defaults
            to all connected integrations.
        user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: User Id
          description: >-
            Scope to a specific user's data (Tier 1). Defaults to all users in
            the app (Tier 3).
        prompt:
          anyOf:
            - type: string
              maxLength: 10000
            - type: 'null'
          title: Prompt
          description: >-
            Custom prompt template. Replaces the default Tier 3 structured
            summary prompt. The formatted resource data is passed as the user
            message regardless of the prompt.
        model:
          type: string
          title: Model
          description: >-
            LLM model for final synthesis. This controls the Stage 2 model in
            multi-pass mode, or the single model in single-pass mode. Stage 1
            extraction always uses Sonnet.
          default: claude-opus-4-6
      type: object
      title: GenerateRequest
      description: |-
        Request body for POST /context-documents/generate.

        All fields are optional. With no fields set, the system will:
        - Include resources from ALL connected integrations
        - Include resources from ALL users in the app (Tier 3)
        - Use the default Tier 3 structured summary prompt
        - Use Claude Opus 4.6 as the final synthesis model

        The `model` field controls the Stage 2 (final synthesis) model.
        Stage 1 (per-source extraction) always uses Sonnet for cost efficiency.
    GenerateResponse:
      properties:
        document_id:
          type: string
          title: Document Id
        status:
          type: string
          title: Status
        created_at:
          type: string
          format: date-time
          title: Created At
      type: object
      required:
        - document_id
        - status
        - created_at
      title: GenerateResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    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:
    APIKey:
      type: http
      description: >-
        API Key or JWT User Token. If using an API Key, set the X-As-User header
        to act as a specific user. A JWT User Token is always scoped to a
        specific user.
      scheme: bearer
      bearerFormat: Bearer <token>
    AsUser:
      type: apiKey
      description: >-
        Optionally set this header to act as a specific user when using an API
        Key, equivalent to first exchanging the API Key for a User Token
      in: header
      name: X-As-User

````