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.
Related Issues
Real GitHub issues where developers encountered this error:
Timeline
First reported:May 15, 2026
Last reported:May 15, 2026