Claude Client¶
llm_annotator.clients.claude_client
¶
Anthropic Claude provider implementation.
ClaudeRuntimeOptions
dataclass
¶
ClaudeRuntimeOptions(
max_tokens: int | None = None,
json_schema: dict[str, Any] | None = None,
effort: Literal["low", "medium", "high", "xhigh", "max"]
| None = None,
thinking_type: Literal[
"enabled", "disabled", "adaptive"
]
| None = None,
thinking_budget: int | None = None,
thinking_display: Literal[
"summarized", "omitted", "full"
]
| None = None,
)
Bases: ProviderRuntimeOptions
Runtime options specific to the Claude provider.
effort
class-attribute
instance-attribute
¶
Controls the amount of effort Claude puts into generating the response, which can affect quality and latency. Higher effort levels may produce better responses but take more time and compute resources. If not specified, the provider default will be used.
thinking_type
class-attribute
instance-attribute
¶
When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards your max_tokens limit.
thinking_budget
class-attribute
instance-attribute
¶
Determines how many tokens Claude can use for its internal reasoning process. Larger budgets can enable more thorough analysis for complex problems, improving response quality. Must be ≥1024 and less than max_tokens.
thinking_display
class-attribute
instance-attribute
¶
When thinking is enabled (or adaptive). Controls how thinking content appears in the response. When set to summarized, thinking is returned normally. When set to omitted, thinking content is redacted but a signature is returned for multi-turn continuity. Defaults to summarized.
ClaudeClient
¶
ClaudeClient(
model: str,
max_workers: int = 4,
api_key: str | None = None,
on_error: OnError = "warn",
)
Bases: Client[ClaudeRuntimeOptions]
Client wrapper for Anthropic Claude APIs.
Initialize the Claude client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Claude model identifier. |
required |
max_workers
|
int
|
Maximum number of concurrent worker threads for |
4
|
api_key
|
str | None
|
Anthropic API key. If not provided, the client will attempt to read from the environment variable |
None
|
on_error
|
OnError
|
Error behavior when generation fails. |
'warn'
|
View source on GitHub: src/llm_annotator/clients/claude_client.py lines 71–95
generate
¶
generate(
*,
messages: list[dict[str, str]],
options: ClaudeRuntimeOptions | None = None,
gen_kwargs: dict[str, Any] | None = None,
) -> Response
Generate a response using Claude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[dict[str, str]]
|
List of message dictionaries. |
required |
options
|
ClaudeRuntimeOptions | None
|
Provider-specific generation options. |
None
|
gen_kwargs
|
dict[str, Any] | None
|
Additional provider-specific generation kwargs that are not covered by the standard options.
Has precedence over |
None
|
Returns:
| Type | Description |
|---|---|
Response
|
A Response object containing the generated response. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If the provider call fails. |
View source on GitHub: src/llm_annotator/clients/claude_client.py lines 132–196
batch_generate
¶
batch_generate(
*,
messages: list[list[dict[str, str]]],
options: ClaudeRuntimeOptions | None = None,
gen_kwargs: dict[str, Any] | None = None,
) -> list[Response]
Generate responses for a batch of inputs concurrently.
The Anthropic API has no native synchronous batch endpoint, so requests are dispatched in parallel using a thread pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[list[dict[str, str]]]
|
List of message lists, one per request. |
required |
options
|
ClaudeRuntimeOptions | None
|
Provider-specific generation options. |
None
|
gen_kwargs
|
dict[str, Any] | None
|
Additional provider-specific generation kwargs that are not covered by the standard options.
Has precedence over |
None
|
Returns:
| Type | Description |
|---|---|
list[Response]
|
A list of Response objects in the same order as the input. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If any individual request fails. |
View source on GitHub: src/llm_annotator/clients/claude_client.py lines 198–246
destroy
¶
Clean up any resources used by the client.
View source on GitHub: src/llm_annotator/clients/claude_client.py lines 293–298