mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-28 00:00:38 +00:00
* feat(cost): price native /v1/messages calls in the Rust route and hand the receipt to logging The Messages route now reads Anthropic wire usage in Rust (a port of calculate_usage plus billed_usage, captured once against main for every P1 provider body and stream) and prices the finished call through a Pricing dependency the Python bridge backs with the model-catalog snapshot. A message body settles Cost::Priced at result_ready. A stream gets Cost::Metered and the route settles its StreamMeter at message_stop from message_start merged with the final message_delta, and injects each usage event's cost itself when the caller asked for it. The proxy hands the route the deployment facts Logging prices with (deployment id, base model, Mantle region, Vertex location, residency) through the existing settings projection, and sends none for custom pricing, a pricing provider override or a Bedrock model_id, which keep today's Python path. The legacy adapter writes the receipt onto Logging through the new record_route_cost contract function instead of popping response_cost, and Logging, the pass-through stream handler and the proxy's stream cost injection read it instead of pricing the call again. * refactor(cost): keep the lint gates flat for the Rust-priced Messages hand-off * fix(cost): test the Anthropic batch request list by truthiness instead of an untyped len * docs(python-bridge): note RoutePricing reads its snapshot through one CostLookup per call * docs(cost): describe price_call as the shared /v1/messages pricing body * fix(cost): run the Claude subscription check before a Rust route's price in non-stream logging A native /v1/messages call priced by the Rust route records its cost on the logging object early. The non-stream success path then kept that cost as already calculated, so a call covered by a Claude subscription logged the token price instead of 0. Route-priced calls now go through response_cost_calculator, which checks the subscription first and then returns the route's price. * refactor(cost): name the keep-a-precomputed-cost check so the success branch stays under PLR0916 * refactor(cost): fold the route-priced check into the precomputed-cost condition to keep the lint and type gates flat * fix(cost): resolve a bedrock mantle/ route's pricing region from the requested model like logging does The Rust route looked up the Mantle pricing region without the model, so a bedrock/mantle/ call dropped its configured region and could be priced at non-regional rates. Pass the requested model, matching the logging path. * fix(cost): price a native Vertex call at the routed deployment's location On the proxy the logger is created before a deployment is picked, so the route read no location from it and priced a regional Vertex deployment at the global default. Resolve the location from the routed request first, as dispatch does, then fall back to the logger's params. * perf(cost): decode each stream event once when injecting the cost With stream cost injection on, every chunk was decoded twice: the meter parsed each SSE event's JSON, then with_injected_cost split the chunk again and reparsed each data line to find the message_delta. observe now parses each event of a whole-frame chunk into one Value that the meter reads and the injection prices, and with_injected_cost only matches the line text. Chunks that cannot carry an injected cost, and every chunk when injection is off, still read the typed event straight from the text. The meter test now also runs with injection on over a stream cut mid-event, which caught an extra pricing call per split delta in a first draft. |
||
|---|---|---|
| .. | ||
| host | ||
| messages | ||
| ocr | ||
| trace | ||
| __init__.py | ||
| AGENTS.md | ||
| native_route_wheel_test.py | ||
| stubtest.ini | ||
| test_bindings.py | ||
| test_catalog.py | ||
| test_clickhouse.py | ||
| test_configuration.py | ||
| test_detectors.py | ||
| test_execution.py | ||
| test_failures.py | ||
| test_fork_guard.py | ||
| test_logger.py | ||
| test_public_call.py | ||
| test_runtime.py | ||
| test_token_counter.py | ||
| test_tokenizer.py | ||
| test_verify_linux_native_wheel.py | ||