[PR #2278] [CLOSED] [Other] add legacy /v1/completions for raw-prompt clients (#2277) #3956

Closed
opened 2026-11-07 15:31:59 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2278
Author: @kossum
Created: 10/13/2026
Status: ❌ Closed

Base: main ← Head: serve-completions


📝 Commits (2)

  • 6882615 serve: add the legacy /v1/completions endpoint
  • ac6aeed fix(serve): restore structured SSE errors and avoid duplicate completion text

📊 Changes

6 files changed (+333 additions, -13 deletions)

View changed files

📝 docs/DETAILS.md (+1 -0)
📝 serve/frontend.py (+12 -0)
📝 serve/server.py (+169 -10)
📝 serve/test_monitor.py (+17 -0)
📝 serve/test_server.py (+122 -0)
📝 serve/test_structured.py (+12 -3)

📄 Description

Problem and result

Clients that apply their own chat template need to send a raw prompt to /v1/completions. Strata currently has no endpoint for that.

This adds the legacy OpenAI endpoint with streaming and non-streaming responses, text_completion objects, and token usage. The server doesn't apply the chat template again.

#2277

Approach

The handler uses the existing generation path and accepts one string prompt. max_tokens: 0 or a negative value uses the remaining context.

Explicit thinking-disable flags append the template's no-thinking tail. Without those flags, the prompt passes through unchanged.

Streaming sends each piece of text once. With echo: true, it sends the prompt once at the start; the finish chunk has empty text.

This also keeps the structured-output error handler in the chat endpoint, so a failed streamed response sends an SSE error and [DONE], not another HTTP response inside the stream. Engine errors after streaming starts are handled as SSE errors too.

Validation

Rebased onto main e88ee39d (0.2.0-beta). These local checks ran on 7e08755f.

Passed:

Windows, Python 3.13.2, with jsonschema installed:

uv run --no-project --with regex --with jinja2 --with jsonschema python -m unittest serve.test_server serve.test_structured serve.test_monitor

368 tests, OK, 3 skipped.

Linux, Python 3.11 in Docker, using a dedicated venv with only the pinned requirements.txt packages:

python tools/minimal_server_smoke.py --report /tmp/minimal-server-smoke.json

Reported "passed": true.

git diff --check upstream/main also passed.

Failed:

The full suite in the same Linux venv:

python -m unittest discover -s serve -p 'test_*.py'

888 tests, 2 failures, 18 skipped:

  • test_lifeline.Lifeline.test_the_portable_watcher_ends_the_child_when_the_server_is_killed
  • test_server.VisionTempFiles.test_work_dir_has_no_space_when_temp_has_one

I reran both tests on clean main e88ee39d with the same container and dependencies. Both fail there with the same assertions. I haven't changed either behavior in this PR.

Not run:

  • Live-model testing on this rebased revision. The earlier live checks were on an older revision.
  • CUDA, HIP, SYCL or Metal builds. This PR changes Python serving code, not native backend code.
  • A byte-for-byte comparison of all existing endpoints against the release.

Limits

Only a string prompt and n=1 / best_of=1 are supported. Suffix and logprobs are rejected.

stream_options accepts only include_usage, and only with streaming. Usage still comes on the finish chunk, not a separate choices: [] chunk, so this doesn't yet implement the full OpenAI streaming-usage format.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2278 **Author:** [@kossum](https://github.com/kossum) **Created:** 10/13/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `serve-completions` --- ### 📝 Commits (2) - [`6882615`](https://github.com/Niko1221/Strata/commit/68826151bd6a7725ff0ce240c775682625a39f86) serve: add the legacy /v1/completions endpoint - [`ac6aeed`](https://github.com/Niko1221/Strata/commit/ac6aeeddb34ddbad983d49a63a95b436fdc83f37) fix(serve): restore structured SSE errors and avoid duplicate completion text ### 📊 Changes **6 files changed** (+333 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+1 -0) 📝 `serve/frontend.py` (+12 -0) 📝 `serve/server.py` (+169 -10) 📝 `serve/test_monitor.py` (+17 -0) 📝 `serve/test_server.py` (+122 -0) 📝 `serve/test_structured.py` (+12 -3) </details> ### 📄 Description ## Problem and result Clients that apply their own chat template need to send a raw prompt to `/v1/completions`. Strata currently has no endpoint for that. This adds the legacy OpenAI endpoint with streaming and non-streaming responses, `text_completion` objects, and token usage. The server doesn't apply the chat template again. ## Related discussion #2277 ## Approach The handler uses the existing generation path and accepts one string prompt. `max_tokens: 0` or a negative value uses the remaining context. Explicit thinking-disable flags append the template's no-thinking tail. Without those flags, the prompt passes through unchanged. Streaming sends each piece of text once. With `echo: true`, it sends the prompt once at the start; the finish chunk has empty text. This also keeps the structured-output error handler in the chat endpoint, so a failed streamed response sends an SSE error and `[DONE]`, not another HTTP response inside the stream. Engine errors after streaming starts are handled as SSE errors too. ## Validation Rebased onto main `e88ee39d` (0.2.0-beta). These local checks ran on `7e08755f`. **Passed:** Windows, Python 3.13.2, with jsonschema installed: ```sh uv run --no-project --with regex --with jinja2 --with jsonschema python -m unittest serve.test_server serve.test_structured serve.test_monitor ``` 368 tests, OK, 3 skipped. Linux, Python 3.11 in Docker, using a dedicated venv with only the pinned `requirements.txt` packages: ```sh python tools/minimal_server_smoke.py --report /tmp/minimal-server-smoke.json ``` Reported `"passed": true`. `git diff --check upstream/main` also passed. **Failed:** The full suite in the same Linux venv: ```sh python -m unittest discover -s serve -p 'test_*.py' ``` 888 tests, 2 failures, 18 skipped: - `test_lifeline.Lifeline.test_the_portable_watcher_ends_the_child_when_the_server_is_killed` - `test_server.VisionTempFiles.test_work_dir_has_no_space_when_temp_has_one` I reran both tests on clean main `e88ee39d` with the same container and dependencies. Both fail there with the same assertions. I haven't changed either behavior in this PR. **Not run:** - Live-model testing on this rebased revision. The earlier live checks were on an older revision. - CUDA, HIP, SYCL or Metal builds. This PR changes Python serving code, not native backend code. - A byte-for-byte comparison of all existing endpoints against the release. ## Limits Only a string prompt and `n=1` / `best_of=1` are supported. Suffix and logprobs are rejected. `stream_options` accepts only `include_usage`, and only with streaming. Usage still comes on the finish chunk, not a separate `choices: []` chunk, so this doesn't yet implement the full OpenAI streaming-usage format. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:31:59 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3956
No description provided.