{"record":{"id":"11cd5fc283a7326a","repo":"BerriAI/litellm","slug":"either-text-or-messages-must-be-provided","errorCode":null,"errorMessage":"Either text or messages must be provided","messagePattern":"Either text or messages must be provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/token_counter.py","lineNumber":398,"sourceCode":"        if tools or tool_choice:\n            raise ValueError(\"tools or tool_choice cannot be set if using text\")\n        if isinstance(text, list):\n            text_to_count = \"\".join(t for t in text if isinstance(t, str))\n        elif isinstance(text, str):\n            text_to_count = text\n        count_function: Final = _get_count_function(model, custom_tokenizer)\n        num_tokens = count_function(text_to_count)\n\n    elif messages is not None:\n        new_messages: Final = cast(list[AllMessageValues], convert_list_message_to_dict(messages))\n        params: Final = _MessageCountParams(model, custom_tokenizer)\n        num_tokens = _count_messages(params, new_messages, use_default_image_token_count, default_token_count)\n        if count_response_tokens is False:\n            includes_system_message: Final = any([message.get(\"role\", None) == \"system\" for message in new_messages])\n            num_tokens += _count_extra(params.count_function, tools, tool_choice, includes_system_message)\n\n    else:\n        raise ValueError(\"Either text or messages must be provided\")\n\n    return num_tokens\n\n\ndef _count_function_call_tokens(\n    key: str,\n    value: Any,\n    message: Mapping[str, Any],\n    count_function: TokenCounterFunction,\n) -> int:\n    \"\"\"\n    Count tokens contributed by an assistant message's tool/function call payload.\n\n    Handles both the modern `tool_calls` list and the legacy OpenAI\n    `function_call` dict. Only the `arguments` string is counted (matching the\n    existing tool_calls behavior); names are accounted for elsewhere via the\n    tool/function definitions and `tool_choice`.\n    \"\"\"","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/token_counter.py#L380-L416","documentation":"Argument validation in token_counter: neither text nor messages was provided, so there is no content to count tokens for.","triggerScenarios":"Thrown at litellm/litellm_core_utils/token_counter.py:398 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide either 'text' or 'messages' to the token counter.","Check the call site for accidentally omitted arguments."],"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-23T08:17:48.524Z"}