Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(e2e): induce spend failure row deterministically instead of skipping (#34282)

devin-ai-integration[bot]0c2b86e16780
diff --git a/tests/e2e/quota_management/spend_tracking/test_spend_tracking_e2e.py b/tests/e2e/quota_management/spend_tracking/test_spend_tracking_e2e.py
index ea044071c00..b6e33627a5e 100644
--- a/tests/e2e/quota_management/spend_tracking/test_spend_tracking_e2e.py
+++ b/tests/e2e/quota_management/spend_tracking/test_spend_tracking_e2e.py
@@ -23,7 +23,7 @@ import pytest
from e2e_http import Result, Success
from lifecycle import ResourceManager
-from models import ChatResponse, SpendLogs, SpendLogsParams
+from models import ChatResponse, LiteLLMParamsBody, SpendLogs, SpendLogsParams
from spend_e2e_client import SpendClient, SpendLogRow, is_ok, unique_marker, unwrap
pytestmark = pytest.mark.e2e
@@ -502,22 +502,27 @@ def test_each_model_on_a_shared_key_gets_its_own_row(
@pytest.mark.covers("quota_management.spend_tracking.failure.writes_failure_row")
def test_failure_call_writes_failure_status_row(
- client: SpendClient, scoped_key: str
+ client: SpendClient, resources: ResourceManager, scoped_key: str
) -> None:
- result = client.chat(scoped_key, "gemini-2.5-flash", "", max_tokens=1)
- if is_ok(result):
- pytest.skip("call unexpectedly succeeded; could not induce a failure row")
+ model = f"e2e-spend-failure-{unique_marker()}"
+ model_id = client.proxy.create_model(
+ model,
+ LiteLLMParamsBody(model="openai/gpt-5.5", api_key="sk-invalid-e2e-failure-row"),
+ )
+ resources.defer(lambda: client.proxy.delete_model(model_id))
+
+ result = client.chat(scoped_key, model, f"trigger failure {unique_marker()}", max_tokens=1)
+ assert not is_ok(result), (
+ f"a call to a deployment with an invalid upstream key must fail, not succeed: {result}"
+ )
rows = client.poll_logs_for_key(
scoped_key, predicate=lambda rs: any(r.status == "failure" for r in rs)
)
- failure_rows = [r for r in rows if r.status == "failure"]
- if not failure_rows:
- pytest.skip(
- "no failure-status row was logged for the rejected call; "
- "failure logging is environment-specific"
- )
- assert (failure_rows[0].spend or 0) == 0.0, "failed call must not be charged"
+ failure_row = _require_row(
+ rows, lambda r: r.status == "failure", "with status=failure for the rejected call"
+ )
+ assert (failure_row.spend or 0) == 0.0, "failed call must not be charged"
@pytest.mark.covers("quota_management.spend_tracking.spend_calculate.returns_cost")