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

# Generate a consult note

> Stream a clinical draft, receive the saved document, and save the clinician's edits.

Generate a draft from the session's transcript and context, then present it for
clinician review.

**Scopes:** `scribe:generate` to generate, `scribe:read` to retrieve, and
`scribe:write` to save edits. The clinician needs access to the selected templates
and generation entitlements.

## Request generation

`POST /sessions/{session_id}/consult-note`

```bash theme={null}
curl --no-buffer --request POST "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID/consult-note" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --header 'Idempotency-Key: visit-001-note-1' \
  --data "{\"template_ids\":[\"$CORTEXA_TEMPLATE_ID\"],\"output_language_code\":\"en\"}"
```

| Field | Required | Description |
| - | - | - |
| `template_ids` | No | Up to 20 template IDs; select from [available templates](/developers/templates.md) |
| `output_language_code` | No | Language requested for this generation |

If you omit `template_ids`, Cortexa uses the session's template selection or default.

The default response is `200 text/event-stream`. Process each `output.delta` as
it arrives. The final `output.ready` contains the saved document, so you do not
need to poll or fetch the result separately.

## Receive the result

```text theme={null}
event: generation.started
data: {"document_ids":["document_example"],"job_ids":["job_example"]}

id: event_example
event: output.delta
data: {"document_id":"document_example","data":"Synthetic draft: the patient reports improved sleep."}

```

For multiple templates, track each document separately and wait for its
`output.ready`. Completed output can arrive immediately without deltas.
A disconnected stream is incomplete until every document has a result.

See [Streaming](/developers/streaming.md) for the event format, failure handling, and resuming
the same request after a disconnect. For background-only generation, add
`?stream=false` to receive a `202` receipt and follow [Jobs](/developers/jobs.md).

Example completed document:

```json theme={null}
{
  "id": "document_example",
  "session_id": "session_example",
  "status": "ready",
  "title": "Synthetic consultation note",
  "rendered_text": "Synthetic draft: the patient reports improved sleep.",
  "content": {},
  "generation_job_id": "job_example",
  "failure_code": null,
  "current_version": 1
}
```

The generated wording and `content` structure depend on the template and clinical
inputs. `rendered_text` is the display text; do not assume a fixed schema for
`content` across templates.

## Save clinician edits

To edit a particular document, use its ID. To edit the latest completed consult
note generated through the consult-note endpoint, use:

```bash theme={null}
curl --request PATCH "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID/consult-note" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --data '{"base_version":1,"rendered_text":"Clinician-reviewed synthetic note."}'
```

Replace `base_version` with the current value from the document you read.
A stale version returns `409`; retrieve the latest document and resolve the
edits before saving again. If no completed consult note is available, this
endpoint returns `409 CONSULT_NOTE_REQUIRED`.

## Write the result to your EHR

Save the reviewed result through your EHR API or an [approved connector](/developers/connectors.md).
To fill separate EHR fields, use [note sections](/developers/sectional-notes.md). Document PATCH
requests save edits in Cortexa.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.