{"record":{"id":"c175fc41550549ee","repo":"sgl-project/sglang","slug":"thinking-budget-tokens-must-be-1024-got","errorCode":null,"errorMessage":"thinking.budget_tokens must be >= 1024 (got {})","messagePattern":"thinking\\.budget_tokens must be >= 1024 \\(got (.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/srt/entrypoints/anthropic/protocol.py","lineNumber":291,"sourceCode":"    budget is not enforced. ``display=\"omitted\"`` is accepted but\n    similarly cannot suppress reasoning mid-stream and is logged.\n    \"\"\"\n\n    type: Literal[\"enabled\", \"disabled\", \"adaptive\"]\n    budget_tokens: Optional[int] = None\n    display: Optional[Literal[\"summarized\", \"omitted\"]] = None\n\n    @model_validator(mode=\"after\")\n    def _validate_thinking_shape(self):\n        # Cross-field rules mirror the SDK's three discriminated variants.\n        if self.type == \"enabled\":\n            if self.budget_tokens is None:\n                raise ValueError(\n                    \"thinking.budget_tokens is required when \"\n                    \"thinking.type is 'enabled'\"\n                )\n            if self.budget_tokens < 1024:\n                raise ValueError(\n                    \"thinking.budget_tokens must be >= 1024 \"\n                    \"(got {})\".format(self.budget_tokens)\n                )\n        elif self.type == \"disabled\":\n            if self.budget_tokens is not None:\n                raise ValueError(\n                    \"thinking.budget_tokens is not allowed when \"\n                    \"thinking.type is 'disabled'\"\n                )\n            if self.display is not None:\n                raise ValueError(\n                    \"thinking.display is not allowed when \"\n                    \"thinking.type is 'disabled'\"\n                )\n        elif self.type == \"adaptive\":\n            if self.budget_tokens is not None:\n                raise ValueError(\n                    \"thinking.budget_tokens is not allowed when \"","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/anthropic/protocol.py#L273-L309","documentation":"Raised by the Anthropic-compatible endpoint's pydantic field validator when a request sets thinking.type='enabled' with a budget_tokens value below 1024. SGLang mirrors the Anthropic API contract that enabled extended thinking requires a budget of at least 1024 tokens. It is a request-validation error surfaced as a 400 before any inference occurs.","triggerScenarios":"POST /v1/messages with body {\"thinking\": {\"type\": \"enabled\", \"budget_tokens\": 512}} (or any value < 1024). Only fires when type=='enabled'; budget_tokens must be present and >= 1024.","commonSituations":"Porting an OpenAI-style reasoning_effort setting to a small token budget, copying a low budget from another provider, or assuming budget_tokens is optional/permissive. Clients that dynamically compute budget as a fraction of max_tokens can produce < 1024 for short requests.","solutions":["Set thinking.budget_tokens to at least 1024","Ensure budget_tokens is less than max_tokens (Anthropic also requires max_tokens > budget_tokens)","If you want no thinking, use thinking.type='disabled' and omit budget_tokens"],"exampleFix":"// before\n{\"thinking\": {\"type\": \"enabled\", \"budget_tokens\": 512}, \"max_tokens\": 2048}\n// after\n{\"thinking\": {\"type\": \"enabled\", \"budget_tokens\": 1536}, \"max_tokens\": 4096}","handlingStrategy":"validation","validationCode":"def check_thinking(thinking):\n    if thinking.get(\"type\") == \"enabled\":\n        b = thinking.get(\"budget_tokens\")\n        if b is None or b < 1024:\n            raise ValueError(\"budget_tokens must be >= 1024\")","typeGuard":null,"tryCatchPattern":"try: resp = client.messages.create(...)\nexcept ValueError as e:\n    if 'budget_tokens' in str(e): fix_budget_and_retry()\n    else: raise","preventionTips":["Validate thinking config in one shared builder function","Keep budget_tokens >= 1024 and < max_tokens"],"tags":["anthropic","thinking","validation","request-validation","pydantic"],"backgroundTag":"request-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}