Skip to content

feat: rust sglang server openai apis - #33103

Merged
hnyls2002 merged 23 commits into
sgl-project:mainfrom
mrain:cl/rust-openai-apis
Aug 3, 2026
Merged

hnyls2002 merged 23 commits into
sgl-project:mainfrom
mrain:cl/rust-openai-apis

Conversation

@mrain

@mrain mrain commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Motivation

Implemented the full OpenAI APIs for rust sglang server.

Modifications

Implemented APIs:

  • v1/models
  • v1/completions
  • v1/chat/completions

Some design decisions

  • n fanout: Fan-out in HTTP layer — submits n separate GenerateRequests, each with n=1. Matches external API behavior, avoids native n > 1 rejection
  • Auth: --api-key Bearer token gating on all OpenAI endpoints (default: open for no key configured)
  • Deprecated function_call/functions: Explicitly rejected with migration message (Python silently ignores)
  • text_offset: SGLang emits [-1] sentinels; post-processed in completion_response_value since Dynamo types it as u32
  • system_fingerprint: Removed from responses (Python doesn't include it)
  • reasoning_content: null: Serialized into every SSE delta chunk (Python compat)
  • 400 for unknown model: Consistently 400 on generation endpoints (Python convention)

Accuracy Tests

  • Python integration tests: Existing TestOpenAIServer, TestOpenAIFunctionCalling, TestOpenAIResponses classes reused verbatim behind is_rust_server_built() guards via class attribute aliasing
  • Rust unit tests: 26 tests covering deserialization, unary fold ordering, streaming deltas, tool-call parsing, marker buffering, split-marker handling, response lifecycle events, logprob shapes

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ⏳ Run #30788528554
Latest PR Test (Extra): ❌ Run #30788528388

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions github-actions Bot added documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file labels Jul 31, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06511cc44c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rust/sglang-server/src/api_server/openai/chat.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai/chat.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai/chat.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai/responses.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai.rs Outdated
Comment thread scripts/frontend_api_parity.md Outdated
Comment thread scripts/frontend_api_parity.py Outdated
Comment thread rust/sglang-server/src/api_server/frame.rs
Comment thread rust/sglang-server/src/api_server/openai/tools.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai/tests.rs Outdated
Comment thread rust/sglang-server/src/api_server/openai/chat.rs Outdated
Comment thread rust/sglang-server/src/api_server.rs Outdated
@mrain
mrain force-pushed the cl/rust-openai-apis branch from 271ee8e to b7dc477 Compare August 1, 2026 17:20
/// Unlike request streaming decode, this has no request registration or
/// incremental state. The oneshot carries only the reply; callers depend on
/// this service method rather than owning a concrete tokenizer.
pub async fn decode_once(&self, rid: &Rid, token_ids: TokenIds) -> Result<String, Error> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case, there is token-id sequence?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only needed for /v1/completions when the input prompt is a token-id sequence and echo is true.

@hnyls2002

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/openai_server/basic/test_openai_completion_rust.py test/registered/openai_server/basic/test_openai_server.py test/registered/openai_server/function_call/test_openai_function_calling.py

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/openai_server/basic/test_openai_completion_rust.py test/registered/openai_server/basic/test_openai_server.py test/registered/openai_server/function_call/test_openai_function_calling.py:

🚀 1-gpu-5090 (2 tests): ✅ View workflow run

cd test/ && python3 registered/openai_server/basic/test_openai_completion_rust.py
cd test/ && python3 registered/openai_server/basic/test_openai_server.py

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/openai_server/function_call/test_openai_function_calling.py

@hnyls2002
hnyls2002 merged commit e00f32e into sgl-project:main Aug 3, 2026
82 of 185 checks passed
kfhfar pushed a commit to kfhfar/sglang that referenced this pull request Aug 7, 2026
Co-authored-by: Rain Jiang <rain-jiang@outlook.com>
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 16, 2026
Co-authored-by: Rain Jiang <rain-jiang@outlook.com>
jakki-amd pushed a commit to jakki-amd/sglang that referenced this pull request Sep 9, 2026
Co-authored-by: Rain Jiang <rain-jiang@outlook.com>
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
Co-authored-by: Rain Jiang <rain-jiang@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation high priority run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants