From 75e9bb2feadb4d80ef8263f503d22e32a53b8937 Mon Sep 17 00:00:00 2001 From: Ben Kunkle Date: Wed, 23 Sep 2026 01:32:37 +0000 Subject: [PATCH] anthropic: Add Claude Opus 5.5 BYOK support (#64627) # Objective - Make Claude Opus 5.5 usable through Anthropic API keys. ## Solution - Apply Opus 5.5's adaptive-thinking, sampling, tool-choice, Fast mode, compaction, and prefix-binding requirements through the shared Anthropic request path. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - Added Claude Opus 5.5 support to the Anthropic provider. Co-authored-by: Anant Goel --- crates/anthropic/src/anthropic.rs | 17 ++++++--- crates/anthropic/src/completion.rs | 28 +++++++++++++-- .../src/language_models_cloud.rs | 36 ++++++++++++++----- 3 files changed, 64 insertions(+), 17 deletions(-) diff --git a/crates/anthropic/src/anthropic.rs b/crates/anthropic/src/anthropic.rs index ed1e761c894..a8c2fb4f50b 100644 --- a/crates/anthropic/src/anthropic.rs +++ b/crates/anthropic/src/anthropic.rs @@ -22,7 +22,10 @@ pub const ANTHROPIC_API_URL: &str = "https://api.anthropic.com"; pub const FAST_MODE_BETA_HEADER: &str = "fast-mode-2026-02-01"; pub fn supports_fast_mode(model_id: &str) -> bool { - matches!(model_id, "claude-opus-5" | "claude-opus-4-8") + matches!( + model_id, + "claude-opus-5-5" | "claude-opus-5" | "claude-opus-4-8" + ) } /// Model IDs where adaptive thinking runs by default when a request omits the @@ -45,11 +48,14 @@ pub const FABLE_FALLBACK_MODEL_ID: &str = "claude-opus-4-8"; pub const THINKING_BINDING_CONTROLS_BETA_HEADER: &str = "thinking-binding-controls-2026-08-01"; pub fn binds_thinking_blocks_to_prefix(model_id: &str) -> bool { - matches!(model_id, "claude-fable-5-1") + matches!(model_id, "claude-opus-5-5" | "claude-fable-5-1") } pub fn supports_forced_tool_use(model_id: &str) -> bool { - !matches!(model_id, "claude-fable-5-1" | "claude-mythos-5-1") + !matches!( + model_id, + "claude-opus-5-5" | "claude-fable-5-1" | "claude-mythos-5-1" + ) } /// @@ -192,7 +198,8 @@ impl Model { // let supports_compaction = matches!( entry.id.as_str(), - "claude-fable-5-1" + "claude-opus-5-5" + | "claude-fable-5-1" | "claude-fable-5" | "claude-mythos-5-1" | "claude-mythos-5" @@ -1834,7 +1841,7 @@ mod tests { #[test] fn from_listed_enables_fast_mode_and_compaction_for_supported_opus_models() { - for model_id in ["claude-opus-5", "claude-opus-4-8"] { + for model_id in ["claude-opus-5-5", "claude-opus-5", "claude-opus-4-8"] { let model = Model::from_listed(listed_entry(model_id, ModelCapabilities::default())); assert!(model.supports_speed); diff --git a/crates/anthropic/src/completion.rs b/crates/anthropic/src/completion.rs index 7fdfeb319ec..2e6674c7b92 100644 --- a/crates/anthropic/src/completion.rs +++ b/crates/anthropic/src/completion.rs @@ -290,6 +290,12 @@ pub fn into_anthropic( cache_mode: AnthropicPromptCacheMode, compaction_state_owner: &LanguageModelProviderId, ) -> Result { + let requires_adaptive_thinking = model == "claude-opus-5-5"; + let mode = if requires_adaptive_thinking { + AnthropicModelMode::AdaptiveThinking + } else { + mode + }; let max_output_tokens = request .max_output_tokens .map_or(max_output_tokens, |limit| limit.min(max_output_tokens)); @@ -429,6 +435,14 @@ pub fn into_anthropic( None }; + // Opus 5.5 always uses adaptive thinking, which does not accept sampling controls. + // + let temperature = if requires_adaptive_thinking { + None + } else { + request.temperature.or(Some(default_temperature)) + }; + Ok(crate::Request { model, messages: new_messages, @@ -473,7 +487,7 @@ pub fn into_anthropic( }, stop_sequences: Vec::new(), speed: request.speed.map(Into::into), - temperature: request.temperature.or(Some(default_temperature)), + temperature, top_k: None, top_p: None, context_management: request.compact_at_tokens.map(|value| ContextManagement { @@ -1120,6 +1134,7 @@ mod tests { // its requests opt into dropping invalidated blocks instead. Models // without the prefix-binding check must not receive the beta field. for (model, expects_block_binding) in [ + ("claude-opus-5-5", true), ("claude-fable-5-1", true), ("claude-fable-5", false), ("claude-mythos-5-1", false), @@ -1189,10 +1204,11 @@ mod tests { // (model, expects_explicit_opt_out): Claude Opus 5 thinks by default // when the `thinking` field is omitted, so suppressing thinking // requires sending `{"type": "disabled"}`. Earlier Opus models treat - // omission as "off", and Fable rejects `disabled` outright, so both - // must keep omitting the field. + // omission as "off", while Opus 5.5 and Fable reject `disabled` + // outright, so those models must keep omitting the field. for (model, expects_explicit_opt_out) in [ ("claude-opus-5", true), + ("claude-opus-5-5", false), ("claude-opus-4-8", false), ("claude-fable-5", false), ] { @@ -1246,6 +1262,12 @@ mod tests { "{model} should omit the thinking field entirely" ); } + if model == "claude-opus-5-5" { + assert!( + anthropic_request.temperature.is_none(), + "{model} must omit temperature because adaptive thinking is always on" + ); + } } } diff --git a/crates/language_models_cloud/src/language_models_cloud.rs b/crates/language_models_cloud/src/language_models_cloud.rs index a3dbd57cd6f..6aa0fc2c164 100644 --- a/crates/language_models_cloud/src/language_models_cloud.rs +++ b/crates/language_models_cloud/src/language_models_cloud.rs @@ -271,7 +271,9 @@ impl CloudLanguageModel { self.model.id.to_string(), 1.0, self.model.max_output_tokens as u64, - if enable_thinking { + if enable_thinking && effort.is_some() { + AnthropicModelMode::AdaptiveThinking + } else if enable_thinking { AnthropicModelMode::Thinking { budget_tokens: Some(4_096), } @@ -281,14 +283,6 @@ impl CloudLanguageModel { AnthropicPromptCacheMode::Automatic, &ANTHROPIC_PROVIDER_ID, )?; - if enable_thinking && effort.is_some() { - request.thinking = Some(anthropic::Thinking::Adaptive { - display: Some(anthropic::AdaptiveThinkingDisplay::Summarized), - // The cloud proxy owns the beta header needed for block binding. - block_binding: None, - }); - request.output_config = Some(anthropic::OutputConfig { effort }); - } if !self.model.supports_fast_mode { request.speed = None; } @@ -2114,6 +2108,30 @@ mod tests { ); } + #[test] + fn opus_55_hosted_requests_use_adaptive_thinking_with_prefix_binding() -> Result<()> { + let mut model = cloud_anthropic_test_model(FakeHttpClient::with_404_response()); + Arc::make_mut(&mut model.model).id = + cloud_llm_client::LanguageModelId("claude-opus-5-5".into()); + for effort in [None, Some("high")] { + let request = model.anthropic_request(LanguageModelRequest { + thinking_allowed: true, + thinking_effort: effort.map(str::to_string), + temperature: Some(0.25), + ..Default::default() + })?; + let body = serde_json::to_value(request)?; + assert_eq!(body["thinking"]["type"], "adaptive"); + assert_eq!( + body["thinking"]["block_binding"]["prefix_mismatch_behavior"], + "drop_block" + ); + assert_eq!(body["output_config"]["effort"].as_str(), effort); + assert!(body.get("temperature").is_none()); + } + Ok(()) + } + #[gpui::test] async fn retention_consent_gates_counting_compaction_and_generation( cx: &mut gpui::TestAppContext,