Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: honor the effort level Claude Code sends on /v1/messages (#9941)
Nilay565cecd40b7e
diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.pyindex b9efa173906..1f73bf47b48 100644--- a/studio/backend/models/inference.py+++ b/studio/backend/models/inference.py@@ -3265,6 +3265,9 @@ class AnthropicThinkingConfig(BaseModel):model_config = {"extra": "allow"}+_ANTHROPIC_EFFORT_LEVELS = frozenset({"none", "minimal", "low", "medium", "high", "max", "xhigh"})++class AnthropicMessagesRequest(BaseModel):model: str = "default"max_tokens: Optional[int] = None@@ -3301,6 +3304,9 @@ class AnthropicMessagesRequest(BaseModel):Literal["none", "minimal", "low", "medium", "high", "max", "xhigh"]] = Nonepreserve_thinking: Optional[bool] = None+ # Anthropic's current spelling of the effort dial. Claude Code sends the tier+ # here, never in reasoning_effort, so without this the level is dropped.+ output_config: Optional[dict] = Nonesession_id: Optional[str] = Nonethread_id: Optional[str] = Field(None,@@ -3325,6 +3331,22 @@ class AnthropicMessagesRequest(BaseModel):)model_config = {"extra": "allow"}+ @model_validator(mode = "after")+ def _effort_from_output_config(self) -> "AnthropicMessagesRequest":+ if self.reasoning_effort is not None or not isinstance(self.output_config, dict):+ return self+ # Only once thinking is already on. `reasoning_effort` is the x-unsloth+ # override that deliberately outranks `thinking` (a named level means+ # "think"), but Claude Code sends output_config.effort on EVERY request,+ # including with thinking off -- adopting it there would re-enable+ # thinking the caller switched off and pin the level the user never set.+ if self.resolved_enable_thinking() is not True:+ return self+ effort = self.output_config.get("effort")+ if isinstance(effort, str) and effort in _ANTHROPIC_EFFORT_LEVELS:+ self.reasoning_effort = effort+ return self+def resolved_enable_thinking(self) -> Optional[bool]:"""Effective on/off, preferring the x-unsloth field over `thinking`."""if self.enable_thinking is not None:diff --git a/studio/backend/tests/test_anthropic_messages.py b/studio/backend/tests/test_anthropic_messages.pyindex 93e7a199cd1..245e2d04530 100644--- a/studio/backend/tests/test_anthropic_messages.py+++ b/studio/backend/tests/test_anthropic_messages.py@@ -4527,3 +4527,69 @@ class TestPreserveThinkingHonoursTheBackendDefault:asyncio.run(anthropic_count_tokens(payload, request = _Request(), current_subject = "t"))assert seen["count_messages"] == gen_messages+++def test_effort_resolved_from_output_config():+ # Claude Code sends the tier as output_config.effort, never as reasoning_effort.+ assert (+ _basic_payload(+ output_config = {"effort": "high"}, thinking = {"type": "adaptive"}+ ).reasoning_effort+ == "high"+ )+++def test_explicit_reasoning_effort_outranks_output_config():+ assert (+ _basic_payload(output_config = {"effort": "low"}, reasoning_effort = "max").reasoning_effort+ == "max"+ )+++def test_unknown_output_config_effort_is_ignored():+ # thinking on, so an ignored level is the level check talking, not the gate below.+ adaptive = {"type": "adaptive"}+ assert (+ _basic_payload(output_config = {"effort": "turbo"}, thinking = adaptive).reasoning_effort+ is None+ )+ assert (+ _basic_payload(+ output_config = {"format": {"type": "json"}}, thinking = adaptive+ ).reasoning_effort+ is None+ )+++# Claude Code sends output_config.effort on every request, thinking on or off, so+# adopting it unconditionally would turn `reasoning_effort` into an always-present+# override -- and a named level means "think" from _anthropic_reasoning_args down.+_EFFORT_THINKING_OFF_SHAPES = [+ ({}, None),+ ({"thinking": {"type": "disabled"}}, False),+ ({"enable_thinking": False}, False),+]++[email protected]("fields, expected_enable", _EFFORT_THINKING_OFF_SHAPES)+def test_output_config_effort_never_switches_thinking_back_on(fields, expected_enable):+ from routes.inference import _anthropic_reasoning_args++ payload = _basic_payload(output_config = {"effort": "high"}, **fields)+ # Left unset, so nothing downstream reads a level the caller never asked for.+ assert payload.reasoning_effort is None+ args = _anthropic_reasoning_args(payload)+ assert args["enable_thinking"] is expected_enable+ assert args["reasoning_effort"] is None+++def test_x_unsloth_effort_still_outranks_thinking_when_sent_explicitly():+ # The gate applies to output_config only: an explicit reasoning_effort keeps+ # the documented precedence covered by _THINKING_EFFORT_MATRIX.+ from routes.inference import _anthropic_reasoning_args++ args = _anthropic_reasoning_args(+ _basic_payload(thinking = {"type": "disabled"}, reasoning_effort = "high")+ )+ assert args["enable_thinking"] is True+ assert args["reasoning_effort"] == "high"