Skip to main content
SGLang supports parsing reasoning content (chain-of-thought) from final answers for reasoning models like DeepSeek-R1, DeepSeek-V3, Qwen3, and others. This enables you to display reasoning and final answers separately in your application.

Supported Models

Model-Specific Behaviors

  • DeepSeek-R1: No <think> start tag, jumps directly to thinking content
  • DeepSeek-R1-0528: Generates both <think> start and </think> end tags
  • Both handled by the same deepseek-r1 parser
  • DeepSeek-V3.1/V3.2: Hybrid model supporting both thinking and non-thinking modes
  • Use the deepseek-v3 parser and thinking parameter (NOT enable_thinking)
  • Standard Qwen3 (e.g., Qwen3-2507): Use qwen3 parser, supports enable_thinking in chat templates
  • Qwen3-Thinking (e.g., Qwen3-235B-A22B-Thinking-2507): Use qwen3 or qwen3-thinking, always thinks
Uses special ◁think▷ and ◁/think▷ tags. For agentic tool use, also specify --tool-call-parser kimi_k2.
Uses special <|channel|>analysis<|message|> and <|end|> tags for analysis content.

Quick Start

Launch Server

The --reasoning-parser argument specifies which parser to use for interpreting reasoning content in the model’s output.

OpenAI-Compatible API

The API follows the DeepSeek API design with:
  • reasoning_content: The chain-of-thought reasoning
  • content: The final answer

Non-Streaming Request

Streaming Request

Buffered Streaming

Buffer reasoning content until complete, then stream it in one chunk:

Disable Reasoning Separation

To get the raw output with reasoning tags:

Native API Usage

You can also use the native SGLang API:

Generate with Native API

Parse Reasoning

Parser Details

DeepSeek-R1 Parser

Handles both tag variants:
  • Models that omit <think> start tag
  • Models that include both <think> and </think> tags

DeepSeek-V3 Parser

Supports hybrid thinking mode controlled by the thinking parameter:

Qwen3 Parser

Standard Qwen3 models support enable_thinking in the chat template:

Kimi K2 Parser

Uses Unicode triangle characters for thinking delimiters:

Implementation Details

Reasoning parsing is implemented through specialized parser classes that:
  1. Detect reasoning boundaries - Identify start and end tags in the output stream
  2. Extract reasoning content - Separate thinking from final answer
  3. Handle streaming - Support both buffered and unbuffered streaming modes
  4. Format responses - Map to OpenAI-compatible response format
Parsers are registered in the function call system:
Source: python/sglang/srt/function_call/function_call_parser.py:48

Configuration Options

Performance Considerations

  • Unbuffered (stream_reasoning=True): Lower latency, reasoning appears token-by-token
  • Buffered (stream_reasoning=False): Better UX for long reasoning, appears all at once
Parsing adds minimal overhead (<1ms per request). The parser operates on the output stream and does not affect generation speed.

Use Cases

Debugging

Display reasoning to understand model’s decision process

Educational Tools

Show step-by-step problem solving

Transparency

Provide visibility into AI reasoning for high-stakes decisions

Analysis

Log and analyze reasoning patterns