"""Anthropic provider — authenticates via ``ANTHROPIC_API_KEY``.""" from environs import Env from langchain_anthropic import ChatAnthropic from langchain_core.language_models import BaseChatModel from pydantic import SecretStr from skill_eval_runner.providers import Provider, register _env = Env() _env.read_env() def make_model(model_name: str) -> BaseChatModel: """Build a ``ChatAnthropic`` model, requiring ``ANTHROPIC_API_KEY``.""" api_key = _env.str("ANTHROPIC_API_KEY", None) if not api_key: raise SystemExit( "ANTHROPIC_API_KEY is not set.\n" " Add it to a .env file or export ANTHROPIC_API_KEY=sk-..." ) # ChatAnthropic's pydantic field aliases ("model", "max_tokens") aren't visible to # mypy without the pydantic plugin; the kwargs are valid at runtime. model: BaseChatModel = ChatAnthropic( # type: ignore[call-arg] model=model_name, api_key=SecretStr(api_key), max_tokens=16384, ) return model register( Provider( name="anthropic", default_model="claude-sonnet-4-6", small_model="claude-haiku-4-5", large_model="claude-sonnet-4-6", make_model=make_model, ) )