Book: Hexagonal Architecture in Python
Companion code: hexagonal-python-examples — every listing from the book, free on GitHub
My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools
Me: xgabriel.com | GitHub
Your chat endpoint has already sent 200 OK and forty tokens when the model says it is overloaded. Anthropic's error docs describe exactly this case: after a stream starts, the API has already returned a 200, so it sends an error as an error event, and the SDK doesn't retry the request . The status code can't change anymore. Whatever the browser sees next is up to your route handler.
So what does your handler do? If it iterates the SDK's stream directly, branches on SDK event types and formats SSE inline, you can only find out with a live model that happens to fail at the right moment. That test doesn't exist, so the branch ships untested.
The fix is a boundary. The stream becomes a port that yields your own Chunk type.…