---
title: "Context Documents API reference"
canonical_url: https://zentrik.ai/docs/api/context-documents
markdown_url: https://zentrik.ai/docs/api/context-documents.md
last_reviewed: 2026-10-17
---

# Context Documents API reference

Context documents are workspace knowledge files used by retrieval and product context surfaces. Use these endpoints to import text, upload files, scope documents to products, and inspect previewable content. The context-sources endpoints keep an imported source current: a whole folder kept by path, sent again by a scheduled job with only the files that changed.

- Human reference: https://zentrik.ai/docs/api/context-documents
- Complete Markdown index: https://zentrik.ai/docs/api/index.md
- Base URL: `https://zentrik.ai/api`
- Authentication: `Authorization: Bearer YOUR_API_KEY`
- Shared pagination and rate limits: https://zentrik.ai/docs/api/index.md#shared-conventions

## GET /external/v1/context-documents — List all context documents

Operation ID: `list-context-documents`

List context documents in the current workspace. Raw storage keys are never returned.

Required API key scopes: `context-documents:read`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `limit` | number | No | Maximum number of documents to return. |
| `offset` | number | No | Number of documents to skip. |

### Example request

```curl
curl -X GET 'https://zentrik.ai/api/external/v1/context-documents?limit=20' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 200 | Success | Context documents were successfully retrieved. | Array<ContextDocument> |

### Example response

```json
[
  {
    "id": "context-document-uuid",
    "fileName": "activation-research.md",
    "mimeType": "text/markdown",
    "size": 1834,
    "description": "Research notes for activation planning.",
    "productId": "product-uuid",
    "workspaceId": "workspace-uuid",
    "vectorFileId": "file-vector-id",
    "indexingStatus": "indexed",
    "createdAt": "2026-05-14T10:00:00Z",
    "updatedAt": "2026-05-14T10:00:00Z"
  }
]
```

---

## GET /external/v1/context-documents/:id — Get one context document

Operation ID: `get-context-document`

Retrieve metadata for one context document in the current workspace.

Required API key scopes: `context-documents:read`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | uuid | Yes | The context document UUID. |

### Example request

```curl
curl -X GET https://zentrik.ai/api/external/v1/context-documents/context-document-uuid \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 200 | Success | The context document was successfully retrieved. | ContextDocument |
| 404 | Not Found | No context document found with the provided id. | — |

### Example response

```json
{
  "id": "context-document-uuid",
  "fileName": "activation-research.md",
  "mimeType": "text/markdown",
  "size": 1834,
  "description": "Research notes for activation planning.",
  "productId": "product-uuid",
  "workspaceId": "workspace-uuid",
  "vectorFileId": "file-vector-id",
  "indexingStatus": "indexed",
  "createdAt": "2026-05-14T10:00:00Z",
  "updatedAt": "2026-05-14T10:00:00Z"
}
```

---

## GET /external/v1/context-documents/:id/content — Preview context document content

Operation ID: `get-context-document-content`

Preview text-like context document content. Large content is truncated to the documented limit.

Required API key scopes: `context-documents:read`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | uuid | Yes | The context document UUID. |

### Example request

```curl
curl -X GET https://zentrik.ai/api/external/v1/context-documents/context-document-uuid/content \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 200 | Success | The preview payload was returned. | — |

### Example response

```json
{
  "supported": true,
  "content": "# Activation research",
  "contentFormat": "markdown",
  "truncated": false,
  "maxChars": 40000,
  "sourceUrl": null,
  "sourceLabel": null
}
```

---

## POST /external/v1/context-documents — Import a text context document

Operation ID: `create-context-document`

Import a text or markdown context document from JSON. The document is stored and indexed for retrieval.

Required API key scopes: `context-documents:write`

### JSON request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `fileName` | string | Yes | Display file name, including extension. |
| `content` | string | Yes | Text content to store and index. |
| `mimeType` | string | No | Defaults to text/markdown. |
| `productId` | uuid \| null | No | Optional product scope. Omit or null for global workspace context. |
| `description` | string \| null | No | Human-readable context note. |

### Example request

```json
{
  "fileName": "activation-research.md",
  "content": "# Activation research\n\nTeams need clearer setup progress.",
  "mimeType": "text/markdown",
  "productId": "product-uuid",
  "description": "Research notes for activation planning."
}
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 201 | Created | The context document was stored and queued for retrieval indexing. | ContextDocument |

### Example response

```json
{
  "id": "context-document-uuid",
  "fileName": "activation-research.md",
  "mimeType": "text/markdown",
  "size": 1834,
  "description": "Research notes for activation planning.",
  "productId": "product-uuid",
  "workspaceId": "workspace-uuid",
  "vectorFileId": "file-vector-id",
  "indexingStatus": "indexed",
  "createdAt": "2026-05-14T10:00:00Z",
  "updatedAt": "2026-05-14T10:00:00Z"
}
```

---

## POST /external/v1/context-documents/upload — Upload a context document file

Operation ID: `upload-context-document`

Upload a binary or text file as multipart/form-data. The file field name must be file.

Required API key scopes: `context-documents:write`

### JSON request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | file | Yes | The file to upload. Maximum size is 50 MB. |
| `productId` | uuid \| null | No | Optional product scope. |
| `description` | string \| null | No | Human-readable context note. |

### Example request

```curl
curl -X POST https://zentrik.ai/api/external/v1/context-documents/upload \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -F 'file=@activation-research.md' \
  -F 'productId=product-uuid'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 201 | Created | The context document file was uploaded. | ContextDocument |

### Example response

```json
{
  "id": "context-document-uuid",
  "fileName": "activation-research.md",
  "mimeType": "text/markdown",
  "size": 1834,
  "description": "Research notes for activation planning.",
  "productId": "product-uuid",
  "workspaceId": "workspace-uuid",
  "vectorFileId": "file-vector-id",
  "indexingStatus": "indexed",
  "createdAt": "2026-05-14T10:00:00Z",
  "updatedAt": "2026-05-14T10:00:00Z"
}
```

---

## PATCH /external/v1/context-documents/:id — Update a context document

Operation ID: `update-context-document`

Update document metadata. Changing productId re-indexes the document with the new retrieval scope.

Required API key scopes: `context-documents:write`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | uuid | Yes | The context document UUID. |

### JSON request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `fileName` | string | No | Updated display file name. |
| `description` | string \| null | No | Updated context note. |
| `productId` | uuid \| null | No | Replacement product scope. Null makes the document global. |

### Example request

```curl
curl -X PATCH https://zentrik.ai/api/external/v1/context-documents/context-document-uuid \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"productId":null}'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 200 | Updated | The context document was successfully updated. | ContextDocument |

---

## DELETE /external/v1/context-documents/:id — Delete a context document

Operation ID: `delete-context-document`

Delete a context document, its stored file, and its retrieval index entry when present.

Required API key scopes: `context-documents:delete`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | uuid | Yes | The context document UUID. |

### Example request

```curl
curl -X DELETE https://zentrik.ai/api/external/v1/context-documents/context-document-uuid \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 200 | Deleted | The context document was successfully deleted. | — |

---

## GET /external/v1/context-sources — List imported sources

Operation ID: `list-context-sources`

List the imported sources of the workspace: folders brought in whole and kept by path. Each says how many documents it holds, when its files last arrived and who sent them.

Required API key scopes: `context-documents:read`

### Example request

```curl
curl -X GET https://zentrik.ai/api/external/v1/context-sources \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 200 | Success | Imported sources were returned. | — |

### Example response

```json
[
  {
    "id": "source-uuid",
    "name": "Product repository",
    "productId": null,
    "documents": 214,
    "snapshot": {
      "id": "snapshot-uuid",
      "sourceRef": "a1b2c3d",
      "completedAt": "2026-11-10T06:00:00Z",
      "by": "Marta Ruiz"
    }
  }
]
```

---

## POST /external/v1/context-sources — Create an imported source

Operation ID: `create-context-source`

Create an empty imported source. It holds nothing until its first snapshot completes.

Required API key scopes: `context-documents:write`

### JSON request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | The name people and agents see. Up to 200 characters. |
| `productId` | uuid \| null | No | Optional product scope. Omit or null for every product. |

### Example request

```json
{
  "name": "Product repository"
}
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 201 | Created | The source was created. | — |

### Example response

```json
{
  "id": "source-uuid",
  "name": "Product repository",
  "productId": null,
  "documents": 0,
  "snapshot": null
}
```

---

## POST /external/v1/context-sources/:sourceId/snapshots — Start a snapshot of a source

Operation ID: `start-context-source-snapshot`

Start a snapshot by sending the manifest of the whole folder: every path with its SHA-256 and size. The reply lists, in upload, the paths whose bytes Zentrik does not hold yet, and in changes what completing will add, change, move and remove. An unchanged folder asks for nothing. Starting a snapshot abandons an earlier one that was never completed.

Required API key scopes: `context-documents:write`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `sourceId` | uuid | Yes | The imported source UUID. |

### JSON request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `manifest` | Array<{ path, contentHash, size }> | Yes | One entry per file, up to 20,000. path is relative to the folder, contentHash is the lowercase hex SHA-256 of the file, size is in bytes. |
| `sourceRef` | string | No | What you call this state of the folder, such as a commit. Up to 200 characters. |

### Example request

```json
{
  "sourceRef": "a1b2c3d",
  "manifest": [
    {
      "path": "README.md",
      "contentHash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
      "size": 1832
    }
  ]
}
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 201 | Started | The snapshot is open and says which files to send. | — |

### Example response

```json
{
  "collectionId": "source-uuid",
  "snapshotId": "snapshot-uuid",
  "status": "open",
  "sourceRef": "a1b2c3d",
  "outcomes": {
    "unchanged": 212,
    "pending": 2
  },
  "changes": {
    "added": 1,
    "modified": 1,
    "renamed": 0,
    "removed": 0
  },
  "upload": [
    "docs/pricing.md",
    "docs/onboarding/checklist.md"
  ],
  "attention": [],
  "summary": {}
}
```

---

## POST /external/v1/context-sources/:sourceId/snapshots/:snapshotId/files — Send the files a snapshot asks for

Operation ID: `send-context-source-files`

Send files the open snapshot asked for as multipart/form-data: up to 100 files a request in the field files, and their paths as one JSON list in the field paths, in the same order. A file whose bytes do not match its manifest hash is refused, because the folder changed while it was being read.

Required API key scopes: `context-documents:write`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `sourceId` | uuid | Yes | The imported source UUID. |
| `snapshotId` | uuid | Yes | The snapshot UUID returned when the snapshot was started. |

### JSON request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `files` | file[] | Yes | The files to send. Up to 100 a request, 50 MB each. |
| `paths` | string | Yes | A JSON list of the manifest paths of those files, in the same order. |

### Example request

```curl
curl -X POST https://zentrik.ai/api/external/v1/context-sources/source-uuid/snapshots/snapshot-uuid/files \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -F 'files=@docs/pricing.md' \
  -F 'paths=["docs/pricing.md"]'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 201 | Received | Each file is listed with its outcome. | — |

### Example response

```json
[
  {
    "path": "docs/pricing.md",
    "outcome": "received"
  }
]
```

---

## POST /external/v1/context-sources/:sourceId/snapshots/:snapshotId/complete — Complete a snapshot

Operation ID: `complete-context-source-snapshot`

Make the snapshot what everyone reads, in one step. It is refused while files are still awaited unless excludePending is true; a file left out keeps its previous content and is named in the receipt.

Required API key scopes: `context-documents:write`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `sourceId` | uuid | Yes | The imported source UUID. |
| `snapshotId` | uuid | Yes | The snapshot UUID returned when the snapshot was started. |

### JSON request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `excludePending` | boolean | No | Complete without the files that never arrived. |

### Example request

```json
{
  "excludePending": true
}
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 201 | Completed | The receipt accounts for every path. | — |
| 409 | Files awaited | Files have not arrived and excludePending was not set. | — |

### Example response

```json
{
  "collectionId": "source-uuid",
  "snapshotId": "snapshot-uuid",
  "status": "complete",
  "sourceRef": "a1b2c3d",
  "outcomes": {
    "unchanged": 212,
    "retained": 2
  },
  "changes": {
    "added": 1,
    "modified": 1,
    "renamed": 0,
    "removed": 0
  },
  "upload": [],
  "attention": [],
  "summary": {}
}
```

---

## GET /external/v1/context-sources/:sourceId/snapshots/:snapshotId — Read a snapshot receipt

Operation ID: `get-context-source-snapshot`

Read the receipt of a snapshot: every path by outcome, what changed, and anything that did not become readable with the reason.

Required API key scopes: `context-documents:read`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `sourceId` | uuid | Yes | The imported source UUID. |
| `snapshotId` | uuid | Yes | The snapshot UUID returned when the snapshot was started. |

### Example request

```curl
curl -X GET https://zentrik.ai/api/external/v1/context-sources/source-uuid/snapshots/snapshot-uuid \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### Responses

| Status | Meaning | Description | Schema |
| --- | --- | --- | --- |
| 200 | Success | The receipt was returned. | — |

### Example response

```json
{
  "collectionId": "source-uuid",
  "snapshotId": "snapshot-uuid",
  "status": "complete",
  "sourceRef": "a1b2c3d",
  "outcomes": {
    "unchanged": 212,
    "retained": 2
  },
  "changes": {
    "added": 1,
    "modified": 1,
    "renamed": 0,
    "removed": 0
  },
  "upload": [],
  "attention": [],
  "summary": {}
}
```
