Anthropic lm invoker
Defines a module to interact with Anthropic language models.
AnthropicLMInvoker(model_name, api_key=None, model_kwargs=None, default_hyperparameters=None, tools=None, response_schema=None, output_analytics=False, retry_config=None, thinking=False, input_transformer=InputTransformerType.IDENTITY, output_transformer=OutputTransformerType.IDENTITY)
Bases: BaseLMInvoker
A language model invoker to interact with Anthropic language models.
Examples:
lm_invoker = AnthropicLMInvoker(model_name="claude-sonnet-4-5")
result = await lm_invoker.invoke("Hi there!")
Supported features
- Basic invocation
- Streaming output
- Message roles
- Multimodal input a. Text b. Document c. Image
- Structured output
- Tool calling
- Native tools a. Code interpreter b. Skill c. Web search
- Thinking
- Output analytics
- Retry and timeout
- Extra capabilities a. Input transformer b. Output transformer c. Batch invocation
For full documentation and examples, please refer to the LM Invoker tutorial: https://gdplabs.gitbook.io/sdk/gen-ai-sdk/tutorials/inference/lm-invoker
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
str
|
The model ID of the language model. |
model_provider |
str
|
The provider of the language model. |
model_name |
str
|
The name of the language model. |
client |
AsyncAnthropic
|
The Anthropic client instance. |
default_config |
dict[str, Any]
|
Default config for invoking the model. |
tools |
list[Tool]
|
Tools provided to the model to enable tool calling. |
response_schema |
ResponseSchema | None
|
The schema of the response. If provided, the model will output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary. |
output_analytics |
bool
|
Whether to output the invocation analytics. |
retry_config |
RetryConfig
|
The retry configuration for the language model. |
thinking |
ThinkingConfig
|
The thinking configuration for the language model. |
input_transformer |
InputTransformerType
|
The type of input transformer to use. |
output_transformer |
OutputTransformerType
|
The type of output transformer to use. |
Initializes the AnthropicLmInvoker instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The name of the Anthropic language model. |
required |
api_key
|
str | None
|
The Anthropic API key. Defaults to None, in which case the
|
None
|
model_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments for the Anthropic client. |
None
|
default_hyperparameters
|
dict[str, Any] | None
|
Default hyperparameters for invoking the model. Defaults to None. |
None
|
tools
|
list[LMTool] | None
|
Tools provided to the model to enable tool calling. Defaults to None, in which case an empty list is used. |
None
|
response_schema
|
ResponseSchema | None
|
The schema of the response. If provided, the model will output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary. Defaults to None. |
None
|
output_analytics
|
bool
|
Whether to output the invocation analytics. Defaults to False. |
False
|
retry_config
|
RetryConfig | None
|
The retry configuration for the language model. Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used. |
None
|
thinking
|
bool | ThinkingConfig
|
A boolean or ThinkingConfig object to configure thinking. Defaults to False. |
False
|
input_transformer
|
InputTransformerType
|
The type of input transformer to use. Defaults to InputTransformerType.IDENTITY, which returns the input without transformation. |
IDENTITY
|
output_transformer
|
OutputTransformerType
|
The type of output transformer to use. Defaults to OutputTransformerType.IDENTITY, which returns the output without transformation. |
IDENTITY
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
batch
cached
property
The batch operations for the language model.
Returns:
| Name | Type | Description |
|---|---|---|
AnthropicBatchOperations |
AnthropicBatchOperations
|
The batch operations for the language model. |
skill
cached
property
The skill operations for the language model.
Returns:
| Name | Type | Description |
|---|---|---|
AnthropicSkillOperations |
AnthropicSkillOperations
|
The skill operations for the language model. |