{"record":{"id":"71858fff915265b6","repo":"BerriAI/litellm","slug":"request-must-contain-content-to-count-tokens","errorCode":null,"errorMessage":"Request must contain content to count tokens","messagePattern":"Request must contain content to count tokens","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/count_tokens/transformation.py","lineNumber":282,"sourceCode":"                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\")\n\n                if \"content\" not in message:\n                    raise ValueError(f\"Message {i} must have a 'content' field\")\n        else:\n            # For InvokeModel format, we need at least some content to count tokens\n            # The content structure varies by model, so we do minimal validation\n            if len(request_data) <= 1:  # Only has 'model' field\n                raise ValueError(\"Request must contain content to count tokens\")\n","sourceCodeStart":264,"sourceCodeEnd":283,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/count_tokens/transformation.py#L264-L283","documentation":"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).","triggerScenarios":"Sending {'model': 'amazon.nova-...'} alone, or {'model': m, 'inputText': ''} where inputText was deleted as empty leaving only model.","commonSituations":"Default request templates that start from {'model': model} and conditionally add fields, all of which evaluated false for the given input.","solutions":["Add at least one content field appropriate to the model (e.g. inputText, prompt, or embedding input)","Skip the count-tokens call entirely when your pipeline produced no content — the count would be meaningless"],"exampleFix":"# before\nreq = {'model': 'amazon.titan-embed-text-v2:0'}\n\n# after\nreq = {'model': 'amazon.titan-embed-text-v2:0', 'inputText': 'text to count'}","handlingStrategy":"validation","validationCode":"if len({k for k in req if k != \"model\"}) == 0:\n    raise ValueError(\"Request must contain content to count tokens\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Skip count-tokens calls when your pipeline produced no content","Ensure InvokeModel-style payloads carry at least one content field (inputText/prompt)"],"tags":["bedrock","count-tokens","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}