Skip to content

fix: include provider metadata for embedding and rerank - #37896

Closed
Apricooooot wants to merge 2 commits into
BerriAI:mainfrom
Apricooooot:bugfix/provider-budget-embedding-rerank
Closed

Apricooooot wants to merge 2 commits into
BerriAI:mainfrom
Apricooooot:bugfix/provider-budget-embedding-rerank

Conversation

@Apricooooot

@Apricooooot Apricooooot commented Aug 21, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Embedding and rerank spend never reaches provider budgets
  • Successful requests emit missing-provider callback errors

How it solves it:

  • Include the resolved provider in embedding logging metadata
  • Include the resolved provider in rerank logging metadata

User Flow

Before: a proxy administrator sees successful embedding and rerank requests, but their Bedrock provider budget silently under-counts spend

  1. The administrator starts the proxy with Bedrock embedding and rerank models plus a monthly Bedrock provider budget
  2. A developer sends POST http://localhost:4000/v1/embeddings with model titan-embed-v2 and receives 200 with an embedding data array
  3. The proxy logs ValueError: custom_llm_provider is required, and GET http://localhost:4000/provider/budgets shows no embedding spend increase
  4. The developer sends POST http://localhost:4000/v1/rerank with model cohere-rerank-v3-5 and receives 200 with a ranked results array
  5. The proxy logs the same error, and GET http://localhost:4000/provider/budgets shows no rerank spend increase

After: the same successful requests are attributed to Bedrock, so the provider budget includes their spend

  1. The administrator starts the proxy with the same Bedrock models and monthly provider budget
  2. The developer sends the same embedding request and receives 200
  3. No missing-provider callback error appears, and the Bedrock provider spend increases
  4. The developer sends the same rerank request and receives 200
  5. No missing-provider callback error appears, and the Bedrock provider spend increases again

Relevant issues

Fixes #37877

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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-1 and a real local Redis instance

Models:

Embedding: bedrock/amazon.titan-embed-text-v2:0
Rerank: bedrock/arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0
Redis: 127.0.0.1:6379

Shared proxy configuration:

model_list:
  - model_name: titan-embed-v2
    litellm_params:
      model: bedrock/amazon.titan-embed-text-v2:0
      aws_region_name: us-east-1
      aws_profile_name: litellm-e2e

  - model_name: cohere-rerank-v3-5
    litellm_params:
      model: bedrock/arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0
      aws_region_name: us-east-1
      aws_profile_name: litellm-e2e

router_settings:
  provider_budget_config:
    bedrock:
      budget_limit: 5
      time_period: 1mo
  redis_host: 127.0.0.1
  redis_port: 6379

general_settings:
  master_key: sk-1234

The same proxy configuration and requests were used on the parent commit and the PR commit

Before the fix at bb99f5774e

Initial 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:

$ grep -n "custom_llm_provider is required" \
    /tmp/provider-budget-before.log |
  tail -n 10
445:    raise ValueError("custom_llm_provider is required")
446:ValueError: custom_llm_provider is required
618:    raise ValueError("custom_llm_provider is required")
619:ValueError: custom_llm_provider is required

After the fix at a09750dcc5

The 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.002 cost 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:

$ grep -n "custom_llm_provider is required" \
    /tmp/provider-budget-after.log |
  tail -n 10

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

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing Apricooooot:bugfix/provider-budget-embedding-rerank (7e432ce) with litellm_internal_staging (a9c7b84)

Open in CodSpeed

@Apricooooot
Apricooooot marked this pull request as ready for review August 22, 2026 06:21
@greptile-apps

greptile-apps Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR propagates the resolved provider into embedding and rerank logging metadata so callbacks can correctly attribute provider spend.

  • Passes the resolved embedding provider through get_litellm_params.
  • Adds the resolved rerank provider to callback logging parameters.
  • Adds focused regression tests for Bedrock embedding and Cohere rerank metadata.

Confidence Score: 5/5

The 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.

Important Files Changed

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

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:44
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:59
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 14:59
@github-actions

Copy link
Copy Markdown
Contributor

#37877 was fixed by #38172 on main, so this pull request is closed. Reopen it if something was missed.

@github-actions github-actions Bot closed this Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: provider budget never counts embedding or rerank spend — RouterBudgetLimiting raises "custom_llm_provider is required"

2 participants