Streaming
Receive the answer as server-sent events while it is written.
Set stream to true on any of the three APIs to receive server-sent events as the answer is written. The Python examples continue from the client set up on Chat Completions or Messages.
stream = client.chat.completions.create(
model="raon-1-mini-preview",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)- On Chat Completions,
stream_options.include_usageadds token usage in a final chunk. - With curl, add
-Nso the output is not buffered.

