fix(router): propagate custom cost_per_token from db model_info in fallback path - #25888
Conversation
…llback path Signed-off-by: Zerohertz <ohg3417@gmail.com>
…allback path Signed-off-by: Zerohertz <ohg3417@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryFixes a bug in Confidence Score: 5/5Safe to merge — the fix is minimal, backward-compatible, and well-tested. The production change is two lines that mirror an existing pattern ( No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/router.py | Reads input_cost_per_token and output_cost_per_token from db_model_info in the model_info is None fallback branch — consistent with the existing mode extraction pattern; no logic concerns. |
| tests/test_litellm/test_router.py | Adds two unit tests covering the new fallback cost propagation; tests are mock-only (no real network calls). Minor: from unittest.mock import patch is imported inline inside both new test functions, but patch is already at module level on line 5. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[get_model_group_info] --> B{model_id present?}
B -- yes --> C[get_deployment_model_info]
C -- success --> D[model_info from LiteLLM map]
C -- exception --> E[model_info = None fallback]
B -- no --> E
E --> F[db_model_info = model.get model_info]
F --> G[Extract mode]
F --> H[Extract input cost per token - NEW]
F --> I[Extract output cost per token - NEW]
G --> J[Build ModelMapInfo fallback]
H --> J
I --> J
D --> K[Use model_info directly]
J --> L[Build ModelGroupInfo]
K --> L
Reviews (1): Last reviewed commit: "test(router): propagate custom cost_per_..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
custom cost_per_token from db model_info in fallback path
|
There are over 300 Linting CI issues.
|
5b3762f
into
BerriAI:litellm_oss_branch
Relevant issues
Fixes #25874
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Unit tests — 2 new tests added and passing:
test_model_group_info_cost_from_db_model_info— verifiesinput_cost_per_token/output_cost_per_tokenare read fromdb_model_infowhenget_deployment_model_infofailstest_model_group_info_cost_none_when_db_model_info_has_no_cost— verifies values remainNonewhendb_model_infohas no cost fieldsType
🐛 Bug Fix
Changes
When a model is not found in LiteLLM's built-in model cost map (
model_info is Noneinget_model_group_info()), the fallbackModelMapInfowas hardcodinginput_cost_per_tokenandoutput_cost_per_tokentoNone, ignoring any custom cost values the user had configured in the database'smodel_info.This fix reads
input_cost_per_tokenandoutput_cost_per_tokenfromdb_model_info(the user's database/config model_info), consistent with howmodeis already read from the same source. If the keys are not present,.get()returnsNone, preserving backward compatibility.Before
After