litellm/tests/unit/proxy/spend_tracking
kenneth-berri a3df6bbb86
Some checks are pending
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
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 (type-discipline, litellm/scripts/type_discipline_gate.py) (push) Waiting to run
CodSpeed Benchmarks / benchmarks (push) Waiting to run
Publish lint base counts / publish (test-quality, litellm/scripts/test_quality_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 passed (push) Blocked by required conditions
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
Terraform Provider / gofmt, vet, build, test (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
smoke / smoke-rust-bridge (push) Waiting to run
smoke / core-checks (push) Blocked by required conditions
smoke / py3.14 (push) Blocked by required conditions
smoke / py3.15 (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
LiteLLM Rust DB / db-queries (push) Waiting to run
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Waiting to run
unit / OpenAI SDK 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 / 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 / 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-utils-1 (push) Blocked by required conditions
unit / core-utils-2 (push) Blocked by required conditions
unit / integrations-1 (push) Blocked by required conditions
unit / integrations-2 (push) Blocked by required conditions
unit / llms-providers-1 (push) Blocked by required conditions
unit / llms-providers-2 (push) Blocked by required conditions
unit / router-2 (push) Blocked by required conditions
unit / ui-unit (typecheck) (push) Blocked by required conditions
unit / ui-unit (vitest-1) (push) Blocked by required conditions
unit / ui-unit (vitest-2) (push) Blocked by required conditions
unit / ui-unit (vitest-3) (push) Blocked by required conditions
unit / dashboard-build (push) Blocked by required conditions
unit / caching-local (push) Blocked by required conditions
unit / endpoints (push) Blocked by required conditions
unit / enterprise-package (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 / mcp-server (push) Blocked by required conditions
unit / proxy-auth (push) Blocked by required conditions
unit / proxy-extras (push) Blocked by required conditions
unit / proxy-hooks-client (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 / proxy-subprocess (push) Blocked by required conditions
unit / redis-py 8.0.1 compatibility (push) Blocked by required conditions
unit / unit passed (push) Blocked by required conditions
VS Code Extension / vscode-extension (push) Waiting to run
unit / llms-anthropic (push) Blocked by required conditions
unit / proxy-endpoints-1 (push) Blocked by required conditions
unit / proxy-endpoints-2 (push) Blocked by required conditions
unit / proxy-feature-endpoints-1 (push) Blocked by required conditions
unit / proxy-feature-endpoints-2 (push) Blocked by required conditions
unit / proxy-infra-db-spend (push) Blocked by required conditions
unit / proxy-infra-routing (push) Blocked by required conditions
unit / router-1 (push) Blocked by required conditions
unit / router-3 (push) Blocked by required conditions
unit / router-4 (push) Blocked by required conditions
unit / enterprise-routing-1 (push) Blocked by required conditions
unit / enterprise-routing-2 (push) Blocked by required conditions
unit / proxy-utils (push) Blocked by required conditions
unit / root-1 (push) Blocked by required conditions
unit / root-2 (push) Blocked by required conditions
unit / python-310 (push) Blocked by required conditions
unit / lint-runtime (push) Blocked by required conditions
unit / ui-unit (type-tests) (push) Blocked by required conditions
unit / ui-unit (vitest-4) (push) Blocked by required conditions
unit / helm (push) Blocked by required conditions
unit / rust-bridge (push) Waiting to run
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 / responses-caching-types (push) Blocked by required conditions
unit / rust-bridge-harness (push) Blocked by required conditions
unit / redis-py 7.4.1 compatibility (push) Blocked by required conditions
GitHub Actions Security Analysis / zizmor (push) Waiting to run
feat(spend): provider cost reconciliation for OpenAI, Bedrock, Azure and Vertex AI (#55259)
* feat(spend): capture rate upper bound, settle days, configurable OpenAI admin base and a dashboard page

The spend capture-rate check only alerted when LiteLLM tracked less than the provider billed, always ended its window at yesterday, and read the OpenAI bill from a fixed URL. This adds an optional upper_threshold so a rate above the bill also alerts, settle_days to leave out recent days while a bill settles, OPENAI_ADMIN_API_BASE for OpenAI environments with their own API base, and an admin-only Cost Reconciliation page in the dashboard that calls GET /spend/capture_rate.

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

* fix(ui): register the cost reconciliation legacy route, label the gap by direction, shorten the bill request error

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

* feat(spend): read the Bedrock bill from AWS Cost Explorer for the capture-rate check

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

* feat(ui): pick the provider on the cost reconciliation page

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

* feat(spend): read the Azure bill from Cost Management for the capture-rate check

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

* fix(spend): type the capture-rate settings read and clear the Bedrock gauge in the startup test

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

* refactor(spend): share one billing HTTP client across provider readers

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

* fix(spend): parse the Azure UsageDate without a naive datetime

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

* refactor(spend): flatten the per-scope Azure rows with chain

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

* feat(ui): show every provider on the cost reconciliation page with daily charts

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

* feat(ui): move cost reconciliation into Usage as Provider Cost Reconciliation

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

* feat(ui): show provider cost reconciliation as a Usage tab next to Errors

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

* fix(ui): let the Usage tab strip wrap on narrow windows

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

* style(ui): format UsagePageView

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

* fix(spend): treat a Cost Explorer day without UnblendedCost as an unreadable bill

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

* fix(spend): sign Cost Explorer for the endpoint's region and treat billing timeouts as an unreadable bill

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

* fix(spend): refuse overlapping Azure scopes, read 204 as no charges, and render the real chart in the page test

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

* fix(ui): show a matched bill as no difference instead of billed more

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

* feat(spend): reconcile Vertex AI spend against the Cloud Billing BigQuery export

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

* fix(spend): report a BigQuery job error as an unreadable Vertex AI bill

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

* test(spend): cover vertex_ai in the capture rate endpoint and scheduled job tests

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

* fix(spend): compare the Vertex AI bill net of credits

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

* feat(spend): default the capture rate settle delay to 3 days

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

* test(spend): pin the settle delay in the vertex_ai capture rate test

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

* test(spend): type the Vertex AI billing export test helper

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

* feat(ui): mark the provider cost reconciliation tab as beta

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

* feat(spend): store the provider bills the scheduled capture-rate check reads

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

* fix(otel): name the provider billed-spend table as a Prisma span relation

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

* feat(spend): default the capture rate upper threshold to 1.1

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

* feat(spend): reconcile Bedrock spend against AWS Cost Explorer (#55271)

* feat(spend): read the Bedrock bill from AWS Cost Explorer for the capture-rate check

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

* feat(ui): pick the provider on the cost reconciliation page

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

* fix(spend): type the capture-rate settings read and clear the Bedrock gauge in the startup test

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

* refactor(spend): share one billing HTTP client across provider readers

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

* fix(spend): treat a Cost Explorer day without UnblendedCost as an unreadable bill

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

* fix(spend): sign Cost Explorer for the endpoint's region and treat billing timeouts as an unreadable bill

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

---------

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

* test(ui): drop setup comment in reconciliation test

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

* fix(spend): reuse a stored bill only for the billing filters it was read with

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

* fix(spend): read an Azure bill longer than a month in monthly windows

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

* fix(spend): stop a Vertex AI billing query BigQuery has not finished in time

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

* refactor(spend): read Azure windows with one comprehension clause

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

* refactor(spend): bind the stored bill's filters once and type the new test

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

* test(spend): type the Vertex AI billing export tests

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

* test(spend): type and bind the stored bill tests; drop the schema comment

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

* fix(spend): read only the unstored runs of days and match stored bills on endpoint and configured projects

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

* fix(spend): stop reading the provider after a failed span; document the configured project fallback

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

* style(ui): drop comments that restate the reconciliation helpers

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

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-12-01 17:17:51 -08:00
..
native_budgets_golden fix(proxy): size the budget hold for Gemini native generateContent bodies (#53412) 2026-11-22 23:03:18 +00:00
__init__.py
native_budgets_replica.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
test_ai_tool_budget.py feat(proxy): add per AI tool limits for teams and members (#55520) 2026-12-01 22:08:26 +00:00
test_background_interaction_settlement.py fix(interactions): keep background interaction bills through crashes, late restarts, and deployment keys (#45743) 2026-10-16 12:00:08 +00:00
test_baseline_accounting.py fix(router): preserve native baseline identity and accounting (#44960) 2026-10-07 11:00:31 -07:00
test_budget_reservation.py feat(cost): price Claude token calls, budget holds and auth price checks in Rust (#52484) 2026-11-23 22:00:28 +00:00
test_budget_reservation_redis_failure.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
test_budget_reservation_redis_failure_ledger.py feat(budgets): run the ledger's post-call spend counter step in rust (#52166) 2026-11-20 16:31:03 -08:00
test_budget_reservation_rust.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_budget_reservation_rust_ledger.py feat(budgets): run the ledger's post-call spend counter step in rust (#52166) 2026-11-20 16:31:03 -08:00
test_carried_budget_state.py fix(proxy): show committed spend in the remaining budget gauges (#49199) 2026-11-09 20:05:37 +00:00
test_cloudzero_endpoints.py
test_committed_spend.py fix(proxy): show committed spend in the remaining budget gauges (#49199) 2026-11-09 20:05:37 +00:00
test_compression_savings.py
test_cost_finalization.py feat(proxy): add a surcharge on customer requests (#52406) 2026-11-19 00:45:10 +08:00
test_customer_budget_alerts.py feat(proxy): add app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08:00
test_customer_cost_margin.py feat(cost): price Claude token calls, budget holds and auth price checks in Rust (#52484) 2026-11-23 22:00:28 +00:00
test_customer_window_accounting.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_customer_window_accounting_rust.py feat(budgets): replace the python budget hold and settle engine with a rust engine admitted at auth (#51535) 2026-11-15 16:03:51 -08:00
test_input_tokens.py fix(proxy): size the budget hold for Gemini native generateContent bodies (#53412) 2026-11-22 23:03:18 +00:00
test_key_metadata_recovery.py fix: cap cold MCP schema workers at usable CPUs and deflake wall-clock unit tests (#45791) 2026-10-15 00:47:59 -07:00
test_native_budget_checks.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_native_budgets.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_native_budgets_ledger.py feat(budgets): run the ledger's post-call spend counter step in rust (#52166) 2026-11-20 16:31:03 -08:00
test_native_budgets_proxy_path.py test(budgets): isolate Gemini golden pricing from catalog changes (#55544) 2026-12-01 11:35:17 -08:00
test_native_budgets_proxy_path_ledger.py feat(budgets): run the ledger's post-call spend counter step in rust (#52166) 2026-11-20 16:31:03 -08:00
test_native_spend_log_row_type.py refactor(rust): rename spend log crates to spend-log-row and callbacks-spend-log (#55178) 2026-11-30 17:54:13 +00:00
test_performance_alerts.py feat(alerts): detect daily changes in recorded usage (#50666) 2026-11-11 18:23:02 -08:00
test_ptu_feature_flag.py feat(proxy): split Azure PTU deployments across teams with per-team PTU ceilings and PTU-hour reporting (#43043) 2026-10-15 18:44:30 +00:00
test_ptu_flat_cost_rollup.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_rust_spend_counters.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_savings.py fix(spend): keep a NaN or infinite cost from wedging daily spend writes (#48829) 2026-10-30 08:27:35 -07:00
test_search_api_logging.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_session_page.py fix(spend): read only the newest rows when paging sessions (LIT-8513) (#48886) 2026-11-03 10:51:09 -08:00
test_session_spend_total.py feat(auto_router): report a session's whole spend and name why savings stay unestimated (#51066) 2026-11-10 17:07:11 -08:00
test_spend_capture_rate.py feat(spend): provider cost reconciliation for OpenAI, Bedrock, Azure and Vertex AI (#55259) 2026-12-01 17:17:51 -08:00
test_spend_counter_batch.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
test_spend_counter_batch_ledger.py fix(proxy): write a cold spend counter's cached spend once (#52806) 2026-11-24 13:00:34 -08:00
test_spend_event.py feat(proxy): add per AI tool limits for teams and members (#55520) 2026-12-01 22:08:26 +00:00
test_spend_event_producer.py test(unit): keep unix socket paths in unit tests under the macOS AF_UNIX limit (#45040) 2026-10-28 20:23:22 -07:00
test_spend_log_error_logger.py
test_spend_logs_ledger_setting.py feat(spend-logs): rust spend log callback (#52182) 2026-11-20 16:31:04 -08:00
test_spend_management_endpoints.py feat(spend): provider cost reconciliation for OpenAI, Bedrock, Azure and Vertex AI (#55259) 2026-12-01 17:17:51 -08:00
test_spend_query_optimization.py fix(spend logs): sort session-grouped logs by the session total the Cost cell shows (#55232) 2026-11-30 17:11:41 -08:00
test_spend_tracking_utils.py fix(spend): write legacy spend rows when metadata is excluded from the logging payload (#55496) 2026-12-01 15:56:20 -08:00
test_subscription_billing_periods.py feat(usage): show subscription-covered providers and account fees separately (#44772) 2026-10-30 03:58:36 -07:00