sgl-project/sglang · error · ValueError

return_token_ids is not supported with streaming on /v1/chat

Error message

return_token_ids is not supported with streaming on /v1/chat/completions. Please set stream=false when using return_token_ids=true.

What it means

Streaming is incompatible with return_token_ids=true on /v1/chat/completions; generated token IDs are only returned in the non-streaming response. The server rejects the combination up front.

Source

Thrown at python/sglang/srt/entrypoints/openai/serving_chat.py:991

            if request.chat_template_kwargs
            else None
        )
        if self.is_gpt_oss and reasoning_effort == "none":
            raise ValueError(
                f"Harmony does not support reasoning effort {reasoning_effort}"
            )

        if reasoning_effort is not None:
            request.reasoning_effort = reasoning_effort

        if request.stream:
            if request.return_prompt_token_ids:
                raise ValueError(
                    "return_prompt_token_ids is not supported with streaming. "
                    "Please set stream=false when using return_prompt_token_ids=true."
                )
            if request.return_token_ids:
                raise ValueError(
                    "return_token_ids is not supported with streaming on "
                    "/v1/chat/completions. Please set stream=false when using "
                    "return_token_ids=true."
                )
            if request.return_meta_info:
                raise ValueError(
                    "return_meta_info is not supported with streaming. "
                    "Please set stream=false when using return_meta_info=true."
                )

        is_multimodal = self.tokenizer_manager.model_config.is_multimodal

        # Process messages and apply chat template
        processed_messages = self._process_messages(request, is_multimodal)
        # Build sampling parameters
        sampling_params = request.to_sampling_params(
            stop=processed_messages.stop,
            model_generation_config=self.default_sampling_params,

View on GitHub (pinned to 0132848349)

Solutions

  1. Set stream=false to receive generated token IDs
  2. Or remove return_token_ids when streaming

Example fix

// before
{"stream": true, "return_token_ids": true}
// after
{"stream": false, "return_token_ids": true}
Defensive patterns

Strategy: validation

Validate before calling

if body.get("stream"):
    body["return_token_ids"] = False
# or assert not (stream and return_token_ids)

Type guard

def stream_compat_ok(b): return not (b.get('stream') and b.get('return_token_ids'))

Prevention

When it happens

Trigger: POST /v1/chat/completions with {"stream": true, "return_token_ids": true}.

Common situations: Debugging tokenization during streaming demos; reusing a non-streaming request payload with stream flipped to true.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/d4ecfc2aa2fe4a28. Report an issue: GitHub.