{"record":{"id":"cf12614d1c45edcd","repo":"BerriAI/litellm","slug":"counttokens-processing-error-e-cf1261","errorCode":null,"errorMessage":"CountTokens processing error: {e}","messagePattern":"CountTokens processing error: (.+?)","errorType":"http","errorClass":"BedrockError","httpStatus":500,"severity":"error","filePath":"litellm/llms/bedrock/count_tokens/handler.py","lineNumber":130,"sourceCode":"            final_response: Final = self.transform_bedrock_response_to_anthropic(bedrock_response)\n\n            verbose_logger.debug(\"Final response: %s\", final_response)\n\n            return final_response\n\n        except BedrockError:\n            # Re-raise Bedrock exceptions as-is\n            raise\n        except httpx.HTTPStatusError as e:\n            # HTTP errors - preserve the actual status code\n            verbose_logger.error(\"HTTP error in CountTokens handler: %s\", e)\n            raise BedrockError(\n                status_code=e.response.status_code,\n                message=e.response.text,\n            )\n        except Exception as e:\n            verbose_logger.error(\"Error in CountTokens handler: %s\", e)\n            raise BedrockError(\n                status_code=500,\n                message=f\"CountTokens processing error: {e}\",\n            )\n","sourceCodeStart":112,"sourceCodeEnd":134,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/count_tokens/handler.py#L112-L134","documentation":"The generic fallback exception handler in the async CountTokens handler: any exception that is neither BedrockError nor httpx.HTTPStatusError is wrapped into BedrockError(status_code=500, message='CountTokens processing error: {e}'). The original exception text is preserved in the message, so the root cause is readable there.","triggerScenarios":"Response JSON parsing failures (invalid JSON body), errors inside request transformation (transform_bedrock_request_to_anthropic), network errors other than HTTPStatusError (ConnectError, ReadTimeout after the 30s httpx timeout), or None values in litellm_params breaking string handling.","commonSituations":"Transient network breakage, an AWS endpoint returning HTML error pages (proxy interference), passing unsupported input shapes (e.g. tool blocks) the transformer does not expect.","solutions":["Read the wrapped message — it contains the original exception repr, which names the real fault","Enable litellm verbose logging (litellm.set_verbose=True or LITELLM_LOG=DEBUG) to see the logged root cause","Fix the underlying issue: retry on network errors, simplify the message payload if transformation fails"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await count_tokens_handler(...)\nexcept BedrockError as e:\n    if e.status_code == 500 and e.message.startswith(\"CountTokens processing error\"):\n        # unwrap root cause text and retry on transient network causes\n        if \"timeout\" in e.message.lower() or \"connect\" in e.message.lower():\n            await asyncio.sleep(1); retry()\n        else:\n            raise","preventionTips":["Enable litellm debug logging so the pre-wrap exception is visible","Retry once on transient causes; do not retry blindly on 500s with parse errors"],"tags":["bedrock","count-tokens","error-handling","aws"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}