
Streaming delivers tokens to your app as they're generated — essential for responsive, ChatGPT-like user experiences.
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)Use Server-Sent Events (SSE) to stream tokens from your backend to your frontend. This is exactly how ChatGPT works under the hood.
Reference:
TaskLoco™ — The Sticky Note GOAT