BerriAI/litellm · error · ValueError
Azure Content Safety: api_key is required
Error message
Azure Content Safety: api_key is required
What it means
Init guard for Azure Content Safety guardrails: litellm_params.api_key is empty, so calls to the Content Safety endpoint cannot be authenticated.
Source
Thrown at litellm/proxy/guardrails/guardrail_hooks/azure/__init__.py:16
from typing import TYPE_CHECKING, Final
from litellm.types.guardrails import SupportedGuardrailIntegrations
from .prompt_shield import AzureContentSafetyPromptShieldGuardrail
from .text_moderation import AzureContentSafetyTextModerationGuardrail
if TYPE_CHECKING:
from litellm.types.guardrails import Guardrail, LitellmParams
def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"):
import litellm
if not litellm_params.api_key:
raise ValueError("Azure Content Safety: api_key is required")
if not litellm_params.api_base:
raise ValueError("Azure Content Safety: api_base is required")
azure_guardrail: Final = litellm_params.guardrail.split("/")[1]
guardrail_name: Final = guardrail.get("guardrail_name")
if not guardrail_name:
raise ValueError("Azure Content Safety: guardrail_name is required")
if azure_guardrail == "prompt_shield":
azure_content_safety_guardrail: (
AzureContentSafetyPromptShieldGuardrail | AzureContentSafetyTextModerationGuardrail
) = AzureContentSafetyPromptShieldGuardrail(
guardrail_name=guardrail_name,
**{
**litellm_params.model_dump(exclude_none=True),
"api_key": litellm_params.api_key,
"api_base": litellm_params.api_base,View on GitHub (pinned to 77b7c6c40c)
Solutions
- Provide an api_key for Azure Content Safety via guardrail config or environment.
Example fix
litellm_params: api_key: os.environ/AZURE_CONTENT_SAFETY_KEY
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/proxy/guardrails/guardrail_hooks/azure/__init__.py:16 when the library encounters an invalid state.
Common situations: Azure Content Safety guardrail configured without an API key.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/046e0c4cd9482188.
Report an issue: GitHub.