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-AnthropicRetrieversAgentslangchain-coreAffected 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

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state