The client stream halts midway without returning an explicit error.
Why this happens
Network dropouts or absent socket read timeouts cause the streaming HTTP connection to stall indefinitely.
Answer 1: Configure explicit HTTP client timeouts
import httpx
from anthropic import Anthropic
client = Anthropic(timeout=httpx.Timeout(60.0))
stream = client.messages.stream(
model="claude-sonnet-4-5-20250929",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a long essay"}]
)
