> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroruntime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic

> Python API reference for the anthropic llm plugin.

<Card title="Usage guide" icon="book" href="/plugins/llm/anthropic" horizontal>
  Setup, environment variables, and Python/JavaScript/Go usage examples.
</Card>

## AnthropicLLM

Anthropic Claude LLM plugin.

Wraps the Anthropic Messages API with optional extended thinking support,
streaming-first generation, and tool/function calling.

### Constructor

```python theme={null}
AnthropicLLM(*, api_key: 'str | None' = None, model: 'AnthropicLLMModel | str' = 'claude-sonnet-4-20250514', temperature: 'float' = 0.7, max_output_tokens: 'int' = 1024, top_p: 'float | None' = None, top_k: 'int | None' = None, stop_sequences: 'list[str] | str | None' = None, thinking_budget: 'int | None' = None, **kwargs)
```

<ParamField path="api_key" type="str | None">
  Anthropic API key. Falls back to the `ANTHROPIC_API_KEY` environment variable when omitted.
</ParamField>

<ParamField path="model" type="AnthropicLLMModel | str" default="claude-sonnet-4-20250514">
  Claude model ID to use. Defaults to `"claude-sonnet-4-20250514"` (Claude Sonnet 4). Other options include `"claude-opus-4-20250514"` (most capable), `"claude-haiku-3-5-20241022"` (fastest/cheapest). Accepts any `AnthropicLLMModel` enum value or a raw string model ID.
</ParamField>

<ParamField path="temperature" type="float" default="0.7">
  Sampling temperature in `[0.0, 1.0]`. Lower values produce more deterministic output; higher values increase creativity. Defaults to `0.7`.
</ParamField>

<ParamField path="max_output_tokens" type="int" default="1024">
  Maximum number of tokens the model may generate per response. Defaults to `1024`. The legacy `max_tokens` kwarg is accepted for backward compatibility and overrides this value when it equals the default.
</ParamField>

<ParamField path="top_p" type="float | None">
  Nucleus sampling probability mass in `(0.0, 1.0]`. Mutually exclusive with `temperature`: set one or the other, not both. Defaults to `None` (disabled).
</ParamField>

<ParamField path="top_k" type="int | None">
  Restrict sampling to the top-K most likely tokens at each step. Defaults to `None` (disabled).
</ParamField>

<ParamField path="stop_sequences" type="list[str] | str | None">
  One or more strings at which the model will stop generating. Accepts a single string or a list of strings. Defaults to `None`.
</ParamField>

<ParamField path="thinking_budget" type="int | None">
  Token budget for Claude's extended thinking (chain-of-thought reasoning). `None` disables thinking; set to a positive integer (e.g. `1024`) to enable. The legacy `thinking=&#123;"budget_tokens": N&#125;` kwarg is also accepted.
</ParamField>

### aclose

```python theme={null}
def aclose(self) -> 'None'
```

Release any resources held by the provider.

### cancel\_current\_generation

```python theme={null}
def cancel_current_generation(self) -> 'None'
```

Cancel the in-progress generation for the active session, if any.

### chat

```python theme={null}
def chat(self, messages: 'Any', tools: 'Any' = None, conversational_graph: 'Any' = None, **kwargs: 'Any') -> 'AsyncIterator[LLMResponse]'
```

Generate a streamed chat completion.

<ParamField path="messages" type="Any" required>
  The conversation history to send to the model.
</ParamField>

<ParamField path="tools" type="Any">
  Optional tool definitions the model may call.
</ParamField>

<ParamField path="conversational_graph" type="Any">
  Optional conversational graph guiding the exchange.
</ParamField>

<ResponseField name="returns" type="AsyncIterator[LLMResponse]">
  LLMResponse: Response chunks produced as the model generates output.
</ResponseField>

### emit

```python theme={null}
def emit(self, event: 'T', *args: 'Any') -> 'None'
```

Emit an event, invoking all registered handlers with the given arguments.

Handlers are called in registration order. Coroutine handlers are
scheduled on the running event loop. If the emitter is closed, the call
is a no-op.

<ParamField path="event" type="T" required>
  The event to emit.
</ParamField>

### off

```python theme={null}
def off(self, event: 'T', callback: 'Callable[..., Any]') -> 'None'
```

Remove a previously registered handler for an event.

If the handler is not registered for the event, the call is a no-op.

<ParamField path="event" type="T" required>
  The event the handler was registered for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any]" required>
  The handler to remove.
</ParamField>

### on

```python theme={null}
def on(self, event: 'T', callback: 'Callable[..., Any] | None' = None) -> 'Callable[..., Any]'
```

Register a handler for an event.

Can be used directly by passing a callback, or as a decorator when
`callback` is omitted.

<ParamField path="event" type="T" required>
  The event to listen for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any] | None">
  The handler to invoke when the event is emitted. If `None`, a decorator is returned that registers the decorated function.
</ParamField>

<ResponseField name="returns" type="Callable[..., Any]">
  The registered callback when `callback` is provided, otherwise a decorator that registers and returns the function it wraps.
</ResponseField>

***

## AnthropicLLMModel

```python theme={null}
AnthropicLLMModel = typing.Literal['claude-opus-4-8', 'claude-sonnet-4-6', 'claude-haiku-4-5', 'claude-haiku-4-5-20251001', 'claude-fable-5', 'claude-opus-4-7', 'claude-sonnet-4-5']
```
