Both endpoints require
scribe:generate and an Idempotency-Key.
Prepare the session’s input first. See Notes and Documents
for request fields.
Open the stream
200 OK with Content-Type: text/event-stream. cURL’s
--no-buffer displays events as they arrive. A typical sequence is:
Handle each event
A consult-note request can contain several templates. Events can interleave, so
maintain separate text and completion state for every
document_id. Wait for an
output.ready for every requested document before treating the whole request as
successful. A closed connection alone does not establish success.
output.ready includes the saved content and current_version. Use it for
review and edits; no additional GET is needed.
If the request reuses completed output, the stream may return output.ready
immediately without any deltas. In that case job_ids may be empty.
Parse events on your backend
Use an HTTP client that supports streaming POST requests. Send the request body and authorization header, then parse the SSE response. Read complete SSE frames separated by blank lines. Parse each frame’sdata as
JSON and dispatch on its event field. A network chunk can contain half a frame
or several frames. Parse JSON after assembling a complete frame. Preserve
UTF-8 characters across chunk boundaries and ignore heartbeat comments beginning
with :. Keep the latest event id after you apply that event.
Reconnect after a disconnect
Generation continues in the background when the connection closes. To observe the same work again:- Send the same POST URL, body, grant, and
Idempotency-Key. - If you retained the applied partial text and its event cursor, send the cursor
in
Last-Event-IDto resume after it. - If you lost that local state, omit
Last-Event-IDand rebuild from the replay. - Accept an immediate
output.readyif the document completed while disconnected.
Handle failures
Before the stream starts, authentication, validation, permissions, and other request errors use the normal HTTP status and JSON error body. Check the status and content type before parsing SSE. After200 headers have been sent, a generation failure is reported through
output.failed or generation.failed. Inspect failure_code; partial text is
not a completed clinical document. A network error or EOF without the expected
completion events calls for reconnecting or retrieving the document’s status.
Replaying a failed operation does not start a fresh attempt. Resolve the failure
and use a new operation key when intentionally requesting new generation.
Use a background job instead
For a backend workflow that does not need live text, add?stream=false to either
generation endpoint. This returns the 202 application/json receipt:
stream=false. An Accept: application/json header alone does not select JSON mode.
Custom-template responses, Ask AI, transcription, and coding retain their own
processing flows. The stream option applies only to the two endpoints above.