Repository navigation
fix: include provider metadata for embedding and rerank - #37896
Closed
Apricooooot wants to merge 2 commits into
Closed
Apricooooot wants to merge 2 commits into
Apricooooot wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Apricooooot
marked this pull request as ready for review
August 22, 2026 06:21
Contributor
Greptile SummaryThe PR propagates the resolved provider into embedding and rerank logging metadata so callbacks can correctly attribute provider spend.
Confidence Score: 5/5The PR appears safe to merge, with the provider metadata changes narrowly scoped and covered by focused tests. The resolved provider is added only to existing logging metadata structures, preserving request dispatch while fixing callback and spend attribution for embedding and rerank calls.
|
| Filename | Overview |
|---|---|
| litellm/main.py | Propagates the provider resolved by get_llm_provider into embedding logging parameters without changing provider dispatch. |
| litellm/rerank_api/main.py | Adds the resolved rerank provider to the metadata passed through logging and downstream callback handling. |
| tests/test_litellm/llms/bedrock/embed/test_embedding.py | Adds a mocked regression test asserting that resolved Bedrock provider metadata is logged. |
| tests/test_litellm/rerank_api/test_main.py | Adds a mocked Cohere rerank regression test asserting that resolved provider metadata is logged. |
Reviews (1): Last reviewed commit: "fix: include provider metadata for embed..." | Re-trigger Greptile
7 tasks done
devin-ai-integration
Bot
changed the base branch from
litellm_internal_staging
to
main
September 23, 2026 14:59
Contributor
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.
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a proxy administrator sees successful embedding and rerank requests, but their Bedrock provider budget silently under-counts spend
POST http://localhost:4000/v1/embeddingswith modeltitan-embed-v2and receives200with an embeddingdataarrayValueError: custom_llm_provider is required, andGET http://localhost:4000/provider/budgetsshows no embedding spend increasePOST http://localhost:4000/v1/rerankwith modelcohere-rerank-v3-5and receives200with a rankedresultsarrayGET http://localhost:4000/provider/budgetsshows no rerank spend increaseAfter: the same successful requests are attributed to Bedrock, so the provider budget includes their spend
200200Relevant issues
Fixes #37877
Linear ticket
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
Reproduced against real Amazon Bedrock on-demand APIs in
us-east-1and a real local Redis instanceModels:
Shared proxy configuration:
The same proxy configuration and requests were used on the parent commit and the PR commit
Before the fix at
bb99f5774eInitial provider budget:
$ curl -sS http://localhost:4000/provider/budgets \ -H "Authorization: Bearer sk-1234" {"providers":{"bedrock":{"budget_limit":5.0,"time_period":"1mo","spend":0.0,"budget_reset_at":"<redacted timestamp>"}}}The real Titan embedding request succeeded:
$ curl -sS http://localhost:4000/v1/embeddings \ -H "Authorization: Bearer sk-1234" \ -H "Content-Type: application/json" \ -d '{"model":"titan-embed-v2","input":["LiteLLM provider budget E2E"]}' | python3 -c 'import json,sys; d=json.load(sys.stdin); print({"object":d.get("object"),"model":d.get("model"),"dimensions":len(d["data"][0]["embedding"]) if d.get("data") else None,"error":d.get("error")})' {'object': 'list', 'model': 'titan-embed-v2', 'dimensions': 1024, 'error': None}Provider spend remained zero:
$ curl -sS http://localhost:4000/provider/budgets \ -H "Authorization: Bearer sk-1234" {"providers":{"bedrock":{"budget_limit":5.0,"time_period":"1mo","spend":0.0,"budget_reset_at":"<redacted timestamp>"}}}The real Cohere rerank request also succeeded:
$ curl -sS http://localhost:4000/v1/rerank \ -H "Authorization: Bearer sk-1234" \ -H "Content-Type: application/json" \ -d '{"model":"cohere-rerank-v3-5","query":"Which document is about Python?","documents":["Python is a programming language.","The Pacific Ocean is the largest ocean."],"top_n":2}' | python3 -c 'import json,sys; d=json.load(sys.stdin); print({"results":d.get("results"),"error":d.get("error")})' {'results': [{'index': 0, 'relevance_score': 0.22250619530677795}, {'index': 1, 'relevance_score': 0.012204752303659916}], 'error': None}Provider spend still remained zero:
$ curl -sS http://localhost:4000/provider/budgets \ -H "Authorization: Bearer sk-1234" {"providers":{"bedrock":{"budget_limit":5.0,"time_period":"1mo","spend":0.0,"budget_reset_at":"<redacted timestamp>"}}}The budget callback raised once for each request:
After the fix at
a09750dcc5The same real Titan embedding request succeeded:
$ curl -sS http://localhost:4000/v1/embeddings \ -H "Authorization: Bearer sk-1234" \ -H "Content-Type: application/json" \ -d '{"model":"titan-embed-v2","input":["LiteLLM provider budget E2E"]}' | python3 -c 'import json,sys; d=json.load(sys.stdin); print({"object":d.get("object"),"model":d.get("model"),"dimensions":len(d["data"][0]["embedding"]) if d.get("data") else None,"error":d.get("error")})' {'object': 'list', 'model': 'titan-embed-v2', 'dimensions': 1024, 'error': None}Its cost was added to the Bedrock provider budget:
$ curl -sS http://localhost:4000/provider/budgets \ -H "Authorization: Bearer sk-1234" {"providers":{"bedrock":{"budget_limit":5.0,"time_period":"1mo","spend":1.8e-07,"budget_reset_at":"<redacted timestamp>"}}}The same real Cohere rerank request succeeded:
$ curl -sS http://localhost:4000/v1/rerank \ -H "Authorization: Bearer sk-1234" \ -H "Content-Type: application/json" \ -d '{"model":"cohere-rerank-v3-5","query":"Which document is about Python?","documents":["Python is a programming language.","The Pacific Ocean is the largest ocean."],"top_n":2}' | python3 -c 'import json,sys; d=json.load(sys.stdin); print({"results":d.get("results"),"error":d.get("error")})' {'results': [{'index': 0, 'relevance_score': 0.22250619530677795}, {'index': 1, 'relevance_score': 0.012204752303659916}], 'error': None}Its
$0.002cost was also added to the Bedrock provider budget:$ curl -sS http://localhost:4000/provider/budgets \ -H "Authorization: Bearer sk-1234" {"providers":{"bedrock":{"budget_limit":5.0,"time_period":"1mo","spend":0.00200018,"budget_reset_at":"<redacted timestamp>"}}}The provider-resolution error no longer appeared:
The command produced no output
The requests succeeded on both revisions; the behavioral difference is that the PR commit records both costs in the Bedrock provider budget instead of dropping them from spend tracking
Type
🐛 Bug Fix
Caveats (if any)
None
Final Attestation