{"record":{"id":"fc597930428a015b","repo":"BerriAI/litellm","slug":"model-is-required-in-request-body","errorCode":null,"errorMessage":"Model is required in request body","messagePattern":"Model is required in request body","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py","lineNumber":826,"sourceCode":"    \"\"\"\n    Handle AWS Bedrock CountTokens API requests.\n\n    This function processes count_tokens endpoints like:\n    - /v1/messages/count_tokens\n    - /v1/messages/count-tokens\n    \"\"\"\n    from litellm.llms.bedrock.common_utils import BedrockError\n    from litellm.llms.bedrock.count_tokens.handler import BedrockCountTokensHandler\n    from litellm.proxy.proxy_server import llm_router\n\n    try:\n        # Initialize the handler\n        handler: Final = BedrockCountTokensHandler()\n\n        # Extract model from request body\n        model: Final = request_body.get(\"model\")\n        if not model:\n            raise HTTPException(status_code=400, detail={\"error\": \"Model is required in request body\"})\n\n        # Get model parameters from router\n        litellm_params: Final = {\"user_api_key_dict\": user_api_key_dict}\n        resolved_model = model  # Default fallback\n\n        if llm_router:\n            deployments: Final = llm_router.get_model_list(model_name=model)\n            if deployments and len(deployments) > 0:\n                # Get the first matching deployment\n                deployment: Final = deployments[0]\n                model_litellm_params: Final = deployment.get(\"litellm_params\", {})\n\n                # Get the resolved model ID from the configuration\n                if \"model\" in model_litellm_params:\n                    resolved_model = model_litellm_params[\"model\"]\n\n                # Copy all litellm_params - BaseAWSLLM will handle AWS credential discovery\n                for key, value in model_litellm_params.items():","sourceCodeStart":808,"sourceCodeEnd":844,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py#L808-L844","documentation":"Thrown by the Bedrock CountTokens handler when the request body to /v1/messages/count_tokens (or count-tokens) has no 'model' key or an empty value; the model string is required to route the request through the LiteLLM router before counting tokens.","triggerScenarios":"Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:826 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add the model field to the request body of the count-tokens/generate request.","Verify the JSON body is parsed correctly (Content-Type: application/json)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}