---
title: Edit a context document
description: Change a threat model or text document in place.
url: https://www.hacktron.ai/docs/api/context-documents/edit-context-document
---

# Edit a context document

Edits a threat model or a Markdown or text context document in place, as the editor in Hacktron does. Send `edits`, `append`, or both. You need the member role or above.

- Each of up to 20 `edits` replaces its `old_text` with `new_text`, in order. `old_text` must appear exactly once in the document as [`GET /context-documents/{id}`](/docs/api/context-documents/get-context-document) returns it.
- `append` adds Markdown at the end of the document, after a blank line.
- Edits to a threat model are kept as your team's own, so later syncs leave those lines alone.

A request whose edits change nothing returns `400 Bad Request`, and so does a document over 2 MB, which you edit in Hacktron instead. If the document changes while the edit is applied, for example by a threat model sync, the API returns `409 Conflict`. Read the document again and redo the edit.

## Request

`POST /context-documents/{id}/edit`

Send an [API key](/docs/api/authentication) with the `write` scope in the `X-Api-Key` header.

:::examples

```bash title="Request" wrap=false
curl -X POST "https://api.hacktron.ai/v1/context-documents/<id>/edit" \
  -H "X-Api-Key: $HACKTRON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "edits": [
    {
      "old_text": "fetches only public http and https URLs",
      "new_text": "fetches only public https URLs"
    }
  ],
  "append": "## Accepted risks\n\nPreviews of redirecting URLs follow at most three redirects."
}'
```

```json title="Response 200 OK" showLineNumbers=false wrap=false
{
  "id": "5e6f7a8b-9c0d-4e1f-8a2b-3c4d5e6f7a8b",
  "name": "Link previews: security decisions",
  "kind": "document",
  "updated_at": "2026-11-08T10:20:44.000Z",
  "readable": true
}
```

:::

### Path parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `id` | string, required | |

### Body

A required `application/json` body.

| Field | Type | Description |
| --- | --- | --- |
| `edits` | array of object | Replacements, applied in order. |
| `edits[].old_text` | string, required | Text to replace; it must appear exactly once in the document. |
| `edits[].new_text` | string, required | Replacement text; empty deletes old_text. |
| `append` | string | Markdown to add at the end of the document. |

## Responses

### 200 OK

| Field | Type | Description |
| --- | --- | --- |
| `id` | string (uuid), required | |
| `name` | string, required | |
| `kind` | string, required | One of `threat_model`, `application_threat_model`, or `document`. |
| `updated_at` | string (date-time), required | |
| `readable` | boolean, required | Whether the content is text this API returns; PDFs open in Hacktron. |

### 400 Bad Request

A replacement's text isn't in the document exactly once, the edits change nothing, or the document isn't text.

### 409 Conflict

The document changed while the edit was applied, such as by a threat model sync; read it again and redo the edit.
