Repository navigation
fix(router): resolve custom_llm_provider for embeddings in budget limiter - #30294
manan-tech wants to merge 2 commits into
Conversation
…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
Greptile SummaryFixes a
Confidence Score: 5/5The 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.
|
| 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 SummaryFixes a log-noise regression where every successful embedding call emitted a non-blocking
Confidence Score: 4/5The 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
|
| 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 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.
|
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 |
|
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. |
Relevant issues
Fixes #30276
Type
Bug Fix
Changes
RouterBudgetLimiting.async_log_success_eventresolved the provider only fromkwargs["litellm_params"]["custom_llm_provider"]. For embeddings that value is alwaysNone:embedding()builds its loggedlitellm_paramsfrom residual**kwargs, and becausecustom_llm_provideris a named parameter ofembedding()it can never appear in**kwargs. Withprovider_budget_configset, the followingraise ValueError("custom_llm_provider is required")fired on every successful embedding and surfaced as a non-blockingLoggingError, so log noise scaled with embedding volume even when no embedding provider had a budget configured. Chat completions were unaffected becausecompletion()passes the resolved provider explicitlyThe limiter now resolves the provider from the locations populated for every call type, preferring
litellm_paramsso chat behavior is identical, then falling back to the top-levelkwargs["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 exceptionKeeping 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
After this change the same embedding success event resolves the provider and logs cleanly. The minimal standalone reproduction in the issue (a
Routerwithprovider_budget_configset plus a singleaembeddingcall against any OpenAI-compatible embedding endpoint) no longer emits theLoggingError, which is exactly what an operator running a clean-logs gate observesThe 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 whoselitellm_paramscarrycustom_llm_providerasNone, 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 changePre-Submission checklist
router_strategyunit suite locally (tests/test_litellm/router_strategy/): 339 passed, 4 skipped; fullmake test-unitwill run in CI@greptileaiand confirm a Confidence Score of at least 4/5 before requesting a maintainer review