Skip to content

Reasoning and tool calling ​

Use this reference to select reasoning and tool-call parsers and to enforce a reasoning-token budget.

Parser options ​

The following table summarizes the parser options and their engine-side behavior:

ParameterPurpose
--reasoning-parserExtracts reasoning content from model outputs in the SMG gateway. The engine also uses the parser's single-token block markers to emit cumulative reasoning_tokens in output batches, independently of --grammar-backend. The engine uses the same markers to enforce a request's thinking_budget, which requires --grammar-backend xgrammar. For budget behavior, see Thinking budget on this page. Parsers without known markers report zero reasoning_tokens.
--tool-call-parserParses OpenAI-compatible tool-call payloads in the SMG gateway.

Parser values ​

Common --reasoning-parser values include kimi_k25, base, qwen3, deepseek_r1, deepseek_v31, and deepseek_v41. Common --tool-call-parser values include kimik2, qwen, deepseek_v4, json, and passthrough.

The SMG gateway validates parser names. Use the values accepted by the bundled tokenspeed-smg package.

Default parser selection ​

When you specify neither parser and the model family has no parser defaults, ts serve passes --reasoning-parser passthrough to the gateway. If the model's tokenizer_config.json declares a response_template and you have not supplied another --tokenizer, ts serve instead passes --parser symphony, --reasoning-parser hf, and --tool-call-parser hf. The bundled tokenspeed-smg gateway then selects both parsers from that template. Any parser option that you name keeps its existing behavior.

Thinking budget ​

Requirements ​

A request's thinking_budget bounds how many tokens its reasoning block may hold. The engine reads the budget from the request's sampling parameters. The Dynamo frontend carries it as thinking_budget or nvext.max_thinking_tokens. If a gateway's request schema has neither field, the gateway cannot pass on the budget, and the reasoning block remains unbounded.

The engine enforces a budget only when all of the following conditions are true:

  • The server sets --reasoning-parser to a parser with known single-token block markers, such as longcat_xml.
  • The server uses --grammar-backend xgrammar.
  • The prompt ends inside an open reasoning block. In other words, the last marker in the prompt is the opening marker, as produced by a chat template that runs with thinking enabled.

Budget enforcement ​

Once the reasoning block contains thinking_budget tokens, the grammar bitmask permits only the closing marker at the next position. If the model has already started a multi-token implicit closing sequence, the bitmask also permits the next token in that sequence. The answer follows the closing marker. A budget of 0 closes the block at the first token.

The model can close the block before it exhausts the budget. DeepSeek V4.1 can also end reasoning with its tool-block opener, which acts as an implicit closing sequence. After the block ends, the budget no longer constrains generation.

The closing marker remains an ordinary sampled token. Grammar enforcement does not rewrite the tokens seen by speculative verification, the accepted frontier, or the request's token history. The count depends only on the prompt and the committed output, so prefix caching and either role of a disaggregated deployment do not change it.

JSON Schema compatibility ​

You can combine a budget with json_schema. The engine holds the reasoning block to the budget inside the same structural tag that makes the schema wait for the block, so one grammar carries both constraints. Each distinct budget value compiles and caches its own grammar for a given schema.

Request validation ​

A non-negative budget has no effect when the prompt does not end inside an open block or the server's parser has no known single-token markers. In these cases, the request runs as if it had no budget.

The server returns an HTTP 400 Bad Request status code in the following cases:

  • The budget is negative, regardless of the prompt.
  • The prompt ends inside an open block, and the server runs with --grammar-backend none. Budget enforcement requires the grammar bitmask.
  • The prompt ends inside an open block, and the request combines the budget with regex, ebnf, or structural_tag; with a json_object response; or with a json_schema value that is not valid JSON. These options constrain the reply from its first token, including the reasoning block.

TokenSpeed documentation