Skip to content

Refresh callable Azure API keys before requests#2992

Open
LittleChenLiya wants to merge 3 commits intoopenai:mainfrom
LittleChenLiya:fix-azure-callable-api-key-refresh
Open

Refresh callable Azure API keys before requests#2992
LittleChenLiya wants to merge 3 commits intoopenai:mainfrom
LittleChenLiya:fix-azure-callable-api-key-refresh

Conversation

@LittleChenLiya
Copy link

Summary

Fix Azure clients so callable api_key providers are refreshed before each request.

AzureOpenAI and AsyncAzureOpenAI override _prepare_options() to add Azure-specific auth headers, but they were not refreshing callable API keys before setting the api-key header. As a result, dynamic API key providers were not applied to requests or retries.

Changes

  • refresh callable API keys at the start of AzureOpenAI._prepare_options()
  • refresh callable API keys at the start of AsyncAzureOpenAI._prepare_options()
  • add sync and async regression tests covering callable api_key providers across retries

Testing

  • python -m pytest tests/lib/test_azure.py -n 0
  • python -m pytest tests/test_client.py -k "api_key_before_after_refresh or api_key_refresh_on_retry or bearer_token_refresh_async" -n 0

Closes #2626

@LittleChenLiya LittleChenLiya requested a review from a team as a code owner March 19, 2026 10:46
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a67dbb199

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The callable api_key feature seems to be broken for Azure OpenAI clients

1 participant