Skip to content

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

Closed
@TomSteenbergen

Description

@TomSteenbergen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions