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

# Add clinical context

> Provide relevant history and attachments before generating a note or document.

Add patient history, reports, and previous consultation notes before generation.

**Scopes:** `scribe:write` to change context; `scribe:read` to retrieve it.

## Add background text

Set `background_context` when [creating a session](/developers/sessions.md), or update it with
`PATCH /sessions/{session_id}`:

```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":"Synthetic encounter. Relevant history: follow-up for sleep concerns. No medication changes documented."}'
```

Send the complete background text, up to 100,000 characters. PATCH replaces the
existing value.

## Upload a report

`POST /sessions/{session_id}/context-documents` accepts multipart form data.
Use the field name `files` for each file and an `Idempotency-Key` for the upload.

```bash theme={null}
curl --request POST "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID/context-documents" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Idempotency-Key: visit-001-context-1' \
  --form 'files=@./synthetic-report.txt;type=text/plain'
```

Use a local file containing synthetic clinical information. For multiple files,
repeat `--form 'files=@...'`; do not set the multipart boundary yourself.

| Description | Value |
| - | - |
| Files per request | 1–10 |
| Total file content | At most 50 MiB |
| Supported types | PDF, DOCX, TXT, Markdown, JPEG, PNG, WebP |
| Retry | Keep the same files and idempotency key for the same upload |

The `201` response contains an `items` array. Each item identifies an attachment:
`id`, `name`, `mime_type`, `size_bytes`, `status`, and `index_status`.
The upload response does not mean extraction and indexing have finished.

## Wait for usable context

```bash theme={null}
curl "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID/context-documents" \
  --header "Authorization: Bearer $CORTEXA_JWT"
```

The response is paginated. Wait for both `status: "ready"` and
`index_status: "ready"` on each required attachment before generating. These fields
also show extraction or indexing failures.

## Remove an attachment

`DELETE /sessions/{session_id}/context-documents`

```bash theme={null}
curl --request DELETE "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID/context-documents" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --data '{"document_ids":["context_document_example"]}'
```

Replace the illustrative ID with one returned by the attachment list. The
response is `{"deleted": true}`. This detaches the files from the session; it
does not delete the clinician's library copy or rewrite existing generated notes.

## Link previous consultations

Use `PUT /sessions/{session_id}/context/sessions` to choose previous consultations
whose notes provide context for future generation:

```bash theme={null}
curl --request PUT "$CORTEXA_API_BASE/sessions/$CORTEXA_SESSION_ID/context/sessions" \
  --header "Authorization: Bearer $CORTEXA_JWT" \
  --header 'Content-Type: application/json' \
  --data '{"session_ids":["previous_session_example"]}'
```

Choose up to 20 other sessions for the **same patient and grant**. Each source
needs a completed consult note. The response and corresponding GET return the
linked session IDs. Each generation reads the latest completed consult note from
each linked session, including saved edits. You do not need to link the session
again after editing or generating a new source note. An empty list removes every link.

Linked notes can be used without new audio; any active or failed transcription
must still be resolved. Generation skips deleted or inaccessible sources and uses
the latest remaining completed note. Moving a source to another patient excludes it.
Context changes apply to future generation; existing documents keep their text.

A different patient returns `422 CONTEXT_PATIENT_MISMATCH`; a resource outside the
grant returns `404`; a source without a completed note returns
`409 CONSULT_NOTE_REQUIRED`. Updates are atomic: an invalid source leaves the
previous links in place.

Continue with [consult notes](/developers/notes.md) or [documents](/developers/documents.md).


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