litellm-mirror/tests/litellm/test_cost_calculator.py
Krrish Dholakia 078e2d341b feat(cost_calculator.py): support reading litellm response cost header in client sdk
allows consistent cost tracking when sdk is calling proxy
2025-03-17 15:12:01 -07:00

32 lines
698 B
Python

import json
import os
import sys
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from unittest.mock import MagicMock, patch
from pydantic import BaseModel
from litellm.cost_calculator import response_cost_calculator
def test_cost_calculator():
class MockResponse(BaseModel):
_hidden_params = {"additional_headers": {"x-litellm-response-cost": 1000}}
result = response_cost_calculator(
response_object=MockResponse(),
model="",
custom_llm_provider=None,
call_type="",
optional_params={},
cache_hit=None,
base_model=None,
)
assert result == 1000