{"record":{"id":"79a41c5ea0961918","repo":"BerriAI/litellm","slug":"api-base-is-required-for-generic-guardrail-api-se","errorCode":null,"errorMessage":"api_base is required for Generic Guardrail API. Set GENERIC_GUARDRAIL_API_BASE environment variable or pass it in litellm_params","messagePattern":"api_base is required for Generic Guardrail API\\. Set GENERIC_GUARDRAIL_API_BASE environment variable or pass it in litellm_params","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py","lineNumber":198,"sourceCode":"        fail_on_error: bool | None = True,\n        extra_headers: list | None = None,\n        streaming_end_of_stream_only: bool | None = None,\n        streaming_sampling_rate: int | None = None,\n        streaming_transform_mode: Literal[\"block_only\", \"incremental_diff\"] | None = None,\n        **kwargs,\n    ):\n        self.async_handler = get_async_httpx_client(llm_provider=httpxSpecialProvider.GuardrailCallback)\n        self.headers = headers or {}\n        self.extra_headers = extra_headers or []\n\n        # If api_key is provided, add it as x-api-key header\n        if api_key:\n            self.headers[\"x-api-key\"] = api_key\n\n        base_url = api_base or os.environ.get(\"GENERIC_GUARDRAIL_API_BASE\")\n\n        if not base_url:\n            raise ValueError(\n                \"api_base is required for Generic Guardrail API. \"\n                \"Set GENERIC_GUARDRAIL_API_BASE environment variable or pass it in litellm_params\"\n            )\n\n        # Append the endpoint path if not already present\n        if not base_url.endswith(\"/beta/litellm_basic_guardrail_api\"):\n            base_url = base_url.rstrip(\"/\")\n            self.api_base = f\"{base_url}/beta/litellm_basic_guardrail_api\"\n        else:\n            self.api_base = base_url\n\n        self.additional_provider_specific_params = additional_provider_specific_params or {}\n\n        self.unreachable_fallback: Literal[\"fail_closed\", \"fail_open\"] = unreachable_fallback\n\n        self.fail_on_error: bool = True if fail_on_error is None else fail_on_error\n\n        # Read by UnifiedLLMGuardrails.async_post_call_streaming_iterator_hook","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py#L180-L216","documentation":"ValueError raised in GenericGuardrailAPI.__init__ when neither the api_base parameter nor the GENERIC_GUARDRAIL_API_BASE environment variable is set. The generic guardrail needs a full endpoint URL to POST to, and after this check it appends '/beta/litellm_basic_guardrail_api' to the base. It fails at guardrail construction time (config load / startup).","triggerScenarios":"A guardrails-config entry with guardrail: generic_guardrail_api and no api_base in litellm_params while GENERIC_GUARDRAIL_API_BASE is unset; env var misspelled (GUARDRAIL vs GUARDRAILS); secret injection pipeline missing the variable.","commonSituations":"Bringing up a self-hosted/custom guardrail service for the first time; porting config between environments where the base URL was only in one env; the endpoint path suffix behavior surprising users who passed a full URL without the expected suffix.","solutions":["Set GENERIC_GUARDRAIL_API_BASE to your guardrail service root (e.g. https://guardrail.internal).","Or pass api_base directly in litellm_params for the guardrail.","If you pass a full URL, include /beta/litellm_basic_guardrail_api or it will be appended automatically.","Restart the proxy after fixing the environment."],"exampleFix":"# before\nlitellm_params:\n  guardrail: generic_guardrail_api\n  api_key: os.environ/GUARDRAIL_API_KEY\n\n# after\nlitellm_params:\n  guardrail: generic_guardrail_api\n  api_key: os.environ/GUARDRAIL_API_KEY\n  api_base: os.environ/GENERIC_GUARDRAIL_API_BASE","handlingStrategy":"validation","validationCode":"import os, yaml\n\ncfg = yaml.safe_load(open('config.yaml'))\nfor g in cfg.get('guardrails', []):\n    p = g.get('litellm_params', {})\n    if p.get('guardrail') == 'generic_guardrail_api' and not (p.get('api_base') or os.getenv('GENERIC_GUARDRAIL_API_BASE')):\n        raise SystemExit(f\"guardrail '{g.get('guardrail_name')}' has no api_base\")","typeGuard":null,"tryCatchPattern":"try:\n    guardrail = GenericGuardrailAPI(litellm_params=cfg)\nexcept ValueError as e:\n    if 'GENERIC_GUARDRAIL_API_BASE' in str(e):\n        logger.error('config incomplete: %s', e)\n        raise\n    raise","preventionTips":["Set GENERIC_GUARDRAIL_API_BASE in every environment's deployment manifest.","Remember the /beta/litellm_basic_guardrail_api suffix is appended to the base automatically.","Lint guardrail configs in CI before rollout."],"tags":["generic-guardrail","guardrail","api-base","config","startup"],"backgroundTag":"missing-env-var","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}