BETA
Documentation
Python SDK Streaming
Set stream=True to receive token deltas over server-sent events instead of waiting for the full response.
main.py
stream = client.chat.completions.create(
model="gpt-5.6-sol",
messages=[{"role": "user", "content": "Say this is a test"}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")The stream ends with data: [DONE]. Apily automatically adds stream_options: {"include_usage": true} to every streaming request that doesn't already set it, so the final chunk carries token usage — no extra parameter needed on your end.