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 legacy text /completions endpoint (#34431)

mubashir1osmaniad79b314c56a
diff --git a/tests/e2e/coverage_registry/llm_nonconversational.yaml b/tests/e2e/coverage_registry/llm_nonconversational.yaml
index f581a82d29a..584c7120134 100644
--- a/tests/e2e/coverage_registry/llm_nonconversational.yaml
+++ b/tests/e2e/coverage_registry/llm_nonconversational.yaml
@@ -1,4 +1,5 @@
# LLM non-conversational endpoints. Grounded in litellm/proxy endpoints + llms/ handlers.
+- {id: llm.completions.openai.basic.nonstream.works, module: llm, tier: P0, subject_endpoint: completions, route: openai, capability: basic, streaming: nonstream, assertions: [works], source: "test_completions_endpoint_e2e.py", rationale: "Legacy text /completions endpoint, second-highest production request volume"}
- {id: llm.embeddings.openai.basic.nonstream.works, module: llm, tier: P0, subject_endpoint: embeddings, route: openai, capability: basic, streaming: nonstream, assertions: [works], source: "test_embeddings_endpoint_e2e.py:23", rationale: "Core endpoint, live vector response"}
- {id: llm.embeddings.openai.input_validation.nonstream.works, module: llm, tier: P1, subject_endpoint: embeddings, route: openai, capability: input_validation, streaming: nonstream, assertions: [works], source: "vendor strategy §9.3 / LIT-4778", rationale: "Missing model/input on /embeddings return client or known server errors"}
- {id: llm.embeddings.openai.basic.nonstream.cost_logged, module: llm, tier: P0, subject_endpoint: embeddings, route: openai, capability: basic, streaming: nonstream, assertions: [cost_logged], source: "SPEND_TRACKING_COVERAGE_MATRIX.md:34", rationale: "Cost tracking on embeddings"}
diff --git a/tests/e2e/coverage_registry/schema.py b/tests/e2e/coverage_registry/schema.py
index 7146c01a1a3..8b391c04114 100644
--- a/tests/e2e/coverage_registry/schema.py
+++ b/tests/e2e/coverage_registry/schema.py
@@ -27,6 +27,7 @@ class FailBeforeFix(str, Enum):
LlmEndpoint = Literal[
"chat_completions",
+ "completions",
"messages",
"responses",
"embeddings",
diff --git a/tests/e2e/llm_translation/endpoints_client.py b/tests/e2e/llm_translation/endpoints_client.py
index b324ffce548..b5c81864da7 100644
--- a/tests/e2e/llm_translation/endpoints_client.py
+++ b/tests/e2e/llm_translation/endpoints_client.py
@@ -90,6 +90,12 @@ class RichMessagesRequest(BaseModel):
messages: list[RichMessage]
+class CompletionsRequest(BaseModel):
+ model: str
+ prompt: str
+ max_tokens: int = 32
+
+
class EmbeddingsRequest(BaseModel):
model: str
input: str
@@ -204,6 +210,14 @@ class MessagesResult(BaseModel):
return "".join(block.text or "" for block in self.content)
+class CompletionChoice(BaseModel):
+ text: str | None = None
+
+
+class CompletionsResult(BaseModel):
+ choices: list[CompletionChoice] = []
+
+
class EmbeddingItem(BaseModel):
embedding: list[float] = []
@@ -344,6 +358,15 @@ class EndpointsClient:
),
)
+ def text_completions(
+ self, key: str, model: str, prompt: str, *, max_tokens: int = 32
+ ) -> StreamingResponse:
+ return self._send(
+ "/v1/completions",
+ key,
+ CompletionsRequest(model=model, prompt=prompt, max_tokens=max_tokens),
+ )
+
def embeddings(self, key: str, model: str, text: str) -> StreamingResponse:
return self._send("/embeddings", key, EmbeddingsRequest(model=model, input=text))
diff --git a/tests/e2e/llm_translation/test_completions_endpoint_e2e.py b/tests/e2e/llm_translation/test_completions_endpoint_e2e.py
new file mode 100644
index 00000000000..3fc506e4de9
--- /dev/null
+++ b/tests/e2e/llm_translation/test_completions_endpoint_e2e.py
@@ -0,0 +1,46 @@
+"""Live e2e: POST /v1/completions returns a real text completion.
+
+The legacy text-completion endpoint (prompt-style, non-chat) is the second-busiest
+route in production yet was previously uncovered; the rest of the "completions"
+surface is chat only. Registers an OpenAI instruct deployment at runtime (deleted
+on teardown), drives /v1/completions through the gateway, and asserts real
+generated text came back so a regression that empties the completion fails here.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from e2e_config import unique_marker
+from e2e_http import require_successful_call
+from endpoints_client import CompletionsResult, EndpointsClient
+from lifecycle import ResourceManager
+from models import LiteLLMParamsBody
+
+pytestmark = pytest.mark.e2e
+
+
+class TestCompletionsEndpoint:
+ @pytest.mark.covers("llm.completions.openai.basic.nonstream.works")
+ def test_text_completion_returns_text(
+ self, endpoints_client: EndpointsClient, resources: ResourceManager
+ ) -> None:
+ model = f"e2e-completions-{unique_marker()}"
+ model_id = endpoints_client.create_model(
+ model,
+ LiteLLMParamsBody(
+ model="text-completion-openai/gpt-3.5-turbo-instruct",
+ api_key="os.environ/OPENAI_API_KEY",
+ ),
+ )
+ resources.defer(lambda: endpoints_client.delete_model(model_id))
+ key = resources.key()
+
+ result = endpoints_client.text_completions(
+ key, model, "Finish this sentence in a few words: the capital of France is"
+ )
+ require_successful_call(result)
+ parsed = CompletionsResult.model_validate_json(result.body)
+ assert parsed.choices, f"/v1/completions returned no choices: {result.body[:300]}"
+ completion = (parsed.choices[0].text or "").strip()
+ assert completion, f"/v1/completions returned an empty completion: {result.body[:300]}"