BerriAI/litellm · error · ValueError
messages parameter is required for Converse input
Error message
messages parameter is required for Converse input
What it means
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.
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)
Example fix
# before
body = {'model': 'bedrock/...', 'messages': []}
# after
body = {'model': 'bedrock/...', 'messages': [{'role': 'user', 'content': 'hello'}]} Defensive patterns
Strategy: validation
Validate before calling
def validate_converse_messages(body: dict) -> None:
if 'messages' in body or 'system' in body: # converse-shaped
msgs = body.get('messages')
if not isinstance(msgs, list) or len(msgs) == 0:
raise ValueError('Converse count_tokens body needs a non-empty messages list') Type guard
def is_converse_with_messages(body: dict) -> bool:
if 'messages' not in body:
return False
msgs = body['messages']
return isinstance(msgs, list) and len(msgs) > 0 Try / catch
try:
handler.count_tokens(body)
except ValueError as e:
if 'messages parameter is required' in str(e):
raise ConversationEmptyError('nothing to count') from e
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Message must be a dictionary
- Message must have a 'content' field
- Message must have a 'role' field
- messages must be a list
- model parameter is required
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/fba3f3b32dc74384.
Report an issue: GitHub.
Appendix: 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 77b7c6c40c)