openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Add support for token providers in the native OpenAI client

Open samuelwcm opened this issue 1 year ago • 1 comments

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • [X] This is a feature request for the Python library

Describe the feature or improvement you're requesting

Our project utilizes both OpenAI and Azure OpenAI APIs, which our organisation manages through an API gateway. The gateway provides its own short-lived JWTs and serves as a mediator between clients and these APIs, with some organisational logic over the top.

For Azure APIs, we use the AzureOpenAI.azure_ad_token_provider parameter to automatically refresh access tokens. Unfortunately, OpenAI's standard clients lack this feature.

As a workaround, we have written a custom class extending openai.AsyncOpenAI, with api_key defined as an @property getter to handle token refreshes. However, this workaround is not ideal due to the extra maintenance required. Ideally, OpenAI's clients would natively support token providers the same way as the Azure ones do.

Would there be interest in adding this feature? I'm willing to make this contribution myself!

Additional context

No response

samuelwcm avatar Feb 15 '24 08:02 samuelwcm

Thanks for sharing your use-case!

May I ask what's wrong with using the AzureOpenAI class?

rattrayalex avatar Feb 15 '24 15:02 rattrayalex