sgl-project/sglang · error · ValueError
thinking.budget_tokens is not allowed when thinking.type is
Error message
thinking.budget_tokens is not allowed when thinking.type is 'adaptive'
What it means
Raised by the Anthropic-compatible endpoint's validator when thinking.type='adaptive' (SGLang's adaptive thinking mode) and a budget_tokens value is also supplied. Adaptive thinking decides the budget itself, so an explicit budget_tokens is contradictory and rejected with a 400.
Source
Thrown at python/sglang/srt/entrypoints/anthropic/protocol.py:308
if self.budget_tokens < 1024:
raise ValueError(
"thinking.budget_tokens must be >= 1024 "
"(got {})".format(self.budget_tokens)
)
elif self.type == "disabled":
if self.budget_tokens is not None:
raise ValueError(
"thinking.budget_tokens is not allowed when "
"thinking.type is 'disabled'"
)
if self.display is not None:
raise ValueError(
"thinking.display is not allowed when "
"thinking.type is 'disabled'"
)
elif self.type == "adaptive":
if self.budget_tokens is not None:
raise ValueError(
"thinking.budget_tokens is not allowed when "
"thinking.type is 'adaptive'"
)
return self
class AnthropicTaskBudget(BaseModel):
"""Claude 4.7 ``output_config.task_budget`` — soft hint, not a hard cap.
Mirrors ``BetaTokenTaskBudgetParam`` in the Anthropic SDK: ``total``
and ``type`` are required; ``remaining`` is the client-tracked
countdown used for compaction. The hard cap on generation is still
``max_tokens``; we never enforce ``task_budget`` ourselves.
"""
type: Literal["tokens"]
total: int = Field(gt=0)
remaining: Optional[int] = Field(default=None, ge=0)View on GitHub (pinned to 0132848349)
Solutions
- Remove budget_tokens when using thinking.type='adaptive'
- Use thinking.type='enabled' with budget_tokens if you need an explicit cap
Example fix
// before
{"thinking": {"type": "adaptive", "budget_tokens": 2048}}
// after
{"thinking": {"type": "adaptive"}} Defensive patterns
Strategy: validation
Validate before calling
if thinking["type"] == "adaptive":
thinking = {"type": "adaptive"} Prevention
- Adaptive mode takes no budget; don't reuse enabled-mode payloads
When it happens
Trigger: POST /v1/messages with {"thinking": {"type": "adaptive", "budget_tokens": 2048}}.
Common situations: Switching a request template from 'enabled' to 'adaptive' without cleaning out budget_tokens; assuming adaptive accepts an upper bound like some providers' adaptive modes do.
Related errors
- thinking.budget_tokens must be >= 1024 (got {})
- thinking.budget_tokens is not allowed when thinking.type is
- thinking.display is not allowed when thinking.type is 'disab
- Model is required
- max_tokens must be positive
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/a5f9150eafd6d722.
Report an issue: GitHub.