Streaming
Deltas as they arrive, a terminal usage frame with the charge, and clear rules for fallback and disconnects.
Server-sent events
Set stream: true and read data: frames as they arrive — each is a chat.completion.chunk. The last frame before data: [DONE] carries usage and the same yelno object as a non-streaming response; its cost.state is final once the provider reported usage and provisional until then.
stream = client.chat.completions.create(model="openai/gpt-4o", messages=msgs, stream=True)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage: # last frame before [DONE]
meta = chunk.model_extra["yelno"]
print(meta["provider"], meta["cost"]["customer_nanos"], meta["cost"]["state"]) # openai 6400000 finalFrame types
Fallback mid-stream
If an attempt fails with a retriable error (rate_limit, overloaded, provider_error), the gateway moves to the next planned attempt — up to your policy's max_attempts — and you see an error frame followed by the next attempt's frames; every attempt and its state is listed in the terminal yelno.attempts. A non-retriable error ends the stream: the error frame is followed by the terminal frame with request_state: "failed", then [DONE].