Repository navigation
test(integration): embeddings, rerank, completions and moderations cost cases - #42020
Conversation
…st cases 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>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
|
…ase bills nothing Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Pushed 23f5df0 tightening the zero cost header assertion per Greptile. No findings rebutted, CI on the new head is pending. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 23f5df0. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…sions' into litellm_cost_shard_embeddings_rerank Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # tests/integration/contracts.json # tests/integration/cost_calculation/cost_tracking_case.py # tests/integration/cost_calculation/cost_tracking_cases.json
…shard_embeddings_rerank
TLDR
Problem this solves:
How it solves it:
x-litellm-response-cost(moderations)User Flow
Before: a proxy admin has no shard proving what embeddings, rerank, legacy completions or moderations cost
usage.prompt_tokens: 21backmeta.billed_units.search_units: 3backtests/integration/run.py costonly covers chat, responses and messagesAfter: each of those calls has a scripted case with the exact spend, header and row pinned
tests/integration/run.py cost/v1/embeddings,/v1/rerank,/v1/completionsor/v1/moderations, receives a literal provider body, and asserts the response cost header, the persisted spend row and its token countsRelevant issues
Builds on #41999 (harness fields this data needs). Diff shows both until that one lands, then this rebases to main
Affected release
Linear ticket
Resolves LIT-8192
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Test data only, the proxy code path is unchanged. Proof is the shard against the scripted upstream that the shard itself starts (no provider spend by design)
Before (9bd648b)
tests/integration/run.py cost -k "embeddings or rerank or completions or moderations"selects nothingAfter (8137d87)
tests/integration/run.py cost -k "embeddings or rerank or completions or moderations"against a fresh proxy and empty Redis:22 passed, 366 deselected in 36.83smake lintpassesType
✅ Test
Caveats (if any)
Three things the run surfaced, pinned as current behaviour rather than fixed here. Gemini embeddings ignore the body's
usageMetadata.promptTokenCountand recount the input locally (the case sends 7 in the body and is billed for 3). Bedrock Cohere embeddings carry no token count on the wire, so that row is also a local recount. Rerank rows persist 0 prompt and 0 completion tokens even though the cost calculator sets completion tokens to the search unitsTwo cases were dropped: Together rerank has no per query rate path and always bills 0, and Azure
/v1/completionsagainst a well formed OpenAI completions body fails inside the proxy's response conversion ('NoneType' object has no attribute 'get'), which looks like a real bug worth its own ticketLink to Devin session: https://app.devin.ai/sessions/5425681f498543a19de84adcf8daeed8
Open in Devin Desktop: https://app.devin.ai/desktop/session/5425681f498543a19de84adcf8daeed8?variant=devin
Note
Low Risk
Test and fixture data only; no production billing or proxy logic changes in this diff.
Overview
Expands the cost integration shard with 22 scripted cases that assert spend,
x-litellm-response-cost, and ledger rows for/v1/embeddings,/v1/rerank,/v1/completions, and/v1/moderations—covering OpenAI/Azure embeddings, Cohere/Bedrock rerank (including per-query pricing), legacy text completions (including streaming), Together completions/embeddings, Vertex/Gemini/Fireworks embedding wires, and zero-spend moderations.The harness gains cost-map fields (
input_cost_per_query, etc.), provider routing forcohere,bedrock,text-completion-openai, andvertex_ai-embedding-models, broader OpenAI model-prefix rules for embedding/moderation endpoints, and Vertex credentials for anyvertex_ai*provider.test_cost_trackingnow treats a missing cost header as OK when expected spend is 0.contracts.jsonregisters the new parametrized tests underquota_management.spend_tracking.cost_matrix.logs_cost.Reviewed by Cursor Bugbot for commit 23f5df0. Bugbot is set up for automated code reviews on this repo. Configure here.