yera.models.interfaces.llms.anthropic
Module containing the interface to Anthropic LLMs.
Symbols
AnthropicLLM
BaseLLMInterfaceInterface to Anthropic LLM.
This class provides a wrapper around the Anthropic API client, handling configuration, model selection, and streaming interactions with Claude models. It supports both standard chat completions and structured output generation for models that support it (Claude 4.5+).
Attributes
The identifier of the Claude model to use.
Connection configuration for the Anthropic API.
Whether the selected model supports structured outputs.
Lazy-initialised Anthropic API client instance.
Methods
AnthropicLLM.start
start() → NoneInitialize the Anthropic API client.
Creates and stores an Anthropic client instance using the configured connection settings. This method must be called before making any API requests via the client property.
AnthropicLLM.stop
stop() → NoneShut down and clear the Anthropic API client.
Releases the Anthropic client instance by setting it to None. After calling this method, start() must be called again before further API requests can be made.
AnthropicLLM.chat
chat(
messages: list[Message],
max_tokens: int = 4096,
**anthropic_kw,
) → Iterator[str]Stream a chat completion response with extended thinking support.
Sends a conversation to the Anthropic API and streams the response as a series of text tokens. Extended thinking is enabled by default with a 1024 token budget for internal reasoning.
System messages are extracted from the message list and combined into a single system parameter, as the Anthropic API only accepts a single system prompt at the start of a conversation.
Parameters
List of Message objects representing the conversation history. Messages with role="system" are extracted and combined into the system parameter. Other messages are passed as conversation turns.
Maximum number of tokens to generate in the response. Defaults to 4096.
Additional keyword arguments passed to the Anthropic API (e.g., temperature, top_p, stop_sequences).
AnthropicLLM.make_struct
make_struct(
messages: list[Message],
max_tokens: int = 4096,
**anthropic_kw,
) → Iterator[str]Stream a structured output response conforming to a provided schema.
Generates a response that conforms to the structure defined by the provided Pydantic model class. For models supporting native structured outputs (Claude 4.5+), uses the native API. For older models, falls back to tool use with the schema as the tool's input_schema.
System messages are extracted from the message list and combined into a single system parameter, as the Anthropic API only accepts a single system prompt at the start of a conversation.
Parameters
List of Message objects representing the conversation history. Messages with role="system" are extracted and combined into the system parameter. Other messages are passed as conversation turns.
A Pydantic model class defining the desired output structure. The model will be transformed into a JSON schema for the API.
Maximum number of tokens to generate in the response. Defaults to 4096.
Additional keyword arguments passed to the Anthropic API (e.g., temperature, top_p).
Raises
If the model does not support structured outputs and the tool use fallback was not invoked.