diff --git a/src/openai/lib/azure.py b/src/openai/lib/azure.py index 4fcae24788..ea4d6f6f17 100644 --- a/src/openai/lib/azure.py +++ b/src/openai/lib/azure.py @@ -347,11 +347,13 @@ def _get_azure_ad_token(self) -> str | None: return None @override - def _auth_headers(self, security: SecurityOptions) -> dict[str, str]: # noqa: ARG002 + def _auth_headers(self, security: SecurityOptions) -> dict[str, str]: if self._azure_ad_token is not None: return {"Authorization": f"Bearer {self._azure_ad_token}"} if self.api_key and self.api_key != API_KEY_SENTINEL: + if security.get("bearer_auth", False): + return {"Authorization": f"Bearer {self.api_key}"} return {"api-key": self.api_key} return {} @@ -669,11 +671,13 @@ async def _get_azure_ad_token(self) -> str | None: return None @override - def _auth_headers(self, security: SecurityOptions) -> dict[str, str]: # noqa: ARG002 + def _auth_headers(self, security: SecurityOptions) -> dict[str, str]: if self._azure_ad_token is not None: return {"Authorization": f"Bearer {self._azure_ad_token}"} if self.api_key and self.api_key != API_KEY_SENTINEL: + if security.get("bearer_auth", False): + return {"Authorization": f"Bearer {self.api_key}"} return {"api-key": self.api_key} return {}