(self, *, config_class: type = AnthropicModelConfig, **kwargs)
| 111 | ] |
| 112 | |
| 113 | def __init__(self, *, config_class: type = AnthropicModelConfig, **kwargs): |
| 114 | self.config = config_class(**kwargs) |
| 115 | # Resolve endpoint-specific values from the environment so they stay out of configs. |
| 116 | if self.config.model_name_env: |
| 117 | model_name = os.getenv(self.config.model_name_env, "") |
| 118 | if not model_name: |
| 119 | raise ValueError(f"Set the {self.config.model_name_env} environment variable to the model name.") |
| 120 | self.config.model_name = model_name |
| 121 | if self.config.base_url_env: |
| 122 | base_url = os.getenv(self.config.base_url_env, "") |
| 123 | if not base_url: |
| 124 | raise ValueError(f"Set the {self.config.base_url_env} environment variable to the API base URL.") |
| 125 | self.config.base_url = base_url |
| 126 | api_key = os.getenv(self.config.api_key_env, "") |
| 127 | if not api_key: |
| 128 | raise ValueError(f"API key not found. Set the {self.config.api_key_env} environment variable.") |
| 129 | client_kwargs: dict[str, Any] = {"api_key": api_key} |
| 130 | if self.config.base_url: |
| 131 | client_kwargs["base_url"] = self.config.base_url |
| 132 | self.client = anthropic.Anthropic(**client_kwargs) |
| 133 | |
| 134 | @staticmethod |
| 135 | def _set_cache_control_on_last_message(messages: list[dict]) -> list[dict]: |
nothing calls this directly
no outgoing calls
no test coverage detected