C.W.K.
Stream
Lesson 03 of 06 · published

Responses API Streaming

~22 min · streaming, responses-api, semantic-events

Level 0Tokenizer
0 XP0/54 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

The Responses API uses typed semantic events — each event has a descriptive type field, making it much easier to handle different types of output.

Key Event Types

EventDescription
response.createdResponse object created
response.in_progressProcessing underway
response.output_text.deltaText token(s) — main content
response.output_text.doneText generation complete
response.function_call_arguments.deltaTool call args streaming
response.function_call_arguments.doneTool call args complete
response.completedFull response complete
response.failedError occurred

Code

for event in stream — typed events·python
stream = client.responses.create(
    model="gpt-5.4",
    input="Write a poem about the ocean.",
    stream=True,
)

for event in stream:
    match event.type:
        case "response.output_text.delta":
            print(event.delta, end="", flush=True)
        case "response.function_call_arguments.delta":
            print(f"[tool args: {event.delta}]")
        case "response.completed":
            print(f"\\n\\nDone. Tokens: {event.response.usage.total_tokens}")
        case "error":
            print(f"Error: {event.message}")

External links

Exercise

Build an EventLogger that prints every semantic event with a 4-color terminal scheme — text deltas in green, tool events in cyan, errors in red, done events in dim white. Use it to follow a complex tool-using prompt end to end.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.