Claude API · Streaming

Stream asynchronously

Use the async client with async with and async for.

async_client = anthropic.AsyncAnthropic()

async with async_client.messages.stream(
    model="claude-opus-5-5",
    max_tokens=64000,
    messages=[{"role": "user", "content": "Write a story"}],
) as stream:
    async for text in stream.text_stream:
        print(text, end="", flush=True)

Official Claude API documentation

More streaming commands

All streaming commands · Claude API cheatsheet

Was this page helpful?