{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/bedrock/count_tokens/transformation.py#L264-L283","documentation":"Raised when a count-tokens request is detected as InvokeModel format (not messages-based) but contains nothing besides the 'model' field (len(request_data) <= 1). InvokeModel bodies vary per model family, so litellm only enforces that some content field (inputText, prompt, etc.) exists — a body carrying only 'model' gives the tokenizer nothing to count.","triggerScenarios":"Sending {'model': 'bedrock/...'} alone; sending {'model': ..., 'metadata': {...}}-style wrappers whose real content field was dropped; mistakenly using an InvokeModel shape when you meant to send Converse messages.","commonSituations":"Stripping fields while debugging until only model remains; building the body from a config template whose content placeholder is empty; provider format confusion between Converse and InvokeModel styles.","solutions":["Add the content field your model expects, e.g. {'model': 'bedrock/titan...', 'inputText': 'hello'}","If you intended Converse format, send 'messages': [...] — its presence switches the request to the Converse branch","Log the final request body right before the call to catch over-aggressive field stripping"],"exampleFix":"# before\nbody = {'model': 'bedrock/amazon.titan-embed-text-v2:0'}\n\n# after\nbody = {'model': 'bedrock/amazon.titan-embed-text-v2:0', 'inputText': 'hello world'}","handlingStrategy":"validation","validationCode":"def validate_invoke_model_body(body: dict) -> None:\n    if 'messages' not in body and len([k for k in body if k != 'model']) == 0:\n        raise ValueError(\n            'InvokeModel count_tokens body needs a content field (e.g. inputText) besides model'\n        )","typeGuard":null,"tryCatchPattern":"try:\n    handler.count_tokens(body)\nexcept ValueError as e:\n    if 'must contain content' in str(e):\n        body['inputText'] = body.pop('text', '') or DEFAULT_TEXT\n        handler.count_tokens(body)\n    else:\n        raise","preventionTips":["Decide Converse vs InvokeModel shape per provider and centralize it","Log the final body keys before sending to catch stripped fields","Template bodies should fail loudly when placeholders render empty"],"tags":["bedrock","count-tokens","validation","empty-payload","invoke-model"],"backgroundTag":"missing-required-argument","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}