in pyrit/prompt_target/openai/openai_target.py [0:0]
def _set_auth_headers(self, use_aad_auth, passed_api_key) -> None:
self._api_key = default_values.get_non_required_value(
env_var_name=self.api_key_environment_variable, passed_value=passed_api_key
)
if self._api_key:
# This header is set as api-key in azure and bearer in openai
# But azure still functions if it's in both places and in fact,
# in Azure foundry it needs to be set as a bearer
self._headers["Api-Key"] = self._api_key
self._headers["Authorization"] = f"Bearer {self._api_key}"
if use_aad_auth:
logger.info("Authenticating with AzureAuth")
scope = get_default_scope(self._endpoint)
self._azure_auth = AzureAuth(token_scope=scope)
self._headers["Authorization"] = f"Bearer {self._azure_auth.get_token()}"