Replace hardcoded model aliases with dot-to-hyphen normalization
All checks were successful
Build Nanobot OAuth / build (push) Successful in 1m52s
All checks were successful
Build Nanobot OAuth / build (push) Successful in 1m52s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user