RemoteProtocolError: peer closed connection without sending complete message body (incomplete chunked read)

Hello, I’m reposting an issue I opened yesterday on the Github repository openai-python (github[dot]com/openai/openai-python/issues/2065). I’ve been asked to post here instead, since the issue seemed more related to the API than to the SDK.

I’ve been encountering an issue recently, without changing my codebase:

When chatting with the model, after a few turns I often get an error that I never had before, which crashes my app (see video in the GitHub issue, the crash occurs at ~1m20s).

I feel like it happens mostly during long responses, hence the tasks shown in the video, but I may be wrong about this.

Did something change recently on the OpenAI API side?

Hi! I’m sure something changed, I use langchain in my projects and I had to change a method where I instantiate the OpenAI agent.

Hi, which method do you changed? We’re also using the agent with langchain and have this issue yet. Thanks a lot

Hi!
In my app, we change the llm instance from

       _llm = ChatOpenAI(temperature=temperature, streaming=False, model_name=open_ai_model)

to

 _llm = init_chat_model(temperature=temperature, model_provider='openai',
                               model=open_ai_model, streaming=False)

This change and updating the langchain-openai and langchain-core library to the last version.

The frequency of this error was reduced considerably, but not completely, from occurring in half of the executions to approximately 10%.

  • The function init_chat_model allows to use it with several providers, besides OpenAI, and I have not encountered the error with others. I am waiting to see if langchain-openai releases an update with something related to this problem.

I have updated the openai library to 1.61.0 version and I can no longer reproduce the error (I can’t say for sure that it is solved, but that it is less frequent).

Can I ask you which version you use of the HTTPX library? Thanks

I ran a few tests and could not re-produce the bug anymore (even without updating the python package to 1.62.0).

I guess something was broken then fixed on the API side and we’ll never know the why and the how!

I too have this issue and tried both 1.59 and 1.61 versions :frowning:

Any update is really appreciated !

I have changed the configuration of my client to use the model “gpt-4o-2024-11-20” which is the latest gtp-4o, at the time of my post gtp-4o points to gpt-4o-2024-08-06.
Now it works without issue

1 Like

Good catch, I had not thought about testing other models!

I also seem to have less failures using gpt-4o-2024-11-20, but I still got one during my testing… It is also worth noting that the output style changes quite much between these two versions.

Some explanation and advice from the OpenAI team would be welcome.

I also have the same issue, updating the package to 1.62.0 did not help to eliminate the issue.

From our side, the model update resolves the issue (model=‘gpt-4o-2024-11-20’). No errors occurred after multiple tests.

Has anyone found a solution while using this model version gpt-4o-2024-08-06?

Hello! in my case, the error occurred again (I do not understand why), but I solved it (for now and I hope it stays that way), using the model gpt-4o-2024-11-20 . I don’t know why gpt-4o keeps pointing to the other one which is older.

Hello everyone,
I’m working on a PDF RAG app and I’m also getting an error like mentioned in the title of the post.

In my PDF RAG app, I use gpt-4o-mini as the LLM . I use LLM to process pdfs ( I create summaries of images and text chunks , then I store those summaries to Pinecone vector store and the original text chunks and images to MongoDB doc store ) and to facilitate QA .

See attached screenshots below :

I get this error very few times right now but why am I getting it ?

Relevant Package Versions :

langchain-openai==0.1.14
openai==1.35.10
langchain==0.2.17
langchain-community==0.2.19
langchain-core==0.2.43
aiohttp==3.9.5
httpcore==1.0.5
httplib2==0.22.0
httptools==0.6.1
httpx==0.27.2
httpx-sse==0.4.0

1 Like

My app is a Streamlit app