litellm - 💡(How to fix) Fix [Bug]: Trim Messages function does not support "File" content type.

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Traceback (most recent call last): File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 745, in _count_content_list raise ValueError( ...<2 lines>... ) ValueError: Invalid content item type: file. Expected str or dict with 'type' field (text, image_url, tool_use, tool_result, thinking).

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 7229, in trim_messages current_tokens = token_counter(model=model or "", messages=messages) File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 2320, in token_counter return _get_token_counter_new()( ~~~~~~~~~~~~~~~~~~~~~~~~^ model, ^^^^^^ ...<7 lines>... default_token_count, ^^^^^^^^^^^^^^^^^^^^ ) ^ File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 422, in token_counter num_tokens = _count_messages( params, new_messages, use_default_image_token_count, default_token_count ) File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 483, in _count_messages num_tokens += _count_content_list( ~~~~~~~~~~~~~~~~~~~^ params.count_function, ^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... default_token_count, ^^^^^^^^^^^^^^^^^^^^ ) ^ File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 753, in _count_content_list raise ValueError( ...<2 lines>... ) ValueError: Error getting number of tokens from content list: Invalid content item type: file. Expected str or dict with 'type' field (text, image_url, tool_use, tool_result, thinking)., default_token_count=None

Code Example

Traceback (most recent call last):
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 745, in _count_content_list
    raise ValueError(
    ...<2 lines>...
    )
ValueError: Invalid content item type: file. Expected str or dict with 'type' field (text, image_url, tool_use, tool_result, thinking).

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 7229, in trim_messages
    current_tokens = token_counter(model=model or "", messages=messages)
  File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 2320, in token_counter
    return _get_token_counter_new()(
           ~~~~~~~~~~~~~~~~~~~~~~~~^
        model,
        ^^^^^^
    ...<7 lines>...
        default_token_count,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 422, in token_counter
    num_tokens = _count_messages(
        params, new_messages, use_default_image_token_count, default_token_count
    )
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 483, in _count_messages
    num_tokens += _count_content_list(
                  ~~~~~~~~~~~~~~~~~~~^
        params.count_function,
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        default_token_count,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 753, in _count_content_list
    raise ValueError(
    ...<2 lines>...
    )
ValueError: Error getting number of tokens from content list: Invalid content item type: file. Expected str or dict with 'type' field (text, image_url, tool_use, tool_result, thinking)., default_token_count=None
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Litellm does not support "file" as a valid content type when trimming. I expected all valid content_types to be supported, or worst case ignored.

Steps to Reproduce

  1. Construct message payload with a "file" like PDF input (https://docs.litellm.ai/docs/completion/document_understanding)
  2. Attempt to trim messages (https://docs.litellm.ai/docs/completion/message_trimming)

Relevant log output

Traceback (most recent call last):
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 745, in _count_content_list
    raise ValueError(
    ...<2 lines>...
    )
ValueError: Invalid content item type: file. Expected str or dict with 'type' field (text, image_url, tool_use, tool_result, thinking).

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 7229, in trim_messages
    current_tokens = token_counter(model=model or "", messages=messages)
  File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 2320, in token_counter
    return _get_token_counter_new()(
           ~~~~~~~~~~~~~~~~~~~~~~~~^
        model,
        ^^^^^^
    ...<7 lines>...
        default_token_count,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 422, in token_counter
    num_tokens = _count_messages(
        params, new_messages, use_default_image_token_count, default_token_count
    )
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 483, in _count_messages
    num_tokens += _count_content_list(
                  ~~~~~~~~~~~~~~~~~~~^
        params.count_function,
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        default_token_count,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/token_counter.py", line 753, in _count_content_list
    raise ValueError(
    ...<2 lines>...
    )
ValueError: Error getting number of tokens from content list: Invalid content item type: file. Expected str or dict with 'type' field (text, image_url, tool_use, tool_result, thinking)., default_token_count=None

What part of LiteLLM is this about?

No response

What LiteLLM version are you on ?

v1.83.14

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: Trim Messages function does not support "File" content type.