Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 14 / Topic 3 of 7

Streaming

Users should see words as they generate, not a spinner:

# examples/03_streaming_print_the_reply_as_it.py (ran against the local mock)
with client.messages.stream(model="claude-opus-5-5", max_tokens=64000,
                            messages=[...]) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    final = stream.get_final_message()
# stop_reason: end_turn | output tokens: 20

The context manager handles the server-sent events; get_final_message() gives the assembled message with usage. Total latency is unchanged — perceived latency is transformed.

Done here? The practice set for Part 14 — 4 exercises with solutions — is on the part page.

Search the guide