{"record":{"id":"e7ebaaf5eda2d239","repo":"BerriAI/litellm","slug":"api-error-error-response-status-code","errorCode":null,"errorMessage":"API error: {error.response.status_code}","messagePattern":"API error: (.+?)","errorType":"exception","errorClass":"LassoGuardrailAPIError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py","lineNumber":618,"sourceCode":"            error,\n            extra={\n                \"guardrail_name\": getattr(self, \"guardrail_name\", \"unknown\"),\n                \"message_type\": message_type,\n                \"error_type\": type(error).__name__,\n            },\n        )\n\n        # Handle specific error types if httpx is available\n        if HTTPX_AVAILABLE:\n            if isinstance(error, httpx.TimeoutException):\n                raise LassoGuardrailAPIError(\"Lasso API timeout\")\n            elif isinstance(error, httpx.HTTPStatusError):\n                if error.response.status_code == 401:\n                    raise LassoGuardrailMissingSecrets(\"Invalid API key\")\n                elif error.response.status_code == 429:\n                    raise LassoGuardrailAPIError(\"Lasso API rate limit exceeded\")\n                else:\n                    raise LassoGuardrailAPIError(f\"API error: {error.response.status_code}\")\n\n        # Generic error handling\n        raise LassoGuardrailAPIError(f\"Failed to verify request safety with Lasso API: {error}\")\n\n    def _log_masking_applied(\n        self,\n        message_type: Literal[\"PROMPT\", \"COMPLETION\"],\n        response: dict[str, Any],\n    ) -> None:\n        \"\"\"Log masking application with structured context.\"\"\"\n        conversation_id: Final = getattr(self, \"conversation_id\", \"unknown\")\n        verbose_proxy_logger.debug(\n            \"Lasso masking applied\",\n            extra={\n                \"guardrail_name\": getattr(self, \"guardrail_name\", \"unknown\"),\n                \"message_type\": message_type,\n                \"violations_count\": len(response.get(\"findings\", {})),\n                \"masked_fields\": len(response.get(\"messages\", [])),","sourceCodeStart":600,"sourceCodeEnd":636,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py#L600-L636","documentation":"Catch-all LassoGuardrailAPIError for any Lasso API HTTP error other than 401 and 429 — httpx raised HTTPStatusError and the status code fell through the specific branches. The message embeds the raw status code (e.g. 'API error: 503'), which is the key diagnostic.","triggerScenarios":"The guardrail's call to the Lasso API returns an error status other than 401/429: 400 for a malformed/unsupported payload, 403 for permission or plan restrictions, 404 for a wrong api_base/endpoint, 413 for oversized payloads, or 5xx during a Lasso-side incident.","commonSituations":"Lasso 5xx outages or maintenance windows; a litellm version change sending a request shape the deployed Lasso endpoint rejects; a customized/wrong api_base in the guardrail config; extremely large prompts tripping 413.","solutions":["Read the status code from the message and the Lasso response details in the preceding log line, then act on that specific status.","For 5xx, check the Lasso status page and retry later — these are server-side and transient in most cases.","For 403/404, verify the guardrail's api_base/endpoint configuration and that your key's plan permits the API being called.","For 400/413, reduce or reshape the payload, and upgrade litellm if the request schema changed between versions."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"from litellm.proxy.guardrails.guardrail_hooks.lasso.lasso import LassoGuardrailAPIError\nimport re\n\ndef lasso_status_code(err: Exception) -> int | None:\n    \"\"\"Extract the HTTP status embedded in 'API error: <code>' messages.\"\"\"\n    if isinstance(err, LassoGuardrailAPIError):\n        m = re.search(r\"API error: (\\d{3})\", str(err))\n        if m:\n            return int(m.group(1))\n    return None","tryCatchPattern":"from litellm.proxy.guardrails.guardrail_hooks.lasso.lasso import LassoGuardrailAPIError\n\ntry:\n    result = await guardrail_hook(data)\nexcept LassoGuardrailAPIError as e:\n    code = lasso_status_code(e)\n    if code and 500 <= code < 600:\n        # Lasso-side incident: circuit-break, then degrade per your policy\n        trip_lasso_circuit_breaker(cooldown_s=60)\n        raise\n    raise  # 4xx (other than 401/429) = config/payload problem — fix, don't retry","preventionTips":["Pin your litellm version and check Lasso release notes before upgrading — request-shape mismatches surface as 400/404.","Verify the guardrail's api_base matches the Lasso endpoint your key/workspace uses.","Cap prompt sizes sent to the guardrail to avoid 413s.","Treat repeated 5xx as an incident: alert, don't retry-loop."],"tags":["http-error","lasso","guardrails","api-status"],"backgroundTag":"http-error-response","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}