diff --git a/backend/app/llm/client.py b/backend/app/llm/client.py index f9951fa0..9fc6a5b9 100644 --- a/backend/app/llm/client.py +++ b/backend/app/llm/client.py @@ -116,6 +116,14 @@ def __init__(self, model_config: ModelConfig): self.api_key = api_key self.model = model_config.model self.temperature = model_config.temperature + # Reasoning models on some gateways reject the `temperature` parameter + # entirely. Omit it for the Anthropic Messages protocol so those models + # (e.g. Claude Opus 4.8) accept the request; other protocols keep it. + self.request_temperature = ( + None + if protocol is ModelApiProtocol.ANTHROPIC_MESSAGES + else self.temperature + ) self.max_output_tokens = model_config.max_output_tokens legacy_extra_body = getattr(model_config, "legacy_extra_body", {}) protocol_options = getattr(model_config, "protocol_options", {}) @@ -160,7 +168,7 @@ def generate_text( request: dict[str, Any] = { "model": self.model, "messages": request_messages, - "temperature": self.temperature, + "temperature": self.request_temperature, "max_tokens": max_output_tokens, } if cancellation is not None: @@ -290,7 +298,7 @@ def generate_text_stream( stream_request = { "model": self.model, "messages": request_messages, - "temperature": self.temperature, + "temperature": self.request_temperature, "max_tokens": current_max_tokens, **_thinking_request_kwargs( getattr(self, "thinking_mode", ""), diff --git a/backend/app/llm/protocol_drivers.py b/backend/app/llm/protocol_drivers.py index 5c3d46e0..1706e9e3 100644 --- a/backend/app/llm/protocol_drivers.py +++ b/backend/app/llm/protocol_drivers.py @@ -388,8 +388,12 @@ def _anthropic_request(request: dict[str, Any]) -> dict[str, Any]: "model": request["model"], "messages": converted, "max_tokens": request["max_tokens"], - "temperature": request["temperature"], } + # Some gateways expose reasoning models (e.g. Claude Opus 4.8) that reject the + # `temperature` parameter outright. Only include it when a value is provided. + temperature = request.get("temperature") + if temperature is not None: + payload["temperature"] = temperature system = "\n\n".join(part for part in system_parts if part) if system: payload["system"] = system