Skip to content

fix(router): resolve custom_llm_provider for embeddings in budget limiter - #30294

Closed
manan-tech wants to merge 2 commits into
BerriAI:mainfrom
manan-tech:fix-router-budget-embedding-provider-resolution
Closed

manan-tech wants to merge 2 commits into
BerriAI:mainfrom
manan-tech:fix-router-budget-embedding-provider-resolution

Conversation

@manan-tech

Copy link
Copy Markdown

Relevant issues

Fixes #30276

Type

Bug Fix

Changes

RouterBudgetLimiting.async_log_success_event resolved the provider only from kwargs["litellm_params"]["custom_llm_provider"]. For embeddings that value is always None: embedding() builds its logged litellm_params from residual **kwargs, and because custom_llm_provider is a named parameter of embedding() it can never appear in **kwargs. With provider_budget_config set, the following raise ValueError("custom_llm_provider is required") fired on every successful embedding and surfaced as a non-blocking LoggingError, so log noise scaled with embedding volume even when no embedding provider had a budget configured. Chat completions were unaffected because completion() passes the resolved provider explicitly

The limiter now resolves the provider from the locations populated for every call type, preferring litellm_params so chat behavior is identical, then falling back to the top-level kwargs["custom_llm_provider"] and the standard logging object. When the provider is genuinely absent the limiter skips provider-budget enforcement instead of raising, so deployment-budget and tag-budget enforcement keep running rather than being aborted by the exception

Keeping the fix in the limiter means it also covers the other non-chat entrypoints that share the same residual-kwargs pattern (transcription, speech) without touching each call site

Screenshots / Proof of Fix

Before, with a provider budget configured, every successful embedding emitted

LiteLLM.LoggingError: [Non-Blocking] Exception occurred while success logging
  File ".../litellm/router_strategy/budget_limiter.py", line 448, in async_log_success_event
    raise ValueError("custom_llm_provider is required")
ValueError: custom_llm_provider is required

After this change the same embedding success event resolves the provider and logs cleanly. The minimal standalone reproduction in the issue (a Router with provider_budget_config set plus a single aembedding call against any OpenAI-compatible embedding endpoint) no longer emits the LoggingError, which is exactly what an operator running a clean-logs gate observes

The behavior is locked in by a regression test at tests/test_litellm/router_strategy/test_budget_limiter.py. It drives an embedding-shaped success event whose litellm_params carry custom_llm_provider as None, then asserts that no error is raised and that the resolved provider's budget is still incremented. It fails on the previous code with the exact issue error and passes with this change

Pre-Submission checklist

  • I have added meaningful tests
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Ran the mocked router_strategy unit suite locally (tests/test_litellm/router_strategy/): 339 passed, 4 skipped; full make test-unit will run in CI
  • I will request a Greptile review by commenting @greptileai and confirm a Confidence Score of at least 4/5 before requesting a maintainer review

…iter

RouterBudgetLimiting.async_log_success_event read the provider only from
litellm_params, which is None for embedding calls (the embedding entrypoint
builds logged params from residual kwargs, so the named custom_llm_provider
never lands there). With provider_budget_config set this raised
'custom_llm_provider is required' on every successful embedding, surfacing as
non-blocking LoggingError noise.

Resolve the provider from the locations populated for all call types
(litellm_params, then top-level kwargs, then the standard logging object) and
skip provider-budget enforcement when it is genuinely absent instead of
raising. Chat behavior is unchanged since litellm_params still takes
precedence. Deployment and tag budgets now keep enforcing even when the
provider is missing.

Fixes BerriAI#30276
@CLAassistant

CLAassistant commented Jun 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@manan-tech

Copy link
Copy Markdown
Author

@greptileai

@greptile-apps

greptile-apps Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a ValueError("custom_llm_provider is required") that fired on every successful embedding when provider_budget_config was set, because embedding() never populates litellm_params["custom_llm_provider"] — it only surfaces the resolved provider in top-level kwargs and the standard logging object. The limiter now walks three sources in priority order and silently skips provider-budget enforcement when all are None, so deployment and tag budgets continue running uninterrupted.

  • budget_limiter.py: replaces the single-source lookup + hard raise with a three-source or-chain (litellm_params → kwargs["custom_llm_provider"] → standard_logging_object), guarded by a conditional so a None provider skips only the provider-budget block.
  • test_budget_limiter.py: new test file covering both the happy path (provider resolved from top-level kwargs, spend incremented) and the silent-skip branch (all sources None, no spend recorded, no exception raised).

Confidence Score: 5/5

The change is safe to merge — it narrows the failure surface without altering any spending or enforcement logic for the paths that were already working.

The fix is minimal and surgical: two changed lines in the production file and a new test-only file. The or-chain is well-ordered (preserving existing chat-completion behaviour), StandardLoggingPayload is a TypedDict so .get() is safe, and skipping provider enforcement when the provider is absent is strictly less disruptive than raising. Deployment and tag budgets execute regardless, so no spend tracking regresses. The tests are fully mocked, cover both the fixed path and the new silent-skip branch, and impose no real network calls.

No files require special attention.

Important Files Changed

Filename Overview
litellm/router_strategy/budget_limiter.py Replaces the hard raise on missing custom_llm_provider with a three-source fallback (litellm_params → top-level kwargs → standard_logging_object), then skips provider-budget enforcement when all sources return None; deployment and tag budgets are unaffected.
tests/test_litellm/router_strategy/test_budget_limiter.py New test file with two async tests: one validates that an embedding-shaped event (litellm_params.custom_llm_provider=None, resolved provider in top-level kwargs) correctly increments provider spend; the other asserts that the fully-unresolved case silently skips without raising or recording spend. All mocked, no real network calls.

Reviews (3): Last reviewed commit: "test(router): cover the provider-budget ..." | Re-trigger Greptile

@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a log-noise regression where every successful embedding call emitted a non-blocking ValueError("custom_llm_provider is required") when a provider_budget_config was configured, because embedding() never populates litellm_params["custom_llm_provider"] the way completion() does.

  • async_log_success_event now resolves the provider via a three-step fallback (litellm_params → top-level kwargs → standard_logging_payload) and silently skips provider-budget enforcement when all sources are None, instead of raising. Chat-completion behavior is unchanged because litellm_params is tried first.
  • A new mock-only regression test constructs an embedding-shaped event with litellm_params.custom_llm_provider=None, confirms no error is raised, and asserts the provider spend is correctly incremented through the fallback path.

Confidence Score: 4/5

The change is a well-scoped, additive fallback with no behaviour change for chat completions; the only new path is the silent skip when all three provider sources are absent.

The core logic is straightforward and the regression test directly validates the broken path. The one gap is that there is no test for the 'all sources absent → silent skip' branch that the PR description explicitly calls out as new behaviour; that branch runs silently in production without a unit-level assertion confirming it. The fix itself is correct and isolated.

The disable_budget_sync monkeypatch in the test patches the class method before instantiation — which is the right ordering — but asyncio.create_task() is called inside __init__, so a brief glance at that interaction is worthwhile in future review passes.

Important Files Changed

Filename Overview
litellm/router_strategy/budget_limiter.py Replaces the hard raise ValueError for a missing provider with a three-step fallback chain (litellm_params → top-level kwargs → standard_logging_payload), then silently skips provider-budget enforcement when all sources are absent; deployment-budget and tag-budget paths are unaffected.
tests/test_litellm/router_strategy/test_budget_limiter.py New regression test that drives an embedding-shaped success event with litellm_params.custom_llm_provider=None, asserts no error is raised, and verifies the provider spend is correctly incremented via the fallback resolution path.

Reviews (2): Last reviewed commit: "fix(router): resolve custom_llm_provider..." | Re-trigger Greptile

@codecov

codecov Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Address review feedback: add a regression test for the new silent-skip path
where no provider can be resolved from litellm_params, the top-level kwargs, or
the standard logging object. Asserts async_log_success_event neither raises nor
records provider spend. Fails if the previous 'custom_llm_provider is required'
raise is reintroduced.
@manan-tech

Copy link
Copy Markdown
Author

Added a regression test for the silent-skip branch flagged in review: when no provider resolves from any of the three sources, async_log_success_event now has explicit coverage asserting it neither raises nor records provider spend (it fails if the old 'custom_llm_provider is required' raise comes back). @greptileai

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Sep 12, 2026
@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:24
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@github-actions github-actions Bot removed the stale label Sep 14, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 16:04
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 16:04
@github-actions

Copy link
Copy Markdown
Contributor

#30276 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_config raises 'custom_llm_provider is required' on every successful embedding call

3 participants