mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
* fix(ocr-errors): preserve public error and timeout contracts Classify reqwest timeouts as a typed CoreError::Timeout and add CoreError::public_status_code() as the single exhaustive mapping from a typed core error to its public HTTP status. The Python bridge raises a typed RustOcrError carrying that status instead of a generic RuntimeError, and litellm.ocr()/aocr() translate it into the matching public exception so AuthenticationError/401, NotFoundError/404, BadRequestError/4xx, InternalServerError/5xx and Timeout are preserved end to end instead of collapsing to APIConnectionError/500. Reject empty or whitespace-only 200 bodies so they fail loudly rather than becoming an empty OCR success; invalid JSON already fails. Upstream error bodies stay bounded and sanitized. Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(ocr-errors): map invalid OCR input to BadRequestError Invalid caller input (bad document type, non-dict document, unusable file input) was raised as a plain ValueError inside ocr()/aocr() and collapsed to APIConnectionError/500 through the generic handler. Route every OCR failure through one _map_ocr_exception host mapping: typed RustOcrError keeps its status-based public exception, a plain ValueError becomes BadRequestError/400, and a pydantic ValidationError (malformed response, not client input) stays on the generic path. Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * refactor(ocr-errors): data-minimize public errors and preserve status-specific exceptions Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * refactor(ocr-errors): preserve exact unknown status and privatize input error Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * refactor(ocr-errors): exhaustive match mapper and typed error tests Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(ocr-errors): sanitize InvalidRequest public message Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * refactor(ocr-errors): raise typed public union and drop NotFound provider miss Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(ocr-errors): map malformed provider responses to sanitized 500 and hide input-error detail Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| .cargo | ||
| crates | ||
| .gitignore | ||
| ADDING_A_PROVIDER.md | ||
| AGENTS.md | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CLAUDE.md | ||
| README.md | ||
LiteLLM Rust
This workspace contains the staged Rust implementation for LiteLLM.
Rust starts as a pure transform core used by the existing Python host. Python continues to own auth, configuration, network I/O, retries, routing, logging, callbacks, spend tracking, and customer plugins until each Rust path has parity coverage and production evidence.
Crates
| Crate | Role | Pure / I/O |
|---|---|---|
| litellm-core | Translation layer — types, route contracts (traits), provider transforms (modules under providers/), and the router. Builds requests/responses; no network. | Pure |
| litellm-ai-gateway | Routes + host — the only crate that touches the network. HTTP/WebSocket I/O (modules under io/) plus the axum server binary (behind the server feature). |
I/O |
| litellm-python-bridge | PyO3 cdylib exposing Rust to the litellm Python SDK — a thin adapter over litellm-ai-gateway's I/O. | Binding |
Dependency direction (acyclic): litellm-core ← litellm-ai-gateway ← litellm-python-bridge.
Layout
crates/
core/ Route contracts, shared pure types, errors, and templates.
src/ocr/
providers/ Provider-specific pure transforms.
src/mistral/ocr/transformation.rs
python-bridge/ PyO3 bridge for Python LiteLLM.
The folder shape should follow the Python provider tree:
providers/src/<provider>/<route>/transformation.rs. The bridge should expose
one function per top-level route, starting with ocr(payload).
Checks
Run these before pushing Rust changes. GitHub Actions runs the same checks for
changes under litellm-rust/.
cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace