Anthropic Sonnet 4.5 fails in LangGraph: top_p set to -1 by default #364

Closed
opened 2026-02-15 18:16:14 -05:00 by yindo · 1 comment
Owner

Originally created by @pavlo-tkhir on GitHub (Sep 29, 2025).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).

Example Code

The following code


import { ChatAnthropic } from "@langchain/anthropic";
import { HumanMessage } from "@langchain/core/messages";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

const agentModel = new ChatAnthropic({
  modelName: "claude-sonnet-4-5"
});

const agent = createReactAgent({
  llm: agentModel,
  tools: []
});

const messagesResponse = await agent.invoke(
  { messages: [new HumanMessage("Hello world")] },
  { streamMode: "messages" }
);

Error Message and Stack Trace (if applicable)

node:internal/modules/run_main:123
    triggerUncaughtException(
    ^

BadRequestError: 400 {"type":"error","error":{"type":"invalid_request_error","message":"`top_p` cannot be set to -1 for this model."},"request_id":"req_011CTdN3E89wfFad1sM7HCPC"}
    at Function.generate (/Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/@langchain/anthropic/node_modules/@anthropic-ai/sdk/src/core/error.ts:63:14)
    at Anthropic.makeStatusError (/Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/@langchain/anthropic/node_modules/@anthropic-ai/sdk/src/client.ts:412:28)
    at Anthropic.makeRequest (/Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/@langchain/anthropic/node_modules/@anthropic-ai/sdk/src/client.ts:645:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async makeCompletionRequest (file:///Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/@langchain/anthropic/dist/chat_models.js:858:24)
    at async RetryOperation._fn (/Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/p-retry/index.js:50:12) {
  status: 400,
  headers: Headers {},
  requestID: 'req_011CTdN3E89wfFad1sM7HCPC',
  error: {
    type: 'error',
    error: {
      type: 'invalid_request_error',
      message: '`top_p` cannot be set to -1 for this model.'
    },
    request_id: 'req_011CTdN3E89wfFad1sM7HCPC'
  },
  attemptNumber: 1,
  retriesLeft: 6,
  pregelTaskId: '74bee9cf-1d26-5257-bc1c-c9dcd1760bcf'
}

Node.js v20.19.1

Description

  • I'm trying to call "claude-sonnet-4-5" model without providing any parameters
  • I expect to get a response (the same code works for 4.0 model)
  • Setting topP to any non -1 value fails with another error: {"type":"invalid_request_error","message":"temperature and top_p cannot both be specified for this model. Please use only one."}

System Info

Node version: v20.19.1
Operating system: darwin arm64
Package manager: npm
Package manager version: N/A

@langchain/anthropic -> @0.3.28, , @"^0.3.28", @"*"
@langchain/core -> @0.3.78, , @"^0.3.78", @">=0.3.58, @">=0.2.31, @">=0.2.21
@langchain/community -> @0.3.49, , @"^0.3.49"
zod -> @3.25.76, , @"^3.25.76", @"^3.23.8", @"^3.25.32", @"^3.24.1"
@langchain/weaviate -> @0.2.1, , @"^0.2.0"
langchain -> @0.3.30, , @">=0.2.3

Originally created by @pavlo-tkhir on GitHub (Sep 29, 2025). ### Checked other resources - [x] I added a very descriptive title to this issue. - [x] I searched the LangGraph.js documentation with the integrated search. - [x] I used the GitHub search to find a similar question and didn't find it. - [x] I am sure that this is a bug in LangGraph.js rather than my code. - [x] The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package). ### Example Code The following code ```typescript import { ChatAnthropic } from "@langchain/anthropic"; import { HumanMessage } from "@langchain/core/messages"; import { createReactAgent } from "@langchain/langgraph/prebuilt"; const agentModel = new ChatAnthropic({ modelName: "claude-sonnet-4-5" }); const agent = createReactAgent({ llm: agentModel, tools: [] }); const messagesResponse = await agent.invoke( { messages: [new HumanMessage("Hello world")] }, { streamMode: "messages" } ); ``` ### Error Message and Stack Trace (if applicable) ``` node:internal/modules/run_main:123 triggerUncaughtException( ^ BadRequestError: 400 {"type":"error","error":{"type":"invalid_request_error","message":"`top_p` cannot be set to -1 for this model."},"request_id":"req_011CTdN3E89wfFad1sM7HCPC"} at Function.generate (/Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/@langchain/anthropic/node_modules/@anthropic-ai/sdk/src/core/error.ts:63:14) at Anthropic.makeStatusError (/Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/@langchain/anthropic/node_modules/@anthropic-ai/sdk/src/client.ts:412:28) at Anthropic.makeRequest (/Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/@langchain/anthropic/node_modules/@anthropic-ai/sdk/src/client.ts:645:24) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async makeCompletionRequest (file:///Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/@langchain/anthropic/dist/chat_models.js:858:24) at async RetryOperation._fn (/Users/gecko/Documents/Work/01-personal/craftbase/platform/src/playground/langgraph-playground/custom-agents/node_modules/p-retry/index.js:50:12) { status: 400, headers: Headers {}, requestID: 'req_011CTdN3E89wfFad1sM7HCPC', error: { type: 'error', error: { type: 'invalid_request_error', message: '`top_p` cannot be set to -1 for this model.' }, request_id: 'req_011CTdN3E89wfFad1sM7HCPC' }, attemptNumber: 1, retriesLeft: 6, pregelTaskId: '74bee9cf-1d26-5257-bc1c-c9dcd1760bcf' } Node.js v20.19.1 ``` ### Description * I'm trying to call "claude-sonnet-4-5" model without providing any parameters * I expect to get a response (the same code works for 4.0 model) * Setting topP to any non -1 value fails with another error: {"type":"invalid_request_error","message":"`temperature` and `top_p` cannot both be specified for this model. Please use only one."} ### System Info Node version: v20.19.1 Operating system: darwin arm64 Package manager: npm Package manager version: N/A -------------------- @langchain/anthropic -> @0.3.28, , @"^0.3.28", @"*" @langchain/core -> @0.3.78, , @"^0.3.78", @">=0.3.58, @">=0.2.31, @">=0.2.21 @langchain/community -> @0.3.49, , @"^0.3.49" zod -> @3.25.76, , @"^3.25.76", @"^3.23.8", @"^3.25.32", @"^3.24.1" @langchain/weaviate -> @0.2.1, , @"^0.2.0" langchain -> @0.3.30, , @">=0.2.3
yindo closed this issue 2026-02-15 18:16:14 -05:00
Author
Owner

@hntrl commented on GitHub (Sep 29, 2025):

Hey @pavlo-tkhir! See the related issue in langchainjs. Upgrading to @langchain/anthropic@0.3.29 will fix.

@hntrl commented on GitHub (Sep 29, 2025): Hey @pavlo-tkhir! See the [related issue](https://github.com/langchain-ai/langchainjs/issues/9067) in langchainjs. Upgrading to `@langchain/anthropic@0.3.29` will fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#364