sgl-project/sglang · error · ValueError

return_prompt_token_ids is not supported with streaming. Ple

Error message

return_prompt_token_ids is not supported with streaming. Please set stream=false when using return_prompt_token_ids=true.

What it means

_convert_to_internal_request rejects stream=true combined with return_prompt_token_ids=true on /v1/chat/completions. Prompt token IDs are only returned in the non-streaming response object.

Source

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

        request: ChatCompletionRequest,
        raw_request: Request = None,
    ) -> tuple[GenerateReqInput, ChatCompletionRequest]:
        reasoning_effort = (
            request.chat_template_kwargs.pop("reasoning_effort", None)
            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

View on GitHub (pinned to 0132848349)

Solutions

  1. Set stream=false when you need prompt token IDs
  2. Or drop return_prompt_token_ids for streaming and count tokens client-side via /tokenize

Example fix

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

Strategy: validation

Validate before calling

if body.get("stream"):
    body.pop("return_prompt_token_ids", None)
    body.pop("return_token_ids", None)
    body.pop("return_meta_info", None)

Type guard

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

Prevention

When it happens

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

Common situations: Sharing one request-builder between streaming and non-streaming paths with debug flags always on; wanting token counts for streaming cost accounting.

Related errors


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