Fix spend tracking for OCR/aOCR requests (log pages_processed + recognize OCRResponse) - #16070
Merged
Conversation
|
@OrionCodeDev is attempting to deploy a commit to the CLERKIEAI Team on Vercel. A member of the Team first needs to authorize it. |
ishaan-jaff
suggested changes
Oct 29, 2025
ishaan-jaff
left a comment
Contributor
There was a problem hiding this comment.
reviewed, minor changes pls
Contributor
Author
|
@ishaan-jaff i push updated version with helper and some unit test (unit tests is not my best pros) |
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…ognize `OCRResponse`) (BerriAI#16070) * fix-ocr-cost * fix1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type
🐛 Bug Fix
Changes
This merge request fixes an issue where OCR requests did not accrue spend in the database—the
spendcolumns remained unchanged because OCR responses don’t expose token-basedusagelike text models. After this change, OCR costs are correctly computed and persisted.What was wrong
usage_info(withpages_processed) instead of the usual token-basedusage.usage, OCR requests were treated as having no billable usage, leaving spend at0.What this MR does
Recognize OCR responses in logging pipeline
litellm/litellm_core_utils/litellm_logging.pyOCRResponseto_is_recognized_call_type_for_logging, ensuring OCR calls are handled by the standard logging path.Translate OCR
usage_info→ normalizedusagefor spend trackinglitellm/proxy/spend_tracking/spend_tracking_utils.pyget_logging_payload():response_objto a dict early.call_type in ["ocr", "aocr"], readusage_info(supports dict, Pydantic.model_dump(), or__dict__).usageobject with:prompt_tokens = 0,completion_tokens = 0,total_tokens = 0pages_processedpopulated fromusage_info.pages_processed(default0).Result / Impact
spendfields update as expected for OCR/AOCR calls.Test plan (proposed)
tests/litellm/spend_tracking/test_ocr_spend_tracking.pythat:usage_info = {"pages_processed": N}.get_logging_payload(call_type="ocr", ...).usage.pages_processed == Nand that spend is computed from pages (not tokens).make test-unitgreen.Backwards compatibility
ocr/aocrcalls and does not alter token-based accounting.Notes
0for OCR and relies onpages_processedto drive cost computation.