Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
anthropic: Add support for Sonnet and Haiku 5.5 (#65555)
Oleksiy Syvokon077458d9493d
diff --git a/crates/anthropic/src/anthropic.rs b/crates/anthropic/src/anthropic.rsindex a8c2fb4f50b..1b23a88228e 100644--- a/crates/anthropic/src/anthropic.rs+++ b/crates/anthropic/src/anthropic.rs@@ -33,14 +33,14 @@ pub fn supports_fast_mode(model_id: &str) -> bool {/// explicit `thinking: {"type": "disabled"}`.////// On earlier Opus models omitting `thinking` means thinking is off; Claude-/// Opus 5 flipped that default. Claude Fable 5 and Claude Mythos 5 also think-/// by default, but they reject `{"type": "disabled"}` with a 400 error, so-/// they are deliberately excluded here (thinking cannot be turned off for-/// them at all).+/// Opus 5 flipped that default, as did Claude Haiku 5.5. Claude Fable 5 and+/// Claude Mythos 5 also think by default, but they reject `{"type":+/// "disabled"}` with a 400 error, so they are deliberately excluded here+/// (thinking cannot be turned off for them at all).////// <https://platform.claude.com/docs/en/about-claude/models/migration-guide#migrating-to-claude-opus-5>pub fn requires_explicit_thinking_opt_out(model_id: &str) -> bool {- matches!(model_id, "claude-opus-5")+ matches!(model_id, "claude-opus-5" | "claude-haiku-5-5")}pub const FABLE_MODEL_ID_PREFIX: &str = "claude-fable-5";@@ -48,13 +48,16 @@ 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-opus-5-5" | "claude-fable-5-1")+ matches!(+ model_id,+ "claude-opus-5-5" | "claude-fable-5-1" | "claude-sonnet-5-5" | "claude-haiku-5-5"+ )}pub fn supports_forced_tool_use(model_id: &str) -> bool {!matches!(model_id,- "claude-opus-5-5" | "claude-fable-5-1" | "claude-mythos-5-1"+ "claude-opus-5-5" | "claude-fable-5-1" | "claude-mythos-5-1" | "claude-sonnet-5-5")}@@ -208,8 +211,10 @@ impl Model {| "claude-opus-4-8"| "claude-opus-4-7"| "claude-opus-4-6"+ | "claude-sonnet-5-5"| "claude-sonnet-5"| "claude-sonnet-4-6"+ | "claude-haiku-5-5");let mut extra_beta_headers = Vec::new();@@ -900,6 +905,10 @@ pub enum Thinking {/// by default (see [`requires_explicit_thinking_opt_out`]); only accepted/// at effort `high` or below.Disabled,+ /// The lowest thinking setting, for models that think by default but+ /// reject [`Thinking::Disabled`] (Claude Sonnet 5.5).+ #[serde(rename = "between_tools")]+ BetweenTools,}#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]diff --git a/crates/anthropic/src/completion.rs b/crates/anthropic/src/completion.rsindex 2e6674c7b92..b0cf8fde2df 100644--- a/crates/anthropic/src/completion.rs+++ b/crates/anthropic/src/completion.rs@@ -290,7 +290,10 @@ pub fn into_anthropic(cache_mode: AnthropicPromptCacheMode,compaction_state_owner: &LanguageModelProviderId,) -> Result<crate::Request> {- let requires_adaptive_thinking = model == "claude-opus-5-5";+ let requires_adaptive_thinking = matches!(+ model.as_str(),+ "claude-opus-5-5" | "claude-sonnet-5-5" | "claude-haiku-5-5"+ );let mode = if requires_adaptive_thinking {AnthropicModelMode::AdaptiveThinking} else {@@ -422,21 +425,23 @@ pub fn into_anthropic(}),AnthropicModelMode::Default => None,}+ } else if model == "claude-sonnet-5-5" {+ Some(Thinking::BetweenTools)} else if crate::requires_explicit_thinking_opt_out(&model) {- // On Claude Opus 5, omitting the `thinking` field no longer means+ // On Claude Opus 5 and Haiku 5.5, omitting the `thinking` field no longer means// "off": the model runs adaptive thinking by default, so features// that suppress thinking (e.g. inline assist) must opt out// explicitly. `disabled` is only accepted at effort `high` or below;// that holds here because `output_config` is never sent when thinking- // is disallowed, and the server-side default effort is `high`.+ // is disallowed, and the server-side default effort is `high` or below.// <https://platform.claude.com/docs/en/about-claude/models/migration-guide#migrating-to-claude-opus-5>Some(Thinking::Disabled)} else {None};- // Opus 5.5 always uses adaptive thinking, which does not accept sampling controls.- // <https://platform.claude.com/docs/en/models/opus-5-5/overview>+ // These models reject non-default sampling controls even when thinking is off.+ // <https://platform.claude.com/docs/en/build-with-claude/thinking#sampling-parameters>let temperature = if requires_adaptive_thinking {None} else {@@ -1271,6 +1276,59 @@ mod tests {}}+ #[test]+ fn test_thinking_disallowed_sends_between_tools_for_sonnet_5_5() {+ // Claude Sonnet 5.5 thinks by default but rejects `disabled`, so+ // suppressing thinking must send its lowest setting instead.+ let request = LanguageModelRequest {+ messages: vec![LanguageModelRequestMessage {+ role: Role::User,+ content: vec![MessageContent::Text("Hi".to_string())],+ cache: false,+ reasoning_details: None,+ }],+ thread_id: None,+ prompt_cache_key: None,+ prompt_id: None,+ intent: None,+ stop: vec![],+ temperature: None,+ tools: vec![],+ tool_choice: None,+ thinking_allowed: false,+ thinking_effort: None,+ speed: None,+ compact_at_tokens: None,+ max_output_tokens: None,+ };++ let anthropic_request = into_anthropic(+ request,+ "claude-sonnet-5-5".to_string(),+ 1.0,+ 128_000,+ AnthropicModelMode::AdaptiveThinking,+ AnthropicPromptCacheMode::Automatic,+ &ANTHROPIC_PROVIDER_ID,+ )+ .unwrap();++ let request_json = serde_json::to_value(&anthropic_request).unwrap();+ assert_eq!(+ request_json["thinking"],+ serde_json::json!({ "type": "between_tools" })+ );+ assert!(anthropic_request.output_config.is_none());+ assert!(anthropic_request.temperature.is_none());++ let count_tokens_json =+ serde_json::to_value(anthropic_request.into_count_tokens_request()).unwrap();+ assert_eq!(+ count_tokens_json["thinking"],+ serde_json::json!({ "type": "between_tools" })+ );+ }+#[test]fn test_no_cache_control_when_caching_disabled() {let request = LanguageModelRequest {diff --git a/crates/copilot_chat/src/model.rs b/crates/copilot_chat/src/model.rsindex ee7e2ddd29b..25f18894e0d 100644--- a/crates/copilot_chat/src/model.rs+++ b/crates/copilot_chat/src/model.rs@@ -154,7 +154,12 @@ pub fn stream_completion(}if model.supports_adaptive_thinking() {- if anthropic_request.thinking.is_some() {+ if matches!(+ anthropic_request.thinking,+ Some(+ anthropic::Thinking::Enabled { .. } | anthropic::Thinking::Adaptive { .. }+ )+ ) {anthropic_request.thinking = Some(anthropic::Thinking::Adaptive {display: Some(anthropic::AdaptiveThinkingDisplay::Summarized),// Thinking block binding needs a beta header on