Skip to content

fix: strip top_p and guard temperature for Claude 4.x Anthropic models#184

Open
robertnama wants to merge 1 commit into
szczyglis-dev:masterfrom
robertnama:fix/anthropic-temperature-top-p-claude4x
Open

fix: strip top_p and guard temperature for Claude 4.x Anthropic models#184
robertnama wants to merge 1 commit into
szczyglis-dev:masterfrom
robertnama:fix/anthropic-temperature-top-p-claude4x

Conversation

@robertnama
Copy link
Copy Markdown

Problem

PyGPT sends both temperature and top_p to the Anthropic API simultaneously. Claude 4.x models reject this combination with HTTP 400:

temperature and top_p cannot both be specified for this model

Additionally, the entire Opus 4.x family (claude-opus-4-0, claude-opus-4-5, claude-opus-4-7, …) and claude-3-7-sonnet (extended-thinking models) have deprecated temperature entirely — any request that includes it returns HTTP 400:

`temperature` is deprecated for this model

Fix

In src/pygpt_net/provider/api/anthropic/chat.py, replace the unconditional temperature + top_p block with a model-aware version:

  • top_p is never sent to Anthropic (always causes the error when temperature is also present)
  • temperature is omitted for model IDs starting with claude-opus-4- or claude-3-7-sonnet; all other models keep their configured value

Models tested

Model temperature top_p
claude-sonnet-4-5, claude-sonnet-4-6, claude-3-* ✅ sent ❌ removed
claude-opus-4-*, claude-3-7-sonnet-* ❌ removed ❌ removed

Notes

The _no_temp prefix tuple can be extended as Anthropic deprecates temperature on further models.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant