Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
|
Closing as superseded: #40189 landed the same model-router flat-fee guard in completion_cost, proven live with the fee charged once. Thanks for the contribution! |
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 developer routing through Azure AI Foundry Model Router sees double the expected spend
azure-model-router)cost_per_tokenfolds the flat $0.14 per million input-token fee into prompt cost, andcompletion_costthen adds the same fee again through its additional_costs hookAfter: the same request is billed the flat fee once
Relevant issues
Type
🐛 Bug Fix
Changes
completion_costcomputes token cost viaazure_aicost_per_token, which already folds the Model Router flat fee into prompt cost whenever it detects the router from the responsemodelor therequest_model(is_router_request). Right after, forcustom_llm_provider == "azure_ai",completion_costseparately computed the same flat fee through_get_additional_costsand summed it into the total, so any request where the token path detected the router was charged the fee twice. This guards the additional_costs branch: when_is_azure_model_router(model)or_is_azure_model_router(request_model_for_cost)is true, the token path already billed the fee, so additional_costs is left unset. The hidden-params-only path (response carries the underlying model, router known only from_hidden_params) is unchanged and still bills the fee once through additional_costs.Screenshots / Proof of Fix
For a pure
azure-model-routerresponse with 5000 prompt tokens,completion_costnow returns a single flat fee (5000 * rate / 1e6) instead of twice that. Regression testtests/test_litellm/llms/azure_ai/test_azure_ai_cost_calculator.py::TestAzureModelRouterCostBreakdown::test_additional_costs_in_cost_breakdownasserts the single-fee total; it fails on the pre-fix code (double) and passes after. All 32 tests in that file pass.Final Attestation