The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(anthropic): send fast mode only to the Opus models the docs list
emozilla78a50c28fc45
diff --git a/agent/anthropic_adapter.py b/agent/anthropic_adapter.pyindex 7137bce7237..82e4ca40fd4 100644--- a/agent/anthropic_adapter.py+++ b/agent/anthropic_adapter.py@@ -91,7 +91,6 @@ _NO_XHIGH_CLAUDE_SUBSTRINGS = ("claude-opus-4-6", "claude-opus-4.6", "claude-son# 400 (Portal flags them ``reasoning.mandatory``). The failure is asymmetric — a missing entry# 400s the turn, a spurious one only leaves thinking on — so when in doubt, add the family._MANDATORY_THINKING_CLAUDE_SUBSTRINGS = ("claude-fable",)-_FAST_MODE_SUPPORTED_SUBSTRINGS = ("opus-4-8", "opus-4.8", "opus-5")def _is_claude_model(model: str | None) -> bool:@@ -195,11 +194,11 @@ def _forbids_sampling_params(model: str) -> bool:def _supports_fast_mode(model: str) -> bool:- """True for models accepting ``speed: "fast"`` (Opus 4.8 / Opus 5, Claude API only). Explicit- allowlist, not a version floor: Opus 4.6 had fast mode and lost it (requests silently run and- bill at standard speed), Opus 4.7 hard-400s on the param. Dedicated ``...-fast`` ids select- fast inference via the model field and must NOT also receive the speed parameter."""- return "-fast" not in model and any(v in model for v in _FAST_MODE_SUPPORTED_SUBSTRINGS)+ """True for models accepting ``speed: "fast"`` (Opus 4.8 / Opus 5 / Opus 5.5, Claude API only).+ The list lives in ``agent.model_metadata`` so the wire gate and the ``/fast`` toggle agree."""+ from agent.model_metadata import is_anthropic_fast_mode_model++ return is_anthropic_fast_mode_model(model)# Beta headers safe on ordinary/native Anthropic requests. GA on Claude 4.6+ (harmless no-opdiff --git a/agent/model_metadata.py b/agent/model_metadata.pyindex 9b468e5f25b..f1e6f2bb102 100644--- a/agent/model_metadata.py+++ b/agent/model_metadata.py@@ -440,6 +440,21 @@ def is_grok_46_family(model: str) -> bool:return name == "grok-4.6" or name.startswith("grok-4.6-")+# Claude models that accept ``speed: "fast"`` (https://platform.claude.com/docs/en/build-with-claude/fast-mode).+# Exact ids, not a family prefix: Opus 4.7 answers the parameter with an error, Opus 4.6 silently+# runs and bills at standard speed, and a future Opus is unsupported until the docs list it.+_ANTHROPIC_FAST_MODE_MODELS = frozenset({"claude-opus-4-8", "claude-opus-5", "claude-opus-5-5"})+++def is_anthropic_fast_mode_model(model: Optional[str]) -> bool:+ """Whether *model* accepts Anthropic fast mode. Accepts vendor-prefixed, dotted, variant and+ dated spellings (``anthropic/claude-opus-5.5``, ``claude-opus-4-8-20260601``). Dedicated+ ``...-fast`` ids select fast inference through the model field and are not in the list."""+ name = str(model or "").strip().lower().split(":", 1)[0].rsplit("/", 1)[-1]+ name = re.sub(r"(\d)\.(\d)", r"\1-\2", name)+ return re.sub(r"-\d{8}$", "", name) in _ANTHROPIC_FAST_MODE_MODELS++_CONTEXT_LENGTH_KEYS = ("context_length", "context_window", "context_size", "max_context_length", "max_position_embeddings","max_model_len", "max_input_tokens", "max_sequence_length", "max_seq_len", "n_ctx_train", "n_ctx", "ctx_size",diff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex 24c41b75c03..4fa57de4f40 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -1154,13 +1154,11 @@ def model_supports_fast_mode(model_id: Optional[str]) -> bool:def _is_anthropic_fast_model(model_id: Optional[str]) -> bool:- """Accepts the Anthropic Fast Mode ``speed`` param (Opus 4.8 / Opus 5 only) — deliberately NOT a- general "fast model" check: Opus 4.7 hard-400s on it, and dedicated ``…-fast`` ids select fast- inference via the model field and must not also get it."""- base = _strip_vendor_prefix(str(model_id or "")).split(":")[0]- if not base.startswith("claude-") or "-fast" in base:- return False- return any(v in base for v in ("opus-4-8", "opus-4.8", "opus-5"))+ """Accepts the Anthropic Fast Mode ``speed`` param (Opus 4.8 / Opus 5 / Opus 5.5 only) —+ deliberately NOT a general "fast model" check. The list lives in ``agent.model_metadata``."""+ from agent.model_metadata import is_anthropic_fast_mode_model++ return is_anthropic_fast_mode_model(model_id)def _fast_mode_route_supported(diff --git a/tests/hermes_cli/test_fast_command.py b/tests/hermes_cli/test_fast_command.pyindex f4f22303966..1fece97263c 100644--- a/tests/hermes_cli/test_fast_command.py+++ b/tests/hermes_cli/test_fast_command.py@@ -180,7 +180,7 @@ class TestAnthropicFastMode(unittest.TestCase):def test_anthropic_opus_supported(self):from hermes_cli.models import model_supports_fast_mode- # Per the live fast-mode docs: Opus 4.8 + Opus 5, Claude API only.+ # Per the live fast-mode docs: Opus 4.8, Opus 5 and Opus 5.5, Claude API only.# Native Anthropic format (hyphens)assert model_supports_fast_mode("claude-opus-4-8") is True# OpenRouter format (dots)@@ -190,15 +190,21 @@ class TestAnthropicFastMode(unittest.TestCase):assert model_supports_fast_mode("anthropic/claude-opus-4.8") is Trueassert model_supports_fast_mode("claude-opus-5") is Trueassert model_supports_fast_mode("anthropic/claude-opus-5") is True+ assert model_supports_fast_mode("claude-opus-5-5") is True+ assert model_supports_fast_mode("claude-opus-5.5") is True+ assert model_supports_fast_mode("anthropic/claude-opus-5.5") is True+ # Dated snapshot ids resolve to their family+ assert model_supports_fast_mode("claude-opus-4-8-20260601") is Truedef test_anthropic_unsupported_models_excluded(self):- """The speed=fast parameter is gated to Opus 4.8 / Opus 5.+ """The speed=fast parameter is gated to Opus 4.8 / Opus 5 / Opus 5.5.Per https://platform.claude.com/docs/en/build-with-claude/fast-mode:Opus 4.6 LOST fast mode 2026-06-29 (the param is silently ignored —standard speed at standard billing — so a toggle would do nothing);Opus 4.7 hard-400s; Sonnet/Haiku never had it; dedicated ``…-fast``ids select fast inference via the model field, not the parameter.+ The list is exact: an Opus the docs do not name is unsupported."""from hermes_cli.models import model_supports_fast_mode@@ -210,6 +216,9 @@ class TestAnthropicFastMode(unittest.TestCase):assert model_supports_fast_mode("claude-opus-4-7") is Falseassert model_supports_fast_mode("claude-opus-4-8-fast") is Falseassert model_supports_fast_mode("anthropic/claude-opus-4.8-fast") is False+ assert model_supports_fast_mode("anthropic/claude-opus-5-fast") is False+ assert model_supports_fast_mode("claude-opus-5-6") is False+ assert model_supports_fast_mode("claude-fable-5") is Falseassert model_supports_fast_mode("anthropic/claude-sonnet-4.6") is Falseassert model_supports_fast_mode("anthropic/claude-opus-4-7") is False@@ -221,7 +230,7 @@ class TestAnthropicFastMode(unittest.TestCase):def test_fast_command_hidden_for_anthropic_sonnet(self):- """Sonnet doesn't support fast mode (Opus 4.8/5 only) — /fast must be hidden."""+ """Sonnet doesn't support fast mode (Opus 4.8/5/5.5 only) — /fast must be hidden."""cli_mod = _import_cli()stub = SimpleNamespace(provider="anthropic", requested_provider="anthropic",@@ -271,6 +280,20 @@ class TestAnthropicFastModeAdapter(unittest.TestCase):assert "extra_headers" in kwargsassert _FAST_MODE_BETA in kwargs["extra_headers"].get("anthropic-beta", "")+ def test_fast_mode_on_opus_5_5_and_not_on_unlisted_opus(self):+ from agent.anthropic_adapter import build_anthropic_kwargs++ def _speed(model):+ return build_anthropic_kwargs(+ model=model, messages=[{"role": "user", "content": [{"type": "text", "text": "hi"}]}],+ tools=None, max_tokens=None, reasoning_config=None, fast_mode=True,+ ).get("extra_body", {}).get("speed")++ assert _speed("claude-opus-5-5") == "fast"+ assert _speed("claude-opus-5") == "fast"+ # An Opus the docs don't list answers ``speed`` with an error: never send it.+ assert _speed("claude-opus-5-6") is None+def test_fast_mode_off_no_speed(self):from agent.anthropic_adapter import build_anthropic_kwargsdiff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.mdindex f5842278d5d..793c8b339cf 100644--- a/website/docs/user-guide/configuration.md+++ b/website/docs/user-guide/configuration.md@@ -1938,7 +1938,7 @@ The override applies automatically everywhere: CLI startup, `hermes -p` one-shot## Fast Mode-Fast mode asks the provider for faster output at a premium price: OpenAI [Priority Processing](https://openai.com/api-priority-processing/) (`service_tier: priority`), xAI Priority Processing on Grok 4.6, and Anthropic [Fast Mode](https://platform.claude.com/docs/en/build-with-claude/fast-mode) (`speed: fast`, Opus 4.8 / Opus 5 only). It is **off by default**.+Fast mode asks the provider for faster output at a premium price: OpenAI [Priority Processing](https://openai.com/api-priority-processing/) (`service_tier: priority`), xAI Priority Processing on Grok 4.6, and Anthropic [Fast Mode](https://platform.claude.com/docs/en/build-with-claude/fast-mode) (`speed: fast`, Opus 4.8 / Opus 5 / Opus 5.5 only). It is **off by default**.```yamlagent: