BerriAI/litellm · error · ValueError
messages parameter is required for Converse input
Error message
messages parameter is required for Converse input
What it means
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.
Source
Thrown at litellm/llms/bedrock/count_tokens/transformation.py:264
Validate the incoming count tokens request.
Supports both Converse and InvokeModel input formats.
Args:
request_data: The request payload
Raises:
ValueError: If the request is invalid
"""
if not request_data.get("model"):
raise ValueError("model parameter is required")
input_type: Final = self._detect_input_type(request_data)
if input_type == "converse":
# Validate Converse format (messages-based)
messages: Final = request_data.get("messages", [])
if not messages:
raise ValueError("messages parameter is required for Converse input")
if not isinstance(messages, list):
raise ValueError("messages must be a list")
for i, message in enumerate(messages):
if not isinstance(message, dict):
raise ValueError(f"Message {i} must be a dictionary")
if "role" not in message:
raise ValueError(f"Message {i} must have a 'role' field")
if "content" not in message:
raise ValueError(f"Message {i} must have a 'content' field")
else:
# For InvokeModel format, we need at least some content to count tokens
# The content structure varies by model, so we do minimal validation
if len(request_data) <= 1: # Only has 'model' field
raise ValueError("Request must contain content to count tokens")View on GitHub (pinned to 6c2dcb801b)
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
Example fix
# before
req = {'model': model}
# after
req = {'model': model, 'messages': [{'role': 'user', 'content': [{'text': 'hello'}]}]} Defensive patterns
Strategy: validation
Validate before calling
def has_converse_messages(req: dict) -> bool:
return isinstance(req.get("messages"), list) and len(req["messages"]) > 0 Prevention
- Never strip empty-but-present message arrays before count-tokens calls
- Build Converse payloads from a checked template containing at least one user turn
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- model parameter is required
- messages must be a list
- Message {i} must be a dictionary
- Message {i} must have a 'role' field
- Message {i} must have a 'content' field
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/fba3f3b32dc74384.
Report an issue: GitHub.