diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/generic_guardrail_api.py b/litellm/types/proxy/guardrails/guardrail_hooks/generic_guardrail_api.py index 4a868c48352..8e9d8dae6a9 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/generic_guardrail_api.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/generic_guardrail_api.py @@ -108,6 +108,20 @@ class GenericGuardrailAPIConfigModel( ): """Configuration parameters for the Generic Guardrail API guardrail""" + api_base: str | None = Field( + default=None, + description=( + "Base URL of the guardrail service implementing the LiteLLM Basic Guardrail API spec; " + "LiteLLM appends /beta/litellm_basic_guardrail_api to it. Falls back to the " + "GENERIC_GUARDRAIL_API_BASE environment variable, and initialization fails when neither is set." + ), + ) + + api_key: str | None = Field( + default=None, + description="API key for the guardrail service, sent as the x-api-key header.", + ) + optional_params: GenericGuardrailAPIOptionalParams | None = Field( default_factory=GenericGuardrailAPIOptionalParams, description="Optional parameters for the Generic Guardrail API guardrail", diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_generic_guardrail_api.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_generic_guardrail_api.py index 523ec1a37b4..67c2409f3e7 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_generic_guardrail_api.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_generic_guardrail_api.py @@ -1150,6 +1150,26 @@ class TestGenericGuardrailAPIStreamingConfig: assert GenericGuardrailAPI.get_config_model() is GenericGuardrailAPIConfigModel + def test_config_model_exposes_api_base_and_api_key(self): + from litellm.types.proxy.guardrails.guardrail_hooks.generic_guardrail_api import ( + GenericGuardrailAPIConfigModel, + ) + + assert set(GenericGuardrailAPIConfigModel.model_fields) >= {"api_base", "api_key"} + + @pytest.mark.asyncio + async def test_ui_provider_specific_params_expose_connection_fields(self): + from litellm.proxy.guardrails.guardrail_endpoints import ( + get_provider_specific_params, + ) + + provider_params = await get_provider_specific_params() + generic_params = provider_params["generic_guardrail_api"] + + assert generic_params["api_base"]["type"] == "string" + assert generic_params["api_key"]["type"] == "string" + assert generic_params["optional_params"]["type"] == "nested" + def test_streaming_transform_mode_defaults_block_only(self): guardrail = GenericGuardrailAPI( api_base="https://api.test.guardrail.com",