{"record":{"id":"dba34be8e2ec838f","repo":"BerriAI/litellm","slug":"token-counting-request-failed-with-status-respons","errorCode":null,"errorMessage":"Token counting request failed with status {response.status_code}: {error_text}","messagePattern":"Token counting request failed with status (.+?): (.+?)","errorType":"http","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/vertex_ai_partner_models/count_tokens/handler.py","lineNumber":186,"sourceCode":"\n        # Get async HTTP client\n        from litellm import LlmProviders\n\n        async_client: Final = get_async_httpx_client(llm_provider=LlmProviders.VERTEX_AI)\n\n        # Make the request\n        # Note: Partner models (especially Claude) accept Anthropic Messages API format directly\n        response: Final = await async_client.post(\n            endpoint_url,\n            headers=headers,\n            json=request_data,\n            timeout=30.0,\n        )\n\n        # Check for errors\n        if response.status_code != 200:\n            error_text: Final = response.text\n            raise ValueError(f\"Token counting request failed with status {response.status_code}: {error_text}\")\n\n        # Parse response\n        result: Final = response.json()\n\n        # Return token count\n        # Vertex AI Anthropic returns: {\"input_tokens\": 123}\n        return {\n            \"input_tokens\": result.get(\"input_tokens\", 0),\n            \"tokenizer_used\": \"vertex_ai_partner_models\",\n        }\n","sourceCodeStart":168,"sourceCodeEnd":197,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/vertex_ai_partner_models/count_tokens/handler.py#L168-L197","documentation":"Raised after the async POST to the Vertex count-tokens endpoint returns a non-200 status. The handler surfaces the upstream status code and error body because the token-count request itself was rejected by Vertex.","triggerScenarios":"Thrown at litellm/llms/vertex_ai/vertex_ai_partner_models/count_tokens/handler.py:186 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the status code and error text in the message for the upstream cause (auth, model access, quota).","Verify credentials, model availability in the region, and that the countTokens endpoint is reachable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}