Skip to content

Commit bd2e879

Browse files
Moeblackbennetbo
andauthored
anthropic: Allow configured models to opt into fast mode (#58225)
Adds support for enabling Anthropic fast mode on configured models. Previously, Anthropic models configured through `language_models.anthropic.available_models` were always marked as not supporting fast mode, so `speed: "fast"` would be stripped before sending requests even when the configured model supported Anthropic fast mode. This adds an optional `supports_fast_mode` field to configured Anthropic models. When enabled, the model is marked as supporting fast mode and the required Anthropic beta header is added automatically. Built-in fast-mode model detection remains the fallback when the setting is omitted. Testing: - `cargo fmt --package anthropic --package language_models --package settings_content` - `cargo test -p language_models available_model --lib` - `cargo test -p anthropic from_listed_enables_fast_mode --lib` - `cargo check -p language_models` - Manual: verified in a local build that a configured Anthropic model can send fast mode requests correctly. Release Notes: - agent: Allow specifying if fast mode is supported for custom anthropic models Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
1 parent 5032923 commit bd2e879

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

crates/anthropic/src/anthropic.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ pub mod batches;
1919
pub mod completion;
2020

2121
pub const ANTHROPIC_API_URL: &str = "https://api.anthropic.com";
22-
const FAST_MODE_BETA_HEADER: &str = "fast-mode-2026-02-01";
22+
pub const FAST_MODE_BETA_HEADER: &str = "fast-mode-2026-02-01";
23+
24+
pub fn supports_fast_mode(model_id: &str) -> bool {
25+
matches!(
26+
model_id,
27+
"claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8"
28+
)
29+
}
2330

2431
pub const FABLE_MODEL_ID_PREFIX: &str = "claude-fable-5";
2532
pub const FABLE_FALLBACK_MODEL_ID: &str = "claude-opus-4-8";
@@ -156,10 +163,7 @@ impl Model {
156163
AnthropicModelMode::Default
157164
};
158165

159-
let supports_speed = matches!(
160-
entry.id.as_str(),
161-
"claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8"
162-
);
166+
let supports_speed = supports_fast_mode(&entry.id);
163167

164168
// <https://platform.claude.com/docs/en/build-with-claude/compaction#supported-models>
165169
let supports_compaction = matches!(

crates/language_models/src/provider/anthropic.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,17 @@ fn available_model_to_anthropic_model(available: &AvailableModel) -> anthropic::
333333
AnthropicModelMode::Thinking { .. } | AnthropicModelMode::AdaptiveThinking
334334
);
335335
let supports_adaptive_thinking = matches!(mode, AnthropicModelMode::AdaptiveThinking);
336+
let supports_speed = available
337+
.supports_fast_mode
338+
.unwrap_or_else(|| anthropic::supports_fast_mode(&available.name));
339+
let mut extra_beta_headers = available.extra_beta_headers.clone();
340+
if supports_speed
341+
&& !extra_beta_headers
342+
.iter()
343+
.any(|header| header.trim() == anthropic::FAST_MODE_BETA_HEADER)
344+
{
345+
extra_beta_headers.push(anthropic::FAST_MODE_BETA_HEADER.to_string());
346+
}
336347

337348
anthropic::Model {
338349
display_name: available
@@ -347,7 +358,7 @@ fn available_model_to_anthropic_model(available: &AvailableModel) -> anthropic::
347358
supports_thinking,
348359
supports_adaptive_thinking,
349360
supports_images: true,
350-
supports_speed: false,
361+
supports_speed,
351362
supports_compaction: false,
352363
supported_effort_levels: if supports_adaptive_thinking {
353364
vec![
@@ -361,7 +372,7 @@ fn available_model_to_anthropic_model(available: &AvailableModel) -> anthropic::
361372
vec![]
362373
},
363374
tool_override: available.tool_override.clone(),
364-
extra_beta_headers: available.extra_beta_headers.clone(),
375+
extra_beta_headers,
365376
}
366377
}
367378

crates/settings_content/src/language_model.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ pub struct AnthropicAvailableModel {
106106
pub default_temperature: Option<f32>,
107107
#[serde(default)]
108108
pub extra_beta_headers: Vec<String>,
109+
/// Whether Anthropic's fast mode is available for this model.
110+
pub supports_fast_mode: Option<bool>,
109111
/// The model's mode (e.g. thinking)
110112
pub mode: Option<ModelMode>,
111113
}

0 commit comments

Comments
 (0)