From 8ce365511f84d863fb4e43600a7823733ece4f35 Mon Sep 17 00:00:00 2001 From: mubashir1osmani Date: Sat, 25 Jul 2026 10:54:28 -0700 Subject: [PATCH] test(e2e): cover /openai chat passthrough cost logging (#34470) The /openai/{endpoint} passthrough forwards a raw OpenAI-format request to api.openai.com (or OPENAI_API_BASE) with the proxy's OPENAI_API_KEY swapped in, and still logs a costed pass_through_endpoint SpendLogs row. Nothing exercised that path end to end. Adds a live /openai/v1/chat/completions passthrough test that asserts a 2xx completion and a costed row with custom_llm_provider=openai, mirroring the gemini and anthropic passthrough cost tests, and registers llm.chat_completions.openai.passthrough.nonstream.cost_logged. --- .../coverage_registry/llm_conversational.yaml | 1 + .../e2e/llm_translation/passthrough_client.py | 19 +++++++++++++++++++ .../llm_translation/test_passthrough_e2e.py | 12 ++++++++++++ 3 files changed, 32 insertions(+) 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" +@pytest.mark.covers("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.