---
title: "Generate a context document"
method: POST
path: "/context-documents/generate"
tags: ["Context Documents"]
---

# Generate a context document

`POST /context-documents/generate`

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

This endpoint is async — it creates a ContextDocument record with status
PROCESSING, emits an Inngest event, and returns immediately. The actual
synthesis (which can take 1-15 minutes depending on data volume) happens
in the background via the generate_context_document Inngest function.

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.

## Request body

- GenerateRequest — 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.
  - `sources` string[], nullable — Integration sources to include (e.g., ['gmail', 'slack']). Defaults to all connected integrations.
  - `user_id` string, nullable — Scope to a specific user's data (Tier 1). Defaults to all users in the app (Tier 3).
  - `prompt` string, nullable — 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` string — 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.

## Response `200`

Successful Response

- GenerateResponse
  - `document_id` string, required
  - `status` string, required
  - `created_at` string, date-time, required

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/hyperspell/apis/hyperspell-api.md) · [All operations](https://skmtc.net/hyperspell/apis/hyperspell-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/hyperspell/hyperspell-api/versions/5721acd588e6/schema)
