Repository navigation
[Feat] sgl-router: Add API profiles, a vendor API contract as one YAML file - #42345
Open
whybeyoung wants to merge 1 commit into
Open
whybeyoung wants to merge 1 commit into
whybeyoung wants to merge 1 commit into
Conversation
A hosted endpoint has to match a vendor's API contract: sampling rules, the largest output it allows, request size and image limits, the model names it answers to and the error type its 400s carry. Today only the sampling part can be configured (`--override-sampling-params`). An API profile declares the whole contract in one YAML file; vendor presets are compiled in and a deployment file can `extends` one. - `sampling`: the `--override-sampling-params` contract as a section, parsed and enforced by the existing code. The flag still works and replaces the section when given. - `output.max_tokens`: `cap` with `on_exceed: reject | clamp`, and a `default` injected when a request sets no budget. - `limits`: `max_body_bytes` (replaces the 32 MiB default) and `max_images` per request. - `models.aliases`: names accepted besides `--model-id`. - `errors.bad_request_type`: replaces `type` in every 400 body. Lookup: --api-profile-file, --api-profile, SGLANG_ROUTER_API_PROFILE, /etc/sgl-router/profile.yaml, then `openai-compatible`, which enforces nothing, so behavior is unchanged without a profile. --print-profile shows the merged result. Presets: openai-compatible, moonshot-kimi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Goal: let an operator declare a vendor's whole API contract in one YAML file, instead of assembling it from flags, and reuse that contract across deployments.
Serving a model "the way vendor X serves it" takes more than sampling defaults. A vendor's acceptance checks also cover:
typeits 400 errors carry.Today only the sampling part is configurable (
--override-sampling-params, #39000–#39002). Everything else is either hard-coded (the 32 MiB body limit) or not possible at all. Each new vendor contract would otherwise mean another set of flags, repeated in every deployment manifest.An API profile is that contract as a YAML file:
--api-profile moonshot-kimiis a complete contract.extendsa preset and change only what differs.Modifications
Profile sections (every key is optional; an unknown key fails startup):
sampling--override-sampling-paramscontract as a section, parsed and enforced by the same code (parse_sampling_overrides,resolve_sampling_defaults). The flag still works and, when given, replaces the section.output.max_tokenscap, withon_exceed: reject(400) orclamp, and adefaultinjected when a request sets no budget. Read with the engine's precedence (max_completion_tokens, thenmax_tokens).limitsmax_body_bytesreplaces the 32 MiB default (413 above it);max_imagescapsimage_urlparts per request (400).models.aliases--model-idand routed as it.errors.bad_request_typetypein every 400 body: router rejections and engine errors.Selection: the first source that is set wins.
--api-profile-file--api-profileSGLANG_ROUTER_API_PROFILE/etc/sgl-router/profile.yaml, which lets a vendor-specific image bake one inopenai-compatible, which enforces nothingextendsmerges a file onto a preset or another file: maps merge, scalars replace, andnulldeletes an inherited key.--print-profileprints the merged result and exits.Presets:
openai-compatible: the no-op default.moonshot-kimi: Moonshot's immutable sampling, the case [Router] Fleet-wide sampling contract 1/3: the config surface #39000 was built for, now one flag.Request path:
PreparedRequest::chat.append_fields. Only a clamp re-serializes the body.output,limits.max_images,modelsanderrorsapply to/v1/chat/completions. The body limit applies to every inference route.Code:
src/profile/module:mod.rsholds the types and validation,load.rshandles presets, files andextends, andenforce.rsholds the request-time checks.profiles/*.yamlpresets.ModelConfigin the tests gains one line,profile: Default::default().Not in this PR:
/v1/responsesand/v1/messages([Feat] sgl-router: Serve the OpenAI Responses API on /v1/responses #42314, [sgl-router] Serve the Anthropic Messages API on /v1/messages #42316). They follow once those land.Accuracy Tests
N/A: no model or kernel change.
extendsmerge and null-delete, cycle detection, selection order, output budget (inject / reject / clamp), image counting, and 400 retyping for both error shapes.tests/proxy/api_profile.rs): budget injected, rejected and clamped on the wire; aliases; image limit; body limit; error type; the sampling section; and flag precedence.cargo test(lib and proxy) andcargo clippy --all-targets -D warningspass.Speed Tests and Profiling
Without a profile there is no new work on the request path. With one:
max_imagesparsesmessages, and only when it is set.Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #37096145028
Latest PR Test (Extra): ❌ Run #37096144904
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.