fix: strip top_p and guard temperature for Claude 4.x Anthropic models#184
Open
robertnama wants to merge 1 commit into
Open
fix: strip top_p and guard temperature for Claude 4.x Anthropic models#184robertnama wants to merge 1 commit into
robertnama wants to merge 1 commit into
Conversation
Claude 4.x models reject requests that specify both temperature and top_p simultaneously (HTTP 400). Additionally, Opus 4.x models and claude-3-7-sonnet have deprecated the temperature parameter entirely (also HTTP 400). - Remove top_p from all Anthropic API requests - Skip temperature for model IDs starting with claude-opus-4- or claude-3-7-sonnet; all other models keep their configured temperature Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PyGPT sends both
temperatureandtop_pto the Anthropic API simultaneously. Claude 4.x models reject this combination with HTTP 400:Additionally, the entire Opus 4.x family (
claude-opus-4-0,claude-opus-4-5,claude-opus-4-7, …) andclaude-3-7-sonnet(extended-thinking models) have deprecatedtemperatureentirely — any request that includes it returns HTTP 400:Fix
In
src/pygpt_net/provider/api/anthropic/chat.py, replace the unconditionaltemperature+top_pblock with a model-aware version:top_pis never sent to Anthropic (always causes the error whentemperatureis also present)temperatureis omitted for model IDs starting withclaude-opus-4-orclaude-3-7-sonnet; all other models keep their configured valueModels tested
claude-sonnet-4-5,claude-sonnet-4-6,claude-3-*claude-opus-4-*,claude-3-7-sonnet-*Notes
The
_no_tempprefix tuple can be extended as Anthropic deprecatestemperatureon further models.