{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/bedrock/count_tokens/transformation.py#L246-L282","documentation":"Raised by validate_count_tokens_request when the request's input is detected as Converse format (it has a 'messages' key / messages-based shape) but the messages value is empty or absent. Converse-format requests are identified by structure, and token counting requires at least one message to count.","triggerScenarios":"Sending {'model': '...', 'messages': []} or omitting messages entirely while other keys (or the detector heuristic) mark the request as Converse-style; passing messages in a different key ('prompt', 'input') so the real list looks empty.","commonSituations":"Building the request dynamically and filtering out all messages (e.g. empty conversation guard); confusing InvokeModel bodies ({'inputText': ...}) with Converse bodies; testing with placeholder empty payloads.","solutions":["Include at least one message: messages=[{'role': 'user', 'content': 'hello'}]","If you meant InvokeModel format, remove the 'messages' key so the detector routes to the inputText-style branch","Double-check that your serialization isn't dropping the field (requests library ignoring None, JSON schema stripping empty lists)"],"exampleFix":"# before\nbody = {'model': 'bedrock/...', 'messages': []}\n\n# after\nbody = {'model': 'bedrock/...', 'messages': [{'role': 'user', 'content': 'hello'}]}","handlingStrategy":"validation","validationCode":"def validate_converse_messages(body: dict) -> None:\n    if 'messages' in body or 'system' in body:  # converse-shaped\n        msgs = body.get('messages')\n        if not isinstance(msgs, list) or len(msgs) == 0:\n            raise ValueError('Converse count_tokens body needs a non-empty messages list')","typeGuard":"def is_converse_with_messages(body: dict) -> bool:\n    if 'messages' not in body:\n        return False\n    msgs = body['messages']\n    return isinstance(msgs, list) and len(msgs) > 0","tryCatchPattern":"try:\n    handler.count_tokens(body)\nexcept ValueError as e:\n    if 'messages parameter is required' in str(e):\n        raise ConversationEmptyError('nothing to count') from e\n    raise","preventionTips":["Guard upstream: skip the API call when a conversation has zero messages","Name the field exactly 'messages' when porting from other APIs","Add unit tests covering empty-conversation flows"],"tags":["bedrock","count-tokens","validation","messages","converse"],"backgroundTag":"missing-required-argument","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}