{"record":{"id":"bdea424ccc358275","repo":"BerriAI/litellm","slug":"model-parameter-is-required-bdea42","errorCode":null,"errorMessage":"model parameter is required","messagePattern":"model parameter is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/count_tokens/transformation.py","lineNumber":256,"sourceCode":"        }\n        \"\"\"\n        input_tokens: Final = bedrock_response.get(\"inputTokens\", 0)\n\n        return {\"input_tokens\": input_tokens}\n\n    def validate_count_tokens_request(self, request_data: dict[str, Any]) -> None:\n        \"\"\"\n        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\")","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/count_tokens/transformation.py#L238-L274","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)"],"exampleFix":"# before\nresp = await handler.count_tokens({'messages': msgs}, ...)\n\n# after\nresp = await handler.count_tokens({'model': 'anthropic.claude-3-5-sonnet-20240620-v1:0', 'messages': msgs}, ...)","handlingStrategy":"validation","validationCode":"def validate_count_tokens_request(req: dict) -> None:\n    if not req.get(\"model\"):\n        raise ValueError(\"model parameter is required\")","typeGuard":"def has_model(req: dict) -> bool:\n    return isinstance(req, dict) and isinstance(req.get(\"model\"), str) and bool(req[\"model\"].strip())","tryCatchPattern":null,"preventionTips":["setdefault('model', configured_model) when assembling count-token payloads","Reject requests without model at your API boundary with a 400 before they reach LiteLLM"],"tags":["bedrock","count-tokens","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}