{"record":{"id":"61f395061536edb9","repo":"BerriAI/litellm","slug":"compresr-guardrail-requires-an-api-key-set-api-k","errorCode":null,"errorMessage":"Compresr guardrail requires an API key. Set `api_key` in the guardrail config or the COMPRESR_API_KEY env var.","messagePattern":"Compresr guardrail requires an API key\\. Set `api_key` in the guardrail config or the COMPRESR_API_KEY env var\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py","lineNumber":525,"sourceCode":"        compress_history: bool | None = None,\n        compress_last_user: bool | None = None,\n        enable_retrieval: bool | None = None,\n        guardrail_name: str | None = None,\n        event_hook: GuardrailEventHooks | list[GuardrailEventHooks] | Mode | None = None,\n        default_on: bool = False,\n        unreachable_fallback: str | None = None,\n        max_bytes_per_call: int | None = None,\n        allow_bypass_header: bool | None = None,\n        dynamic: bool | None = None,\n        dynamic_min_ratio: float | None = None,\n        dynamic_max_ratio: float | None = None,\n        compression_params: dict[str, object] | None = None,\n    ):\n        raw_api_base: Final = (api_base or get_secret_str(\"COMPRESR_API_BASE\") or DEFAULT_API_BASE).rstrip(\"/\")\n        self.compresr_api_base = _validate_api_base(raw_api_base)\n        self.compresr_api_key = api_key or get_secret_str(\"COMPRESR_API_KEY\")\n        if not self.compresr_api_key:\n            raise ValueError(\n                \"Compresr guardrail requires an API key. Set `api_key` in the \"\n                \"guardrail config or the COMPRESR_API_KEY env var.\"\n            )\n        self.compression_model = model or DEFAULT_COMPRESSION_MODEL\n        self.target_compression_ratio = (\n            DEFAULT_TARGET_COMPRESSION_RATIO if target_compression_ratio is None else target_compression_ratio\n        )\n        self.coarse = True if coarse is None else coarse\n        self.min_chars_to_compress = (\n            DEFAULT_MIN_CHARS_TO_COMPRESS if min_chars_to_compress is None else min_chars_to_compress\n        )\n        self.compress_tool_outputs = True if compress_tool_outputs is None else compress_tool_outputs\n        self.compress_system = False if compress_system is None else compress_system\n        self.compress_history = False if compress_history is None else compress_history\n        self.compress_last_user = False if compress_last_user is None else compress_last_user\n        self.enable_retrieval = True if enable_retrieval is None else enable_retrieval\n        self.unreachable_fallback: Literal[\"fail_closed\", \"fail_open\"] = (\n            \"fail_open\" if unreachable_fallback == \"fail_open\" else \"fail_closed\"","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py#L507-L543","documentation":"ValueError raised in the Compresr guardrail constructor when no API key is found: the api_key param is empty and the COMPRESR_API_KEY environment variable (via get_secret_str) is also unset. Compresr is a prompt-compression service that requires authenticated calls, so the guardrail fails fast at init instead of sending unauthenticated requests that would fail per-call.","triggerScenarios":"Adding a guardrail: compresr entry without api_key in a process whose environment lacks COMPRESR_API_KEY; secret-manager reference for COMPRESR_API_KEY failing to resolve; deploying with docker/systemd where the env var was never injected.","commonSituations":"Local works (env var in shell) but containerized proxy fails at startup; key stored under a different name (COMPRESR_TOKEN); .env file not loaded by the deployment.","solutions":["Set COMPRESR_API_KEY in the proxy's runtime environment (and restart).","Or pass api_key: in the guardrail's litellm_params (secret-manager references supported).","Verify resolution before startup: the proxy logs which secrets loaded; or run `printenv COMPRESR_API_KEY` inside the service context."],"exampleFix":"# before\nguardrails:\n  - guardrail_name: compresr-compress\n    litellm_params:\n      guardrail: compresr\n\n# after\n#   export COMPRESR_API_KEY=<key>\nguardrails:\n  - guardrail_name: compresr-compress\n    litellm_params:\n      guardrail: compresr\n      api_key: os.environ/COMPRESR_API_KEY","handlingStrategy":"validation","validationCode":"import os\nfrom litellm import get_secret_str\nif not (get_secret_str(\"COMPRESR_API_KEY\") or os.environ.get(\"COMPRESR_API_KEY\")):\n    raise SystemExit(\"COMPRESR_API_KEY must be set to use the compresr guardrail\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Startup preflight script asserting all guardrail secrets resolve before the proxy accepts traffic.","Manage keys via litellm secret-manager references so local/CI/prod parity is enforced.","Bake env checks into the container entrypoint; fail before bind, not on first request."],"tags":["litellm","guardrails","compresr","api-key","configuration","startup"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}