From 9990e80d61d64f8322902c737ed264187d355ac8 Mon Sep 17 00:00:00 2001 From: wylab Date: Fri, 13 Feb 2026 15:46:10 +0100 Subject: [PATCH] Replace hardcoded model aliases with dot-to-hyphen normalization Instead of maintaining a brittle alias dict mapping model names to dated API IDs, simply normalize dots to hyphens. The Anthropic API accepts both claude-sonnet-4-5 and dated variants like claude-sonnet-4-5-20250929, so no alias table is needed. This lets users write "claude-sonnet-4.5" or "claude-sonnet-4-5" interchangeably. Co-Authored-By: Claude Opus 4.6 --- nanobot/providers/anthropic_oauth.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/nanobot/providers/anthropic_oauth.py b/nanobot/providers/anthropic_oauth.py index d6dd29c..8b6bf7e 100644 --- a/nanobot/providers/anthropic_oauth.py +++ b/nanobot/providers/anthropic_oauth.py @@ -46,19 +46,14 @@ class AnthropicOAuthProvider(LLMProvider): return f"{self.api_base.rstrip('/')}/v1/messages" return self.ANTHROPIC_API_URL - # Short aliases that need dated suffixes for the API - MODEL_ALIASES: dict[str, str] = { - "claude-sonnet-4": "claude-sonnet-4-20250514", - "claude-opus-4": "claude-opus-4-20250514", - "claude-haiku-3-5": "claude-haiku-4-5-20241022", - "claude-sonnet-4-5": "claude-sonnet-4-5-20250929", - "claude-opus-4-5": "claude-opus-4-5-20250929", - "claude-opus-4-6": "claude-opus-4-6", - } + @staticmethod + def _normalize_model(model: str) -> str: + """Normalize model name for the Anthropic API. - def _resolve_model_alias(self, model: str) -> str: - """Resolve short model aliases to full dated IDs.""" - return self.MODEL_ALIASES.get(model, model) + Anthropic model IDs use hyphens (claude-sonnet-4-5), but users often + write dots (claude-sonnet-4.5). Normalize so both work. + """ + return model.replace(".", "-") async def _get_client(self) -> httpx.AsyncClient: """Get or create async HTTP client.""" @@ -253,8 +248,8 @@ class AnthropicOAuthProvider(LLMProvider): if "/" in model: model = model.split("/")[-1] - # Resolve short aliases to dated model IDs (API requires dated suffixes) - model = self._resolve_model_alias(model) + # Normalize dots to hyphens (claude-sonnet-4.5 -> claude-sonnet-4-5) + model = self._normalize_model(model) system, prepared_messages = self._prepare_messages(messages) anthropic_tools = self._convert_tools_to_anthropic(tools)