Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
GET {base}/key/inforeturns 401, 403 or 404, LiteLLM now falls back to a self-scoped UTC month-to-date spend report instead of failing. It requestsGET {base}/key/spend/report?start_date=YYYY-MM-01&end_date=YYYY-MM-DD, and on 401/403/404 againGET {base}/user/spend/reportwith the same query. Noapi_keyorinternal_user_idparameters are sent.The body must be a non-empty array of rows with a finite
total_cost >= 0. Each row is summed once andmodel_detailsis ignored. Empty,{},null, non-JSON,[null],[{}], string, negative,1e309and overflowing-sum bodies are parse errors. The result isCostSnapshotUSDused = sum, no limit, periodKey spend only (<start>–<end> UTC)orUser spend only (…)(en dash), plus an informational primary window carrying the same label (UsageSnapshotrequires a primary lane; same pattern as ai&). It has no identity, no reset date and no budget percentage. Zero spend is valid.Transport errors, 429, 5xx and 400 do not switch scope. A 401/403 on the final report maps to
AuthRequired, and 404 or any other status maps to an error naming only the status. Report bodies are never echoed, and serde messages are not surfaced. The report body read is bounded to 4 MiB."Now" is injected (
fetch_key_usage(.., now)) so the date and UTC month-boundary cases are testable.One incidental fix:
management_urlusedUrl::join, which dropped a configured path prefix (https://h/proxy/v1/produced/key/infoinstead of/proxy/key/info). It now appends the endpoint to the (/v1-stripped) prefix. That is required for the tagged paths/proxy/key/info,/proxy/key/spend/reportand/proxy/user/spend/report.Upstream reference
edb71a2c1/ fix(litellm): fall back to self-scoped spend reports steipete/CodexBar#3853).Sources/CodexBarCore/Resources/Plugins/litellm.ts(request(..., allowUnavailable),keyRoot === undefinedbranch),Sources/CodexBarCore/Providers/LiteLLM/LiteLLMProviderDescriptor.swift(costPresenter),docs/litellm.md("Spend-only deployments"),Tests/CodexBarTests/LiteLLMSpendReportTests.swift.https://proxy.example.com/proxy/v1/, 2026-09-01 to 2026-09-21, UTC boundary at2027-01-01T00:00:01Z), usingmockito(already a dev-dependency).Ported / Deferred
Ported: everything in the scope above.
Not part of this item (predates 0.65.0): the tagged plugin's
user/infoandteam/infofollow-ups,user_id/team_idvalidation, the https-or-private-http endpoint policy, and preserving a?querysuffix on the base URL (the local code drops it, as before).No UI code was changed. The cost has no limit and the label lives in the cost period and the informational primary window, following the existing ai& pattern. I did not add a card-render test.
Validation
Run on the pinned toolchain (
cargo +1.98.0) with a process-localCARGO_TARGET_DIR:cargo +1.98.0 fmt --all -- --check: cleancargo +1.98.0 clippy --workspace --all-targets -- -D warnings: passcargo +1.98.0 test -p codexbar litellm: 14 passed, 0 failed (11 new, 3 existing)Affected areas
rust/src/providers/litellm)UI proof
Not applicable.