Add refresh auth headers (sync and async) as alternate approach to allow bearer tokens to be refreshed#17
Draft
johanste wants to merge 59 commits into
Draft
Add refresh auth headers (sync and async) as alternate approach to allow bearer tokens to be refreshed#17johanste wants to merge 59 commits into
johanste wants to merge 59 commits into
Conversation
* feat(api): make model and inputs not required to create response * release: 1.90.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
* feat(api): update api shapes for usage and code interpreter * release: 1.91.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
* chore(tests): skip some failing tests on the latest python versions * chore(internal): add tests for breaking change detection * move over parse and stream methods out of beta * update docs * update tests * remove old beta files * fix relative import * fix(ci): release-doctor — report correct token name * feat(api): webhook and deep research support * release: 1.92.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com> Co-authored-by: David Meadows <[email protected]>
* chore(api): remove unsupported property * release: 1.92.2 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
* chore(readme): fix version rendering on pypi * feat(api): add file_url, fix event ID * release: 1.95.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
…low bearer tokens to be updated
johanste
commented
Jul 11, 2025
|
|
||
| @override | ||
| def _prepare_options(self, options: FinalRequestOptions) -> FinalRequestOptions: | ||
| self.refresh_auth_headers() |
Owner
Author
There was a problem hiding this comment.
It is not great to. have to remember to call refresh_auth_headers before accessing them. But since the current implementation is a (sync) property, we have to somehow allow for async refresh.
We could do the refresh in the sync context, but I believe that the asymmetry between sync and async is worse than splitting it apart for both sync and async clients....
| return Querystring(array_format="brackets") | ||
|
|
||
| def refresh_auth_headers(self): | ||
| bearer_token = self.bearer_token_provider() if self.bearer_token_provider else self.api_key |
Collaborator
There was a problem hiding this comment.
I don't have context for the change, but it looks like if the api_key or token is an empty string, they've updated the code to not send the header: https://github.com/openai/openai-python/blob/main/src/openai/_client.py#L286
… Propagate bearer_token_provider in the `copy` method.
* add tests, fix copy, add token provider to module client * fix lint * ignore for azure copy * revert change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes being requested
Provide callable to allow refresh of the bearer token. The callable must support IO calls being made and thus has to be async in an asynchronous context.
Additional context & links