# Best Practices for Handling Mid-Stream Errors (Responses API)

**URL:** <https://community.openai.com/t/best-practices-for-handling-mid-stream-errors-responses-api/1370883>\
**Category:** API\
**Created:** [January 4, 2026, 2:42pm UTC](https://community.openai.com/t/best-practices-for-handling-mid-stream-errors-responses-api/1370883 "2026-01-04T14:42:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joao\_Abrantes](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/joao_abrantes/32/710441_2.png) [@Joao\_Abrantes](https://community.openai.com/u/Joao_Abrantes)\
**Post date:** [January 4, 2026, 2:42pm UTC](https://community.openai.com/t/best-practices-for-handling-mid-stream-errors-responses-api/1370883/1 "2026-01-04T14:42:46Z")

</div>

I am using the async client in the following way:

```python
stream = await client.responses.create(
    model="gpt-4.1",
    input=input_messages,
    previous_response_id=previous_response_id,
    stream=True,
)

async for event in stream: # <-- Error occurs here, mid-stream
    if event.type == 'response.created':
        response_id = event.response.id
    elif event.type == 'response.content_part.added':
        # Push to UI immediately
        send_to_client(event.part.text)
    elif event.type == 'response.output_text.delta':
        send_to_client(event.delta)
    elif event.type == 'response.completed':
        # Success
        pass

```

Sometimes I get a random error during the for loop. Example of error:  
`httpx.RemoteProtocolError: peer closed connection without sending complete message body (incomplete chunked read)`

My question is what is the best way to handle this?

My stream is already in the middle, I may have already called some tools, sent some tokens to the client, etc.
