Skip to main content

Completions

The completions endpoint generates text based on a prompt. This endpoint is compatible with OpenAI’s /v1/completions API.

Request

Parameters

Required

string
required
Model name. Supports LoRA adapters via base-model:adapter-name syntax.
string | array
required
The prompt(s) to generate completions for. Can be:
  • A single string
  • An array of strings for batch processing
  • An array of token IDs
  • An array of arrays of token IDs for batch processing

Sampling Parameters

integer
default:"16"
Maximum number of tokens to generate.
number
default:"1.0"
Sampling temperature between 0 and 2. Higher values make output more random.
number
default:"1.0"
Nucleus sampling threshold. Only tokens with cumulative probability >= top_p are considered.
integer
default:"-1"
Only sample from the top K tokens. -1 disables this.
number
default:"0.0"
Minimum probability threshold for sampling.
integer
default:"1"
Number of completions to generate for each prompt.
integer
Random seed for deterministic generation.
string | array
Stop sequences. Generation stops when these sequences are encountered.
array
Stop token IDs. Generation stops when these token IDs are encountered.

Penalization

number
default:"0.0"
Penalizes tokens based on their frequency in the generated text. Range: [-2.0, 2.0].
number
default:"0.0"
Penalizes tokens based on whether they appear in the generated text. Range: [-2.0, 2.0].
number
default:"1.0"
Penalizes repeated tokens. 1.0 means no penalty.

Structured Output

object
Format of the response. Options:
  • {"type": "text"} - Plain text (default)
  • {"type": "json_object"} - Valid JSON object
  • {"type": "json_schema", "json_schema": {...}} - JSON matching a schema
string
JSON schema string for constrained generation.
string
Regular expression pattern for constrained generation.
string
EBNF grammar for constrained generation.

Other Parameters

boolean
default:"false"
Whether to stream the response.
object
Streaming options:
  • include_usage: Include usage statistics in final chunk
  • continuous_usage_stats: Include usage stats in each chunk
boolean
default:"false"
Whether to echo the prompt in the completion.
integer
Number of top log probabilities to return for each token.
object
Bias certain tokens. Maps token IDs to bias values between -100 and 100.
integer
Generate best_of completions and return the best one.
string
Text to append after the completion.

SGLang Extensions

boolean
default:"false"
Continue generation even after EOS token.
boolean
default:"true"
Whether to skip special tokens in the output.
boolean
default:"false"
Do not trim stop sequences from output.
string | array
Regular expression(s) to use as stop conditions.
integer
default:"0"
Minimum number of tokens to generate.
string
Path to LoRA adapter weights.
boolean
default:"false"
Return hidden states from the model.
boolean
default:"false"
Return expert routing information for MoE models.
boolean
default:"false"
Return detailed cache hit information.

Response

string
Unique identifier for the completion.
string
Always "text_completion".
integer
Unix timestamp of creation time.
string
Model used for generation.
array
Array of completion choices.
integer
Choice index in the array.
string
Generated text.
object | null
Log probability information if requested.
array
List of generated tokens.
array
Log probabilities for each token.
array
Top log probabilities for each position.
array
Character offsets for each token.
string
Reason for completion end:
  • stop: Natural stop or stop sequence
  • length: Max tokens reached
  • content_filter: Content filtering
  • abort: Request aborted
integer | string | null
The stop sequence that was matched, if any.
object
Token usage statistics.
integer
Number of tokens in the prompt.
integer
Number of tokens in the completion.
integer
Total tokens used (prompt + completion).
object
Details about prompt tokens.
integer
Number of cached tokens from prefix cache.
object
SGLang-specific extensions (only present when requested).
string
Expert routing information for MoE models.
object
Detailed cache hit information.
integer
Tokens from device (GPU) cache.
integer
Tokens from host (CPU) cache.
integer
Tokens from L3 storage backend (if enabled).
string
Type of storage backend used.

Streaming Response

When stream=true, the response is sent as Server-Sent Events (SSE):

Examples

Basic Completion

Streaming Completion

JSON Output

Batch Processing

See Also