Change8
Error2 reports

Fix OpenrouterException

in LiteLLM

Solution

OpenrouterException in litellm often arises from discrepancies between the expected and actual token counts reported by OpenRouter, particularly with models that have fractional token usage (e.g., image generation). Round the `prompt_tokens` and `completion_tokens` values within the overloaded `openrouter_response` function in `litellm/integrations/openrouter.py` to the nearest integer before passing them to the `Usage` object to ensure compliance with OpenRouter's integer-based validation, then potentially adjust `cost` accordingly. This rounding prevents validation errors caused by fractional values.

Timeline

First reported:May 15, 2026
Last reported:May 15, 2026

Need More Help?

View the full changelog and migration guides for LiteLLM

View LiteLLM Changelog