{"record":{"id":"ce5daa07fd6795f8","repo":"BerriAI/litellm","slug":"messages-required-for-token-counting","errorCode":null,"errorMessage":"messages required for token counting","messagePattern":"messages required for token counting","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/vertex_ai_partner_models/count_tokens/handler.py","lineNumber":126,"sourceCode":"\n        Returns:\n            Dict containing token count information\n\n        Raises:\n            ValueError: If required parameters are missing or invalid\n        \"\"\"\n        # Strip version suffixes (@default, @20251001, etc.) — the Vertex AI\n        # count-tokens endpoint does not accept versioned model names.\n        model = self._strip_version_suffix(model)\n        if \"model\" in request_data:\n            request_data = {\n                **request_data,\n                \"model\": self._strip_version_suffix(request_data[\"model\"]),\n            }\n\n        # Validate request\n        if \"messages\" not in request_data:\n            raise ValueError(\"messages required for token counting\")\n\n        # Extract Vertex AI credentials and settings\n        vertex_credentials: Final = self.get_vertex_ai_credentials(litellm_params)\n        vertex_project: Final = self.get_vertex_ai_project(litellm_params)\n\n        # Check for count_tokens specific location override\n        vertex_count_tokens_location: Final = litellm_params.get(\"vertex_count_tokens_location\")\n        vertex_location_raw: Final = self.get_vertex_ai_location(litellm_params)\n\n        # Determine final location with precedence:\n        # 1. vertex_count_tokens_location (if provided)\n        # 2. vertex_location (if provided)\n        # 3. Default to us-east5 for Claude models when no location is set\n        # Supported regions: us-east5, europe-west1, asia-southeast1\n        # https://docs.cloud.google.com/vertex-ai/generative-ai/docs/partner-models/claude/count-tokens\n        if vertex_count_tokens_location:\n            vertex_location: str = vertex_count_tokens_location\n        elif vertex_location_raw:","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/vertex_ai_partner_models/count_tokens/handler.py#L108-L144","documentation":"Request validation in the partner-model count_tokens handler: after version-suffix stripping, the payload has no 'messages' key. The Vertex count-tokens endpoint requires the message list to estimate tokens.","triggerScenarios":"Thrown at litellm/llms/vertex_ai/vertex_ai_partner_models/count_tokens/handler.py:126 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-empty 'messages' list to the token counting call.","Ensure the messages argument is not dropped or None before invoking count_tokens."],"exampleFix":null,"handlingStrategy":"validation","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"}