AnthropicEngine =============== The :class:`.AnthropicEngine` is used to make requests to the Anthropic API. **TL;DR** .. code-block:: python # see https://docs.anthropic.com/claude/docs/models-overview for a list of model IDs from kani.engines.anthropic import AnthropicEngine engine = AnthropicEngine(api_key=os.getenv("ANTHROPIC_API_KEY"), model="claude-sonnet-4-0") Reference --------- .. autoclass:: kani.engines.anthropic.AnthropicEngine :noindex: .. autoclass:: kani.engines.anthropic.AnthropicUnknownPart :noindex: :members: :exclude-members: model_config, model_fields, model_computed_fields :class-doc-from: class Recipes ------- Server-Side Tools ^^^^^^^^^^^^^^^^^ To enable server-side tools, you pass them as additional arguments to the ``tools`` API argument. You can do this by overriding ``AnthropicEngine._prepare_request``. .. code-block:: python from kani.engines.anthropic import AnthropicEngine class AnthropicServersideToolsEngine(AnthropicEngine): def __init__(self, *args, additional_tools: list = None, **kwargs): super().__init__(*args, **kwargs) self.additional_tools = additional_tools or [] # override prepare_request to inject serverside tool configs def _prepare_request(self, messages, functions): kwargs, prompt_msgs = super()._prepare_request(messages, functions) if self.additional_tools: kwargs.setdefault("tools", []) kwargs["tools"].extend(self.additional_tools) return kwargs, prompt_msgs web_search_engine = AnthropicServersideToolsEngine(..., additional_tools=[ {"name": "web_search", "type": "web_search_20250305"} ]) PDF File Inputs ^^^^^^^^^^^^^^^ .. code-block:: python from kani import Kani from kani.engines.anthropic import AnthropicEngine from kani.ext.multimodal_core import BinaryFilePart engine = AnthropicEngine(api_key=os.getenv("ANTHROPIC_API_KEY"), model="claude-sonnet-4-0") ai = Kani(engine) msg = await ai.chat_round([ BinaryFilePart.from_file("/path/to/file.pdf"), "Summarize this PDF." ]) print(msg.text)