Skip to content

Anthropic backend

actantial.backends.anthropic.AnthropicBackend

Bases: LLMBackend

Backend for Anthropic API models.

Wraps the Anthropic Messages API to provide text generation compatible with the actantial pipeline.

__init__(model_name='claude-haiku-4-5', system_prompt='You are a helpful assistant.', temperature=0, api_key=None)

Initialise the Anthropic backend and validate the model.

Parameters:

Name Type Description Default
model_name str

Anthropic model identifier (e.g., "claude-haiku-4-5", "claude-sonnet-4-6").

'claude-haiku-4-5'
system_prompt str

System-level instruction passed to the model on every request.

'You are a helpful assistant.'
temperature float

Sampling temperature in [0, 1]; higher values increase randomness. Defaults to 0 for deterministic output.

0
api_key Optional[str]

Anthropic API key. If None, read from the ANTHROPIC_API_KEY environment variable.

None

generate(prompt, max_new_tokens=2048, **kwargs)

Generate text from a prompt.

Parameters:

Name Type Description Default
prompt str

The input prompt string.

required
max_new_tokens int

Maximum number of tokens to generate.

2048
**kwargs Any

Additional parameters passed to the Anthropic Messages API.

{}

Returns:

Type Description
str

The generated text string, excluding the input prompt.