BerriAI/litellm · error · ValueError
model parameter is required
Error message
model parameter is required
What it means
Validation in the Bedrock CountTokens transformation: the request payload must include a 'model' field before the request can be transformed and sent. Both Converse-style and InvokeModel-style inputs require it, since the model is embedded in the AWS endpoint path.
Source
Thrown at litellm/llms/bedrock/count_tokens/transformation.py:256
}
"""
input_tokens: Final = bedrock_response.get("inputTokens", 0)
return {"input_tokens": input_tokens}
def validate_count_tokens_request(self, request_data: dict[str, Any]) -> None:
"""
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")View on GitHub (pinned to 6c2dcb801b)
Solutions
- Include a non-empty 'model' in the request_data sent to count tokens
- Default it from your routing config before calling LiteLLM: request_data.setdefault('model', model)
Example fix
# before
resp = await handler.count_tokens({'messages': msgs}, ...)
# after
resp = await handler.count_tokens({'model': 'anthropic.claude-3-5-sonnet-20240620-v1:0', 'messages': msgs}, ...) Defensive patterns
Strategy: validation
Validate before calling
def validate_count_tokens_request(req: dict) -> None:
if not req.get("model"):
raise ValueError("model parameter is required") Type guard
def has_model(req: dict) -> bool:
return isinstance(req, dict) and isinstance(req.get("model"), str) and bool(req["model"].strip()) Prevention
- setdefault('model', configured_model) when assembling count-token payloads
- Reject requests without model at your API boundary with a 400 before they reach LiteLLM
When it happens
Trigger: Calling count tokens with a payload containing only messages/inputText but no 'model' key, or model set to an empty string / None (falsy values are rejected).
Common situations: Building the request dict dynamically and skipping model when it was passed as a separate argument, or a client that assumes the proxy infers the model from config.
Related errors
- messages parameter is required for Converse input
- 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/bdea424ccc358275.
Report an issue: GitHub.