Repository navigation
fix(ocr): support token-priced billing - #39785
yujonglee-berri wants to merge 2 commits into
Conversation
Greptile SummaryThis PR adds token-priced OCR billing, centralizes OCR usage normalization, preserves provider usage for structured DeepSeek responses, and updates spend tracking and model pricing. The previous structured-response usage finding is fully fixed. Mapping-form structured content now has a validation fallback regression Confidence Score: 4/5The PR needs a consistent fallback for invalid mapping-form OCR content before it appears safe to merge Mapping content is validated outside the existing ValidationError fallback, so malformed structured pages can turn an otherwise successful provider response into a failed OCR call. The previous structured-response usage issue is fully fixed because usage now always comes from the outer provider response Files Needing Attention: litellm/llms/vertex_ai/ocr/deepseek_transformation.py
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/ocr/deepseek_transformation.py | Preserves outer provider usage but can reject malformed mapping content that previously fell back safely |
| litellm/llms/base_llm/ocr/transformation.py | Adds shared token fields and normalization for OCR usage |
| litellm/cost_calculator.py | Selects token pricing when split OCR token usage and token rates are available |
| litellm/proxy/spend_tracking/spend_tracking_utils.py | Preserves token-based OCR usage while retaining page-billing defaults |
| litellm/litellm_core_utils/litellm_logging.py | Normalizes OCR usage_info without treating unrelated response usage_info as token usage |
Reviews (2): Last reviewed commit: "fix(ocr): harden token usage billing" | Re-trigger Greptile
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
@greptileai Please review the latest hardening commit, which preserves outer usage for structured OCR responses and centralizes usage normalization. |
| if isinstance(content, Mapping): | ||
| return _DeepSeekOCRContent.model_validate(content) |
There was a problem hiding this comment.
If provider content is a mapping with invalid page fields, validation escapes the fallback and fails an otherwise successful OCR response
| if isinstance(content, Mapping): | |
| return _DeepSeekOCRContent.model_validate(content) | |
| if isinstance(content, Mapping): | |
| try: | |
| return _DeepSeekOCRContent.model_validate(content) | |
| except ValidationError: | |
| return None |
Knowledge Base Used: Provider adapters and capabilities
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer receives successful Vertex DeepSeek OCR output, but the recorded spend can be zero
After: the same request records provider-priced token spend
Relevant issues
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
No live provider run was captured
Type
🐛 Bug Fix
Caveats (if any)
Low
Validation
Final Attestation