Context
On the streaming endpoints, the error handler reads e.response.text after raise_for_status() on a response opened with client.stream(...). A streamed body isn't read automatically, so accessing .text raises httpx.ResponseNotRead. The handler itself throws, and the real upstream error is lost.
Specifically, the error reads:
httpx.ResponseNotRead: Attempted to access streaming response content, without having called read().
Moving await e.response.aread() into the except block doesn't help either: by then the async with client.stream(...) context has closed the stream, raising httpx.StreamClosed.
Affected code
-
bedrock_routes.py- the except httpx.HTTPStatusError branches in the converse-stream and invoke-with-response-stream generators read e.response.text, but the body was never read (raise_for_status() fires before any aiter_bytes()).
-
bedrock_service_httpx.py - same pattern in the STS handler (e.response.text[:200] on a non-OK streamed response).
Suggested fix
- In
bedrock_routes.py, check the status and read the body inside the async with block (before it closes): replace raise_for_status() + the HTTPStatusError branch with an explicit if resp.status_code >= 400: await resp.aread() then surface resp.text.
- In
bedrock_service_httpx.py, add await e.response.aread() before reading e.response.text.
Note: Reproducible with a local server returning 403 on a streaming POST. In this scenario, e.response.text raises httpx.ResponseNotRead; reading inside the async with returns the body.
Context
On the streaming endpoints, the error handler reads
e.response.textafterraise_for_status()on a response opened withclient.stream(...). A streamed body isn't read automatically, so accessing.textraiseshttpx.ResponseNotRead. The handler itself throws, and the real upstream error is lost.Specifically, the error reads:
httpx.ResponseNotRead: Attempted to access streaming response content, without having called
read().Moving
await e.response.aread()into theexceptblock doesn't help either: by then theasync with client.stream(...)context has closed the stream, raisinghttpx.StreamClosed.Affected code
bedrock_routes.py- theexcept httpx.HTTPStatusErrorbranches in theconverse-streamandinvoke-with-response-streamgenerators reade.response.text, but the body was never read (raise_for_status()fires before anyaiter_bytes()).bedrock_service_httpx.py- same pattern in the STS handler (e.response.text[:200]on a non-OK streamed response).Suggested fix
bedrock_routes.py, check the status and read the body inside theasync withblock (before it closes): replaceraise_for_status()+ theHTTPStatusErrorbranch with an explicitif resp.status_code >= 400: await resp.aread()then surfaceresp.text.bedrock_service_httpx.py, addawait e.response.aread()before readinge.response.text.Note: Reproducible with a local server returning 403 on a streaming POST. In this scenario,
e.response.textraiseshttpx.ResponseNotRead; reading inside theasync withreturns the body.