mirascope.core.anthropic.call | Mirascope
MirascopeLilypad

mirascope.core.anthropic.call

Alias call

A decorator for calling the Anthropic API with a typed function.

Usage

This decorator is used to wrap a typed function that calls the Anthropic API. It parses the prompt template of the wrapped function as the messages array and templates the input arguments for the function into each message's template.

Example:

from mirascope.core import prompt_template
from mirascope.core.anthropic import anthropic_call


@anthropic_call("claude-3-5-sonnet-20240620")
def recommend_book(genre: str) -> str:
    return f"Recommend a {genre} book"

response = recommend_book("fantasy")
print(response.content)

Parameters

NameTypeDescription
modelstrThe Anthropic model to use in the API call.
streamboolWhether to stream the response from the API call.
toolslist[BaseTool | Callable]The tools to use in the Anthropic API call.
response_modelBaseModel | BaseTypeThe response model into which the response should be structured.
output_parser(AnthropicCallResponse | ResponseModelT) => AnyA function for parsing the call response whose value will be returned in place of the original call response.
json_modeboolWhether to use JSON Mode.
clientobjectAn optional custom client to use in place of the default client.
call_paramsAnthropicCallParamsThe `AnthropicCallParams` call parameters to use in the API call.

Returns

TypeDescription
CallableThe decorator for turning a typed function into an Anthropic API call.

Alias to: mirascope.core.anthropic._call.anthropic_call