litellm/tests/integration/spend/test_spend_calculate.py
devin-ai-integration[bot] 3db94b932e
fix(spend): return 400 from /spend/calculate for a model with no pricing row (#42497)
* fix(spend): return 400 from /spend/calculate for a model with no pricing row

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(spend): assert error type and param for unpriced /spend/calculate

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(spend): move the repro to tests/integration

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: alias ModelNotMappedError re-export to satisfy F401

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(utils): raise ModelNotMappedError only when the pricing row is missing

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: kerry <kerry@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-22 15:44:00 -07:00

20 lines
896 B
Python

import uuid
from typing import Final
import pytest
from integration._support.client import JSON_OBJECT, Gateway, object_value, string_value
@pytest.mark.covers("quota_management.spend_tracking.spend_calculate.rejects_unpriced_model")
def test_spend_calculate_rejects_unpriced_model_with_400(gateway: Gateway) -> None:
model: Final = f"openrouter/integration-unpriced-{uuid.uuid4().hex}"
response: Final = gateway.request(
"POST",
"/spend/calculate",
{"model": model, "messages": [{"role": "user", "content": "price this request"}]},
)
assert response.status_code == 400, response.text
error: Final = object_value(JSON_OBJECT.validate_json(response.text)["error"])
assert error["type"] == "invalid_request_error", response.text
assert error["param"] == "model", response.text
assert model in string_value(error["message"]), response.text