Issue evidence · AI API · BerriAI/litellm

Counting tokens for a base64 PDF has no cost bound

GitHub issue: https://github.com/BerriAI/litellm/issues/45676

Reproduced

Token counting parses every PDF page in-process with no limit, so a small upload can stall the worker.

What Badgr ran

Counted tokens for synthetic PDFs on LiteLLM main: 20 and 200 text pages, and one page holding 0.2 M, 1.6 M and 6.4 M characters.

What came back

  • 200 pages (167 KiB upload): 0.56 s.
  • One page, 1.6 M characters (15 KiB): 1.0 s.
  • One page, 6.4 M characters (55 KiB): 22 s, growing faster than the text size.

Measured on a laptop; the issue's own table has larger absolute numbers on its hardware.

Checked 2026-10-10 in Badgr’s local development environment.

← All issue evidence