AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

ChatAnthropic Forwards Deprecated Top_k To Claude Opus 5 Causing HTTP 400

ChatAnthropic in langchain-anthropic 1.6.1 sends top_k=10 to claude-opus-5, which Anthropic has deprecated for Opus 4.7 and later, resulting in a 400 BadRequestError. The client should validate locally and reject unsupported parameters before making a network request.

highConfidence 92%Langchain-AnthropicAffected V1.6.1

Origin Analysis

langchain-anthropic's ChatAnthropic includes top_k in the request payload whenever it is not None, without model-specific validation of deprecated sampling parameters. Anthropic's API rejects non-default values of temperature, top_p, and top_k for Opus 4.7+ models, but the client does not check this before sending.
1. Set ANTHROPIC_API_KEY. 2. Run: ```python import os import anthropic from langchain_anthropic import ChatAnthropic model = 'claude-opus-5' control = ChatAnthropic(model=model, max_tokens=8, max_retries=0) print(control.invoke('Reply with exactly: hi').content) subject = ChatAnthropic(model=model, top_k=10, max_tokens=8, max_retries=0) print(subject.invoke('Reply with exactly: hi').content) ``` 3. Observe: control succeeds; subject raises anthropic.BadRequestError with status 400 and message '`top_k` is deprecated for this model.'

Fixing Code Block

Edge Case Audit

This hotfix only addresses top_k; temperature and top_p remain vulnerable to the same deprecation and may still cause 400 errors if users set non-default values. The list of deprecated models is hardcoded and must be updated as Anthropic adds or renames models. Users who previously relied on the client silently forwarding top_k will now get an exception, but this is intended behavior. Rollback: revert this method to the previous version to restore old behavior.

Ecosystem Topology