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

Auth flow of custom http client not invoked when making a request #1026

Closed
1 task done
TomSteenbergen opened this issue Dec 27, 2023 · 3 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@TomSteenbergen
Copy link

TomSteenbergen commented Dec 27, 2023

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

When passing a custom http client to the OpenAI client, it does not properly use the custom client's auth flow.

In the client's _request method, self.custom_auth is passed to self._client.send (link to source code).

The property custom_auth however is simply defined as return None (link to source code).

Because we explicitly pass None to the auth argument of the send method of the httpx client, the client doesn't use the default value USE_CLIENT_DEFAULT for the auth argument (link to source code).

Is there a reason why we have this custom_auth property on the client? If we do not pass it to the auth argument of self._client.send, everything works as expected and the auth logic of the custom httpx client is properly invoked.

To Reproduce

openai_client = OpenAI(
    api_key="<API_KEY>",
    base_url="<BASE_URL>",
    http_client="<HTTP_CLIENT>",
)

completion = openai_client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Last name of the president of the United States",
        }
    ],
    model="gpt-3.5-turbo",
)  # Does not invoke the authentication flow of the client passed using `http_client`.

Code snippets

No response

OS

MacOS 14.2

Python version

3.11.6

Library version

1.3.9

@TomSteenbergen TomSteenbergen added the bug Something isn't working label Dec 27, 2023
@TomSteenbergen TomSteenbergen changed the title Authentication of custom http client not used when making a request Auth flow of custom http client not invoked when making a request Dec 27, 2023
@RobertCraigie
Copy link
Collaborator

Sorry about this, we should have a fix out shortly.

@TomSteenbergen
Copy link
Author

Awesome, thanks @RobertCraigie. Let me know if I can help by filing a PR or reviewing.

@RobertCraigie
Copy link
Collaborator

@TomSteenbergen PR is here: #1028

This fix will be included in the next release.

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

3 participants