{"record":{"id":"897e741d90839c85","repo":"BerriAI/litellm","slug":"unsupported-type-type-value-for-key-function-ca","errorCode":null,"errorMessage":"Unsupported type {type(value)} for key function_call in message {message}","messagePattern":"Unsupported type (.+?) for key function_call in message (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/token_counter.py","lineNumber":429,"sourceCode":"\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    \"\"\"\n    if key == \"tool_calls\":\n        if not isinstance(value, list):\n            raise ValueError(f\"Unsupported type {type(value)} for key tool_calls in message {message}\")\n        total = 0\n        for tool_call in value:\n            if \"function\" not in tool_call:\n                raise ValueError(f\"Unsupported tool call {tool_call} must contain a function key\")\n            function_arguments = tool_call[\"function\"].get(\"arguments\", \"\")\n            total += count_function(str(function_arguments))\n        return total\n    if key == \"function_call\":\n        if not isinstance(value, Mapping):\n            raise ValueError(f\"Unsupported type {type(value)} for key function_call in message {message}\")\n        return count_function(str(value.get(\"arguments\", \"\")))\n    raise ValueError(f\"Unexpected key {key!r}; expected 'tool_calls' or 'function_call'\")\n\n\ndef _count_messages(\n    params: _MessageCountParams,\n    messages: list[AllMessageValues],\n    use_default_image_token_count: bool,\n    default_token_count: int | None,\n) -> int:\n    \"\"\"\n    Count the number of tokens in a list of messages.\n\n    Args:\n        params (_MessageCountParams): The parameters for counting tokens.\n        messages (List[AllMessageValues]): The list of messages to count tokens in.\n        use_default_image_token_count (bool): When True, will NOT make a GET request to the image URL and instead return the default image dimensions.\n        default_token_count (Optional[int]): The default number of tokens to return for a message block, if an error occurs.","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/token_counter.py#L411-L447","documentation":"Legacy function-call counting guard: the message's 'function_call' key holds a non-dict value, so the legacy OpenAI function_call payload cannot be processed. Fires on type-mismatched assistant messages.","triggerScenarios":"Thrown at litellm/litellm_core_utils/token_counter.py:429 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["function_call in the message must be a dict with name/arguments.","Fix the message structure to match the expected function_call schema."],"exampleFix":null,"handlingStrategy":"type-guard","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"}