yera.models.interfaces.llms.anthropic

Module containing the interface to Anthropic LLMs.

Symbols

class AnthropicLLM — Interface to Anthropic LLMs via the Anthropic SDK.

AnthropicLLM

Interface to Anthropic LLMs via the Anthropic SDK.

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

model_id
type: str

The identifier of the Claude model to use.

connection
type: AnthropicConnection

Connection configuration for the Anthropic API.

client
type: Anthropic

Lazy-initialised Anthropic API client instance.

capabilities
type: AnthropicLLMCapabilities

object defining the capabilities of the LLM.

inference
type: AnthropicLLMInference

object defining the inference params of the LLM.

Methods

start — Initialize the Anthropic API client.
stop — Shut down and clear the Anthropic API client.
chat — Stream a chat completion response from Anthropic.
make_struct — Stream a structured output response conforming to a schema.
with_instruction — Prepend or insert an instruction into the conversation history.

AnthropicLLM.start

start() → None

Initialize 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() → None

Shut 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],
    reasoning_level: ReasoningLevel | None = None,
    **anthropic_kw,
) → Iterator[LLMToken]

Stream a chat completion response from Anthropic.

Thinking content is streamed only when the model thinks and display is "summarized". Under adaptive thinking the model may skip thinking entirely.

Parameters

messages
type: list[Message]

The workspace conversation history.

reasoning_level
type: ReasoningLevel | None = None

Set the reasoning effort level overriding the default (medium)

**anthropic_kw
type: str | int | float | bool

Per-call overrides passed to the Messages API, taking precedence over configured inference parameters.

AnthropicLLM.make_struct

make_struct(
    messages: list[Message],
    reasoning_level: ReasoningLevel | None = None,
    **anthropic_kw,
) → Iterator[LLMToken]

Stream a structured output response conforming to a schema.

The response is constrained by the schema through the API's structured outputs support. Thinking, when the model thinks, is unconstrained and arrives as thinking tokens ahead of the JSON.

Parameters

messages
type: list[Message]

The workspace conversation history.

cls
type: type[TStruct]

A pydantic model class defining the output structure.

reasoning_level
type: ReasoningLevel | None = None

Set the reasoning effort level overriding the default (off)

**anthropic_kw
type: str | float | int | bool

Per-call overrides passed to the Messages API, taking precedence over configured inference parameters.

Raises

ValueError

If the model does not support structured outputs.

AnthropicLLM.with_instruction

with_instruction(
    messages: list[Message],
    instruction: str | None,
) → list[Message]

Prepend or insert an instruction into the conversation history.

Parameters

messages
type: list[Message]

The existing conversation history.

instruction
type: str | None

The extra instruction to inject.

Returns

type: list[Message]

A new list of messages with the instruction incorporated.