Get Started
Streaming
Setstream: true and the answer arrives as OpenAI server-sent events while the worker generates it. OpenAI SDKs and streaming UIs built for them work unchanged.
CodeTYPESCRIPT
The events
The response istext/event-stream. Each event is data: <JSON>:
- The first chunk's
deltacarriesrole: "assistant"and the first text. - Each later chunk's
deltacarries morecontent. - The last chunk has an empty
delta,finish_reason: "stop", and thelightchainobject naming the on-chain job (see Verifying an Answer). data: [DONE].
finish_reason and lightchain together.
The x-lightchain response header carries the same lightchain object from the start, for clients that only read headers.
CodeTEXT
Waiting for the first chunk
Nothing is sent until the first text exists. That can take a while: when none of the key's sessions for the model is free, the call waits for a worker to take on a new one, and a reasoning model thinks before it answers (its reasoning is not forwarded). If a proxy between you and the API cuts idle connections, give it a timeout of a few minutes.Errors
-
Before the first chunk, a failure is an ordinary HTTP error with its status and body, exactly as without streaming: a
402still carriesaccepts, a429still carriesretry-after. -
After the first chunk, the status is already
200, so the stream ends with an error event instead of[DONE]:OpenAI SDKs raise it as an error while you iterate. Send the request again.CodeTEXT
stream_diverged is a rare error code: the worker restarted its answer after the first chunks went out, so the text you received is not the answer it committed on chain. Discard it and send the request again.
Streamed text and the committed answer
The chunks are a best-effort live view. The answer of record is the one the worker commits on chain; the API checks what it streamed against it, sends any part the live view dropped before the last chunk, and reportsstream_diverged if they disagree.
Closing the connection does not cancel the job: it runs to the end and is paid for.