Overview
SGLang provides OpenAI-compatible API endpoints, making it easy to switch from OpenAI to self-hosted models without changing your code.Base URL
All API endpoints are available at:--host and --port flags when launching the server.
Authentication
Optionally enable API key authentication:Chat Completions
Endpoint
Basic Example
Streaming Example
Request Parameters
string
required
Model identifier. Use the model path or served model name.
array
required
Array of message objects with
role and content fields.Roles: system, user, assistant, toolfloat
default:"1.0"
Sampling temperature between 0 and 2. Higher values make output more random.
int
default:"16"
Maximum number of tokens to generate.
float
default:"1.0"
Nucleus sampling threshold. Only tokens with cumulative probability up to
top_p are considered.int
default:"-1"
Top-k sampling. Only the top
top_k tokens are considered. Set to -1 to disable.float
default:"0.0"
Penalty for token frequency. Range: -2.0 to 2.0.
float
default:"0.0"
Penalty for token presence. Range: -2.0 to 2.0.
int
default:"1"
Number of completions to generate for each prompt.
string | array
default:"null"
Stop sequences. Generation stops when these strings are encountered.
bool
default:"false"
Enable streaming responses via Server-Sent Events.
bool
default:"false"
Return log probabilities of output tokens.
int
default:"0"
Number of top log probabilities to return for each token.
Response Format
SGLang-Specific Extensions
JSON Schema Constraints
Generate structured JSON output:Regex Constraints
Cache Reporting
Enable cache hit reporting (requires--enable-cache-report flag):
Text Completions
Endpoint
Example
Request Parameters
string
required
Model identifier.
string | array
required
Text prompt(s) or token IDs to generate completions for.
int
default:"16"
Maximum number of tokens to generate.
float
default:"1.0"
Sampling temperature.
float
default:"1.0"
Nucleus sampling parameter.
int
default:"1"
Number of completions to generate.
bool
default:"false"
Echo the prompt in addition to the completion.
bool
default:"false"
Enable streaming responses.
Embeddings
Endpoint
Example
Request Parameters
string
required
Embedding model identifier.
string | array
required
Text or array of texts to generate embeddings for.
int
default:"null"
Output embedding dimensions (if model supports dimension reduction).
Model Information
List Models
Get Model Details
Health and Status
Health Check
200 OK if the server is healthy.
Server Information
Error Handling
API errors return standard HTTP status codes:400 Bad Request- Invalid request parameters401 Unauthorized- Missing or invalid API key404 Not Found- Model or endpoint not found500 Internal Server Error- Server error503 Service Unavailable- Server is overloaded
Rate Limiting
Configure request limits:int
default:"null"
Maximum number of requests being processed concurrently.
int
default:"null"
Maximum number of requests allowed in the queue.
LoRA Adapters
SGLang supports dynamic LoRA adapter selection per request:See Also
- Native API - SGLang’s native Python API
- Sampling Parameters - Detailed parameter reference
- Server Arguments - Server configuration options
