From f21a75973dbf3f284168968f39775aac594e7015 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 14:11:49 +0000 Subject: [PATCH] fix(guardrails): expose api_base and api_key on the Generic Guardrail API config model --- .../guardrail_hooks/generic_guardrail_api.py | 14 +++++++++++++ .../test_generic_guardrail_api.py | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+) 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 9e198e13902..a062c710e10 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: Optional[str] = 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: Optional[str] = Field( + default=None, + description="API key for the guardrail service, sent as the x-api-key header.", + ) + optional_params: Optional[GenericGuardrailAPIOptionalParams] = 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 5be0d43c250..fcaa69ab3da 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",