litellm/tests/unit/rust_bridge
maciej-berri 0aa3a9203b
Some checks failed
CodSpeed Benchmarks / benchmarks (push) Waiting to run
Cost map pins recheck / rerun-cost-map-guard (push) Waiting to run
Publish lint base counts / publish (basedpyright, litellm/scripts/type_check_gate.py) (push) Waiting to run
LiteLLM Rust DB / db-queries (push) Waiting to run
Terraform Modules / fmt, validate, test (aws) (push) Waiting to run
Terraform Modules / fmt, validate, test (gcp) (push) Waiting to run
unit / llms-providers (push) Blocked by required conditions
unit / proxy-endpoints (push) Blocked by required conditions
unit / proxy-feature-endpoints (push) Blocked by required conditions
unit / auth-checks (push) Blocked by required conditions
unit / budgets (push) Blocked by required conditions
unit / custom-logging (push) Blocked by required conditions
unit / db-and-spend (push) Blocked by required conditions
unit / endpoints-and-responses (push) Blocked by required conditions
unit / enterprise-routing (push) Blocked by required conditions
unit / guardrails-hooks (push) Blocked by required conditions
unit / jwt-and-keys (push) Blocked by required conditions
unit / key-generation (push) Blocked by required conditions
unit / logging-misc (push) Blocked by required conditions
unit / mcp-oauth (push) Blocked by required conditions
unit / proxy-runtime (push) Blocked by required conditions
unit / proxy-server-core (push) Blocked by required conditions
unit / core-auth-spend (push) Blocked by required conditions
unit / core-logging-request-path (push) Blocked by required conditions
unit / rust-bridge (push) Waiting to run
unit / mcp-server (push) Blocked by required conditions
unit / proxy-auth (push) Blocked by required conditions
unit / proxy-extras (push) Blocked by required conditions
Publish lint base counts / publish (openapi-docs, litellm/scripts/openapi_docs_gate.py) (push) Waiting to run
Publish lint base counts / publish (ruff-strict, litellm/scripts/ruff_strict_gate.py) (push) Waiting to run
Publish lint base counts / publish (test-quality, litellm/scripts/test_quality_gate.py) (push) Waiting to run
Publish lint base counts / publish (type-discipline, litellm/scripts/type_discipline_gate.py) (push) Waiting to run
Root entry limit / root-entry-limit (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
lint / lint plan (push) Waiting to run
lint / python (push) Blocked by required conditions
lint / typecheck (push) Blocked by required conditions
lint / e2e-harness (push) Blocked by required conditions
lint / secret-scan (push) Waiting to run
lint / ui (push) Blocked by required conditions
lint / ui-api-types (push) Blocked by required conditions
lint / code-quality (push) Waiting to run
lint / ci-coverage (push) Waiting to run
lint / semgrep (push) Waiting to run
lint / lint passed (push) Blocked by required conditions
smoke / all-extras-py (push) Blocked by required conditions
smoke / smoke-rust-bridge (push) Waiting to run
smoke / dashboard-build (push) Waiting to run
smoke / py (push) Blocked by required conditions
smoke / windows-sdk (push) Waiting to run
smoke / proxy-build-from-pip (push) Waiting to run
smoke / smoke passed (push) Blocked by required conditions
unit / root (push) Blocked by required conditions
unit / proxy-utils (push) Blocked by required conditions
unit / core-auth-request (push) Blocked by required conditions
unit / core-management-cost (push) Blocked by required conditions
unit / core-utils-route (push) Blocked by required conditions
unit / core-router (push) Blocked by required conditions
unit / core-router-core (push) Blocked by required conditions
unit / core-router-retries (push) Blocked by required conditions
unit / changed-tests (push) Blocked by required conditions
unit / lint-runtime (push) Blocked by required conditions
unit / plan (push) Waiting to run
unit / enterprise-managed-files (push) Blocked by required conditions
unit / enterprise-repositories-secrets (push) Blocked by required conditions
unit / proxy-server (push) Blocked by required conditions
unit / lens-python-310 (push) Blocked by required conditions
unit / caching-local (push) Blocked by required conditions
unit / core-utils (push) Blocked by required conditions
unit / endpoints (push) Blocked by required conditions
unit / enterprise-package (push) Blocked by required conditions
unit / integrations (push) Blocked by required conditions
unit / llms-anthropic (push) Blocked by required conditions
unit / llms-bedrock (push) Blocked by required conditions
unit / llms-openai-meta (push) Blocked by required conditions
unit / llms-vertex-ai (push) Blocked by required conditions
unit / mcp-elicitation (push) Blocked by required conditions
unit / proxy-hooks-client (push) Blocked by required conditions
unit / proxy-infra-routing (push) Blocked by required conditions
unit / proxy-subprocess (push) Blocked by required conditions
unit / redis-py 7.4.1 compatibility (push) Blocked by required conditions
unit / redis-py 8.0.1 compatibility (push) Blocked by required conditions
GitHub Actions Security Analysis / zizmor (push) Waiting to run
unit / proxy-infra-db-spend (push) Blocked by required conditions
unit / proxy-infra-root-a-p (push) Blocked by required conditions
unit / proxy-infra-root-q-z (push) Blocked by required conditions
unit / responses-caching-types (push) Blocked by required conditions
unit / router (push) Blocked by required conditions
unit / rust-bridge-harness (push) Blocked by required conditions
unit / ui-unit (push) Waiting to run
unit / docs (push) Blocked by required conditions
unit / helm (push) Blocked by required conditions
unit / OpenAI 2.20.0 compatibility (push) Blocked by required conditions
unit / OpenAI 3.0.0 compatibility (push) Blocked by required conditions
unit / OpenAI 3.25.0 compatibility (push) Blocked by required conditions
unit / redis-py 5.3.1 compatibility (push) Blocked by required conditions
unit / redis-py 6.4.0 compatibility (push) Blocked by required conditions
unit / unit passed (push) Blocked by required conditions
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled
feat(cost): price Claude token calls, budget holds and auth price checks in Rust (#52484)
* feat(cost): add the price, bound and rates query engine to litellm-cost

price() answers a PriceQuery tagged by kind over a RowSource that Model
Catalog will implement. The tokens kind ports the token path of
completion_cost for Claude on Anthropic, Bedrock, Vertex AI and Azure AI,
with speed, geo and regional uplifts, the web search fee, provider-keyed
discount and margin, the stored cost breakdown and prompt-caching savings.
Every other kind and unported case answers NotPorted.

bound() ports the legacy budget hold and rates() returns a row's rates,
its raw key facts and one pricing status for the auth predicates.

Parity fixtures captured once from main's Python pin totals, breakdowns,
savings and holds to the last bit. Copied main bugs are listed in the
crate AGENTS.md.

* feat(python-bridge): price, bound, rates and adjust over model-catalog catalog rows

Model Catalog now feeds the litellm-cost query engine. pricing_rows reads a
CostLookup and fetches the rows one query reads into PricingRows, the core's RowSource, each
candidate keyed by the model name main priced it with, and a lowered row
carries the RowFacts the core reads (mode, max tokens, how float() reads
provider_specific_entry, the raw keys the auth checks read). PricingContext
also holds the discount and margin config. The python-bridge snapshot reads the
host's fallback_generalizations rules with the table and is rebuilt when the
generation or the config values move.

NativeModelCostMap gains price, bound, rates and adjust. Python hands each a
document of raw facts and the bridge reads them the way main's Python did
before it builds the core's typed query. A call the core does not price
answers None so Python keeps pricing it. NativeTokenUsage now takes the core's
TokenUsage document and bills it through TokenUsage::billed, so the counts to
meters conversion exists once.

* feat(cost): price Claude token calls, budget holds and auth price checks in Rust

completion_cost prices a Claude token call on Anthropic, Bedrock, Vertex AI
and Azure AI through NativeModelCostMap.price and stores the receipt's
breakdown, rates and adjustments on the logging object as before. Any call
Rust leaves to Python (another provider or call kind, built-in tools other than
a reported web search, a provider-stated cost, custom per-call prices or a
deferred candidate list) keeps the Python candidate loop for that call.

The Anthropic speed and geo uplifts and the Bedrock geo uplift now come from
the Rust core, and the Python bodies are gone. Discount and margin resolve in
Rust for every kind through NativeModelCostMap.adjust, replacing
_apply_cost_discount, _apply_cost_margin and resolve_cost_discount. The legacy
budget hold calls bound, and the auth checks read token rate keys and positive
token rates from rates.

Tests that patched deleted internals now drive the public functions, and new
cases pin the adapter to main's totals and breakdowns for the captured Claude
fixtures.

* refactor(cost): keep the lint gates flat for the Rust pricing adapter

Split the Rust route's eligibility checks into early returns, read hidden
params and web search options through typed mapping helpers, read the
generalization rules through as_object_list, and sort the stub's __all__.
Adjust and store the token and search costs of a completion_cost candidate in
one helper so no Final is bound inside the candidate loop, type the Model
Router fee dict, and merge the litellm_core_utils imports of the host module.

* test(cost): match the unreadable geo value in the Bedrock ValueError check

* test(cost): bill a price edited in place in litellm.model_cost on the next Rust-priced call

The python-bridge row cache was keyed by row object identity, so editing a price
in place kept billing the old rate until something called changed_in_place().
Lowerings are now reused only while the row reads the same fields.

* docs(cost): say the RowSource is PricingRows over a catalog's PricingTable

* fix(cost): port main's budget hold estimator changes into bound

Main reworked the budget hold while this stack was open (#51752, #53412 and the per-model input counts). The rebase kept main's reservation, window and carry-over code and the Rust bound, so this commit brings the hold up to main

The adapter reads the request: per model, the output caps that reach the provider through each serving deployment (surface, drop params, the Responses minimum, Gemini generationConfig caps) and the output count (n, best_of, candidateCount, router and deployment defaults), plus whether a Gemini body holds inline audio or names a cached content. A model whose input could not be counted is held at its input window without recounting

bound reads the rows: a cached content holds the rest of the input window at the highest cache-read rate, text or audio, inline audio holds input at the higher of the text and audio rates, a counted Gemini prompt reads the `_above_<n>_tokens` prices it reaches, the threshold included, and a group reads those from each deployment's `deployment_pricing`. A row ceiling that is not positive reads the default, and a row missing an input or output rate holds nothing for tokens it would bill there

max_cost_for_cost_info and input_cost_for_cost_info hold one model info row through bound, so main's tests run against the Rust hold unchanged apart from the names

* refactor(cost): carry the RustRefusal rename into the pricing entry point

---------

Co-authored-by: narmstrong-berri <narmstrong@berri.ai>
2026-11-23 22:00:28 +00:00
..
host feat(cost): price Claude token calls, budget holds and auth price checks in Rust (#52484) 2026-11-23 22:00:28 +00:00
messages feat(messages): serve bedrock invoke messages on rust only (#51330) 2026-11-15 16:58:31 -08:00
ocr refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
trace refactor(lens): connect LiteLLM to the independent Lens service (#45529) 2026-10-09 16:17:05 -07:00
__init__.py test: migrate phase 15 legacy tests to tests/unit 2026-09-20 11:55:43 +00:00
AGENTS.md refactor(rust-bridge): decide native routing in the catalog, drop the bypass predicates (#46750) 2026-10-20 15:06:24 -07:00
native_route_wheel_test.py fix(bedrock): omit system prompt from audio transcription and report its token usage (#41565) 2026-10-28 19:23:15 -07:00
stubtest.ini test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_bindings.py refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
test_catalog.py feat(messages): serve bedrock claude_platform messages on rust only (#52681) 2026-11-19 14:34:02 -08:00
test_clickhouse.py refactor(lens): connect LiteLLM to the independent Lens service (#45529) 2026-10-09 16:17:05 -07:00
test_configuration.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_detectors.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00
test_execution.py refactor(rust-bridge): return an unstarted Execution from native entrypoints and drive it in Python (#46299) 2026-10-14 17:50:44 -07:00
test_failures.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_fork_guard.py refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
test_logger.py refactor(rust_bridge): send every Rust log line through one subscriber (#53738) 2026-11-23 17:53:54 +09:00
test_public_call.py fix(rust): run native async calls through python's async wrapper steps (#50423) 2026-11-10 00:24:20 +00:00
test_runtime.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00
test_token_counter.py fix(proxy): count the request's tool_choice on the token count routes (#51133) 2026-11-14 07:53:27 -05:00
test_tokenizer.py refactor(sdk): separate core AWS and tokenizer dependencies (#44447) 2026-10-08 19:07:57 -07:00
test_verify_linux_native_wheel.py chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00