{"record":{"id":"fba3f3b32dc74384","repo":"BerriAI/litellm","slug":"messages-parameter-is-required-for-converse-input","errorCode":null,"errorMessage":"messages parameter is required for Converse input","messagePattern":"messages parameter is required for Converse input","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/count_tokens/transformation.py","lineNumber":264,"sourceCode":"        Validate the incoming count tokens request.\n        Supports both Converse and InvokeModel input formats.\n\n        Args:\n            request_data: The request payload\n\n        Raises:\n            ValueError: If the request is invalid\n        \"\"\"\n        if not request_data.get(\"model\"):\n            raise ValueError(\"model parameter is required\")\n\n        input_type: Final = self._detect_input_type(request_data)\n\n        if input_type == \"converse\":\n            # Validate Converse format (messages-based)\n            messages: Final = request_data.get(\"messages\", [])\n            if not messages:\n                raise ValueError(\"messages parameter is required for Converse input\")\n\n            if not isinstance(messages, list):\n                raise ValueError(\"messages must be a list\")\n\n            for i, message in enumerate(messages):\n                if not isinstance(message, dict):\n                    raise ValueError(f\"Message {i} must be a dictionary\")\n\n                if \"role\" not in message:\n                    raise ValueError(f\"Message {i} must have a 'role' field\")\n\n                if \"content\" not in message:\n                    raise ValueError(f\"Message {i} must have a 'content' field\")\n        else:\n            # For InvokeModel format, we need at least some content to count tokens\n            # The content structure varies by model, so we do minimal validation\n            if len(request_data) <= 1:  # Only has 'model' field\n                raise ValueError(\"Request must contain content to count tokens\")","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/count_tokens/transformation.py#L246-L282","documentation":"When the CountTokens request is detected as Converse-format (messages-based), the 'messages' array must be present and non-empty. An absent, empty, or falsy messages value raises this ValueError before any AWS call.","triggerScenarios":"Sending {'model': m} plus Converse markers (or no InvokeModel-style fields) without messages; sending messages: [] or omitting it entirely after input-shape detection classifies the request as Converse.","commonSituations":"Clients that send generic requests with only model + system prompt, or code paths that strip empty message arrays as a 'cleanup' step before calling count tokens.","solutions":["Include at least one message: [{'role': 'user', 'content': [{'text': '...'}]}]","If you meant InvokeModel-style input, use its native fields (e.g. inputText/prompt) so detection picks the right branch"],"exampleFix":"# before\nreq = {'model': model}\n\n# after\nreq = {'model': model, 'messages': [{'role': 'user', 'content': [{'text': 'hello'}]}]}","handlingStrategy":"validation","validationCode":"def has_converse_messages(req: dict) -> bool:\n    return isinstance(req.get(\"messages\"), list) and len(req[\"messages\"]) > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never strip empty-but-present message arrays before count-tokens calls","Build Converse payloads from a checked template containing at least one user turn"],"tags":["bedrock","count-tokens","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}