BerriAI/litellm · error · HTTPException

Model is required in request body

Error message

Model is required in request body

What it means

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.

Source

Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:826

    """
    Handle AWS Bedrock CountTokens API requests.

    This function processes count_tokens endpoints like:
    - /v1/messages/count_tokens
    - /v1/messages/count-tokens
    """
    from litellm.llms.bedrock.common_utils import BedrockError
    from litellm.llms.bedrock.count_tokens.handler import BedrockCountTokensHandler
    from litellm.proxy.proxy_server import llm_router

    try:
        # Initialize the handler
        handler: Final = BedrockCountTokensHandler()

        # Extract model from request body
        model: Final = request_body.get("model")
        if not model:
            raise HTTPException(status_code=400, detail={"error": "Model is required in request body"})

        # Get model parameters from router
        litellm_params: Final = {"user_api_key_dict": user_api_key_dict}
        resolved_model = model  # Default fallback

        if llm_router:
            deployments: Final = llm_router.get_model_list(model_name=model)
            if deployments and len(deployments) > 0:
                # Get the first matching deployment
                deployment: Final = deployments[0]
                model_litellm_params: Final = deployment.get("litellm_params", {})

                # Get the resolved model ID from the configuration
                if "model" in model_litellm_params:
                    resolved_model = model_litellm_params["model"]

                # Copy all litellm_params - BaseAWSLLM will handle AWS credential discovery
                for key, value in model_litellm_params.items():

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Add the model field to the request body of the count-tokens/generate request.
  2. Verify the JSON body is parsed correctly (Content-Type: application/json).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:826 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/fc597930428a015b. Report an issue: GitHub.