BerriAI/litellm · error · ValueError
Bad Request: model is required for Anthropic Messages Reques
Error message
Bad Request: model is required for Anthropic Messages Request
What it means
Raised by LiteLLMAnthropicMessagesParamHandler when translating an Anthropic /v1/messages request body. The handler pops required kwargs and validates them before building an AnthropicMessagesRequest; 'model' is the first required field. This is a client-side 400-class validation error that fires before any provider call is made.
Source
Thrown at litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py:169
) -> tuple[ChatCompletionRequest | None, dict[str, str]]:
"""
Translate Anthropic request params to OpenAI format, returning tool name mapping.
This method handles truncation of tool names that exceed OpenAI's 64-character
limit. The mapping allows restoring original names when translating responses.
Returns:
Tuple of (openai_request, tool_name_mapping)
- tool_name_mapping maps truncated tool names back to original names
"""
#########################################################
# Validate required params
#########################################################
model: Final = kwargs.pop("model")
messages: Final = kwargs.pop("messages")
if not model:
raise ValueError("Bad Request: model is required for Anthropic Messages Request")
if not messages:
raise ValueError("Bad Request: messages is required for Anthropic Messages Request")
#########################################################
# Created Typed Request Body
#########################################################
request_body: Final = AnthropicMessagesRequest(model=model, messages=messages, **kwargs)
(
translated_body,
tool_name_mapping,
) = LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(anthropic_message_request=request_body)
return translated_body, tool_name_mapping
def translate_completion_output_params(
self,
response: ModelResponse,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Ensure the request body passed to the adapter contains a non-empty 'model' key matching the model to route to (e.g. 'claude-sonnet-4-5').
- If you popped 'model' from kwargs earlier for routing decisions, pass it back in before calling the handler.
- Check for typos in the key name ('model', not 'model_name' or 'modelId') in the request dict.
- If using the pass-through endpoint, send the standard Anthropic Messages JSON body where 'model' is a top-level required field.
Example fix
// before
body = {"messages": [{"role": "user", "content": "hi"}], "max_tokens": 100}
openai_req, mapping = handler.translate_anthropic_request_body(**body) # ValueError
// after
body = {"model": "claude-sonnet-4-5", "messages": [{"role": "user", "content": "hi"}], "max_tokens": 100}
openai_req, mapping = handler.translate_anthropic_request_body(**body) Defensive patterns
Strategy: validation
Validate before calling
def validate_anthropic_body(body: dict) -> None:
if not body.get("model"):
raise ValueError("request body must include a non-empty 'model' field") Type guard
def is_valid_anthropic_request(body: dict) -> bool:
return isinstance(body.get("model"), str) and bool(body["model"].strip()) Try / catch
try:
result = handler.translate_anthropic_request_body(**body)
except ValueError as e:
if "model is required" in str(e):
return http_error(400, "model is required")
raise Prevention
- Validate required Anthropic fields (model, messages, max_tokens) at the API gateway edge before forwarding.
- Use a typed request model (pydantic) mirroring AnthropicMessagesRequest so omissions fail at parse time.
- Never pop 'model' from kwargs for routing without re-injecting it before adapter calls.
When it happens
Trigger: Calling the Anthropic experimental pass-through adapter (translate_anthropic_request_body / the params handler in transformation.py) with a kwargs dict that lacks a 'model' key or has model=None/empty string. Typical when a caller forwards a raw request body or constructs kwargs programmatically and forgets to inject the routed model name.
Common situations: Custom gateways that forward client JSON straight into the adapter without mapping the 'model' field; test fixtures that only set 'messages'; typos like 'model_name' instead of 'model'; code that pops 'model' earlier for routing and forgets to re-insert it.
Related errors
- Bad Request: messages is required for Anthropic Messages Req
- WebSearchInterception: missing follow-up messages
- Invalid first message. Should always start with 'role'='user
- Unable to parse anthropic tool result for message: {message}
- Unable to parse anthropic file message: {message}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/d2c1ef0b5f46b54a.
Report an issue: GitHub.