Claude API · Streaming

Stream and get the full message

Stream for the timeout benefits, then read the complete message at the end.

with client.messages.stream(
    model="claude-opus-5-5",
    max_tokens=64000,
    messages=[{"role": "user", "content": "Write a long report"}],
) as stream:
    message = stream.get_final_message()
print(message.usage.output_tokens)

Official Claude API documentation

More streaming commands

All streaming commands · Claude API cheatsheet

Was this page helpful?