From b5aa6ffd7df401d68fd014c6b0cc6a48e11c32b7 Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Tue, 12 May 2026 14:10:24 +0400 Subject: [PATCH] studio: stop forwarding top_k to Anthropic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude 4.x (Opus / Sonnet / Haiku 4.x) returns 400 'top_k is deprecated for this model' on any request that includes top_k. It was always optional on the older 3.x line, so dropping it unconditionally for every Anthropic call is the simplest path — no per-model gate to maintain. - external_provider._stream_anthropic no longer adds top_k to the Messages body (kept on the method signature for API symmetry). - provider-capabilities sets anthropic.topK = false so the chat settings panel hides the Top K slider for Anthropic providers and chat-adapter does not send top_k in the external request. --- studio/backend/core/inference/external_provider.py | 9 +++++++-- .../frontend/src/features/chat/provider-capabilities.ts | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/studio/backend/core/inference/external_provider.py b/studio/backend/core/inference/external_provider.py index f18075a6a3..04f9b15c74 100644 --- a/studio/backend/core/inference/external_provider.py +++ b/studio/backend/core/inference/external_provider.py @@ -276,8 +276,13 @@ class ExternalProviderClient: # Anthropic rejects requests that set both temperature and top_p "stream": True, } - if top_k is not None and top_k > 0: - body["top_k"] = top_k + # top_k is deprecated on Claude 4.x (Opus / Sonnet / Haiku 4.x return + # 400 with `top_k is deprecated for this model`). It was always + # optional on the older 3.x line too, so we just stop forwarding it + # for every Anthropic call rather than maintaining a per-model gate. + # ``top_k`` is still accepted on the method signature for API + # symmetry with the other stream methods. + del top_k if system: body["system"] = system diff --git a/studio/frontend/src/features/chat/provider-capabilities.ts b/studio/frontend/src/features/chat/provider-capabilities.ts index fd96aa3d6b..b02ec4eaaa 100644 --- a/studio/frontend/src/features/chat/provider-capabilities.ts +++ b/studio/frontend/src/features/chat/provider-capabilities.ts @@ -75,11 +75,14 @@ const PROVIDER_CAPABILITIES: Record = { repetitionPenalty: false, presencePenalty: false, }, - // Anthropic's Messages API accepts top_k but not presence/frequency penalty. + // Anthropic's Messages API rejects presence/frequency penalty, and top_k + // is now deprecated across the Claude 4.x line (Opus / Sonnet / Haiku 4.x + // 400 with "top_k is deprecated for this model"). It was always optional + // on the older 3.x line, so we just drop it for every Anthropic call. anthropic: { temperature: true, topP: true, - topK: true, + topK: false, minP: false, repetitionPenalty: false, presencePenalty: false,