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

# Generate

> API reference for the /api/v1/generate endpoint

## Generate Document

### POST /api/v1/generate

Generate documents based on prompts and retrieved context from the knowledge base with optional filtering to control context sources. Similar to chat but optimized for document generation with optional style/format rules.

**Authentication:** Project API Key from [https://platform.useskald.com](https://platform.useskald.com)

**Request (using Project API Key):**

```json theme={null}
{
    "prompt": "Create a product requirements document for a new mobile app",
    "rules": "Use formal business language. Include sections for: Overview, Requirements, Technical Specifications, Timeline",
    "stream": false,
    "filters": [
        {
            "field": "source",
            "operator": "in",
            "value": ["product-specs", "user-research"],
            "filter_type": "native_field"
        },
        {
            "field": "document_type",
            "operator": "eq",
            "value": "specification",
            "filter_type": "custom_metadata"
        }
    ]
}
```

**Request (using Token Authentication):**

```json theme={null}
{
    "prompt": "Create a product requirements document for a new mobile app",
    "project_id": "project-uuid",
    "rules": "Use formal business language. Include sections for: Overview, Requirements, Technical Specifications, Timeline",
    "stream": false,
    "filters": [
        {
            "field": "tags",
            "operator": "in",
            "value": ["mobile", "product"],
            "filter_type": "native_field"
        }
    ]
}
```

**Parameters:**

* `prompt` (string, required): Description of what document to generate.
* `rules` (string, optional): Style guidelines, format requirements, or structural rules for the generated document.
* `project_id` (UUID, optional): Only required when using Token Authentication.
* `stream` (boolean, optional): Enable streaming responses (default: false).
* `filters` (array of filter objects, optional): Filters to control which memos are used as context. See [Filters](/docs/api-reference/filters) for detailed documentation.

**Filter Support:**

Filters are applied during context retrieval, allowing you to:

* Generate documents from specific sources only (e.g., only technical docs)
* Use only recent content via metadata timestamps
* Include/exclude specific categories
* Combine multiple sources strategically

See [Filters](/docs/api-reference/filters) for complete documentation on filter structure, operators, and examples.

**Response (Non-streaming):**

```json theme={null}
{
    "ok": true,
    "response": "# Product Requirements Document\n\n## Overview\nBased on the context from your knowledge base...",
    "intermediate_steps": []
}
```

**Response (Streaming):**

When `stream: true`, returns Server-Sent Events:

```
Content-Type: text/event-stream

: ping

data: {"type": "token", "content": "#"}

data: {"type": "token", "content": " Product"}

data: {"type": "done"}
```

**Error Responses:**

* Missing prompt (400):

```json theme={null}
{
    "error": "Prompt is required"
}
```

* Invalid filter structure (400):

```json theme={null}
{
    "error": "Invalid filter: <specific error message>"
}
```

**Use Cases:**

* Generate documentation from existing knowledge.
* Create reports based on stored information.
* Compile research summaries with specific formatting.
* Generate technical specifications with style constraints.
* Create focused documents using filtered context sources.

**How It Works:**

1. System retrieves relevant context from knowledge base based on prompt (with optional filters applied).
2. Context is combined with prompt and optional rules.
3. AI agent generates structured document.
4. Response includes citations to source memos.
