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

# Generate your first note

> Create a synthetic encounter, submit a transcript, and retrieve a draft for clinician review.

Create a patient and session, submit a short transcript, and stream your first
consult note. No audio is needed.

## Before you begin

* Complete [sandbox onboarding](/developers/sandbox.md) and [authentication](/developers/authentication.md).
* Load the returned Partner JWT into `CORTEXA_JWT`. It needs `scribe:read`,
  `scribe:write`, and `scribe:generate`.
* The authorized clinician needs an available consult-note template and generation entitlement.
* Run the commands in the same Bash shell with cURL and `jq` available.

The examples use synthetic data and capture returned IDs for subsequent requests.

```bash theme={null}
export CORTEXA_API_BASE='https://sandbox.api.cortexanote.com/v2/scribe/open-api'
export CORTEXA_DEMO_ID="demo-$(date -u +%Y%m%dT%H%M%SZ)"
```

Keep the demo ID and operation keys unchanged when retrying this run.

## 1. Create a synthetic patient

```bash theme={null}
patient_response=$(curl --fail-with-body --request POST "$CORTEXA_API_BASE/patients" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --data "$(jq -n --arg id "$CORTEXA_DEMO_ID-patient" \
    '{external_patient_id:$id,name:"Alex Example"}')")

export CORTEXA_PATIENT_ID=$(jq -r '.id' <<< "$patient_response")
```

The response returns a Cortexa patient ID. Reusing the external ID returns the
same patient within this grant.

## 2. Create the consultation

```bash theme={null}
session_response=$(curl --fail-with-body --request POST "$CORTEXA_API_BASE/sessions" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --data "$(jq -n --arg id "$CORTEXA_DEMO_ID-visit" --arg patient "$CORTEXA_PATIENT_ID" \
    '{external_session_id:$id,patient_id:$patient,title:"Synthetic follow-up",background_context:"Synthetic consultation for integration testing.",output_language_code:"en"}')")

export CORTEXA_SESSION_ID=$(jq -r '.id' <<< "$session_response")
```

The session keeps this consultation's inputs and outputs together. See
[Sessions](/developers/sessions.md) for optional language and template settings.

## 3. Submit the conversation

```bash theme={null}
curl --fail-with-body --request POST "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID/transcript/segments" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --header "Idempotency-Key: $CORTEXA_DEMO_ID-transcript-1" \
  --data '{"segments":[{"speaker":"clinician","text":"How has your sleep been since the last visit?"},{"speaker":"patient","text":"It has improved."},{"speaker":"clinician","text":"We discussed continuing the documented sleep routine and following up in four weeks."}],"language_code":"en","status":"completed"}'
```

The response includes the combined `full_text` and transcript `status`.
For a longer conversation, submit multiple [transcript batches](/developers/transcripts.md).

## 4. Choose an available template

```bash theme={null}
curl --fail-with-body "$CORTEXA_API_BASE/templates/consult-note-templates" \
  --header "Authorization: Bearer $CORTEXA_JWT"
```

Choose an ID from the returned `items`. Load it into `CORTEXA_TEMPLATE_ID`:

```bash theme={null}
read -r -p 'Consult-note template ID: ' CORTEXA_TEMPLATE_ID
export CORTEXA_TEMPLATE_ID
```

If the list is empty, ask your integration contact to enable a template.

## 5. Stream the note

```bash theme={null}
curl --no-buffer --fail-with-body --request POST "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID/consult-note" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --header 'Accept: text/event-stream' \
  --header "Idempotency-Key: $CORTEXA_DEMO_ID-note-1" \
  --data "$(jq -n --arg template "$CORTEXA_TEMPLATE_ID" \
    '{template_ids:[$template],output_language_code:"en"}')" \
  | tee ./cortexa-note-events.txt
```

The `200` response stays open while generation runs. You will see
`generation.started`, followed by text in `output.delta` events, and then an
`output.ready` event containing the saved document. No polling is needed.
Completed output may be returned immediately without deltas.

The command saves the synthetic response to `cortexa-note-events.txt`.

## 6. Read the completed note

This example requested one template. Extract its final document from the saved
SSE events:

```bash theme={null}
sed -n 's/^data: //p' ./cortexa-note-events.txt \
  | jq -s '[.[] | select(.document.status == "ready") | .document] | last' \
  > ./cortexa-note.json

jq -e '.id != null' ./cortexa-note.json
export CORTEXA_DOCUMENT_ID=$(jq -r '.id' ./cortexa-note.json)
jq -r '.rendered_text' ./cortexa-note.json
```

If no ready document was returned, handle the failure event or reconnect using
the same request and key. A closed stream alone is not success. The
[Streaming guide](/developers/streaming.md) explains failures, reconnects, and the optional
`?stream=false` JSON mode for background integrations.

The final document includes `rendered_text`, structured `content`, `status`, and
`current_version`. Present the text for clinician review. To retain edits in
Cortexa, [save a versioned document update](/developers/documents.md#save-an-edit). Use your own
EHR API to save the reviewed text into the mapped encounter.

## Next steps

> [card] [Use audio](/developers/recordings.md)
>
> Replace transcript submission with a complete recording upload.

> [card] [Add background reports](/developers/context.md)
>
> Include relevant clinical context before generation.

> [card] [Create additional outputs](/developers/documents.md)
>
> Generate a referral or other document from the same session.

> [card] [Handle real-world requests](/developers/errors.md)
>
> Add retries, rate-limit handling, and version-conflict recovery.


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