Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8228952
test: derive expected prices from the cost map instead of pinning ven…
kerry-berri Sep 16, 2026
0e8aa60
test: tidy price-derivation cleanup
kerry-berri Sep 16, 2026
df41f67
test: assert cost-map schema instead of tautological rate lookups
kerry-berri Sep 16, 2026
9301aaf
test: add cost map price relationship invariants
kerry-berri Sep 16, 2026
f5940bc
Merge remote-tracking branch 'origin/main' into litellm_remove_brittl…
kerry-berri Sep 17, 2026
ccff1fa
test: derive the remaining cost-map pins from the catalog entry
kerry-berri Sep 17, 2026
c988a50
ci: gate changed tests against a mutated cost map
kerry-berri Sep 17, 2026
6858663
test: share the video cost expectation helper and trim the gate workf…
kerry-berri Sep 17, 2026
26addc5
test: fix remaining cost-map pin and leaked logging event races
kerry-berri Sep 17, 2026
e8f098f
test: hoist the json import to module scope
kerry-berri Sep 17, 2026
eb2be37
test: read cost expectations from the catalog row the code bills against
kerry-berri Sep 17, 2026
9eb6fbc
test: read cost-map keys the implementation resolves and isolate the …
kerry-berri Sep 17, 2026
4be0cf9
test: treat null long-context rates as absent when deriving cache cos…
kerry-berri Sep 17, 2026
b054d54
Merge remote-tracking branch 'origin/litellm_remove_brittle_price_pin…
kerry-berri Sep 17, 2026
0b58281
Merge remote-tracking branch 'origin/litellm_remove_brittle_price_pin…
kerry-berri Sep 17, 2026
9161937
test: restore azure ai cached-token billing coverage with derived rates
kerry-berri Sep 17, 2026
d1b9360
test: drop the cost map independence workflow, keep the gate as a loc…
kerry-berri Sep 17, 2026
68f2c64
test: drop the cost map mutation gate script, its tests and the price…
kerry-berri Sep 18, 2026
c462017
test: delete assertions that pin vendor cost map facts
kerry-berri Sep 18, 2026
84d4d17
Merge remote-tracking branch 'origin/main' into litellm_remove_brittl…
kerry-berri Sep 18, 2026
b97c2d6
test: drop pinned bedrock invoke cost literals
kerry-berri Sep 18, 2026
810df25
test: keep prompt cache prediction logic tests and drop only their pr…
kerry-berri Sep 18, 2026
8504c51
Revert "test: keep prompt cache prediction logic tests and drop only …
kerry-berri Sep 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 0 additions & 190 deletions tests/local_testing/test_completion_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,12 @@ def test_custom_pricing_as_completion_cost_param():
assert round(cost, 5) == round(expected_cost, 5)


def test_get_gpt3_tokens():
max_tokens = get_max_tokens("gpt-3.5-turbo")
print(max_tokens)
assert max_tokens == 4096
# print(results)


# test_get_gpt3_tokens()


def test_get_gemini_tokens():
# # 🦄🦄🦄🦄🦄🦄🦄🦄
max_tokens = get_max_tokens("gemini/gemini-1.5-flash")
assert max_tokens == 8192
print(max_tokens)


# test_get_palm_tokens()


Expand Down Expand Up @@ -273,36 +262,6 @@ def test_cost_azure_gpt_35():
# test_cost_azure_gpt_35()


def test_cost_azure_embedding():
try:
import asyncio

litellm.set_verbose = True

async def _test():
response = await litellm.aembedding(
model="azure/text-embedding-ada-002",
input=["good morning from litellm", "gm"],
)

print(response)

return response

response = asyncio.run(_test())

cost = litellm.completion_cost(completion_response=response)

print("Cost", cost)
expected_cost = float("7e-07")
assert cost == expected_cost

except Exception as e:
pytest.fail(
f"Cost Calc failed for azure/gpt-3.5-turbo. Expected {expected_cost}, Calculated cost {cost}"
)


# test_cost_azure_embedding()


Expand Down Expand Up @@ -639,56 +598,6 @@ def test_vertex_ai_medlm_completion_cost():
assert predictive_cost > 0


def test_vertex_ai_claude_completion_cost():
from litellm import Choices, Message, ModelResponse
from litellm.utils import Usage

os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
litellm.model_cost = litellm.get_model_cost_map(url="")

litellm.set_verbose = True
input_tokens = litellm.token_counter(
model="vertex_ai/claude-3-sonnet@20240229",
messages=[{"role": "user", "content": "Hey, how's it going?"}],
)
print(f"input_tokens: {input_tokens}")
output_tokens = litellm.token_counter(
model="vertex_ai/claude-3-sonnet@20240229",
text="It's all going well",
count_response_tokens=True,
)
print(f"output_tokens: {output_tokens}")
response = ModelResponse(
id="chatcmpl-e41836bb-bb8b-4df2-8e70-8f3e160155ac",
choices=[
Choices(
finish_reason=None,
index=0,
message=Message(
content="It's all going well",
role="assistant",
),
)
],
created=1700775391,
model="claude-3-sonnet",
object="chat.completion",
system_fingerprint=None,
usage=Usage(
prompt_tokens=input_tokens,
completion_tokens=output_tokens,
total_tokens=input_tokens + output_tokens,
),
)
cost = litellm.completion_cost(
model="vertex_ai/claude-3-sonnet",
completion_response=response,
messages=[{"role": "user", "content": "Hey, how's it going?"}],
)
predicted_cost = input_tokens * 0.000003 + 0.000015 * output_tokens
assert cost == predicted_cost


def test_vertex_ai_embedding_completion_cost(caplog):
"""
Relevant issue - https://github.com/BerriAI/litellm/issues/4630
Expand Down Expand Up @@ -1212,105 +1121,6 @@ def test_completion_cost_fireworks_ai(model):
assert cost > 0


def test_cost_azure_openai_prompt_caching():
from litellm.utils import Choices, Message, ModelResponse, Usage
from litellm.types.utils import (
PromptTokensDetailsWrapper,
CompletionTokensDetailsWrapper,
)
from litellm import get_model_info

os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
litellm.model_cost = litellm.get_model_cost_map(url="")

model = "azure/o1-mini"

## LLM API CALL ## (MORE EXPENSIVE)
response_1 = ModelResponse(
id="chatcmpl-3f427194-0840-4d08-b571-56bfe38a5424",
choices=[
Choices(
finish_reason="length",
index=0,
message=Message(
content="Hello! I'm doing well, thank you for",
role="assistant",
tool_calls=None,
function_call=None,
),
)
],
created=1725036547,
model=model,
object="chat.completion",
system_fingerprint=None,
usage=Usage(
completion_tokens=10,
prompt_tokens=14,
total_tokens=24,
completion_tokens_details=CompletionTokensDetailsWrapper(
reasoning_tokens=2
),
),
)

## PROMPT CACHE HIT ## (LESS EXPENSIVE)
response_2 = ModelResponse(
id="chatcmpl-3f427194-0840-4d08-b571-56bfe38a5424",
choices=[
Choices(
finish_reason="length",
index=0,
message=Message(
content="Hello! I'm doing well, thank you for",
role="assistant",
tool_calls=None,
function_call=None,
),
)
],
created=1725036547,
model=model,
object="chat.completion",
system_fingerprint=None,
usage=Usage(
completion_tokens=10,
prompt_tokens=0,
total_tokens=10,
prompt_tokens_details=PromptTokensDetailsWrapper(
cached_tokens=14,
),
completion_tokens_details=CompletionTokensDetailsWrapper(
reasoning_tokens=2
),
),
)

cost_1 = completion_cost(model=model, completion_response=response_1)
cost_2 = completion_cost(model=model, completion_response=response_2)
assert cost_1 > cost_2

model_info = get_model_info(model=model, custom_llm_provider="azure")
usage = response_2.usage

_expected_cost2 = (
(usage.prompt_tokens - usage.prompt_tokens_details.cached_tokens)
* model_info["input_cost_per_token"]
+ (usage.completion_tokens * model_info["output_cost_per_token"])
+ (
usage.prompt_tokens_details.cached_tokens
* model_info["cache_read_input_token_cost"]
)
)

print("_expected_cost2", _expected_cost2)
print("cost_2", cost_2)

assert (
abs(cost_2 - _expected_cost2) < 1e-5
) # Allow for small floating-point differences


def test_completion_cost_vertex_llama3():
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
litellm.model_cost = litellm.get_model_cost_map(url="")
Expand Down
2 changes: 0 additions & 2 deletions tests/test_litellm/batches/test_batch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,8 +1670,6 @@ async def fake_fetch(batch: object, custom_llm_provider: str, litellm_params: di
)

assert (result.usage.prompt_tokens, result.usage.completion_tokens, result.usage.total_tokens) == (1800, 1000, 2800)
# 3e-06 / 1.5e-05 on-demand, halved for batch.
assert result.cost == pytest.approx(1800 * 3e-06 / 2 + 1000 * 1.5e-05 / 2)

# The response model alone cannot price a bedrock batch: this is the $0 bug.
zero_result = await bu._handle_completed_batch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ def test_container_create_response_includes_cost(self, monkeypatch):
in container._hidden_params["additional_headers"]
)

# Verify the cost matches expected value for OpenAI code interpreter (1 session)
# OpenAI charges $0.03 per code interpreter session
expected_cost = StandardBuiltInToolCostTracking.get_cost_for_code_interpreter(
sessions=1, provider="openai"
)
Expand All @@ -387,4 +385,3 @@ def test_container_create_response_includes_cost(self, monkeypatch):
]

assert actual_cost == expected_cost
assert actual_cost == 0.03 # OpenAI code interpreter costs $0.03 per session
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ def test_azure_code_interpreter_zero_sessions(self):
)
assert cost == 0.0, "Should return 0 for zero sessions"

def test_openai_code_interpreter_free(self):
"""Test OpenAI code interpreter cost from model cost map."""
cost = StandardBuiltInToolCostTracking.get_cost_for_code_interpreter(
sessions=5,
provider="openai",
)
assert (
cost == 0.15
), "OpenAI code interpreter should return 0.15 based on current implementation"

@pytest.mark.parametrize(
"input_tokens,output_tokens,expected_cost",
Expand Down Expand Up @@ -222,14 +213,3 @@ def test_none_inputs_return_zero(self):
)
assert StandardBuiltInToolCostTracking.get_cost_for_vector_store(None) == 0.0

def test_constants_loaded_correctly(self):
"""Test that Azure pricing constants are loaded with expected values."""
assert AZURE_FILE_SEARCH_COST_PER_GB_PER_DAY == 0.1

# Code interpreter cost is now in model cost map
azure_container_info = litellm.model_cost.get("azure/container", {})
assert azure_container_info.get("code_interpreter_cost_per_session") == 0.03

assert AZURE_COMPUTER_USE_INPUT_COST_PER_1K_TOKENS == 3.0
assert AZURE_COMPUTER_USE_OUTPUT_COST_PER_1K_TOKENS == 12.0
assert AZURE_VECTOR_STORE_COST_PER_GB_PER_DAY == 0.1
Loading
Loading