From 8c1916b511bec1524bcc06db49847afb9445b245 Mon Sep 17 00:00:00 2001 From: Shardul Vaidya Date: Fri, 6 Feb 2026 00:20:50 +0000 Subject: [PATCH 1/3] Add allow_extended_context setting for Bedrock provider Adds a new setting `allow_extended_context` to the Bedrock provider that enables the 1M token extended context window beta for supported Anthropic models. When enabled, the `anthropic_beta` field is included in requests to Bedrock with the context-1m-2025-08-07 header value. Only models that support extended context (Claude Sonnet 4.5, Claude Opus 4.5) will have the beta header applied when the setting is enabled. Co-authored-by: Ona --- crates/bedrock/src/bedrock.rs | 21 +++++++++++++++---- crates/bedrock/src/models.rs | 12 +++++++++++ .../language_models/src/provider/bedrock.rs | 17 +++++++++++++-- crates/language_models/src/settings.rs | 1 + crates/settings_content/src/language_model.rs | 2 ++ docs/src/ai/llm-providers.md | 21 +++++++++++++++++++ 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/crates/bedrock/src/bedrock.rs b/crates/bedrock/src/bedrock.rs index 744dde38076a5a..c5f0572925efc9 100644 --- a/crates/bedrock/src/bedrock.rs +++ b/crates/bedrock/src/bedrock.rs @@ -31,6 +31,8 @@ use thiserror::Error; pub use crate::models::*; +pub const CONTEXT_1M_BETA_HEADER: &str = "context-1m-2025-08-07"; + pub async fn stream_completion( client: bedrock::Client, request: Request, @@ -39,6 +41,8 @@ pub async fn stream_completion( .model_id(request.model.clone()) .set_messages(request.messages.into()); + let mut additional_fields: HashMap = HashMap::new(); + if let Some(Thinking::Enabled { budget_tokens: Some(budget_tokens), }) = request.thinking @@ -50,10 +54,18 @@ pub async fn stream_completion( Document::Number(AwsNumber::PosInt(budget_tokens)), ), ]); - response = response.additional_model_request_fields(Document::Object(HashMap::from([( - "thinking".to_string(), - Document::from(thinking_config), - )]))); + additional_fields.insert("thinking".to_string(), Document::from(thinking_config)); + } + + if request.allow_extended_context { + additional_fields.insert( + "anthropic_beta".to_string(), + Document::Array(vec![Document::String(CONTEXT_1M_BETA_HEADER.to_string())]), + ); + } + + if !additional_fields.is_empty() { + response = response.additional_model_request_fields(Document::Object(additional_fields)); } if request.tools.as_ref().is_some_and(|t| !t.tools.is_empty()) { @@ -161,6 +173,7 @@ pub struct Request { pub temperature: Option, pub top_k: Option, pub top_p: Option, + pub allow_extended_context: bool, } #[derive(Debug, Serialize, Deserialize)] diff --git a/crates/bedrock/src/models.rs b/crates/bedrock/src/models.rs index 51e1b29f9ad3cf..400dbeb5ff75f0 100644 --- a/crates/bedrock/src/models.rs +++ b/crates/bedrock/src/models.rs @@ -584,6 +584,18 @@ impl Model { } } + pub fn supports_extended_context(&self) -> bool { + matches!( + self, + Model::ClaudeSonnet4 + | Model::ClaudeSonnet4Thinking + | Model::ClaudeSonnet4_5 + | Model::ClaudeSonnet4_5Thinking + | Model::ClaudeOpus4_5 + | Model::ClaudeOpus4_5Thinking + ) + } + pub fn cross_region_inference_id( &self, region: &str, diff --git a/crates/language_models/src/provider/bedrock.rs b/crates/language_models/src/provider/bedrock.rs index da7118f0ec1220..8406f3c7362175 100644 --- a/crates/language_models/src/provider/bedrock.rs +++ b/crates/language_models/src/provider/bedrock.rs @@ -111,6 +111,7 @@ pub struct AmazonBedrockSettings { pub role_arn: Option, pub authentication_method: Option, pub allow_global: Option, + pub allow_extended_context: Option, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, EnumIter, IntoStaticStr, JsonSchema)] @@ -377,6 +378,13 @@ impl State { .and_then(|s| s.allow_global) .unwrap_or(false) } + + fn get_allow_extended_context(&self) -> bool { + self.settings + .as_ref() + .and_then(|s| s.allow_extended_context) + .unwrap_or(false) + } } pub struct BedrockLanguageModelProvider { @@ -667,8 +675,8 @@ impl LanguageModel for BedrockModel { LanguageModelCompletionError, >, > { - let (region, allow_global) = cx.read_entity(&self.state, |state, _cx| { - (state.get_region(), state.get_allow_global()) + let (region, allow_global, allow_extended_context) = cx.read_entity(&self.state, |state, _cx| { + (state.get_region(), state.get_allow_global(), state.get_allow_extended_context()) }); let model_id = match self.model.cross_region_inference_id(®ion, allow_global) { @@ -680,6 +688,8 @@ impl LanguageModel for BedrockModel { let deny_tool_calls = request.tool_choice == Some(LanguageModelToolChoice::None); + let use_extended_context = allow_extended_context && self.model.supports_extended_context(); + let request = match into_bedrock( request, model_id, @@ -687,6 +697,7 @@ impl LanguageModel for BedrockModel { self.model.max_output_tokens(), self.model.mode(), self.model.supports_caching(), + use_extended_context, ) { Ok(request) => request, Err(err) => return futures::future::ready(Err(err.into())).boxed(), @@ -742,6 +753,7 @@ pub fn into_bedrock( max_output_tokens: u64, mode: BedrockModelMode, supports_caching: bool, + allow_extended_context: bool, ) -> Result { let mut new_messages: Vec = Vec::new(); let mut system_message = String::new(); @@ -934,6 +946,7 @@ pub fn into_bedrock( temperature: request.temperature.or(Some(default_temperature)), top_k: None, top_p: None, + allow_extended_context, }) } diff --git a/crates/language_models/src/settings.rs b/crates/language_models/src/settings.rs index 62f0025c755e10..b8f548acbeeac2 100644 --- a/crates/language_models/src/settings.rs +++ b/crates/language_models/src/settings.rs @@ -59,6 +59,7 @@ impl settings::Settings for AllLanguageModelSettings { role_arn: None, // todo(was never a setting for this...) authentication_method: bedrock.authentication_method.map(Into::into), allow_global: bedrock.allow_global, + allow_extended_context: bedrock.allow_extended_context, }, deepseek: DeepSeekSettings { api_url: deepseek.api_url.unwrap(), diff --git a/crates/settings_content/src/language_model.rs b/crates/settings_content/src/language_model.rs index 020383ac98e8af..81ea96e9f23a8c 100644 --- a/crates/settings_content/src/language_model.rs +++ b/crates/settings_content/src/language_model.rs @@ -62,6 +62,8 @@ pub struct AmazonBedrockSettingsContent { pub profile: Option, pub authentication_method: Option, pub allow_global: Option, + /// Enable the 1M token extended context window beta for supported Anthropic models. + pub allow_extended_context: Option, } #[with_fallible_options] diff --git a/docs/src/ai/llm-providers.md b/docs/src/ai/llm-providers.md index f224890b5da57d..61e1c30200d89c 100644 --- a/docs/src/ai/llm-providers.md +++ b/docs/src/ai/llm-providers.md @@ -144,6 +144,27 @@ We will support Cross-Region inference for each of the models on a best-effort b For the most up-to-date supported regions and models, refer to the [Supported Models and Regions for Cross Region inference](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html). +#### Extended Context Window {#bedrock-extended-context} + +Anthropic models on Bedrock support a [1M token extended context window](https://docs.anthropic.com/en/docs/build-with-claude/extended-context) beta. To enable this feature, add `"allow_extended_context": true` to your Bedrock configuration: + +```json [settings] +{ + "language_models": { + "bedrock": { + "authentication_method": "named_profile", + "region": "your-aws-region", + "profile": "your-profile-name", + "allow_extended_context": true + } + } +} +``` + +When enabled, Zed will include the `anthropic_beta` field in requests to Bedrock, enabling the 1M token context window for supported Anthropic models such as Claude Sonnet 4.5 and Claude Opus 4.6. + +> **Note**: Extended context usage may incur additional API costs. Refer to your AWS Bedrock pricing for details. + ### Anthropic {#anthropic} You can use Anthropic models by choosing them via the model dropdown in the Agent Panel. From 5e2be5a1aa23e7b4afa31fc3c7eb279ed6a665e3 Mon Sep 17 00:00:00 2001 From: Shardul Vaidya <31039336+5herlocked@users.noreply.github.com> Date: Mon, 9 Feb 2026 17:39:18 -0500 Subject: [PATCH 2/3] Add new model variants for ClaudeOpus4_6 --- crates/bedrock/src/models.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bedrock/src/models.rs b/crates/bedrock/src/models.rs index 5984762a6df9df..e073f5f17aa095 100644 --- a/crates/bedrock/src/models.rs +++ b/crates/bedrock/src/models.rs @@ -647,6 +647,8 @@ impl Model { | Model::ClaudeSonnet4_5Thinking | Model::ClaudeOpus4_5 | Model::ClaudeOpus4_5Thinking + | Model::ClaudeOpus4_6 + | Model::ClaudeOpus4_6Thinking ) } From 76aaa7dfa19406674ad916a3a4ff4d1deef56c41 Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Thu, 12 Feb 2026 15:19:12 +0100 Subject: [PATCH 3/3] format --- crates/language_models/src/provider/bedrock.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/language_models/src/provider/bedrock.rs b/crates/language_models/src/provider/bedrock.rs index cb3226ad67f12b..0efa5b40baf955 100644 --- a/crates/language_models/src/provider/bedrock.rs +++ b/crates/language_models/src/provider/bedrock.rs @@ -680,9 +680,14 @@ impl LanguageModel for BedrockModel { LanguageModelCompletionError, >, > { - let (region, allow_global, allow_extended_context) = cx.read_entity(&self.state, |state, _cx| { - (state.get_region(), state.get_allow_global(), state.get_allow_extended_context()) - }); + let (region, allow_global, allow_extended_context) = + cx.read_entity(&self.state, |state, _cx| { + ( + state.get_region(), + state.get_allow_global(), + state.get_allow_extended_context(), + ) + }); let model_id = match self.model.cross_region_inference_id(®ion, allow_global) { Ok(s) => s,