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): cover /openai chat passthrough cost logging (#34470)

mubashir1osmani8ce365511f84
diff --git a/tests/e2e/coverage_registry/llm_conversational.yaml b/tests/e2e/coverage_registry/llm_conversational.yaml
index fc3a61c078f..6cb60c19247 100644
--- a/tests/e2e/coverage_registry/llm_conversational.yaml
+++ b/tests/e2e/coverage_registry/llm_conversational.yaml
@@ -2,6 +2,7 @@
- {id: llm.chat_completions.openai.basic.nonstream.works, module: llm, tier: P0, subject_endpoint: chat_completions, route: openai, capability: basic, streaming: nonstream, assertions: [works], source: "proxy_server.py:8455", rationale: "Core endpoint/route/capability"}
- {id: llm.chat_completions.openai.basic.stream.works, module: llm, tier: P0, subject_endpoint: chat_completions, route: openai, capability: basic, streaming: stream, assertions: [works], source: "proxy_server.py:8455", rationale: "Core streaming"}
- {id: llm.chat_completions.openai.basic.nonstream.cost_logged, module: llm, tier: P0, subject_endpoint: chat_completions, route: openai, capability: basic, streaming: nonstream, assertions: [works, cost_logged], source: "proxy_server.py:8455", rationale: "Cost logging regression catch"}
+- {id: llm.chat_completions.openai.passthrough.nonstream.cost_logged, module: llm, tier: P1, subject_endpoint: chat_completions, route: openai, capability: basic, streaming: nonstream, assertions: [works, cost_logged], source: "test_passthrough_e2e.py", rationale: "OpenAI-format chat via the raw /openai/{endpoint} passthrough (/openai/v1/chat/completions); proxy swaps in OPENAI_API_KEY and still logs a costed pass_through_endpoint row (LIT-4752)"}
- {id: llm.chat_completions.openai.tool_use.nonstream.works, module: llm, tier: P0, subject_endpoint: chat_completions, route: openai, capability: tool_use, streaming: nonstream, assertions: [works], source: "model_prices json", rationale: "OpenAI function_calling; high usage"}
- {id: llm.chat_completions.openai.tool_use.stream.works, module: llm, tier: P0, subject_endpoint: chat_completions, route: openai, capability: tool_use, streaming: stream, assertions: [works], source: "model_prices json", rationale: "Tool calls over streaming"}
- {id: llm.chat_completions.openai.vision.nonstream.works, module: llm, tier: P0, subject_endpoint: chat_completions, route: openai, capability: vision, streaming: nonstream, assertions: [works], source: "model_prices json", rationale: "gpt-4o vision; high usage"}
diff --git a/tests/e2e/llm_translation/passthrough_client.py b/tests/e2e/llm_translation/passthrough_client.py
index c74da3e9abc..7aa2eb793ad 100644
--- a/tests/e2e/llm_translation/passthrough_client.py
+++ b/tests/e2e/llm_translation/passthrough_client.py
@@ -102,6 +102,12 @@ class AnthropicMessageBody(BaseModel):
stream: bool = False
+class OpenAIChatBody(BaseModel):
+ model: str
+ messages: list[ChatMessage]
+ max_tokens: int = 64
+
+
class VllmChatBody(BaseModel):
model: str
messages: list[ChatMessage]
@@ -191,6 +197,19 @@ class PassthroughClient:
stream=stream,
)
+ def openai_chat(
+ self, key: str, model: str, text: str, *, max_tokens: int = 64
+ ) -> StreamingResponse:
+ return self.proxy.transport.send(
+ "/openai/v1/chat/completions",
+ headers=self.proxy.transport.bearer(key),
+ json=OpenAIChatBody(
+ model=model,
+ max_tokens=max_tokens,
+ messages=[ChatMessage(role="user", content=text)],
+ ),
+ )
+
def vllm_chat(
self, key: str, model: str, text: str, *, max_tokens: int = 64
) -> StreamingResponse:
diff --git a/tests/e2e/llm_translation/test_passthrough_e2e.py b/tests/e2e/llm_translation/test_passthrough_e2e.py
index ed5c657d23e..b7d4d7cd668 100644
--- a/tests/e2e/llm_translation/test_passthrough_e2e.py
+++ b/tests/e2e/llm_translation/test_passthrough_e2e.py
@@ -160,6 +160,18 @@ def test_anthropic_passthrough_tool_call_logs_cost(
assert row.custom_llm_provider == "anthropic"
[email protected]("llm.chat_completions.openai.passthrough.nonstream.cost_logged")
+def test_openai_passthrough_nonstreaming_logs_cost(
+ client: PassthroughClient, scoped_key: str
+) -> None:
+ result = client.openai_chat(scoped_key, "gpt-5.4-mini", "Say hello in one word")
+ require_successful_call(result)
+
+ row = _fetch_cost_breakdown(client, result)
+ assert row.custom_llm_provider == "openai"
+ assert "gpt-5" in (row.model or "")
+
+
class TestPassthroughModelAllowlist:
"""A passthrough route must honor the calling key's model allow-list.