BerriAI/litellm · error · ValueError

Request must contain content to count tokens

Error message

Request must contain content to count tokens

What it means

Validation for InvokeModel-style (non-Converse) count-tokens requests: when the payload contains only the 'model' key and nothing else, there is no content to count, so it is rejected. InvokeModel bodies vary per model, so the check is intentionally minimal (request must have more than one key).

Source

Thrown at litellm/llms/bedrock/count_tokens/transformation.py:282

                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")

                if "content" not in message:
                    raise ValueError(f"Message {i} must have a 'content' field")
        else:
            # For InvokeModel format, we need at least some content to count tokens
            # The content structure varies by model, so we do minimal validation
            if len(request_data) <= 1:  # Only has 'model' field
                raise ValueError("Request must contain content to count tokens")

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Add at least one content field appropriate to the model (e.g. inputText, prompt, or embedding input)
  2. Skip the count-tokens call entirely when your pipeline produced no content — the count would be meaningless

Example fix

# before
req = {'model': 'amazon.titan-embed-text-v2:0'}

# after
req = {'model': 'amazon.titan-embed-text-v2:0', 'inputText': 'text to count'}
Defensive patterns

Strategy: validation

Validate before calling

if len({k for k in req if k != "model"}) == 0:
    raise ValueError("Request must contain content to count tokens")

Prevention

When it happens

Trigger: Sending {'model': 'amazon.nova-...'} alone, or {'model': m, 'inputText': ''} where inputText was deleted as empty leaving only model.

Common situations: Default request templates that start from {'model': model} and conditionally add fields, all of which evaluated false for the given input.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/71858fff915265b6. Report an issue: GitHub.