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

openai lib preventing reading of headers for an http exception #1149

Open
1 task done
gtmtech opened this issue Feb 13, 2024 · 1 comment
Open
1 task done

openai lib preventing reading of headers for an http exception #1149

gtmtech opened this issue Feb 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@gtmtech
Copy link

gtmtech commented Feb 13, 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

https://github.com/openai/openai-python/blob/main/src/openai/_base_client.py#L980 - raises exceptions if there's an HTTPStatusError, such as a 429, 500 etc.

Which is semi-useful, but as-implemented, it does mean the headers are unavailable for that request.

Headers contain extremely valuable information sometimes, even when there are exceptions, and the library should ideally still return the headers along with the exception somehow, so that on receiving an exception it's possible to still read the headers.

To Reproduce

try:
    stream = sync_client.chat.completions.create(.... stream=True)
except Exception as e:
    print(e)
    print(vars(e))
    print(stream)
    raise e

stream is None, e is an exception with a bubbled up error message from the api, headers not available

Code snippets

see above for code snippets.

OS

macOS

Python version

Python 3.10.12

Library version

openai 1.3.7 and above

@gtmtech gtmtech added the bug Something isn't working label Feb 13, 2024
@rattrayalex
Copy link
Collaborator

sorry about this; you can read the headers with print(e.response.headers). We'll work on making that happen more nicely out of the box.

@openai openai deleted a comment from rattrayalex Feb 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

2 participants