{"record":{"id":"1db1ea02a747e960","repo":"BerriAI/litellm","slug":"completion-response-error","errorCode":null,"errorMessage":"{completion_response[\"error\"]}","messagePattern":"\\{completion_response\\[\"error\"\\]\\}","errorType":"http","errorClass":"AnthropicError","httpStatus":null,"severity":"error","filePath":"litellm/llms/anthropic/chat/transformation.py","lineNumber":2352,"sourceCode":"            provider_specific_fields[\"compaction_blocks\"] = compaction_blocks\n\n        return provider_specific_fields\n\n    def transform_parsed_response(\n        self,\n        completion_response: dict,\n        raw_response: httpx.Response,\n        model_response: ModelResponse,\n        json_mode: bool | None = None,\n        prefix_prompt: str | None = None,\n        speed: str | None = None,\n        tool_name_reverse_map: dict[str, str] | None = None,\n    ):\n        _hidden_params: Final[dict] = {}\n        _hidden_params[\"additional_headers\"] = process_anthropic_headers(dict(raw_response.headers))\n        if \"error\" in completion_response:\n            response_headers: Final = getattr(raw_response, \"headers\", None)\n            raise AnthropicError(\n                message=str(completion_response[\"error\"]),\n                status_code=raw_response.status_code,\n                headers=response_headers,\n            )\n\n        (\n            text_content,\n            citations,\n            thinking_blocks,\n            reasoning_content,\n            tool_calls,\n            web_search_results,\n            tool_results,\n            compaction_blocks,\n        ) = self.extract_response_content(completion_response=completion_response)\n\n        # Reverse-map rewritten tool names back to caller's originals so a\n        # downstream OpenAI-style dispatcher can match on the registered name.","sourceCodeStart":2334,"sourceCodeEnd":2370,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/anthropic/chat/transformation.py#L2334-L2370","documentation":"After a non-streaming call, LiteLLM checks the parsed response body for an 'error' key; if present it raises AnthropicError with that error payload as the message and the HTTP status code from the raw response. This is the Anthropic API's own error (overloaded, invalid_request, authentication, rate limit) surfaced as a Python exception — check status_code to classify it.","triggerScenarios":"Any non-streaming anthropic/ completion where the API responds with an error JSON: 401 bad API key, 429 rate limit, 529 overloaded, 400 invalid_request_error (bad params, context length), or a proxy returning Anthropic-shaped error bodies.","commonSituations":"Hitting rate limits under load; expired/rotated API keys; requests exceeding max tokens/context; Anthropic capacity events (529); misconfigured LiteLLM proxy keys.","solutions":["Inspect exception.status_code and the message body: 401 -> fix ANTHROPIC_API_KEY; 429 -> back off / raise limits; 529 -> retry with jitter; 400 -> fix request params.","For 429/529 use litellm's built-in retries (num_retries) or exponential backoff around the call.","Verify key and base URL env vars are set and current.","Reduce max_tokens or trim input if the error mentions context length."],"exampleFix":"# before\nresp = litellm.completion(model=\"anthropic/claude-sonnet-4-5\", messages=msgs)\n\n# after\nimport litellm, time\nfor attempt in range(5):\n    try:\n        resp = litellm.completion(\n            model=\"anthropic/claude-sonnet-4-5\", messages=msgs,\n            num_retries=3,  # handles 429/529 automatically\n        )\n        break\n    except litellm.exceptions.AnthropicError as e:\n        if e.status_code in (429, 529) and attempt < 4:\n            time.sleep(2 ** attempt)\n            continue\n        raise","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.exceptions import AnthropicError\ntry:\n    resp = litellm.completion(model=MODEL, messages=messages, num_retries=3)\nexcept AnthropicError as e:\n    if e.status_code == 401:\n        rotate_key_and_alert()\n    elif e.status_code in (429, 529):\n        schedule_retry_with_backoff()\n    elif e.status_code == 400:\n        fix_request_from_message(e.message)\n    raise","preventionTips":["Always set num_retries for 429/529 instead of hand-rolling loops.","Monitor status_code distribution to catch key expiry and rate limits early.","Trim context proactively to avoid 400 context-length rejections."],"tags":["anthropic","api-error","rate-limit","auth"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}