{"record":{"id":"d4ecfc2aa2fe4a28","repo":"sgl-project/sglang","slug":"return-token-ids-is-not-supported-with-streaming-o","errorCode":null,"errorMessage":"return_token_ids is not supported with streaming on /v1/chat/completions. Please set stream=false when using return_token_ids=true.","messagePattern":"return_token_ids is not supported with streaming on /v1/chat/completions\\. Please set stream=false when using return_token_ids=true\\.","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/srt/entrypoints/openai/serving_chat.py","lineNumber":991,"sourceCode":"            if request.chat_template_kwargs\n            else None\n        )\n        if self.is_gpt_oss and reasoning_effort == \"none\":\n            raise ValueError(\n                f\"Harmony does not support reasoning effort {reasoning_effort}\"\n            )\n\n        if reasoning_effort is not None:\n            request.reasoning_effort = reasoning_effort\n\n        if request.stream:\n            if request.return_prompt_token_ids:\n                raise ValueError(\n                    \"return_prompt_token_ids is not supported with streaming. \"\n                    \"Please set stream=false when using return_prompt_token_ids=true.\"\n                )\n            if request.return_token_ids:\n                raise ValueError(\n                    \"return_token_ids is not supported with streaming on \"\n                    \"/v1/chat/completions. Please set stream=false when using \"\n                    \"return_token_ids=true.\"\n                )\n            if request.return_meta_info:\n                raise ValueError(\n                    \"return_meta_info is not supported with streaming. \"\n                    \"Please set stream=false when using return_meta_info=true.\"\n                )\n\n        is_multimodal = self.tokenizer_manager.model_config.is_multimodal\n\n        # Process messages and apply chat template\n        processed_messages = self._process_messages(request, is_multimodal)\n        # Build sampling parameters\n        sampling_params = request.to_sampling_params(\n            stop=processed_messages.stop,\n            model_generation_config=self.default_sampling_params,","sourceCodeStart":973,"sourceCodeEnd":1009,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/openai/serving_chat.py#L973-L1009","documentation":"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.","triggerScenarios":"POST /v1/chat/completions with {\"stream\": true, \"return_token_ids\": true}.","commonSituations":"Debugging tokenization during streaming demos; reusing a non-streaming request payload with stream flipped to true.","solutions":["Set stream=false to receive generated token IDs","Or remove return_token_ids when streaming"],"exampleFix":"// before\n{\"stream\": true, \"return_token_ids\": true}\n// after\n{\"stream\": false, \"return_token_ids\": true}","handlingStrategy":"validation","validationCode":"if body.get(\"stream\"):\n    body[\"return_token_ids\"] = False\n# or assert not (stream and return_token_ids)","typeGuard":"def stream_compat_ok(b): return not (b.get('stream') and b.get('return_token_ids'))","tryCatchPattern":null,"preventionTips":["Keep a lint rule: stream=true excludes all return_* debug flags"],"tags":["streaming","token-ids","openai-api","sglang"],"backgroundTag":"incompatible-request-flags","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}