Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All API Errors raised during streaming raise the same generic message ("An error occurred during streaming") #1160

Closed
1 task done
tdene opened this issue Feb 15, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@tdene
Copy link

tdene commented Feb 15, 2024

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

All API Errors raised during streaming raise the same generic message ("An error occurred during streaming").
See line 64 of _streaming.py.

The data["error"] field is completely disregarded for streaming errors. Instead, it could be read to raise the correct type of error.
This is a major quality-of-life issue with custom inference servers that seek to follow the openai standard.

To Reproduce

  1. Spin up a custom inference server.
  2. Have users access it via the openai Python library.
  3. Introduce an arbitrary error in your inference server, and handle it correctly, by returning the error's code, param, and type inside of the streaming response.
  4. Notice that the users will always get the generic "An error occurred during streaming" message.

Code snippets

The relevant part of the codebase uses this code snippet:

if is_mapping(data) and data.get("error"):
    raise APIError(
        message="An error occurred during streaming",
        request=self.response.request,
        body=data["error"],
    )

A different part of the codebase uses this code snippet:

raise self._make_status_error_from_response(err.response) from None

This latter type of functionality should also be used while iterating over a stream.



### OS

Ubuntu 20.04.5 LTS

### Python version

Python v.3.11.6

### Library version

openai v1.11.1
@tdene tdene added the bug Something isn't working label Feb 15, 2024
@clemlesne
Copy link

Frequently having the same issue with GPT-4 0116-Preview on Azure OpenAI.

@tdene
Copy link
Author

tdene commented Feb 29, 2024

Just want to re-emphasize: this is a massive quality-of-life loss that, to me, appears to have a easy quick resolution (just put data["error"] in the message).

@RobertCraigie
Copy link
Collaborator

Sorry about this! The error messages will be improved in the next release https://github.com/openai/openai-python/pull/1218/files

happydeveloper0305 added a commit to happydeveloper0305/openai_python that referenced this issue May 9, 2024
byteboss125 pushed a commit to byteboss125/openai-python that referenced this issue Jun 14, 2024
@vishuhumanliai
Copy link

I'm having this issue with gpt-4o + agent implementation, can anybody help me out?
raise APIError(
openai.APIError: An error occurred during streaming)

@RobertCraigie
Copy link
Collaborator

Are you on the latest version?

@vishuhumanliai
Copy link

Are you on the latest version?
I'm using these versions
openai==1.8.0,
langchain==0.1.1

@RobertCraigie
Copy link
Collaborator

You are on quite an old version that does not include this fix. Please upgrade

happydream9032 pushed a commit to happydream9032/OpenAI_Python that referenced this issue Jul 24, 2024
risingstar0225 added a commit to risingstar0225/openai_py that referenced this issue Jul 26, 2024
megamanics pushed a commit to devops-testbed/openai-python that referenced this issue Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants