diff --git a/backend/windmill-api/src/ai.rs b/backend/windmill-api/src/ai.rs index 34e11e692a..94ec94fb60 100644 --- a/backend/windmill-api/src/ai.rs +++ b/backend/windmill-api/src/ai.rs @@ -169,6 +169,9 @@ struct AIStandardResource { /// Platform for Anthropic API (standard or google_vertex_ai) #[serde(default)] platform: AnthropicPlatform, + /// Enable 1M context window for Anthropic + #[serde(alias = "enable_1M_context", default)] + enable_1m_context: bool, } #[derive(Deserialize, Debug)] @@ -197,6 +200,7 @@ struct AIRequestConfig { #[allow(dead_code)] pub aws_secret_access_key: Option, pub platform: AnthropicPlatform, + pub enable_1m_context: bool, } impl AIRequestConfig { @@ -216,10 +220,12 @@ impl AIRequestConfig { aws_access_key_id, aws_secret_access_key, platform, + enable_1m_context, ) = match resource { AIResource::Standard(resource) => { let region = resource.region.clone(); let platform = resource.platform.clone(); + let enable_1m_context = resource.enable_1m_context; // Skip get_base_url for Bedrock - it uses SDK directly, not HTTP let base_url = if matches!(provider, AIProvider::AWSBedrock) { String::new() @@ -258,6 +264,7 @@ impl AIRequestConfig { aws_access_key_id, aws_secret_access_key, platform, + enable_1m_context, ) } AIResource::OAuth(resource) => { @@ -279,6 +286,7 @@ impl AIRequestConfig { None, None, AnthropicPlatform::Standard, + false, ) } }; @@ -293,6 +301,7 @@ impl AIRequestConfig { aws_access_key_id, aws_secret_access_key, platform, + enable_1m_context, }) } @@ -394,6 +403,10 @@ impl AIRequestConfig { } } + if is_anthropic_sdk && self.enable_1m_context { + request = request.header("anthropic-beta", "context-1m-2025-08-07"); + } + // Add authentication headers if let Some(api_key) = self.api_key { if is_azure { diff --git a/backend/windmill-worker/src/ai/providers/anthropic.rs b/backend/windmill-worker/src/ai/providers/anthropic.rs index d8ce9ffc84..e42e1dc49b 100644 --- a/backend/windmill-worker/src/ai/providers/anthropic.rs +++ b/backend/windmill-worker/src/ai/providers/anthropic.rs @@ -354,11 +354,16 @@ pub struct AnthropicQueryBuilder { #[allow(dead_code)] provider_kind: AIProvider, platform: AnthropicPlatform, + enable_1m_context: bool, } impl AnthropicQueryBuilder { - pub fn new(provider_kind: AIProvider, platform: AnthropicPlatform) -> Self { - Self { provider_kind, platform } + pub fn new( + provider_kind: AIProvider, + platform: AnthropicPlatform, + enable_1m_context: bool, + ) -> Self { + Self { provider_kind, platform, enable_1m_context } } fn is_vertex(&self) -> bool { @@ -582,10 +587,14 @@ impl QueryBuilder for AnthropicQueryBuilder { vec![("Authorization", format!("Bearer {}", api_key))] } else { // Standard Anthropic API uses x-api-key and anthropic-version header - vec![ + let mut headers = vec![ ("x-api-key", api_key.to_string()), ("anthropic-version", ANTHROPIC_VERSION_STANDARD.to_string()), - ] + ]; + if self.enable_1m_context { + headers.push(("anthropic-beta", "context-1m-2025-08-07".to_string())); + } + headers } } } diff --git a/backend/windmill-worker/src/ai/query_builder.rs b/backend/windmill-worker/src/ai/query_builder.rs index 10e510a492..97176869c5 100644 --- a/backend/windmill-worker/src/ai/query_builder.rs +++ b/backend/windmill-worker/src/ai/query_builder.rs @@ -119,6 +119,7 @@ pub fn create_query_builder(provider: &ProviderWithResource) -> Box Box::new(AnthropicQueryBuilder::new( provider.kind.clone(), provider.get_platform().clone(), + provider.get_enable_1m_context(), )), AIProvider::OpenRouter => Box::new(OpenRouterQueryBuilder::new()), // All other providers use the completion endpoint diff --git a/backend/windmill-worker/src/ai/types.rs b/backend/windmill-worker/src/ai/types.rs index 4177680e43..56e1571a6b 100644 --- a/backend/windmill-worker/src/ai/types.rs +++ b/backend/windmill-worker/src/ai/types.rs @@ -190,6 +190,9 @@ pub struct ProviderResource { /// Platform for Anthropic API (standard or google_vertex_ai) #[serde(default)] pub platform: AnthropicPlatform, + /// Enable 1M context window for Anthropic + #[serde(alias = "enable_1M_context", default)] + pub enable_1m_context: bool, } #[derive(Deserialize, Debug)] @@ -232,6 +235,10 @@ impl ProviderWithResource { pub fn get_platform(&self) -> &AnthropicPlatform { &self.resource.platform } + + pub fn get_enable_1m_context(&self) -> bool { + self.resource.enable_1m_context + } } /// Token usage information from the AI provider