AnthropicClient

AnthropicClient(**kwargs: Any)

Initialize the Anthropic API client.

Parameters:
NameDescription
**kwargsType: Any

Instance Attributes

api_key



aws_access_key



aws_region



aws_secret_key



aws_session_token



gcp_auth_token



gcp_project_id



gcp_region



Instance Methods

convert_tools_to_functions

convert_tools_to_functions(tools: list) -> list

Convert tool definitions into Anthropic-compatible functions, updating nested $ref paths in property schemas.

Parameters:
NameDescription
toolsList of tool definitions.

Type: list
Returns:
TypeDescription
listlist: List of functions with updated $ref paths.

cost

cost(self, response) -> float

Calculate the cost of the completion using the Anthropic pricing.

Parameters:
NameDescription
response

create

create(self, params: dict[str, Any]) -> ChatCompletionExtended

Creates a completion using the Anthropic API.

Parameters:
NameDescription
paramsType: dict[str, Any]

get_usage

get_usage(response: ChatCompletion) -> dict

Get the usage of tokens and their cost information.

Parameters:
NameDescription
responseType: ChatCompletion

load_config

load_config(self, params: dict[str, Any]) -> 

Load the configuration for the Anthropic API client.

Parameters:
NameDescription
paramsType: dict[str, Any]

message_retrieval

message_retrieval(self, response) -> list

Retrieve and return a list of strings or a list of Choice.Message from the response.
NOTE: if a list of Choice.Message is returned, it currently needs to contain the fields of OpenAI’s ChatCompletion Message object, since that is expected for function or tool calling in the rest of the codebase at the moment, unless a custom agent is being used.

Parameters:
NameDescription
response

openai_func_to_anthropic

openai_func_to_anthropic(openai_func: dict) -> dict
Parameters:
NameDescription
openai_funcType: dict