0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
168 lines
6.6 KiB
Python
168 lines
6.6 KiB
Python
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
|
|
from headroom.pricing import litellm_pricing
|
|
|
|
|
|
def test_litellm_helpers_when_dependency_is_unavailable(monkeypatch) -> None:
|
|
monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", False)
|
|
monkeypatch.setattr(litellm_pricing, "litellm", None)
|
|
|
|
assert litellm_pricing.get_litellm_model_cost() == {}
|
|
assert litellm_pricing.get_model_pricing("gpt-4o") is None
|
|
assert litellm_pricing.estimate_cost("gpt-4o", input_tokens=1, output_tokens=1) is None
|
|
assert litellm_pricing.list_available_models() == []
|
|
|
|
|
|
def test_litellm_model_pricing_exact_match_and_defaults(monkeypatch) -> None:
|
|
fake_litellm = SimpleNamespace(
|
|
model_cost={
|
|
"gpt-4o": {
|
|
"input_cost_per_token": 0.0000025,
|
|
"output_cost_per_token": 0.00001,
|
|
"max_tokens": 128000,
|
|
}
|
|
}
|
|
)
|
|
monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
|
|
monkeypatch.setattr(litellm_pricing, "litellm", fake_litellm)
|
|
|
|
assert litellm_pricing.get_litellm_model_cost() == fake_litellm.model_cost
|
|
pricing = litellm_pricing.get_model_pricing("gpt-4o")
|
|
assert pricing is not None
|
|
assert pricing.model == "gpt-4o"
|
|
assert pricing.input_cost_per_1m == 2.5
|
|
assert pricing.output_cost_per_1m == 10.0
|
|
assert pricing.max_tokens == 128000
|
|
assert pricing.max_input_tokens is None
|
|
assert pricing.max_output_tokens is None
|
|
assert pricing.supports_vision is False
|
|
assert pricing.supports_function_calling is False
|
|
assert (
|
|
litellm_pricing.estimate_cost("gpt-4o", input_tokens=200_000, output_tokens=300_000) == 3.5
|
|
)
|
|
assert litellm_pricing.list_available_models() == ["gpt-4o"]
|
|
|
|
|
|
def test_litellm_model_pricing_uses_provider_prefixes(monkeypatch) -> None:
|
|
fake_litellm = SimpleNamespace(
|
|
model_cost={
|
|
"openai/gpt-4o-mini": {
|
|
"input_cost_per_token": 0.00000015,
|
|
"output_cost_per_token": 0.0000006,
|
|
"supports_vision": True,
|
|
"supports_function_calling": True,
|
|
"max_input_tokens": 64000,
|
|
"max_output_tokens": 16000,
|
|
}
|
|
}
|
|
)
|
|
monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
|
|
monkeypatch.setattr(litellm_pricing, "litellm", fake_litellm)
|
|
|
|
pricing = litellm_pricing.get_model_pricing("gpt-4o-mini")
|
|
assert pricing is not None
|
|
assert pricing.input_cost_per_1m == 0.15
|
|
assert pricing.output_cost_per_1m == 0.6
|
|
assert pricing.max_input_tokens == 64000
|
|
assert pricing.max_output_tokens == 16000
|
|
assert pricing.supports_vision is True
|
|
assert pricing.supports_function_calling is True
|
|
|
|
|
|
def test_litellm_model_pricing_uses_aliases_and_zero_cost_defaults(monkeypatch) -> None:
|
|
fake_litellm = SimpleNamespace(
|
|
model_cost={
|
|
"claude-sonnet-4-20250514": {
|
|
"input_cost_per_token": None,
|
|
"output_cost_per_token": None,
|
|
}
|
|
}
|
|
)
|
|
monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
|
|
monkeypatch.setattr(litellm_pricing, "litellm", fake_litellm)
|
|
|
|
pricing = litellm_pricing.get_model_pricing("claude-3-5-sonnet-20241022")
|
|
assert pricing is not None
|
|
assert pricing.model == "claude-3-5-sonnet-20241022"
|
|
assert pricing.input_cost_per_1m == 0
|
|
assert pricing.output_cost_per_1m == 0
|
|
assert litellm_pricing.estimate_cost("claude-3-5-sonnet-20241022", input_tokens=1) == 0
|
|
|
|
|
|
def test_litellm_model_pricing_returns_none_for_unknown_models(monkeypatch) -> None:
|
|
monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
|
|
monkeypatch.setattr(litellm_pricing, "litellm", SimpleNamespace(model_cost={}))
|
|
assert litellm_pricing.get_model_pricing("missing") is None
|
|
|
|
|
|
def test_litellm_minimax_mixed_case_with_provider_prefix(monkeypatch) -> None:
|
|
"""MiniMax-M3 must resolve via the `minimax/` prefix even though its
|
|
model name uses mixed case.
|
|
|
|
`resolve_litellm_model()` is what callers in `proxy/cost.py`,
|
|
`proxy/savings_tracker.py`, and `perf/analyzer.py` use to get a
|
|
key LiteLLM's own cost DB recognises. The upstream DB only stores
|
|
the entry under `minimax/MiniMax-M3`, so bare `MiniMax-M3` would
|
|
otherwise miss and the resolver would return the input unchanged.
|
|
"""
|
|
|
|
def fake_cost_per_token(
|
|
model: str, prompt_tokens: int = 0, completion_tokens: int = 0
|
|
) -> tuple[float, float]:
|
|
if model in fake_litellm.model_cost:
|
|
entry = fake_litellm.model_cost[model]
|
|
return (
|
|
entry["input_cost_per_token"] * prompt_tokens,
|
|
entry["output_cost_per_token"] * completion_tokens,
|
|
)
|
|
raise KeyError(f"unknown model: {model}")
|
|
|
|
fake_litellm = SimpleNamespace(
|
|
model_cost={
|
|
"minimax/MiniMax-M3": {
|
|
"input_cost_per_token": 0.0000006,
|
|
"output_cost_per_token": 0.0000024,
|
|
}
|
|
},
|
|
cost_per_token=fake_cost_per_token,
|
|
)
|
|
monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
|
|
monkeypatch.setattr(litellm_pricing, "litellm", fake_litellm)
|
|
|
|
# Bare mixed-case name resolves via the case-insensitive `minimax-` prefix.
|
|
assert litellm_pricing.resolve_litellm_model("MiniMax-M3") == "minimax/MiniMax-M3"
|
|
|
|
|
|
def test_litellm_minimax_preregistration_safety_net(monkeypatch) -> None:
|
|
"""When LiteLLM only ships the prefixed `minimax/MiniMax-M3` entry, the
|
|
module-load pre-registration should also expose the bare `MiniMax-M3`
|
|
key so `estimate_cost()` works on a cold resolver cache (since
|
|
`get_model_pricing` does not know about the `minimax/` prefix).
|
|
"""
|
|
fake_litellm = SimpleNamespace(
|
|
model_cost={
|
|
"minimax/MiniMax-M3": {
|
|
"input_cost_per_token": 0.0000006,
|
|
"output_cost_per_token": 0.0000024,
|
|
}
|
|
}
|
|
)
|
|
monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
|
|
monkeypatch.setattr(litellm_pricing, "litellm", fake_litellm)
|
|
|
|
litellm_pricing._register_minimax_pricing()
|
|
|
|
assert "MiniMax-M3" in fake_litellm.model_cost
|
|
assert fake_litellm.model_cost["MiniMax-M3"]["input_cost_per_token"] == 0.0000006
|
|
# After pre-registration, bare-name estimate_cost works end-to-end.
|
|
assert (
|
|
litellm_pricing.estimate_cost("MiniMax-M3", input_tokens=1_000_000, output_tokens=100_000)
|
|
== 0.84
|
|
)
|
|
# Pre-registration must not clobber a user-customised bare entry.
|
|
fake_litellm.model_cost["MiniMax-M3"] = {"customised": True}
|
|
litellm_pricing._register_minimax_pricing()
|
|
assert fake_litellm.model_cost["MiniMax-M3"] == {"customised": True}
|