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

# Create and manage sessions

> Represent one consultation and keep its transcript, context, and documents together.

A **session** holds one consultation's transcript, context, and documents.
Use the same grant for the patient and session.

**Scopes:** `scribe:read` for reads; `scribe:write` for changes.

## Create a session

`POST /sessions`

```bash theme={null}
curl --request POST "$CORTEXA_API_BASE/sessions" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --data "{\"external_session_id\":\"ehr-visit-001\",\"patient_id\":\"$CORTEXA_PATIENT_ID\",\"title\":\"Synthetic follow-up\",\"background_context\":\"Synthetic patient attending a follow-up.\",\"input_languages\":[\"en\"],\"output_language_code\":\"en\"}"
```

| Field | Required | Description |
| - | - | - |
| `external_session_id` | Yes | Stable encounter ID from your EHR; 1–255 characters |
| `patient_id` | No | Cortexa patient ID from this grant |
| `title` | No | Session label; up to 255 characters |
| `background_context` | No | Relevant clinical background; up to 100,000 characters |
| `input_languages` | No | Up to three input language codes |
| `output_language_code` | No | Language requested for generated output |
| `template_ids` | No | Up to 20 available template IDs to associate with the session |

Example `201` response:

```json theme={null}
{
  "id": "session_example",
  "external_session_id": "ehr-visit-001",
  "patient_id": "patient_example",
  "title": "Synthetic follow-up",
  "status": "idle",
  "background_context": "Synthetic patient attending a follow-up.",
  "input_languages": ["en"],
  "output_language_code": "en",
  "created_at": "2026-11-16T10:00:00Z"
}
```

Save `id` as `CORTEXA_SESSION_ID`. Reusing an external ID returns the existing
session unchanged. Deleted external session IDs remain reserved.

## Reopen a consultation

Use `GET /sessions/{session_id}` to reopen an encounter and retrieve its
[documents](/developers/documents.md). To find it by your encounter ID:

```bash theme={null}
curl --get "$CORTEXA_API_BASE/sessions" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --data-urlencode 'external_session_id=ehr-visit-001'
```

The response uses the standard [paginated list](/developers/errors.md#pagination).
Use the [combined workflow](/developers/session-workflow.md) to create or resume the patient
and session together, or keep the separate creation calls.

## Update session details

`PATCH /sessions/{session_id}` accepts `title`, `background_context`, and
`output_language_code`.

```bash theme={null}
curl --request PATCH "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --data '{"background_context":"Updated synthetic history for the next generation."}'
```

Context changes apply to future generation. To update an existing note,
regenerate its content. To change the patient, use
[patient-session links](/developers/patients.md#attach-existing-sessions); this PATCH does not accept `patient_id`.

## Delete a session

`DELETE /sessions/{session_id}` returns:

```json theme={null}
{"deleted": true}
```

The session is no longer accessible through the partner API. Deleting a patient
and deleting a session are separate operations.

## Choose the next step

> [card] [Add clinical context](/developers/context.md)
>
> Supply background text or upload relevant reports.

> [card] [Submit a transcript](/developers/transcripts.md)
>
> Start with conversation text you already have.

> [card] [Upload a recording](/developers/recordings.md)
>
> Process audio from a completed consultation.

> [card] [Generate the note](/developers/notes.md)
>
> Turn the prepared session into a reviewable draft.


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