diff --git a/litellm-rust/crates/cost/AGENTS.md b/litellm-rust/crates/cost/AGENTS.md new file mode 100644 index 00000000000..ef75f55b5ed --- /dev/null +++ b/litellm-rust/crates/cost/AGENTS.md @@ -0,0 +1,13 @@ +# litellm-cost port rules + +- This crate is a standalone port of Python's cost calculation. Prices, usage, model metadata, response kinds, and feature flags are caller-supplied; there is no Python bridge, no proxy integration, no network, and no env or secret resolution +- Every Rust function maps to a named Python function in `litellm/cost_calculator.py`, `litellm/litellm_core_utils/llm_cost_calc/`, or a provider `cost_calculator.py`/`cost_calculation.py`. Python entry points that also look up models, normalize responses, or choose providers correspond to Rust functions starting from already-selected inputs; `ModelInfoCatalog` supplies the selection layer Python does inline +- Module `foo_cost.rs` mirrors the calculation portion of the matching Python module; `tests/python_foo_cost.rs` carries the mapping evidence, with each test naming the Python test it mirrors (`tests/test_litellm/` mirrors `litellm/` per the repo-root AGENTS.md) +- Preserve Python's precedence and fallback orders exactly: cache hit before provider-reported before calculated cost, discount before margin, wall-clock pricing before provider totals, quality and size key selection order, model-key selection order including duplicate provider prefixes and regional aliases +- Diverge only where Python is observably wrong, and pin each divergence with a test that would fail if either side changed +- Where Python relies on class identity (response kind, usage format, transcription type), Rust takes a serialized `type` tag or a caller-supplied enum because JSON does not preserve identity +- Never pin vendor prices, upstream defaults, or today's date as literals. Fixtures use synthetic rates we own and record only Python-computed outputs, stamped with the generating commit +- Two differential harnesses pin executed-Python behavior: `tests/generate_python_reference.py` -> `tests/python_reference.tsv` for `generic_cost_per_token`, and `tests/generate_python_fixtures.py` -> `tests/python_fixtures.json`, replayed by `tests/python_fixture_replay.rs` across seven surfaces. Regenerate after porting new behavior; numeric rows must stay byte-identical unless the change is intentional +- Every new test must fail on mutated code; mutation-check meaningful cases before pushing +- Shared predicates live in one home: `base_rate_selection::uses_inclusive_token_thresholds` is the only copy of Python's `_INCLUSIVE_THRESHOLD_PROVIDERS`, and `image_cost_router` deployment pricing reads exactly the `CustomPricingLiteLLMParams` field set Python iterates. Reuse an existing shared helper before writing per-surface parsing +- General repo rules (comments, immutability, typing, commits) are in the repo-root AGENTS.md and apply here diff --git a/litellm-rust/crates/cost/README.md b/litellm-rust/crates/cost/README.md deleted file mode 100644 index 21839643ecf..00000000000 --- a/litellm-rust/crates/cost/README.md +++ /dev/null @@ -1,310 +0,0 @@ -# litellm-cost - -This crate calculates token and non-token charges from rates and usage supplied by its caller. It is standalone and has no Python bridge or proxy integration - -Call `compile(&pricing)` once for an immutable plan, then `plan.calculate(&request)` for each supported request. `calculate(&pricing, &request)` compiles on each call. A successful result exposes pre-multiplier component costs, selected rates, the multiplier, and derived `input()`, `output()`, and `total()` values - -`non_token::calculate` totals priced units such as images, pixels, seconds, pages, requests, credits, and guardrail units. `non_token::calculate_image` selects the first available price from ordered pricing tables, with per-image rates ahead of per-pixel rates inside each table. `non_token::calculate_ocr_with_tables` selects each OCR rate from the first table that has it, then `non_token::calculate_ocr` prefers credit pricing when credits are present and otherwise prices pages and annotation pages. `non_token::calculate_ocr_batch` uses deployment batch or standard rates for each page family, then published rates and the page rate as an annotation fallback. `non_token::calculate_video` selects a video-specific per-second rate, then a resolution rate, then the base per-second rate. Unpriced OCR and video usage returns zero, as in Python. Invalid quantities and rates return errors - -`ocr_cost` reads OCR response usage, layers deployment and published rates, bills reported credits first, and distinguishes missing page usage from zero pages. `batch::batch_cost_from_model_info` selects each flat or threshold batch rate from model metadata, applies modality prices and regional uplift, and uses the regular-rate fallback where Python does - -`openai_cost` exposes Python's transcription cost route and video price selection from caller-supplied model metadata. It selects the video-specific rate, then the resolution rate, then the base output rate. `groq_cost` prices executed browser searches and opens separately; the built-in tool dispatcher uses the same function - -`batch::get_batch_cost_rates` selects input, output, cache read, and cache creation rates independently at the highest crossed threshold. `batch::batch_cost_calculator` applies batch modality rates, cache rates, the regular-rate half-price fallback, and an optional regional multiplier to normalized usage. The caller supplies model prices, provider threshold policy, regional multiplier, and token details - -`guardrail_cost` selects regional or base Bedrock guardrail rates from a caller-supplied cost map, preserves unknown per-counter prices, prices Azure Prompt Shield text records, validates hook cost stamps, and merges guardrail charges into a cost breakdown - -`tool_call_cost_tracking` detects chat annotations and Responses output items, counts billable web-search calls, and prices web search, file search, vector storage, computer use, and code interpreter sessions from model metadata and caller-supplied fallback rates. `tool_cost_dispatch::get_cost_for_built_in_tools` applies Python's search, file-search, and Azure assistant precedence, including Gemini and provider-specific web-search usage. `ModelInfoCatalog::completion_cost` can calculate the built-in tool charge from a response. The caller supplies model metadata, response kind, and any configurable fallback rates - -`retrieval_cost` prices rerank search units or tokens according to the selected provider and prices Vertex Search API queries. `ModelInfoCatalog` routes those branches through caller-supplied model metadata - -`completion_cost` joins caller-supplied token, built-in tool, and additional costs, then applies provider discount and margin configuration in Python's order. It also parses provider-reported response cost and preserves the cache-hit, provider-cost, calculated-cost precedence. `ModelInfoCatalog` exposes these operations for the generic token and per-second paths - -`CompletionCost` keeps input, output, built-in tool, and additional charges alongside discount and margin totals. Response WebSocket tier results sum each component across tiers - -`cost_breakdown::cost_breakdown` turns those totals and optional token charges into Python's logging breakdown fields. The caller supplies named additional charges and the pricing basis; no Python logging object is mutated - -`response_cost_calculator_from_response` checks a cache hit and provider-reported hidden cost before calling response pricing. Numeric strings and booleans follow Python's float conversion for reported cost - -`billed_token_rates` resolves the rates used for cache-read, cache-write, and reasoning spend, including TTL splits, off-peak windows, service tiers, token thresholds, and regional uplifts. The breakdown carries those rates so callers can report cost and rate from the same selection. `provider_cache` applies the Fireworks cache-read default to both generic totals and breakdowns - -`prompt_caching_savings` calculates the read discount minus cache-write premium at the request's selected rates, including TTLs, off-peak windows, thresholds, service tiers, and regional uplift - -`image_response_cost` prices complete image response token usage before a caller falls back to per-image pricing. It preserves image input rates when input details are present and treats unclassified output tokens as text. The Gemini and Vertex image-generation wrappers add web-search grounding, prefer token usage, and otherwise charge per returned image. Gemini image edits share generation billing; Vertex image edits use the shared flat image rate. Catalog lookup merges supplied deployment metadata over the shared model entry for Gemini - -`perplexity_cost` uses a reported total when present, including a cost object normalized from Responses usage. Its manual path prices flat or off-peak tokens, citations, reasoning tokens, and search requests. `ModelInfoCatalog::cost_per_token` dispatches this provider to that calculation - -`xai_cost` accepts a finite nonnegative provider total or folds reasoning tokens into older raw completion counts before generic pricing. It also mirrors server-side web-search usage and prices those calls, unless a provider total already covers them. `ModelInfoCatalog::cost_per_token` dispatches xAI through this path - -`dashscope_cost` selects one tier from total input tokens, bills cache reads and writes at that tier, and applies flat off-peak overrides. It preserves explicit zero reasoning rates and the model-level output fallback for input-only tiers. `ModelInfoCatalog::cost_per_token` dispatches Dashscope and its two brand aliases through this path - -`fireworks_cost` resolves an unmapped model to the same parameter-size category used by Python, then applies the Fireworks cache-read default and generic off-peak rates. Exact model prices take priority. The category thresholds are caller-configurable in the standalone helper, with Python's current defaults used by `ModelInfoCatalog` - -`together_cost` checks whether an exact registry row has an input rate, then maps unmapped chat and embedding models to Python's parameter-size categories. `ModelInfoCatalog::cost_per_token` applies chat fallback; `ModelInfoCatalog::together_ai_cost_per_token` accepts the call type for embedding fallback. The helper accepts caller-supplied thresholds, while the catalog uses Python's defaults - -`search_cost` prices search-only calls with per-query rates or max-results tiers. Its Parallel AI path selects a mode price, prefers provider-reported request and extra-result SKUs, and otherwise estimates extra results from request parameters. `ModelInfoCatalog::search_provider_cost_per_query` exposes both routes - -`speech_cost` selects character or token rates for speech, uses output-only generation pricing for caller-supplied Lyria metadata, and selects token or duration pricing for transcription. The duration helper follows Python's output-rate precedence so duplicate input and output rates are billed once - -`speech_cost::count_characters` mirrors Python's whitespace-excluding character count. `completion_cost_from_response` uses a caller-supplied speech prompt when an explicit character count is absent - -`azure_ai_cost` detects Model Router names and fee entries. `ModelInfoCatalog::azure_ai_cost_per_token` prices the response model and adds the routing fee once when the priced or requested model used the router. Missing router deployments bill the fee alone; missing non-router models return an error. The generic catalog method dispatches Azure AI through this route when no request model is supplied - -`completion_cost_from_response` also reads the original Azure AI router name from response hidden parameters when the selected response model names only the served model. A hidden router name takes precedence over a caller-supplied non-router request name, and the fee is billed once - -When the served Azure AI model has its own price, `completion_cost_from_response` keeps the router fee in named additional costs, matching Python's cost breakdown. Direct `cost_per_token` calls continue to include the fee in prompt cost - -`azure_ai_image_cost` prefers token usage, then the returned-image rate, then dimension-based pixel pricing. It accepts request dimensions or response size, explicit image count, and deployment price overrides. `ModelInfoCatalog::azure_ai_image_generation_cost` resolves the model metadata and exposes the route without changing Python billing - -`image_cost_router` recognizes Python's image response call types, normalizes supplied deployment prices, and routes Vertex, Gemini, Azure AI, Recraft, AI/ML, CometAPI, RunwayML, fal.ai, Bedrock, and OpenAI/Azure GPT image generation through the matching Rust calculators. Recraft, AI/ML, CometAPI, and RunwayML share per-returned-image pricing. The default route selects quality and size keys in Python's order, then applies deployment prices - -`bedrock_image_cost` chooses Titan, Nova Canvas, Stability 3, or Stability 1 config behavior by model name. Titan, Nova, and Stability 3 bill returned images from the model entry. Stability 1 selects a size and step-tier catalog key before applying its per-image rate - -`fal_ai_image_cost` prices deployment per-image rates first, then keyed quality and size rows, then model-level per-image or rounded megapixel rates. It also selects passthrough rates by resolution. The standalone catalog supplies the same keyed rows that Python reads from its global model map - -`openai_image_cost` follows GPT image billing precedence: chat usage with an output breakdown, image token usage, chat usage without a breakdown, then flat per-image pricing. It uses the shared image token helper and generic token calculator so image input and output token rates are applied to their reported modalities - -`azure_cost` applies Azure speech's output-per-second rate when response time is present, even if token rates exist. `databricks_cost` maps legacy endpoint prefixes to registry keys before generic token pricing. The Lemonade route returns zero for unmapped and token-priced local models. The Python cost calculator's earlier wall-clock branch still applies when eligible - -`anthropic_cost` applies the served fast-speed multiplier after generic token pricing. The generic calculator already applies the provider-specific geo multiplier, so the Anthropic route does not apply geo twice. The module also reads Anthropic web-search counts from usage or raw responses and prices the direct usage path - -`realtime_cost` collects and combines response usage from realtime and Responses WebSocket events, including nested cache and modality details. `ModelInfoCatalog::responses_ws_token_cost_by_tier` prices each billable WebSocket tier separately. `ModelInfoCatalog::handle_realtime_stream_cost_calculation` selects the first priced session model and adds completed transcription charges. `ModelInfoCatalog::handle_realtime_transcription_cost_calculation` prices those events by duration or audio, text, and output tokens. WebSocket response-level margins, tool charges, and provider-stated costs remain outside this tier calculation - -`tiered_pricing::select_tier_for_input` chooses one rate tier for all tokens in a request with an inclusive upper bound and last-tier fallback. `tiered_pricing::tier_rate` reads numeric or YAML string rates, preserving an explicit zero ahead of a fallback - -`gemini_cost` prices search and Maps grounding with per-query or per-prompt billing, a configured price or the Python fallback, and server-tool usage fallback for search counts. Gemini's token-pricing wrapper still depends on the broader Python generic token calculator - -`vertex_cost` routes Vertex calls by model and call type, prices token usage with Python's above-128k selection, and prices character usage with per-side token fallback. `ModelInfoCatalog::vertex_cost` exposes the call-type route while `cost_per_token` uses the Vertex token wrapper. Both apply the regional endpoint uplift where Python does. The current Python character wrapper uses completion tokens with its above-128k character rate; Rust preserves that behavior - -`generic_usage` parses prompt and completion token details for the shared token calculator, including cached modality splits, cache-write aliases, non-token usage counts, and nested reasoning tokens - -`generic_input` prices the parsed prompt details with caller-supplied base token rates and model-specific audio, image, video, character, query, count, and duration rates. It preserves Python's service-tier fallback and suppresses token charges when a corresponding image-count or media-duration charge applies. Selecting base rates from full model metadata remains separate - -`generic_output` prices text, reasoning, audio, image, and video output tokens and resolves the standard or service-tier reasoning rate. `generic_cost::calculate_generic_cost_with_resolved_rates` joins both sides, adjusts overlapping prompt cache and modality counts, and applies a caller-supplied multiplier. `base_rate_selection` selects flat, service-tier, above-threshold, tier-table, and off-peak rates from model metadata. `calculate_generic_cost_from_model_info_with_region` also selects data-residency, Vertex endpoint, and provider-specific geo multipliers from model metadata and normalized usage at a caller-supplied timestamp - -`custom_pricing::normalize_cache_usage` applies Python's cache field precedence and adjusts prompt tokens when cache counts use the Anthropic convention. `custom_pricing::cost_per_token_custom_pricing_helper` prices normalized usage with caller-supplied token or per-second rates. `ModelInfoCatalog::cost_per_token_with_custom` and `cost_per_token_for_call_with_custom` apply those rates before catalog lookup or call dispatch. The module validates finite nonnegative quantities and rates before calculation - -`catalog::CostCatalog` accepts a caller-supplied map of model keys to flat token rates. `catalog::ModelInfoCatalog` accepts full model metadata and applies per-second rates for eligible modes or cache, service-tier, threshold, off-peak, and regional token pricing to normalized usage. Wall-clock pricing precedes provider-reported totals as in Python. Both use the same model-key selection order as Python's `cost_per_token`, including duplicate provider prefixes and regional keys. Catalog loading stays caller-supplied; specialized image and tool calls use separate catalog methods - -`ModelInfoCatalog::cost_per_token_for_call` joins the ported token, Vertex character, Together embedding, Azure AI router, speech, transcription, rerank, vector-search, search, OCR, and batch paths behind a typed `CostCall`. It uses Python's call-type order where these paths overlap. The caller supplies OCR response data and optional deployment prices - -Response-level search pricing returns after discount and margin, without adding built-in tool charges or caller-supplied additional charges, matching Python's early return - -`responses_usage::transform_response_api_usage_to_chat_usage` converts Responses API and realtime token details into chat-shaped usage, including cache-write aliases, cached modality splits, reasoning text partitioning, and provider extras. `anthropic_usage::transform_anthropic_usage_to_chat_usage` handles Anthropic's cache-excluding input tokens, iteration cache splits, and reported thinking tokens. `interactions_usage::transform_interactions_usage_object` handles Interactions modality, cache, tool-use, and reasoning counts. `transcription_usage::transform_transcription_usage_object` maps tagged transcription token usage and drops duration usage. `usage_dispatch::get_usage_object` selects these formats or chat-shaped conversion. `ChatUsage::token_usage` feeds normalized token counts and cache-write splits into the generic Rust calculator. Rust needs the serialized transcription `type` tag because it cannot inspect Python class identity - -`model_selection` applies Python's request, base-model, response-model, router-price, provider-prefix, and regional-alias precedence to a caller-supplied catalog. The caller supplies known provider names because this standalone crate does not import Python's provider registry - -`model_selection::get_provider_for_cost_calc` uses an explicit provider, a known model prefix, or catalog provider metadata. `completion_cost_from_response` infers it from ordered model candidates before provider-specific pricing, including when the first candidate has no price - -`ModelInfoCatalog::pricing_entry_for_cost_calc` returns the catalog key and model metadata used for cost reporting. Explicit deployment pricing comes first, followed by the selected, response, and requested models - -`zero_cost_diagnostic` identifies missing rates, priced entries that returned zero, and failed calculations from the selected pricing entry and response usage. It also formats the diagnostic warning and counter reason used by Python logging - -`zero_cost_finding` joins response usage and catalog entry lookup, then suppresses findings for cache hits, nonzero charges, and unbilled read or management calls. Background response cost polls remain billable - -`background_cost_polling` mirrors the pure background interaction status gates and capped poll intervals. Python still owns fetching, settlement, logging, and budget reservation release - -`completion_input` prepares serialized responses for pricing. It selects the response kind's call type, model candidates, normalized usage, and the billable service tier from the request, response, usage, or provider traffic type. The caller supplies the response kind because JSON does not preserve Python class identity - -`completion_response::completion_cost_from_response` joins preparation, ordered model fallback, the existing call dispatcher, built-in tool and additional charges, discount, and margin for supported call types. A caller can provide a built-in tool charge or tool settings for calculation from the serialized response and selected model. Token calls use response usage, caller-supplied usage, or a loaded Rust token counter with prompt, messages, and completion text. Explicit custom token and per-second rates take precedence over catalog prices, including for unregistered models. Search, rerank, transcription, and OCR can use response fields without token usage. Image, video, and realtime stream responses return their dedicated costs before discount and margin, as in Python. Responses WebSocket turns use returned service-tier prices and apply fixed margins once per tier. A2A and MCP calls use caller-supplied logging details without catalog prices - -For responses with usage, `PricedCompletionResponse::token_breakdown` carries cache-read, cache-creation, and reasoning charges with the billed token rates. Calls without response usage and early-return media, realtime, A2A, MCP, and Replicate paths have no token breakdown - -Unregistered Replicate responses use Python's time-based fallback and return before discount and margin. The caller can supply its per-second rate; the crate otherwise uses Python's current default. Serialized `created` and `ended` fields provide the duration fallback when no response time is supplied - -`ptu_pricing` ports the shared Azure PTU rules: `ptu_terms` validates a reservation a deployment declares, `zeroed_ptu_pricing` builds the pricing overlay a flat-cost deployment must carry, `is_spilled_over_ptu_request` and `azure_spillover` read the spillover Azure reports in response headers, and `ptu_config_error` / `ptu_identity_error` / `declares_ptu` enforce the registration rules. The feature flag is caller-supplied because env and secret resolution stays in Python - -`base_rate_selection::uses_inclusive_token_thresholds` is the single Rust home of Python's `_INCLUSIVE_THRESHOLD_PROVIDERS` set, consumed by the batch, billed-rate, savings, image, and generic-token paths. `image_cost_router::deployment_pricing` reads exactly the `CustomPricingLiteLLMParams` field set Python iterates, and `completion_response` strips a provider-stated usage cost whenever custom pricing is engaged, matching Python's `_without_provider_stated_cost` gate - -## Python function map - -The Rust module tree does not mirror Python's overall cost module tree. The Python entry points also look up models, normalize responses, and choose providers, while this crate starts with caller-supplied prices and usage. These mappings cover the calculation portions of the functions: - -| Python function | Rust function | Python tests | Rust tests | -| --- | --- | --- | --- | -| `litellm.cost_calculator.completion_cost` response preparation, model fallback, supported call dispatch, and final charges | `litellm_cost::completion_response::completion_cost_from_response` | `test_cost_calculator.py` model fallback, served tier, search, transcription, image, video, realtime, and Responses WebSocket cases; `test_video_generation.py` video response cases | `python_completion_response.rs::response_cost_falls_back_to_served_model_and_bills_served_tier`, `search_response_uses_query_list_and_skips_tool_and_additional_charges`, `transcription_response_uses_hidden_duration_when_tokens_are_absent`, `retrieve_batch_response_uses_batch_rates`, `hidden_provider_selects_pricing_and_margin_after_model_fallback`, `explicit_base_model_suppresses_regional_catalog_lookup`, `image_response_uses_image_route_before_discount_and_margin`, `video_response_prefers_provider_total_without_deployment_and_multiplies_custom_rate`, `video_status_poll_does_not_bill_response_time_as_generation_duration`, `realtime_response_prices_session_tokens_and_completed_transcription`, `responses_websocket_prices_each_tier_and_applies_fixed_margin_per_tier`, `empty_responses_websocket_applies_one_fixed_margin`, `unsupported_call_does_not_silently_bill_as_tokens` | -| `litellm.cost_calculator.completion_cost` empty Azure image model fallback | `litellm_cost::completion_input::prepare_completion_input` | No mapped Python unit test; Python selects `dall-e-2` for an empty Azure image model | `python_completion_response.rs::azure_image_response_uses_dall_e_2_for_empty_model` | -| `A2ACostCalculator.calculate_a2a_cost`, `_calculate_token_based_cost` | `litellm_cost::a2a_cost::calculate_a2a_cost`, `calculate_token_based_cost` | No mapped Python unit test | `python_a2a_mcp_cost.rs::a2a_cost_uses_response_then_query_then_token_rates`, `a2a_cost_returns_zero_without_usage_or_configuration`; `python_completion_response.rs::metadata_priced_calls_use_logging_details_without_catalog_pricing` | -| `MCPCostCalculator.calculate_mcp_tool_call_cost` | `litellm_cost::mcp_cost::calculate_mcp_tool_call_cost` | `test_mcp_cost_calculator.py::TestMCPCostCalculator` | `python_a2a_mcp_cost.rs::mcp_cost_uses_response_then_tool_then_default_price`; `python_completion_response.rs::metadata_priced_calls_use_logging_details_without_catalog_pricing` | -| `litellm.cost_calculator.completion_cost` built-in tool charge | `litellm_cost::completion_response::completion_cost_from_response` with `BuiltInToolCostConfig` | `test_tool_call_cost_tracking.py` and provider built-in tool cases | `python_completion_response.rs::response_cost_prices_built_in_web_search_from_selected_model` | -| `litellm.cost_calculator.completion_cost` token breakdown reporting | `PricedCompletionResponse::token_breakdown` via `ModelInfoCatalog::get_token_type_cost_breakdown` | `test_cost_calculator.py::test_completion_cost_logs_the_rates_it_billed_at`, custom-pricing breakdown case | `python_completion_response.rs::custom_cache_rates_match_python_anthropic_usage`, `response_cost_falls_back_to_served_model_and_bills_served_tier`, `completion_cost_counts_prompt_and_completion_without_response` | -| `litellm.cost_calculator._response_time_ms_for_cost` stamped response duration precedence | `litellm_cost::completion_response::response_time_ms_for_cost` | `test_cost_calculator.py` per-second pricing cases | `python_completion_response.rs::response_time_prefers_numeric_response_stamp`, `stamped_response_time_prices_wall_clock_model` | -| `litellm.cost_calculator.completion_cost` prompt, messages, and completion token counting without a response | `litellm_cost::completion_response::completion_cost_from_response` with `CompletionTextInput` and `litellm_token_counter::TokenCounter` | No mapped Python unit test | `python_completion_response.rs::completion_cost_counts_prompt_and_completion_without_response`, `completion_cost_counts_messages_before_prompt_without_response`, `invalid_messages_do_not_fall_back_to_prompt_pricing`, `response_without_usage_does_not_count_request_text` | -| `litellm.cost_calculator.cost_per_token` custom token and per-second precedence through `completion_cost` | `litellm_cost::completion_response::completion_cost_from_response` with `CustomPricing` | `test_cost_calculator.py` custom pricing cases | `python_completion_response.rs::custom_token_rates_override_catalog_and_provider_reported_cost`, `custom_seconds_use_stamped_response_duration_without_catalog_price`, `custom_seconds_without_response_use_default_empty_text`, `custom_cache_rates_match_python_anthropic_usage`, `responses_websocket_applies_custom_rates_to_each_tier`, `search_response_uses_query_list_and_skips_tool_and_additional_charges` | -| `litellm.cost_calculator._infer_call_type` | `litellm_cost::completion_input::infer_call_type` | `test_cost_calculator.py` call-type cases | `python_completion_input.rs::call_type_prefers_explicit_value` | -| `litellm.cost_calculator._map_traffic_type_to_service_tier`, `_normalize_service_tier`, `_extract_service_tier` | Matching functions in `litellm_cost::completion_input`, `select_service_tier` | `test_cost_calculator.py::test_completion_cost_anthropic_auto_tier_uses_served_priority_rate`, `test_completion_cost_vertex_ai_gemini_flex_traffic_type`, non-string tier cases | `python_completion_input.rs::traffic_type_maps_only_billable_tiers`, `request_auto_defers_to_served_usage_tier`, `request_tier_precedes_response_when_billable`, `traffic_type_is_last_tier_fallback`, `prepared_input_prices_served_priority_rate` | -| `litellm.cost_calculator._select_model_name_for_cost_calc` | `litellm_cost::model_selection::select_model_name_for_cost_calc`, `ModelInfoCatalog::select_model_name_for_cost_calc` | `test_cost_calculator.py` response model, router custom pricing, and regional alias cases | `python_model_selection.rs::custom_pricing_selects_only_a_priced_router_id`, `explicit_base_model_ignores_private_response_model_and_region`, `private_response_model_uses_its_region_and_resolves_alias`, `response_alias_strips_unregistered_segment_only_when_a_price_resolves` | -| `litellm.cost_calculator._get_response_model`, `_get_hidden_str_for_cost_calc`, `_model_contains_known_llm_provider`, `_strip_unregistered_leading_segments` | Matching functions in `litellm_cost::model_selection` | `test_cost_calculator.py` response and alias cases | `python_model_selection.rs::model_selection_helpers_ignore_invalid_hidden_values_and_stop_at_provider_segments` | -| `litellm.cost_calculator._get_provider_for_cost_calc` and `completion_cost` provider inference | `litellm_cost::model_selection::get_provider_for_cost_calc`, `ModelInfoCatalog::get_provider_for_cost_calc`, `completion_cost_from_response` | `test_cost_calculator.py::test_completion_cost_logs_the_rates_it_billed_at` | `python_model_selection.rs::provider_inference_uses_explicit_prefix_or_catalog_metadata`; `python_completion_response.rs::response_cost_infers_provider_for_specialized_pricing`, `response_cost_infers_provider_from_priced_fallback_model` | -| `litellm.cost_calculator.pricing_entry_for_cost_calc` | `ModelInfoCatalog::pricing_entry_for_cost_calc` | No mapped Python unit test | `python_model_selection.rs::pricing_entry_prefers_registered_deployment_to_served_model`, `pricing_entry_reads_deployment_metadata_before_published_price`, `pricing_entry_falls_back_from_unpriced_base_to_served_model` | -| `litellm.cost_calculator._store_cost_breakdown_in_logging_obj`, `Logging.set_cost_breakdown` | `litellm_cost::cost_breakdown::cost_breakdown` returns the breakdown data | `test_cost_calculator.py` cost breakdown cases | `python_cost_breakdown.rs` | -| `litellm.litellm_core_utils.llm_cost_calc.zero_cost_diagnostic.used_pricing_keys`, `diagnose_zero_cost`, `zero_cost_warning`; `Logging._zero_cost_finding` | Matching functions in `litellm_cost::zero_cost_diagnostic`, `zero_cost_finding` | `litellm_core_utils/llm_cost_calc/test_zero_cost_diagnostic.py` | `python_zero_cost_diagnostic.rs` | -| `litellm.interactions.background_cost_polling.is_pollable_background_interaction`, `missing_usage_is_expected`, `_poll_intervals` | Matching functions in `litellm_cost::background_cost_polling` | `interactions/test_background_cost_polling.py` status and interval cases | `python_background_cost_polling.rs` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.generic_cost_per_token` flat token pricing subset | `litellm_cost::calculate` | `test_llm_cost_calc_utils.py` | `calculation.rs`, `python_reference.tsv` | -| `litellm.cost_calculator.default_image_cost_calculator` | `ModelInfoCatalog::default_image_cost_calculator`, `litellm_cost::non_token::calculate_image` | `test_cost_calculator.py::test_default_image_cost_calculator`, `test_llm_cost_calc_utils.py::test_route_image_generation_cost_falls_back_to_requested_quality` and size cases | `python_cost_calculator.rs::default_image_cost_calculator_*`, `python_image_cost_router.rs::route_default_image_cost_*` | -| `litellm.cost_calculator.ocr_cost` | `litellm_cost::ocr_cost::ocr_cost`, `ModelInfoCatalog::cost_per_token_for_call`, `litellm_cost::non_token::calculate_ocr_with_tables` | `test_cost_calculator.py::test_ocr_cost_*` | `python_call_dispatch.rs::ocr_call_*`, `python_cost_calculator.rs::ocr_cost_*` | -| `litellm.cost_calculator.ocr_batch_cost` | `litellm_cost::non_token::calculate_ocr_batch` | `litellm_core_utils/test_litellm_logging.py::test_ocr_only_deployment_pricing_reaches_batch_ocr_cost` | `python_cost_calculator.rs::ocr_batch_cost_*` | -| `litellm.cost_calculator.default_video_cost_calculator` | `litellm_cost::non_token::calculate_video` | `test_video_generation.py::test_video_generation_cost_*` | `python_cost_calculator.rs::default_video_cost_calculator_*` | -| `litellm.llms.openai.cost_calculation.cost_router` | `litellm_cost::openai_cost::cost_router` | No mapped Python test | `python_openai_cost.rs::openai_cost_router_selects_transcription_duration_path` | -| `litellm.llms.openai.cost_calculation._video_resolution_to_cost_field_suffix`, `_video_output_cost_per_second`, `video_generation_cost` with supplied metadata | Matching functions in `litellm_cost::openai_cost` | `test_video_generation.py::test_video_generation_cost_*` | `python_openai_cost.rs::video_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.get_batch_cost_rates` | `litellm_cost::batch::get_batch_cost_rates`, `litellm_cost::batch::batch_cost_rates_from_model_info` | `test_cost_calculator.py::test_batch_cost_calculator_*` | `python_cost_calculator.rs::get_batch_cost_rates_*` | -| `litellm.cost_calculator.batch_cost_calculator` | `litellm_cost::batch::batch_cost_from_model_info`, `ModelInfoCatalog::cost_per_token_for_call`, `litellm_cost::batch::batch_cost_calculator` | `test_cost_calculator.py::test_batch_cost_calculator_*`; `test_llm_cost_calc_utils.py::test_get_batch_cost_rates_crosses_each_components_own_tier`, `test_get_batch_cost_rates_has_no_cache_write_rate_without_a_cache_write_batch_key` | `python_call_dispatch.rs::batch_call_*`, `python_cost_calculator.rs::batch_cost_calculator_*`, `batch_model_info_crosses_input_and_output_thresholds_independently`, `batch_model_info_bills_cache_writes_as_input_without_a_batch_cache_rate` | -| `litellm.cost_calculator.cost_per_token` cache normalization | `litellm_cost::custom_pricing::normalize_cache_usage` | `test_cost_calculator.py::test_custom_pricing_*` | `python_custom_pricing.rs::normalize_cache_usage_*` | -| `litellm.cost_calculator._cost_per_token_custom_pricing_helper` | `litellm_cost::custom_pricing::cost_per_token_custom_pricing_helper` | `test_cost_calculator.py::test_custom_pricing_*` | `python_custom_pricing.rs::cost_per_token_custom_pricing_helper_*` | -| `litellm.cost_calculator.cost_per_token` explicit custom pricing before model lookup and call dispatch | `litellm_cost::catalog::ModelInfoCatalog::cost_per_token_with_custom`, `cost_per_token_for_call_with_custom`, `litellm_cost::custom_pricing::cost_from_chat_usage` | `test_cost_calculator.py` custom pricing cases | `python_custom_pricing.rs::catalog_custom_rates_override_lookup_and_call_dispatch`, `catalog_custom_pricing_falls_back_and_rejects_invalid_rates` | -| `litellm.cost_calculator.cost_per_token` model-key selection and generic token calculation | `litellm_cost::catalog::CostCatalog::select_model_key`, `CostCatalog::cost_per_token` | `test_cost_calculator.py::test_cost_per_token_duplicate_openai_prefix_matches_model_cost`, `test_cost_calculator.py::test_cost_per_token_region_name_applies_to_provider_prefixed_model` | `python_model_lookup.rs::cost_per_token_*` | -| `litellm.cost_calculator.cost_per_token` model-info generic pricing path | `litellm_cost::catalog::ModelInfoCatalog::cost_per_token` | `test_cost_calculator.py` model lookup cases, `test_llm_cost_calc_utils.py` generic pricing cases | `python_model_lookup.rs::model_info_catalog_*` | -| `litellm.cost_calculator.cost_per_token` call-type routing for token, speech, transcription, rerank, vector search, search, OCR, and batch | `ModelInfoCatalog::cost_per_token_for_call` with `CostCall` | `test_cost_calculator.py` call-type cases | `python_call_dispatch.rs` | -| `litellm.cost_calculator._has_token_or_tiered_pricing`, `_bills_wall_clock_seconds`, `_per_second_pricing_cost` | Matching functions in `litellm_cost::per_second`, `ModelInfoCatalog::cost_per_token` precedence | `test_cost_calculator.py` per-second pricing cases | `python_per_second.rs` including `wall_clock_pricing_precedes_provider_reported_cost` | -| `litellm.cost_calculator.get_replicate_completion_pricing` and unregistered Replicate branch of `completion_cost` | `litellm_cost::per_second::get_replicate_completion_pricing`, `completion_response::completion_cost_from_response` | No mapped Python unit test | `python_per_second.rs::replicate_completion_pricing_matches_python_duration_units`; `python_completion_response.rs::unregistered_replicate_response_uses_time_and_skips_margin`, `registered_replicate_model_uses_catalog_rates` | -| `litellm.llms.openai.cost_calculation.cost_per_token` | `ModelInfoCatalog::cost_per_token` OpenAI route | `test_cost_calculator.py` OpenAI cache and service tier cases | `python_generic_provider_routes.rs::generic_provider_wrappers_price_cached_and_output_tokens` | -| `litellm.llms.bedrock.cost_calculation.cost_per_token` | `ModelInfoCatalog::cost_per_token` Bedrock route | `test_cost_calculator.py` Bedrock cache cases | `python_generic_provider_routes.rs::generic_provider_wrappers_price_cached_and_output_tokens` | -| `litellm.llms.gemini.cost_calculator.cost_per_token` | `ModelInfoCatalog::cost_per_token` Gemini route | `test_cost_calculator.py` Gemini pricing cases | `python_generic_provider_routes.rs::generic_provider_wrappers_price_cached_and_output_tokens` | -| `litellm.llms.deepseek.cost_calculator.cost_per_token` | `ModelInfoCatalog::cost_per_token` DeepSeek route | No mapped Python unit test | `python_generic_provider_routes.rs::generic_provider_wrappers_price_cached_and_output_tokens` | -| `litellm.llms.tencent.cost_calculator.cost_per_token` | `ModelInfoCatalog::cost_per_token` Tencent route | No mapped Python unit test | `python_generic_provider_routes.rs::generic_provider_wrappers_price_cached_and_output_tokens` | -| `litellm.llms.amazon_nova.cost_calculation.cost_per_token` | `ModelInfoCatalog::cost_per_token` Amazon Nova route | No mapped Python unit test | `python_generic_provider_routes.rs::generic_provider_wrappers_price_cached_and_output_tokens` | -| `litellm.litellm_core_utils.ptu_pricing.ptu_terms`, `_as_utc`, `_to_utc` | `litellm_cost::ptu_pricing::ptu_terms` | `litellm_core_utils/test_ptu_pricing.py` reservation and window cases | `python_ptu_pricing.rs::a_complete_reservation_is_accepted`, `an_incomplete_reservation_accrues_nothing`, `a_naive_start_is_read_as_utc`, `an_offset_start_is_converted_rather_than_relabelled`, `a_bare_yaml_date_*` | -| `litellm.litellm_core_utils.ptu_pricing.zeroed_ptu_pricing` | `litellm_cost::ptu_pricing::zeroed_ptu_pricing` | `test_ptu_pricing.py` zeroing cases | `python_ptu_pricing.rs::the_standing_rates_are_all_zeroed`, `tiered_pricing_is_emptied_rather_than_zeroed`, `the_search_context_table_is_zeroed_in_place_on_every_deployment`, `a_rate_the_deployment_declares_itself_is_zeroed_too`, `a_setting_that_is_not_a_charge_is_left_alone` | -| `litellm.litellm_core_utils.ptu_pricing.is_spilled_over_ptu_request`, `azure_spillover` | Matching functions in `litellm_cost::ptu_pricing` | `test_ptu_pricing.py` spillover cases | `python_ptu_pricing.rs::the_spillover_header_marks_the_request_as_pay_as_you_go`, `azure_spillover_carries_the_source_deployment_from_raw_headers` | -| `litellm.litellm_core_utils.ptu_pricing.ptu_config_error`, `declares_ptu` | Matching functions in `litellm_cost::ptu_pricing` | `test_ptu_pricing.py` configuration-error cases | `python_ptu_pricing.rs::an_incoherent_reservation_names_its_reason`, `an_inverted_window_is_caught_before_the_count_and_rate_gate` | -| `litellm.litellm_core_utils.ptu_pricing.ptu_identity_error` | `litellm_cost::ptu_pricing::ptu_identity_error` | `test_ptu_pricing.py` identity cases | `python_ptu_pricing.rs::a_reservation_without_an_id_is_refused`, `the_string_zero_is_a_declared_id`, `the_deployment_is_named_when_the_caller_supplies_one` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._uses_inclusive_token_thresholds` | `litellm_cost::base_rate_selection::uses_inclusive_token_thresholds` | `test_llm_cost_calc_utils.py` xai threshold cases | `python_base_rate_selection.rs::inclusive_threshold_providers_stay_pinned_to_the_python_set` | -| `litellm.cost_calculator.completion_cost` provider-stated cost under custom pricing (`_without_provider_stated_cost`) | `litellm_cost::completion_response::without_provider_stated_cost` | `test_cost_calculator.py` custom pricing cases | `python_completion_response.rs::rateless_custom_pricing_strips_provider_reported_cost_like_python` | -| `litellm.cost_calculator.rerank_cost`, `BaseRerankConfig.calculate_rerank_cost`, `JinaAIRerankConfig.calculate_rerank_cost`, `VoyageRerankConfig.calculate_rerank_cost` | `litellm_cost::retrieval_cost::rerank_cost`, `ModelInfoCatalog::rerank_cost` | `test_cost_calculator.py::test_per_query_priced_rerank_deployment_completion_cost_is_nonzero` | `python_retrieval_cost.rs::rerank_cost_*`, `model_info_catalog_routes_retrieval_costs_from_selected_metadata` | -| `litellm.cost_calculator.vector_store_search_cost`, `VertexSearchAPIVectorStoreConfig.calculate_vector_store_cost` | `litellm_cost::retrieval_cost::vector_store_search_cost`, `ModelInfoCatalog::vector_store_search_cost`, `completion_cost_from_response` model API type route | No mapped Python cost test | `python_retrieval_cost.rs::vector_store_search_cost_*`, `python_completion_response.rs::vector_store_response_uses_model_api_type_for_pricing` | -| `litellm.cost_calculator._apply_cost_discount`, `_apply_cost_margin` | `litellm_cost::completion_cost::apply_cost_discount`, `apply_cost_margin` | `test_cost_calculator.py::test_cost_discount_not_applied_to_other_providers`, `test_cost_margin_percentage`, `test_cost_margin_fixed_amount` | `python_completion_cost.rs::apply_cost_*`, `completion_cost_applies_discount_before_provider_margin` | -| `litellm.cost_calculator.completion_cost` total calculation and cost components for generic model info | `litellm_cost::completion_cost::completion_cost`, `ModelInfoCatalog::completion_cost` | `test_cost_calculator.py` margin and discount cases | `python_completion_cost.rs::completion_cost_applies_discount_before_provider_margin`, `model_info_catalog_completion_and_response_cost_use_selected_metadata`; `python_completion_response.rs::responses_websocket_prices_each_tier_and_applies_fixed_margin_per_tier` | -| `litellm.cost_calculator.get_response_cost_from_hidden_params`, `response_cost_calculator` cache and provider-cost precedence | `litellm_cost::completion_cost::get_response_cost_from_hidden_params`, `response_cost_calculator`, `ModelInfoCatalog::response_cost_calculator`, `completion_response::response_cost_calculator_from_response` | `test_cost_calculator.py::test_cost_calculator_with_response_cost_in_additional_headers` | `python_completion_cost.rs::get_response_cost_from_hidden_params_*`, `response_cost_calculator_honors_cache_then_provider_then_calculation`; `python_completion_response.rs::response_cost_calculator_short_circuits_cache_and_provider_cost`, `response_cost_calculator_prices_response_without_provider_override` | -| `litellm.llms.fireworks_ai.cache_pricing.with_default_cache_read_rate`, `litellm.litellm_core_utils.llm_cost_calc.utils.apply_provider_cache_read_default` | `litellm_cost::provider_cache::with_default_cache_read_rate`, `apply_provider_cache_read_default` | `test_llm_cost_calc_utils.py` Fireworks cache cases | `python_provider_cache.rs` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.get_billed_token_rates`, `_custom_pricing_rates`, `_cost_map_billed_rates` | `litellm_cost::billed_token_rates::get_billed_token_rates`, `ModelInfoCatalog::get_billed_token_rates` | `test_llm_cost_calc_utils.py` billed-rate and custom-pricing cases | `python_billed_token_rates.rs::get_billed_token_rates_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.BilledTokenRates.scaled` | `litellm_cost::billed_token_rates::BilledTokenRates::scaled` | `test_llm_cost_calc_utils.py` regional billed-rate cases | `python_billed_token_rates.rs::get_token_type_cost_breakdown_scales_cache_audio_and_ttl_with_region` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.get_token_type_cost_breakdown` | `litellm_cost::billed_token_rates::get_token_type_cost_breakdown`, `ModelInfoCatalog::get_token_type_cost_breakdown` | `test_llm_cost_calc_utils.py` token-type breakdown cases | `python_billed_token_rates.rs::get_token_type_cost_breakdown_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.calculate_prompt_caching_savings` | `litellm_cost::prompt_caching_savings::calculate_prompt_caching_savings`, `ModelInfoCatalog::calculate_prompt_caching_savings` | `proxy/spend_tracking/test_savings.py::test_caching_savings_agree_with_biller_on_the_request_pricing_basis` | `python_prompt_caching_savings.rs` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.calculate_image_response_cost_from_usage` | `litellm_cost::image_response_cost::calculate_image_response_cost_from_usage`, `ModelInfoCatalog::calculate_image_response_cost_from_usage` | `test_llm_cost_calc_utils.py::test_image_response_input_image_tokens_priced_at_image_rate` | `python_image_response_cost.rs` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.prices_tokens` | `litellm_cost::image_response_cost::prices_tokens` | No mapped Python unit test | `python_image_response_cost.rs::image_token_price_presence_controls_token_cost_route` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.flat_image_cost` | `litellm_cost::image_response_cost::flat_image_cost` | `test_llm_cost_calc_utils.py::test_vertex_image_generation_cost_falls_back_to_flat_image_pricing` | `python_image_response_cost.rs::google_image_generation_falls_back_to_images_and_preserves_supplied_prices` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.resolve_image_model_info` | `litellm_cost::image_response_cost::resolve_image_model_info` | `test_llm_cost_calc_utils.py` image-generation deployment metadata cases | `python_image_response_cost.rs::google_image_generation_falls_back_to_images_and_preserves_supplied_prices` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.calculate_image_response_web_search_cost` | `litellm_cost::image_response_cost::calculate_image_response_web_search_cost` for Gemini and Vertex | `llms/vertex_ai/image_generation/test_vertex_ai_image_generation_cost_calculator.py` | `python_image_response_cost.rs::calculate_image_response_web_search_cost_uses_provider_and_billing_unit` | -| `litellm.llms.vertex_ai.image_generation.cost_calculator.cost_calculator` | `litellm_cost::image_response_cost::vertex_image_generation_cost`, `ModelInfoCatalog::google_image_generation_cost` | `llms/vertex_ai/image_generation/test_vertex_ai_image_generation_cost_calculator.py` | `python_image_response_cost.rs::google_image_generation_*` | -| `litellm.llms.gemini.image_generation.cost_calculator.cost_calculator` | `litellm_cost::image_response_cost::gemini_image_generation_cost`, `ModelInfoCatalog::google_image_generation_cost` | `test_llm_cost_calc_utils.py` image-generation cases | `python_image_response_cost.rs::google_image_generation_*` | -| `litellm.llms.gemini.image_edit.cost_calculator.cost_calculator` | `litellm_cost::image_response_cost::gemini_image_edit_cost`, `ModelInfoCatalog::google_image_edit_cost` | No mapped Python unit test | `python_image_response_cost.rs::gemini_image_edit_shares_generation_token_and_search_billing` | -| `litellm.llms.vertex_ai.image_edit.cost_calculator.cost_calculator` | `litellm_cost::image_response_cost::vertex_image_edit_cost`, `ModelInfoCatalog::google_image_edit_cost` | No mapped Python unit test | `python_image_response_cost.rs::vertex_image_edit_uses_flat_shared_rate_even_with_token_usage` | -| `litellm.llms.azure_ai.image_generation.cost_calculator._input_cost_per_pixel` | `litellm_cost::azure_ai_image_cost::input_cost_per_pixel` | `llms/azure_ai/image_generation/test_azure_ai_flux2_image_generation.py` pixel-price cases | `python_azure_ai_image_cost.rs::azure_image_cost_prefers_supplied_image_rate_before_shared_pixel_rate` | -| `litellm.llms.azure_ai.image_generation.cost_calculator.cost_calculator` | `litellm_cost::azure_ai_image_cost::cost_calculator`, `ModelInfoCatalog::azure_ai_image_generation_cost` | `llms/azure_ai/image_generation/test_mai_image_generation.py` token and flat cases; `test_azure_ai_flux2_image_generation.py` pixel cases | `python_azure_ai_image_cost.rs` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.CostCalculatorUtils._call_type_has_image_response` | `litellm_cost::image_cost_router::call_type_has_image_response` | No mapped Python unit test | `python_image_cost_router.rs::call_type_has_image_response_matches_python_call_types` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.deployment_pricing` | `litellm_cost::image_cost_router::deployment_pricing` for image price fields | `test_llm_cost_calc_utils.py` deployment image price cases | `python_image_cost_router.rs::deployment_pricing_ignores_invalid_override_and_normalizes_numeric_string` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.CostCalculatorUtils.route_image_generation_cost_calculator` for Vertex, Gemini, Azure AI, Recraft, AI/ML, CometAPI, RunwayML, and default image pricing | `litellm_cost::image_cost_router::route_image_generation_cost_calculator` | `test_llm_cost_calc_utils.py` image route cases | `python_image_cost_router.rs::route_*` | -| `litellm.llms.recraft.cost_calculator.cost_calculator`, `litellm.llms.aiml.image_generation.cost_calculator.cost_calculator`, `litellm.llms.cometapi.image_generation.cost_calculator.cost_calculator`, `litellm.llms.runwayml.cost_calculator.cost_calculator` | `ModelInfoCatalog::flat_image_generation_cost` through the image router | Provider image generation tests where present | `python_image_cost_router.rs::route_image_generation_prices_flat_providers_with_deployment_rate` | -| `litellm.llms.openai.image_generation.cost_calculator.cost_calculator` for OpenAI/Azure GPT image models | `litellm_cost::openai_image_cost::cost_calculator`, `ModelInfoCatalog::openai_image_generation_cost`, image router | `test_llm_cost_calc_utils.py::test_route_image_generation_cost_bills_deployment_image_price_when_unlisted_model_reports_tokens`, `test_image_response_input_image_tokens_priced_at_image_rate` | `python_openai_image_cost.rs` | -| `litellm.llms.fal_ai.cost_calculator._keyed_size`, `_image_dimensions`, `_keyed_quality`, `_parse_keyed_dimensions` | Matching functions in `litellm_cost::fal_ai_image_cost` | `llms/fal_ai/test_cost_calculator.py` keyed pricing and invalid dimension cases | `python_fal_ai_image_cost.rs::keyed_size_maps_request_shapes`, `image_dimensions_require_positive_integer_provider_fields` | -| `litellm.llms.fal_ai.cost_calculator._keyed_rows`, `_keyed_cost_per_image`, `_flat_cost_per_image` | Matching functions in `litellm_cost::fal_ai_image_cost` | `llms/fal_ai/test_cost_calculator.py` nearest keyed row and megapixel cases | `python_fal_ai_image_cost.rs::keyed_rows_price_response_dimensions_and_choose_nearest_area`, `flat_cost_per_image_rounds_each_response_to_megapixels` | -| `litellm.llms.fal_ai.cost_calculator.fal_ai_passthrough_cost` | `litellm_cost::fal_ai_image_cost::fal_ai_passthrough_cost`, `ModelInfoCatalog::fal_ai_passthrough_cost` | `llms/fal_ai/test_cost_calculator.py` passthrough resolution cases | `python_fal_ai_image_cost.rs::fal_passthrough_selects_resolution_rate_and_falls_back_to_base` | -| `litellm.llms.fal_ai.cost_calculator.cost_calculator` | `litellm_cost::fal_ai_image_cost::cost_calculator`, `ModelInfoCatalog::fal_ai_image_generation_cost`, image router | `llms/fal_ai/test_cost_calculator.py` | `python_fal_ai_image_cost.rs::fal_image_cost_*`, `catalog_fal_image_route_uses_keyed_row_for_image_edit` | -| `litellm.llms.bedrock.image_generation.image_handler.BedrockImageGeneration.get_config_class` | `litellm_cost::bedrock_image_cost::get_config_class` | No mapped Python cost unit test | `python_bedrock_image_cost.rs::get_config_class_matches_model_family` | -| `litellm.llms.bedrock.image_generation.cost_calculator.cost_calculator` and the Titan, Nova Canvas, Stability 3, Stability 1 config calculators | `litellm_cost::bedrock_image_cost::cost_calculator`, `ModelInfoCatalog::bedrock_image_generation_cost`, image router | No mapped Python cost unit test | `python_bedrock_image_cost.rs::bedrock_*`, `stability1_pricing_key_selects_step_tier` | -| `litellm.llms.perplexity.cost_calculator.cost_per_token` | `litellm_cost::perplexity_cost::cost_per_token`, `ModelInfoCatalog::cost_per_token` for Perplexity | `llms/perplexity/test_perplexity_cost_calculator.py` | `python_perplexity_cost.rs` | -| `litellm.llms.xai.cost_calculator._cost_reported_by_xai`, `cost_per_token` | `litellm_cost::xai_cost::reported_cost`, `cost_per_token`, `ModelInfoCatalog::cost_per_token` for xAI | `llms/xai/test_xai_cost_calculator.py`, `test_xai_chat_transformation.py` | `python_xai_cost.rs::xai_cost_per_token_*` | -| `litellm.llms.xai.cost_calculator.apply_server_side_tool_usage_details_to_usage` | `litellm_cost::xai_cost::apply_server_side_tool_usage_details_to_usage` | `llms/xai/test_xai_cost_calculator.py::TestXAIWebSearchCostHelpers` | `python_xai_cost.rs::apply_server_side_tool_usage_details_to_usage_*` | -| `litellm.llms.xai.cost_calculator._web_search_cost_per_call_from_model_info`, `cost_per_web_search_request` | `litellm_cost::xai_cost::web_search_cost_per_call_from_model_info`, `cost_per_web_search_request` | `llms/xai/test_xai_cost_calculator.py::TestXAIWebSearchCostHelpers` | `python_xai_cost.rs::xai_web_search_*`, `python_tool_cost_dispatch.rs` | -| `litellm.llms.dashscope.cost_calculator._extract_token_breakdown`, `_flat_rates`, `_tier_rates`, `_bill`, `cost_per_token` | Matching functions in `litellm_cost::dashscope_cost`, `ModelInfoCatalog::cost_per_token` for Dashscope aliases | `llms/dashscope/test_dashscope_cost_calculator.py` | `python_dashscope_cost.rs` | -| `litellm.llms.dashscope.cost_calculator.TokenBreakdown.total_input_tokens` | `litellm_cost::dashscope_cost::TokenBreakdown::total_input_tokens` | `llms/dashscope/test_dashscope_cost_calculator.py` tier selection cases | `python_dashscope_cost.rs::dashscope_cost_per_token_prices_nested_cache_creation_and_reasoning_at_selected_tier` | -| `litellm.llms.fireworks_ai.cost_calculator.get_base_model_for_pricing`, `_resolve_model_info`, `cost_per_token` | `litellm_cost::fireworks_cost::get_base_model_for_pricing`, `cost_per_token`, `ModelInfoCatalog::cost_per_token` Fireworks fallback | `test_fireworks_serverless_model_costs.py`, `test_llm_cost_calc_utils.py` Fireworks cache cases | `python_fireworks_cost.rs`, `python_provider_cache.rs` | -| `litellm.search.cost_calculator.search_provider_cost_per_query` | `litellm_cost::search_cost::search_provider_cost_per_query`, `ModelInfoCatalog::search_provider_cost_per_query` | `llms/bedrock/search/test_agentcore_search_transformation.py` zero-price case | `python_search_cost.rs` | -| `litellm.llms.parallel_ai.search.cost_calculator._usage_count`, `_effective_mode`, `_effective_max_results`, `parallel_ai_search_cost` | Matching functions in `litellm_cost::search_cost`, `ModelInfoCatalog::search_provider_cost_per_query` | No mapped Python unit test | `python_search_cost.rs` | -| `litellm.responses.utils.ResponseAPILoggingUtils._is_response_api_usage` | `litellm_cost::responses_usage::is_response_api_usage` | `test_responses_utils.py::test_transform_response_api_usage_*` | `python_responses_usage.rs::is_response_api_usage_*` | -| `litellm.responses.utils.ResponseAPILoggingUtils._transform_response_api_usage_to_chat_usage` | `litellm_cost::responses_usage::transform_response_api_usage_to_chat_usage` | `test_responses_utils.py::test_transform_response_api_usage_*`, `test_transform_realtime_usage_*` | `python_responses_usage.rs::transform_response_api_usage_to_chat_usage_*` | -| `litellm.types.utils.text_tokens_without_nested_reasoning` | `litellm_cost::responses_usage::text_tokens_without_nested_reasoning` | `test_responses_utils.py::test_transform_realtime_usage_*` | `python_responses_usage.rs::text_tokens_without_nested_reasoning_*` | -| `litellm.llms.anthropic.chat.transformation.AnthropicConfig.is_anthropic_usage_object` | `litellm_cost::anthropic_usage::is_anthropic_usage_object` | `test_anthropic_chat_transformation.py::test_is_anthropic_usage_object_*` | `python_anthropic_usage.rs::is_anthropic_usage_object_*` | -| `litellm.llms.anthropic.chat.transformation.AnthropicConfig.calculate_usage` | `litellm_cost::anthropic_usage::transform_anthropic_usage_to_chat_usage` | `test_anthropic_chat_transformation.py::test_calculate_usage_*` | `python_anthropic_usage.rs::calculate_usage_*` | -| `litellm.litellm_core_utils.llm_cost_calc.usage_object_transformation.InteractionsUsageObjectTransformation.is_interactions_usage_object` | `litellm_cost::interactions_usage::is_interactions_usage_object` | `test_usage_object_transformation.py::test_detects_interactions_usage_object`, `test_rejects_chat_and_responses_api_usage_objects` | `python_interactions_usage.rs::is_interactions_usage_object_*` | -| `litellm.litellm_core_utils.llm_cost_calc.usage_object_transformation.InteractionsUsageObjectTransformation.transform_interactions_usage_object` | `litellm_cost::interactions_usage::transform_interactions_usage_object` | `test_usage_object_transformation.py::test_transforms_real_omni_video_usage_block`, `test_transforms_reasoning_tokens_spec_field_name`, `test_cached_tokens_subtracted_from_text_input` | `python_interactions_usage.rs::transform_interactions_usage_object_*` | -| `litellm.litellm_core_utils.llm_cost_calc.usage_object_transformation.TranscriptionUsageObjectTransformation.is_transcription_usage_object` | `litellm_cost::transcription_usage::is_transcription_usage_object` | No mapped Python test | `python_transcription_usage.rs::is_transcription_usage_object_*` | -| `litellm.litellm_core_utils.llm_cost_calc.usage_object_transformation.TranscriptionUsageObjectTransformation.transform_transcription_usage_object` | `litellm_cost::transcription_usage::transform_transcription_usage_object` | No mapped Python test | `python_transcription_usage.rs::transform_transcription_usage_object_*` | -| `litellm.cost_calculator._get_transcription_model_name_from_results` | `litellm_cost::realtime_cost::get_transcription_model_name_from_results` | `test_cost_calculator.py::test_get_transcription_model_falls_back_to_session_model` | `python_realtime_cost.rs::get_transcription_model_name_from_results_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.select_cost_metric_for_model` | `litellm_cost::speech_cost::select_cost_metric_for_model` | No mapped Python test | `python_speech_cost.rs::select_cost_metric_for_model_uses_character_first` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._generic_cost_per_character` | `litellm_cost::speech_cost::generic_cost_per_character` | No mapped Python test | `python_speech_cost.rs::generic_cost_per_character_*` | -| `litellm.llms.openai.cost_calculation.cost_per_second` | `litellm_cost::speech_cost::cost_per_second` | `llms/openai/test_cost_calculation.py::test_*` | `python_speech_cost.rs::cost_per_second_bills_one_side_only` | -| `litellm.llms.vertex_ai.common_utils.get_vertex_ai_lyria_generation_cost` with supplied metadata | `litellm_cost::speech_cost::lyria_generation_cost` | `llms/vertex_ai/test_vertex_passthrough_logging_handler.py` Lyria cases | `python_speech_cost.rs::speech_cost_uses_lyria_generation_price_before_character_or_token_rates` | -| `litellm.cost_calculator._transcription_usage_has_token_details` | `litellm_cost::speech_cost::transcription_usage_has_token_details` | No mapped Python test | `python_speech_cost.rs::transcription_cost_selects_token_usage_or_duration_pricing` | -| `litellm.cost_calculator.cost_per_token` speech and transcription branches | `ModelInfoCatalog::speech_cost`, `ModelInfoCatalog::transcription_cost` | No mapped Python test | `python_speech_cost.rs::speech_cost_*`, `transcription_cost_*` | -| `litellm.utils._count_characters` and `litellm.cost_calculator.completion_cost` speech prompt count | `litellm_cost::speech_cost::count_characters`, `completion_cost_from_response` with `speech_prompt` | No mapped Python unit test | `python_speech_cost.rs::count_characters_excludes_whitespace`, `python_completion_response.rs::speech_response_cost_counts_prompt_characters_when_not_supplied` | -| `litellm.llms.azure_ai.cost_calculator.is_azure_model_router`, `is_router_fee_entry`, `_router_fee_entry_name`, `_router_fee_name` | Matching functions in `litellm_cost::azure_ai_cost` | `llms/azure_ai/test_azure_ai_cost_calculator.py::test_is_azure_model_router`, router fee cases | `python_azure_ai_cost.rs::is_azure_model_router_*`, `router_fee_helpers_*` | -| `litellm.llms.azure_ai.cost_calculator.calculate_azure_model_router_flat_cost` | `litellm_cost::azure_ai_cost::calculate_azure_model_router_flat_cost` | `llms/azure_ai/test_azure_ai_cost_calculator.py::TestAzureModelRouterFlatCost` | `python_azure_ai_cost.rs::calculate_azure_model_router_flat_cost_*` | -| `litellm.llms.azure_ai.cost_calculator.cost_per_token` | `ModelInfoCatalog::azure_ai_cost_per_token`, `ModelInfoCatalog::cost_per_token` Azure AI dispatch | `llms/azure_ai/test_azure_ai_cost_calculator.py::TestAzureModelRouterFlatCost`, `TestAzureAIServiceTierCostCalculation` | `python_azure_ai_cost.rs::azure_ai_cost_per_token_*` | -| `litellm.cost_calculator._get_additional_costs` Azure AI router fee | `ModelInfoCatalog::azure_ai_router_fee`, `completion_cost_from_response` named additional costs | `test_cost_calculator.py::test_additional_costs_only_for_azure_ai` | `python_completion_response.rs::azure_ai_response_cost_bills_router_fee_once_from_request_or_hidden_model`, `azure_ai_custom_token_pricing_keeps_router_fee_as_additional_cost` | -| `litellm.cost_calculator.completion_cost` Azure AI request and hidden router names | `litellm_cost::completion_response::completion_cost_from_response` | `test_cost_calculator.py::test_completion_cost_uses_response_model_for_dynamic_routing` | `python_completion_response.rs::azure_ai_response_cost_bills_router_fee_once_from_request_or_hidden_model` | -| `litellm.llms.azure.cost_calculation.cost_per_token` output-per-second path | `litellm_cost::azure_cost::output_per_second_cost`, `ModelInfoCatalog::cost_per_token` Azure dispatch | `test_cost_calculator.py` Azure audio cases | `python_provider_routes.rs::azure_*` | -| `litellm.llms.databricks.cost_calculator._registry_key`, `cost_per_token` | `litellm_cost::databricks_cost::registry_key`, `ModelInfoCatalog::databricks_cost_per_token` | No mapped Python test | `python_provider_routes.rs::databricks_*` | -| `litellm.llms.lemonade.cost_calculator.cost_per_token` | `ModelInfoCatalog::lemonade_cost_per_token` | No mapped Python test | `python_provider_routes.rs::lemonade_*` | -| `litellm.llms.together_ai.cost_calculator.has_together_registry_pricing` | `litellm_cost::together_cost::has_together_registry_pricing` | No mapped Python cost test | `python_together_cost.rs::exact_registry_pricing_requires_input_rate_key` | -| `litellm.llms.together_ai.cost_calculator.get_model_params_and_category`, `get_model_params_and_category_embeddings` | Matching functions in `litellm_cost::together_cost` | No mapped Python cost test | `python_together_cost.rs::chat_size_uses_first_parameter_match_and_python_thresholds`, `embedding_size_uses_embedding_thresholds`, `configured_thresholds_change_category_selection` | -| `litellm.cost_calculator.completion_cost` Together AI fallback branch | `ModelInfoCatalog::cost_per_token`, `ModelInfoCatalog::together_ai_cost_per_token` | No mapped Python cost test | `python_together_cost.rs::catalog_uses_exact_price_or_chat_category`, `catalog_routes_embedding_to_size_category` | -| `litellm.llms.anthropic.cost_calculation.cost_per_token` fast-speed wrapper | `litellm_cost::anthropic_cost::fast_speed_multiplier`, `ModelInfoCatalog::cost_per_token` Anthropic dispatch | `test_cost_calculator.py::test_anthropic_cost_per_token_prices_cache_at_served_tier_with_multiplier`, `test_anthropic_geo_and_fast_multipliers_compose` | `python_anthropic_cost.rs::anthropic_cost_per_token_composes_served_tier_cache_geo_and_fast_once` | -| `litellm.llms.anthropic.cost_calculation.get_anthropic_web_search_requests_from_response` | `litellm_cost::anthropic_cost::get_anthropic_web_search_requests_from_response` | No mapped Python test | `python_anthropic_cost.rs::get_anthropic_web_search_requests_from_response_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.get_web_search_requests`, `get_web_search_requests_from_usage` | Matching functions in `litellm_cost::anthropic_cost` | `llms/anthropic/test_cost_calculation_dict_safety.py` | `python_anthropic_cost.rs::get_web_search_requests_reads_serialized_server_tool_use`, `get_cost_for_anthropic_web_search_prices_server_tool_requests` | -| `litellm.llms.anthropic.cost_calculation.get_cost_for_anthropic_web_search` | `litellm_cost::anthropic_cost::get_cost_for_anthropic_web_search` | `llms/anthropic/test_cost_calculation_dict_safety.py` | `python_anthropic_cost.rs::get_cost_for_anthropic_web_search_*` | -| `litellm.cost_calculator._transcription_usage_cost` | `litellm_cost::realtime_cost::transcription_usage_cost` | `test_cost_calculator.py::test_transcription_usage_cost_returns_zero_for_unknown_type` | `python_realtime_cost.rs::transcription_usage_cost_*` | -| `litellm.cost_calculator.handle_realtime_transcription_cost_calculation` | `litellm_cost::catalog::ModelInfoCatalog::handle_realtime_transcription_cost_calculation` | `test_cost_calculator.py::test_realtime_transcription_no_completed_events_is_zero` | `python_realtime_cost.rs::handle_realtime_transcription_cost_calculation_*` | -| `litellm.cost_calculator.BaseTokenUsageProcessor.combine_usage_objects` | `litellm_cost::realtime_cost::combine_usage_objects` | `test_cost_calculator.py::test_combine_usage_objects_sums_mirrored_cache_write_fields_once` | `python_realtime_cost.rs::collect_realtime_usage_sums_billable_events_without_doubling_cache_writes` | -| `litellm.cost_calculator.RealtimeAPITokenUsageProcessor.collect_usage_from_realtime_stream_results`, `collect_and_combine_usage_from_realtime_stream_results` | Matching functions in `litellm_cost::realtime_cost` | `test_cost_calculator.py` realtime usage cases | `python_realtime_cost.rs::collect_realtime_usage_sums_billable_events_without_doubling_cache_writes` | -| `litellm.cost_calculator.ResponsesWebSocketTokenUsageProcessor.collect_usage_from_responses_ws_results`, `collect_and_combine_usage_from_responses_ws_results`, `partition_results_by_service_tier` | Matching functions in `litellm_cost::realtime_cost` | `test_cost_calculator.py::test_completion_cost_prices_responses_websocket_turns_per_service_tier` | `python_realtime_cost.rs::responses_ws_usage_filters_and_partitions_billable_events_by_service_tier` | -| `litellm.cost_calculator._first_priced_realtime_token_costs`, `handle_realtime_stream_cost_calculation` | `litellm_cost::catalog::ModelInfoCatalog::handle_realtime_stream_cost_calculation` | `test_cost_calculator.py::test_realtime_priceless_deployment_entry_falls_through_to_priced_model`, `test_realtime_explicitly_free_session_model_still_bills_zero` | `python_realtime_cost.rs::handle_realtime_stream_cost_calculation_*` | -| `litellm.cost_calculator._split_responses_ws_logging_object_by_service_tier` token pricing | `litellm_cost::realtime_cost::partition_results_by_service_tier`, `ModelInfoCatalog::responses_ws_token_cost_by_tier` | `test_cost_calculator.py::test_completion_cost_prices_responses_websocket_turns_per_service_tier` | `python_realtime_cost.rs::responses_ws_token_cost_prices_each_tier_at_its_returned_rate` | -| `litellm.cost_calculator.get_usage_object` | `litellm_cost::usage_dispatch::get_usage_object` | `test_cost_calculator.py`, Anthropic and Responses usage tests | `python_usage_dispatch.rs::get_usage_object_*` | -| `litellm.litellm_core_utils.llm_cost_calc.guardrail_cost.billed_guardrail_cost_by_unit` | `litellm_cost::guardrail_cost::billed_guardrail_cost_by_unit` | `test_guardrail_cost.py::test_billed_guardrail_cost_by_unit_*` | `python_guardrail_cost.rs::billed_guardrail_cost_by_unit_*` | -| `litellm.litellm_core_utils.llm_cost_calc.guardrail_cost.bedrock_guardrail_cost_by_unit` | `litellm_cost::guardrail_cost::bedrock_guardrail_cost_by_unit` | `test_guardrail_cost.py::test_bedrock_guardrail_cost_by_unit_*` | `python_guardrail_cost.rs::bedrock_guardrail_cost_by_unit_*` | -| `litellm.litellm_core_utils.llm_cost_calc.guardrail_cost.guardrail_cost_total` | `litellm_cost::guardrail_cost::guardrail_cost_total` | `test_guardrail_cost.py::test_bedrock_guardrail_cost_by_unit_prices_every_counter_it_was_given` | `python_guardrail_cost.rs::bedrock_guardrail_cost_by_unit_preserves_unknown_and_explicit_zero` | -| `litellm.litellm_core_utils.llm_cost_calc.guardrail_cost.bedrock_guardrail_cost` | `litellm_cost::guardrail_cost::bedrock_guardrail_cost` | `test_guardrail_cost.py::test_bedrock_guardrail_cost_*` | `python_guardrail_cost.rs::bedrock_guardrail_cost_*` | -| `litellm.litellm_core_utils.llm_cost_calc.guardrail_cost.azure_prompt_shield_guardrail_cost` | `litellm_cost::guardrail_cost::azure_prompt_shield_guardrail_cost` | `test_guardrail_cost.py::test_azure_prompt_shield_guardrail_cost_*` | `python_guardrail_cost.rs::azure_prompt_shield_guardrail_cost_*` | -| `litellm.litellm_core_utils.llm_cost_calc.guardrail_cost.guardrail_information_cost` | `litellm_cost::guardrail_cost::guardrail_information_cost` | `test_guardrail_cost.py::test_guardrail_information_cost_*` | `python_guardrail_cost.rs::guardrail_information_cost_*` | -| `litellm.litellm_core_utils.llm_cost_calc.guardrail_cost.cost_breakdown_with_guardrail` | `litellm_cost::guardrail_cost::cost_breakdown_with_guardrail` | `test_guardrail_cost.py::test_cost_breakdown_with_guardrail_merges_and_creates` | `python_guardrail_cost.rs::cost_breakdown_with_guardrail_*` | -| `litellm.litellm_core_utils.llm_cost_calc.tool_call_cost_tracking.StandardBuiltInToolCostTracking.get_cost_for_web_search`, `get_default_cost_for_web_search` | `litellm_cost::tool_call_cost_tracking::get_cost_for_web_search`, `get_default_cost_for_web_search` | `test_tool_call_cost_tracking.py::test_web_search_cost_*` | `python_tool_call_cost_tracking.rs::get_cost_for_web_search_selects_context_rate` | -| `StandardBuiltInToolCostTracking.get_cost_for_file_search`, `get_cost_for_vector_store`, `get_cost_for_computer_use`, `get_cost_for_code_interpreter` | Matching functions in `litellm_cost::tool_call_cost_tracking` | `test_azure_assistant_cost_tracking.py` | `python_tool_call_cost_tracking.rs::get_cost_for_*` | -| `StandardBuiltInToolCostTracking._extract_file_search_params`, `_extract_token_counts`, `_safe_convert_to_int` | `litellm_cost::tool_call_cost_tracking::extract_file_search_params`, `extract_token_counts`, `safe_convert_to_int` | `test_tool_call_cost_tracking_dict_safety.py` | `python_tool_call_cost_tracking.rs::extract_params_converts_python_inputs` | -| `StandardBuiltInToolCostTracking.chat_completion_response_includes_annotations`, `response_includes_annotation_type`, `response_includes_output_type`, `response_object_includes_file_search_call`, `response_object_includes_web_search_call`, `_count_web_search_calls` | Matching functions in `litellm_cost::tool_call_cost_tracking` | `test_tool_call_cost_tracking.py` | `python_tool_call_cost_tracking.rs::chat_completion_response_includes_any_annotation`, `response_detection_uses_explicit_api_shape`, `count_web_search_calls_prefers_reported_billable_requests` | -| `StandardBuiltInToolCostTracking.get_cost_for_built_in_tools` | `litellm_cost::tool_cost_dispatch::get_cost_for_built_in_tools`, `ModelInfoCatalog::completion_cost` with `BuiltInToolCharge::FromResponse` | `test_tool_call_cost_tracking.py`, `test_azure_assistant_cost_tracking.py`, Gemini and xAI cost tests | `python_tool_cost_dispatch.rs` | -| `litellm.litellm_core_utils.llm_cost_calc.tiered_pricing.select_tier_for_input` | `litellm_cost::tiered_pricing::select_tier_for_input` | `test_llm_cost_calc_utils.py` tiered pricing cases | `python_tiered_pricing.rs::select_tier_for_input_*` | -| `litellm.litellm_core_utils.llm_cost_calc.tiered_pricing.tier_rate` | `litellm_cost::tiered_pricing::tier_rate` | `test_llm_cost_calc_utils.py` tiered rate cases | `python_tiered_pricing.rs::tier_rate_*` | -| `litellm.llms.gemini.cost_calculator.cost_per_web_search_request` | `litellm_cost::gemini_cost::cost_per_web_search_request` | `llms/gemini/test_cost_calculator.py::test_*billing*`, `test_server_tool_use_fallback_*` | `python_gemini_cost.rs::cost_per_web_search_request_*` | -| `litellm.llms.gemini.cost_calculator.google_maps_grounding_requests` | `litellm_cost::gemini_cost::google_maps_grounding_requests` | `llms/gemini/test_cost_calculator.py::test_maps_*` | `python_gemini_cost.rs::google_maps_grounding_requests_*` | -| `litellm.llms.gemini.cost_calculator.cost_per_google_maps_grounding_request` | `litellm_cost::gemini_cost::cost_per_google_maps_grounding_request` | `llms/gemini/test_cost_calculator.py::test_maps_*` | `python_gemini_cost.rs::cost_per_google_maps_grounding_request_*` | -| `litellm.llms.groq.cost_calculator.cost_per_web_search_request` | `litellm_cost::groq_cost::cost_per_web_search_request`, `litellm_cost::tool_cost_dispatch::get_cost_for_built_in_tools` | No mapped Python unit test | `python_groq_cost.rs::groq_*`, `python_tool_cost_dispatch.rs::get_cost_for_built_in_tools_prices_groq_search_and_browser_open` | -| `litellm.llms.vertex_ai.cost_calculator.cost_router` | `litellm_cost::vertex_cost::cost_router`, `ModelInfoCatalog::vertex_cost` | `test_cost_calculator.py::test_completion_cost_vertex_ai_gemini_flex_traffic_type` | `python_vertex_cost.rs::cost_router_matches_provider_model_and_call_type`, `catalog_vertex_cost_routes_token_and_character_calls` | -| `litellm.llms.vertex_ai.cost_calculator._handle_128k_pricing` | `litellm_cost::vertex_cost::handle_128k_pricing` | `test_cost_calculator.py::test_vertex_uplift_composes_with_above_128k_pricing` | `python_vertex_cost.rs::handle_128k_pricing_selects_each_side_independently` | -| `litellm.llms.vertex_ai.cost_calculator.cost_per_token` | `litellm_cost::vertex_cost::cost_per_token`, `ModelInfoCatalog::cost_per_token` for Vertex | `test_cost_calculator.py::test_vertex_uplift_composes_with_above_128k_pricing` | `python_vertex_cost.rs::cost_per_token_applies_vertex_uplift_to_128k_rates` | -| `litellm.llms.vertex_ai.cost_calculator.cost_per_character` | `litellm_cost::vertex_cost::cost_per_character`, `ModelInfoCatalog::vertex_cost` | `test_cost_calculator.py::test_completion_cost_vertex_ai_gemini_flex_traffic_type`, `test_vertex_regional_deployment_costs_uplift_over_global` | `python_vertex_cost.rs::cost_per_character_falls_back_per_side_and_keeps_served_tier`, `cost_per_character_uses_python_dynamic_output_quantity` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.parse_prompt_tokens_details` | `litellm_cost::generic_usage::parse_prompt_tokens_details` | `test_llm_cost_calc_utils.py` cache and modality cases | `python_generic_usage.rs::parse_prompt_tokens_details_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.get_billable_input_tokens` | `litellm_cost::generic_usage::get_billable_input_tokens` with normalized counts | No mapped Python unit test; used by batch fallback pricing | `python_generic_usage.rs::get_billable_input_tokens_subtracts_cached_tokens`, `python_cost_calculator.rs::batch_cost_calculator_prices_cache_creation_in_regular_fallback` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.parse_completion_tokens_details` | `litellm_cost::generic_usage::parse_completion_tokens_details` | `test_llm_cost_calc_utils.py` reasoning and modality cases | `python_generic_usage.rs::parse_completion_tokens_details_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._get_cost_per_unit` | `litellm_cost::generic_input::get_cost_per_unit` | `test_llm_cost_calc_utils.py` tier and string rate cases | `python_generic_input.rs::get_cost_per_unit_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.calculate_cost_component` | `litellm_cost::generic_input::calculate_cost_component` | `test_llm_cost_calc_utils.py` component cases | `python_generic_input.rs::calculate_cost_component_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.calculate_cache_writing_cost` | `litellm_cost::generic_input::calculate_cache_writing_cost` | `test_llm_cost_calc_utils.py::test_cache_writing_cost_*` | `python_generic_input.rs::calculate_cache_writing_cost_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._calculate_input_cost` | `litellm_cost::generic_input::calculate_input_cost` | `test_llm_cost_calc_utils.py::test_cache_writing_cost_with_zero_creation_tokens_and_ephemeral_details` and modality cases | `python_generic_input.rs::calculate_input_cost_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._resolve_reasoning_token_cost` | `litellm_cost::generic_output::resolve_reasoning_token_cost` | `test_llm_cost_calc_utils.py::test_*reasoning*` | `python_generic_output.rs::resolve_reasoning_token_cost_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.generic_cost_per_token` output and overlap calculation | `litellm_cost::generic_output::calculate_output_cost`, `litellm_cost::generic_cost::billable_prompt_details`, `litellm_cost::generic_cost::calculate_generic_cost_with_resolved_rates` | `test_llm_cost_calc_utils.py::test_generic_cost_per_token_*` | `python_generic_output.rs::calculate_output_cost_*`, `python_generic_cost.rs` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._get_token_base_cost` without off-peak pricing | `litellm_cost::base_rate_selection::get_token_base_cost_without_off_peak` | `test_llm_cost_calc_utils.py` threshold, tier, and cache cases | `python_base_rate_selection.rs::get_token_base_cost_without_off_peak_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._is_within_off_peak_window` | `litellm_cost::off_peak::is_within_off_peak_window` | `test_llm_cost_calc_utils.py` off-peak window cases | `python_off_peak.rs::is_within_off_peak_window_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._is_off_peak` | `litellm_cost::off_peak::is_off_peak` | `test_llm_cost_calc_utils.py` off-peak weekday cases | `python_off_peak.rs::is_off_peak_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._open_off_peak_block` | `litellm_cost::off_peak::open_off_peak_block` | `test_llm_cost_calc_utils.py` off-peak pricing cases | `python_off_peak.rs::open_off_peak_block_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._parse_off_peak_rate` | `litellm_cost::off_peak::parse_off_peak_rate` | `test_llm_cost_calc_utils.py` off-peak rate cases | `python_off_peak.rs::parse_off_peak_rate_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.apply_off_peak_pricing` | `litellm_cost::off_peak::apply_off_peak_pricing` | `test_llm_cost_calc_utils.py::test_apply_off_peak_pricing_treats_bool_as_unset_and_parses_strings` | `python_off_peak.rs::apply_off_peak_pricing_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.TokenRates.billed_reasoning_rate` | `litellm_cost::off_peak::TokenRates::billed_reasoning_rate` | `test_llm_cost_calc_utils.py` off-peak reasoning cases | `python_off_peak.rs::apply_off_peak_pricing_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._get_token_base_cost` with off-peak pricing | `litellm_cost::base_rate_selection::get_token_base_cost` | `test_llm_cost_calc_utils.py` off-peak rate cases | `python_off_peak.rs::get_token_base_cost_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.generic_cost_per_token` with selected model rates and off-peak pricing | `litellm_cost::generic_cost::calculate_generic_cost_from_model_info` | `test_llm_cost_calc_utils.py::test_generic_cost_per_token_*` | `python_generic_cost.rs::calculate_generic_cost_from_model_info_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._get_regional_uplift_multiplier` | `litellm_cost::regional_uplift::get_regional_uplift_multiplier` | `test_llm_cost_calc_utils.py` data-residency cases | `python_regional_uplift.rs::get_regional_uplift_multiplier_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.get_vertex_regional_endpoint_uplift` | `litellm_cost::regional_uplift::get_vertex_regional_endpoint_uplift` | `test_llm_cost_calc_utils.py` Vertex regional cases | `python_regional_uplift.rs::get_vertex_regional_endpoint_uplift_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.get_provider_specific_geo_multiplier` | `litellm_cost::regional_uplift::get_provider_specific_geo_multiplier` | `test_llm_cost_calc_utils.py` inference-geo cases | `python_regional_uplift.rs::get_provider_specific_geo_multiplier_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils.generic_cost_per_token` regional multiplier path | `litellm_cost::generic_cost::calculate_generic_cost_from_model_info_with_region` | `test_llm_cost_calc_utils.py` regional pricing cases | `python_regional_uplift.rs::calculate_generic_cost_from_model_info_with_region_*` | -| `litellm.litellm_core_utils.llm_cost_calc.utils._get_tiered_reasoning_rate` | `litellm_cost::base_rate_selection::get_tiered_reasoning_rate` | `test_llm_cost_calc_utils.py::test_generic_cost_per_token_tiered_pricing_bills_reasoning_at_tier_rate` | `python_base_rate_selection.rs::get_token_base_cost_without_off_peak_uses_one_tier_for_all_token_rates` | - -The Rust dispatcher covers the mapped provider and call-type branches above. The `rstest` cases use synthetic prices and do not prove parity for every Python object shape, exceptional fallback, or model registration path - -`litellm.cost_calculator.has_hidden_params` checks a Python attribute; Rust callers pass `hidden_params` explicitly. `RealtimeAPITokenUsageProcessor.create_logging_realtime_object` constructs a Python logging object; Rust callers pass usage and results directly. `fal_ai_queue_base` reads a proxy transport URL and has no pricing behavior - -The caller states whether `prompt_tokens` includes cache tokens. Threshold selection uses total input tokens for either convention and selects one rate for the whole request. Thresholds are sorted when compiled, and duplicate thresholds or tier overrides fail deterministically. `Fast` selects priority rates; unknown tiers use standard rates - -`Rate::Missing`, `Rate::Null`, and `Rate::Value(0.0)` remain distinct. Missing cache rates fall back to the selected input rate, and an absent one-hour write rate falls back to the selected write rate. Missing input or output rates return typed errors, including for zero usage. Python's sparse-entry behavior remains outside this native contract - -The model-info off-peak path supports UTC windows, wrapping windows, and weekday rules with an IANA timezone. The lower-level compiled pricing plan still supports one non-wrapping UTC daily window. The caller supplies the provider-specific threshold policy. Negative or non-finite rates, ambiguous rules, inconsistent cache counts, incomplete write splits, invalid plan windows and overflow return errors. Callers must decline unsupported inputs before native execution if their public contract accepts those shapes - -This crate accepts a caller-supplied catalog and only supports part of Python's model selection and response normalization. It does not fetch provider prices or cover every provider-stated cost shape. The non-token functions accept already selected prices and do not yet match every Python fallback or warning. This crate does not change proxy behavior. The reference fixture was generated by `tests/generate_python_reference.py` against the Python implementation at the commit recorded in `tests/python_reference.tsv`, using synthetic rates and fixed usage. A second differential fixture set lives in `tests/python_fixtures.json`, generated by `tests/generate_python_fixtures.py` by executing the real Python calculators (`generic_cost_per_token`, `get_billed_token_rates`, `get_batch_cost_rates`, `_is_off_peak`, the responses and Anthropic usage transforms, and `calculate_prompt_caching_savings`) over synthetic multi-feature inputs; `tests/python_fixture_replay.rs` replays all rows and fails on any drift diff --git a/litellm-rust/crates/cost/examples/charge.rs b/litellm-rust/crates/cost/examples/charge.rs deleted file mode 100644 index c5088d067a4..00000000000 --- a/litellm-rust/crates/cost/examples/charge.rs +++ /dev/null @@ -1,38 +0,0 @@ -use litellm_cost::{ - Pricing, PromptConvention, Rate, Rates, Request, ServiceTier, ThresholdPolicy, Usage, calculate, -}; - -fn main() { - let pricing = Pricing { - standard: Rates { - input: Rate::Value(0.001), - output: Rate::Value(0.002), - ..Rates::EMPTY - }, - tiers: &[], - thresholds: &[], - off_peak: None, - }; - let request = Request { - usage: Usage { - prompt_tokens: 100, - completion_tokens: 20, - cache_read_tokens: 0, - cache_write_tokens: 0, - cache_write_5m_tokens: None, - cache_write_1h_tokens: None, - prompt_convention: PromptConvention::IncludesCache, - }, - service_tier: ServiceTier::Standard, - threshold_policy: ThresholdPolicy::Exclusive, - region_multiplier: None, - billed_at_utc_minute: None, - }; - let cost = calculate(&pricing, &request).unwrap(); - println!( - "input={} output={} total={}", - cost.input(), - cost.output(), - cost.total() - ); -}