Skip to content

refactor(ocr): remove the Python OCR execution path and require the Rust route - #43081

Merged
yujonglee-berri merged 9 commits into
now-read-secrets-from-rustfrom
litellm_ocr_rust_only
Sep 25, 2026
Merged

yujonglee-berri merged 9 commits into
now-read-secrets-from-rustfrom
litellm_ocr_rust_only

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #43057 (now-read-secrets-from-rust). Merge that one first; this PR only carries the OCR commit on top

TLDR

Problem this solves:

  • OCR ran in Python unless the Rust route opted in, so two implementations had to stay in sync
  • Python still owned OCR provider configs, request transforms and the HTTP handler path
  • Health checks and Azure AI passthrough cost tracking leaned on those Python configs

How it solves it:

  • catalog.py: Route.OCR is RUST_REQUIRED for every provider, no opt-out
  • litellm.ocr dispatch uses runtime.NO_PYTHON; litellm/ocr/main.py is gone
  • Deletes BaseLLMHTTPHandler.ocr/aocr, BaseOCRConfig, get_provider_ocr_config and every provider ocr/ transformation package (mistral, azure_ai, vertex_ai, cohere, reducto); shared OCR response types stay in litellm/llms/base_llm/ocr/transformation.py
  • Two new native bindings replace the last Python config uses: ocr_health_check_document(model, provider) for health checks and ocr_passthrough_response(model, endpoint, body) for Azure AI passthrough OCR costing, which matches the relayed endpoint against the resolved Azure config's route and returns None for anything else
  • Proxy multipart uploads pass the file to Rust directly instead of base64-encoding in Python
  • Deletes the Python-path and Python-vs-Rust parity tests; native-path tests stay

User Flow

Before: a proxy without the Rust extension still serves OCR through Python, and the two paths can drift

  1. They send POST https://litellm-domain/v1/ocr with "model": "mistral/mistral-ocr-latest" and a document URL
  2. With the extension missing or LITELLM_RUST_OCR opted out, the request runs in Python and returns 200 without x-litellm-rust
  3. With the extension present, the same request runs in Rust and returns 200 with x-litellm-rust

After: every OCR request runs in Rust, and a proxy without the extension says so instead of silently falling back

  1. They send the same POST https://litellm-domain/v1/ocr with "model": "mistral/mistral-ocr-latest"
  2. With the extension present, it returns 200 with x-litellm-rust, for every OCR provider
  3. Without the extension, it fails fast with an error naming the missing Rust implementation instead of running Python
  4. Multipart uploads to https://litellm-domain/v1/ocr, /model/health for OCR models and Azure AI passthrough OCR spend keep working as before

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Type

🧹 Refactoring

Caveats (if any)

Severe

  • OCR now requires the Rust extension; a wheel without it cannot serve /v1/ocr
  • The LITELLM_RUST_OCR opt-out no longer has any effect

Medium

  • litellm.ocr.convert_file_document_to_url_document and get_mime_type are removed; Rust does that conversion
  • BaseOCRConfig, MistralOCRConfig and the provider OCR config classes are no longer importable

Low

  • make lint and the full make test-rust-extension run had not finished at PR open; CI covers them

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/aa43dbb4468742ea97eff2e1bb0a7824
Open in Devin Desktop: https://app.devin.ai/desktop/session/aa43dbb4468742ea97eff2e1bb0a7824?variant=devin
Requested by: @yujonglee-berri

…ust route

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@yujonglee-berri
yujonglee-berri requested a review from a team September 24, 2026 23:38
@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High risk] Removes Python OCR implementations and routes all OCR through Rust.

The PR is not ready to merge because the new OCR test matrix fails at collection.

Findings

  1. P2 Native calls bypass VCR ▶

Summary

The PR removes the Python OCR execution path, requires Rust for OCR, and adds native bindings for health-check documents and Azure AI passthrough costing. Since the previous review, it also revises passthrough route matching and adds a live OCR test matrix.

  • The new matrix cannot be collected on Python 3.11 because of its dataclass default.
  • The previously reported VCR limitation for native OCR tests remains unresolved.

Reviews (2) · Last reviewed commit: "test(ocr): import Final in the health ch..."

Comment thread litellm/rust_bridge/catalog.py Resolved
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/rust_bridge/ocr/entrypoints.py 69.23% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_ocr_rust_only (cc42834) with now-read-secrets-from-rust (d1bc05e)

Open in CodSpeed

yujonglee-berri and others added 6 commits September 24, 2026 23:49
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Replace passthrough_url/passthrough_transform with passthrough_response,
which matches the relayed endpoint against each Azure config's path
segments instead of building a fake request to call get_complete_url.
The binding drops the unused headers, status and api_base arguments.

Catch the ValueError/RuntimeError the binding raises so a relayed body
that is not OCR-shaped falls back to the passthrough object instead of
failing logging, and cover the relay against the real binding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The public litellm.ocr / aocr / Router interface is unchanged by the Rust
migration, so the live provider matrix still applies. Drops the stale VCR skip
list for the deleted test_rust_bridge.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it.

View session

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yujonglee-berri

Copy link
Copy Markdown
Contributor

@greptile-apps wdyt

Comment thread tests/ocr_tests/conftest.py Resolved
@yujonglee-berri
yujonglee-berri merged commit e2302be into main Sep 25, 2026
102 checks passed
@yujonglee-berri
yujonglee-berri deleted the litellm_ocr_rust_only branch September 25, 2026 01:18
yuneng-berri added a commit that referenced this pull request Sep 26, 2026
…3266)

test_update_config_success_callback_normalization replaced
proxy_server.proxy_logging_obj with a MagicMock and never restored it.
Since the proxy unit tests joined tests/unit (#42903), 14 JWT mapping,
end-user and MCP tests on the same xdist worker awaited that mock and
failed. The test now uses monkeypatch.

test_prometheus_logging_callbacks set verbose_logger to DEBUG and
litellm.set_verbose at import, so every worker in the unit job ran with
DEBUG on. That broke caplog equality in the JEV classifier test, the
vertex streaming memory ratio, and four event-loop lag checks. The
module-level setup is removed; nothing in the file depended on it.

#43081 removed the OCR harness modules but left them in the
importability parametrize list.

test_get_model_info_bedrock_region reassigned litellm.model_cost and set
LITELLM_LOCAL_MODEL_COST_MAP without restoring either, and never cleared
the get_model_info caches, so it failed whenever an earlier test had
looked up the regional model. It now uses monkeypatch and invalidates
the caches; the local_testing isolation fixture also invalidates them
after restoring model_cost.

The Windows job hit CircleCI's 10 minute no-output limit while cargo
compiles the Rust crates inside uv sync and uv build. Those two steps now
allow 30 minutes of silence.
yuneng-berri added a commit that referenced this pull request Sep 26, 2026
…3266)

test_update_config_success_callback_normalization replaced
proxy_server.proxy_logging_obj with a MagicMock and never restored it.
Since the proxy unit tests joined tests/unit (#42903), 14 JWT mapping,
end-user and MCP tests on the same xdist worker awaited that mock and
failed. The test now uses monkeypatch.

test_prometheus_logging_callbacks set verbose_logger to DEBUG and
litellm.set_verbose at import, so every worker in the unit job ran with
DEBUG on. That broke caplog equality in the JEV classifier test, the
vertex streaming memory ratio, and four event-loop lag checks. The
module-level setup is removed; nothing in the file depended on it.

#43081 removed the OCR harness modules but left them in the
importability parametrize list.

test_get_model_info_bedrock_region reassigned litellm.model_cost and set
LITELLM_LOCAL_MODEL_COST_MAP without restoring either, and never cleared
the get_model_info caches, so it failed whenever an earlier test had
looked up the regional model. It now uses monkeypatch and invalidates
the caches; the local_testing isolation fixture also invalidates them
after restoring model_cost.

The Windows job hit CircleCI's 10 minute no-output limit while cargo
compiles the Rust crates inside uv sync and uv build. Those two steps now
allow 30 minutes of silence.

(cherry picked from commit 7fc2206)
yuneng-berri added a commit that referenced this pull request Sep 26, 2026
…3266) (#43267)

test_update_config_success_callback_normalization replaced
proxy_server.proxy_logging_obj with a MagicMock and never restored it.
Since the proxy unit tests joined tests/unit (#42903), 14 JWT mapping,
end-user and MCP tests on the same xdist worker awaited that mock and
failed. The test now uses monkeypatch.

test_prometheus_logging_callbacks set verbose_logger to DEBUG and
litellm.set_verbose at import, so every worker in the unit job ran with
DEBUG on. That broke caplog equality in the JEV classifier test, the
vertex streaming memory ratio, and four event-loop lag checks. The
module-level setup is removed; nothing in the file depended on it.

#43081 removed the OCR harness modules but left them in the
importability parametrize list.

test_get_model_info_bedrock_region reassigned litellm.model_cost and set
LITELLM_LOCAL_MODEL_COST_MAP without restoring either, and never cleared
the get_model_info caches, so it failed whenever an earlier test had
looked up the regional model. It now uses monkeypatch and invalidates
the caches; the local_testing isolation fixture also invalidates them
after restoring model_cost.

The Windows job hit CircleCI's 10 minute no-output limit while cargo
compiles the Rust crates inside uv sync and uv build. Those two steps now
allow 30 minutes of silence.

(cherry picked from commit 7fc2206)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant