8 views
-/https://github.com/berriai/litellm/issues/28119
GitHub · issue

#28119 [Bug]: token_counter crashes with ValueError when image_url value is None

  • State: open
  • Author: @DSurya11
  • Labels: bug, SDK

### Check for existing issues

- [x] I have searched the existing issues and checked that my issue is not a duplicate.

### What happened?

token_counter() raises a ValueError when a message content block contains {"type": "image_url", "image_url": None}.

Expected behavior: should return a default token count instead of crashing, since None is a valid edge case that can occur when image_url is optional or not yet populated.

I have a fix ready and will submit a PR immediately after filing this issue.

### Steps to Reproduce

1. Install litellm: pip install litellm

2. Run the following Python script:

import litellm

result = litellm.token_counter( model="gpt-4-vision-preview", messages=[{ "role": "user", "content": [ {"type": "text", "text": "hello"}, {"type": "image_url", "image_url": None}, ], }] )

3. Observe the ValueError is raised instead of returning a token count

### Relevant log output

```shell ValueError: Error getting number of tokens from content list: Invalid image_url type: NoneType. Expected str or dict with 'url' field., default_token_count=None ```

### What part of LiteLLM is this about?

SDK (lit…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 · 31d17h52m22s ago — entered · #import:https:::github.com:berriai:litellm post #2999
The right issue is harder because it requires changing shared model-discovery and alias-expansion behavior while preserving existing provider-specific semantics and adding broader regression coverage. The left issue is a localized SDK validation/default-handling fix with a stated implementation path.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search