litellm/tests/test_litellm/llms/azure
Mateo Wang ec8696faa6
fix(azure): preserve AD token refresh in v1 OpenAI client path (#28627)
* fix(azure): preserve AD token refresh in v1 OpenAI client path

The /openai/v1/ code path (api_version in {"v1", "latest", "preview"})
constructs a plain OpenAI/AsyncOpenAI client, but only forwarded
`api_key` from `azure_client_params`. When `enable_azure_ad_token_refresh`
is set (or any AD-only auth), `api_key` is None and the client
constructor raised "The api_key client option must be set...", breaking
every Azure call with a v1 api_version.

The OpenAI SDK (>=2.20.0) accepts a callable for `api_key` and re-invokes
it on every request via `_refresh_api_key`, so we now forward
`azure_ad_token_provider` directly — preserving the per-request token
refresh behavior of the regular AzureOpenAI client and avoiding the
expiry hole that resolving the token once at client-creation time would
introduce. Static `azure_ad_token` strings fall through to `api_key`.

For the async path we wrap the sync provider returned by azure-identity
in an async function since AsyncOpenAI expects `Callable[[], Awaitable[str]]`.

Fixes #27945

https://claude.ai/code/session_01UnzrDSFUUgp5T2wRoPMxq5

* fix(azure): offload sync token provider to thread in v1 async wrapper

* fix(azure): include AD credential identity in v1 client cache key

---------

Co-authored-by: Claude <noreply@anthropic.com>
(cherry picked from commit 96a2e8b16d)
2026-06-03 22:52:21 +00:00
..
chat style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
image_edit [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
image_generation [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
passthrough fix(azure/passthrough): populate standard_logging_object via logging hook 2026-04-14 08:10:39 +02:00
realtime style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
response [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
text_to_speech style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
videos style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_azure_common_utils.py fix(azure): preserve AD token refresh in v1 OpenAI client path (#28627) 2026-06-03 22:52:21 +00:00
test_azure_cost_calculation.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_azure_exception_mapping.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_azure_fine_tuning_api.py refactor: refactor testing 2026-03-28 18:39:32 -07:00