mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(proxy): read alias budget metadata from litellm_metadata routes
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
e87b51d5b5
commit
300768a943
2 changed files with 36 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ import litellm
|
|||
from litellm._logging import verbose_proxy_logger
|
||||
from litellm.caching.caching import DualCache
|
||||
from litellm.integrations.custom_logger import Span
|
||||
from litellm.litellm_core_utils.core_helpers import get_litellm_metadata_from_kwargs
|
||||
from litellm.litellm_core_utils.duration_parser import duration_in_seconds
|
||||
from litellm.llms.bedrock.common_utils import get_bedrock_base_model
|
||||
from litellm.proxy._types import Litellm_EntityType, UserAPIKeyAuth
|
||||
|
|
@ -465,7 +466,7 @@ class _PROXY_VirtualKeyModelMaxBudgetLimiter(RouterBudgetLimiting):
|
|||
return
|
||||
|
||||
_litellm_params: Final[dict] = kwargs.get("litellm_params", {}) or {}
|
||||
_metadata: Final[dict] = _litellm_params.get("metadata", {}) or {}
|
||||
_metadata: Final[dict] = get_litellm_metadata_from_kwargs(kwargs) or {}
|
||||
payload_metadata: Final = standard_logging_payload.get("metadata") or {}
|
||||
|
||||
model: Final = standard_logging_payload.get("model_group") or standard_logging_payload.get("model")
|
||||
|
|
|
|||
|
|
@ -271,6 +271,40 @@ async def test_async_log_success_event_uses_requested_model_budget():
|
|||
assert cache.in_memory_cache.cache_dict["virtual_key_spend:hash-1:claude-haiku-4-5:1h"] == 5.5e-05
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_log_success_event_reads_requested_model_from_litellm_metadata():
|
||||
cache = DualCache()
|
||||
handler = _PROXY_VirtualKeyModelMaxBudgetLimiter(dual_cache=cache)
|
||||
|
||||
await handler.async_log_success_event(
|
||||
kwargs={
|
||||
"standard_logging_object": {
|
||||
"model_group": "claude-haiku-4-5-20251001",
|
||||
"model": "anthropic/claude-haiku-4-5-20251001",
|
||||
"response_cost": 5.5e-05,
|
||||
"metadata": {"user_api_key_hash": "hash-1"},
|
||||
},
|
||||
"litellm_params": {
|
||||
"metadata": {"trace": "x"},
|
||||
"litellm_metadata": {
|
||||
"user_api_key_model_max_budget": {
|
||||
"claude-haiku-4-5": {
|
||||
"budget_limit": 1e-4,
|
||||
"time_period": "1h",
|
||||
}
|
||||
},
|
||||
"litellm_client_requested_model": "claude-haiku-4-5",
|
||||
},
|
||||
},
|
||||
},
|
||||
response_obj=None,
|
||||
start_time=0,
|
||||
end_time=0,
|
||||
)
|
||||
|
||||
assert cache.in_memory_cache.cache_dict["virtual_key_spend:hash-1:claude-haiku-4-5:1h"] == 5.5e-05
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_fallback_model_within_budget_uses_alias_budget_fallbacks():
|
||||
handler = _PROXY_VirtualKeyModelMaxBudgetLimiter(dual_cache=DualCache())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue