Claude is a family of foundational AI models by Anthropic that can be used in a variety of applications.

Authentication

Set your ANTHROPIC_API_KEY environment. You can get one from Anthropic here.

export ANTHROPIC_API_KEY=***

Example

Use Claude with your Agent:

from phi.agent import Agent, RunResponse
from phi.model.anthropic import Claude

agent = Agent(
    model=Claude(id="claude-3-5-sonnet-20240620"),
    markdown=True
)

# Get the response in a variable
# run: RunResponse = agent.run("Share a 2 sentence horror story.")
# print(run.content)

# Print the response on the terminal
agent.print_response("Share a 2 sentence horror story.")

Params

ParameterTypeDefaultDescription
idstr"claude-3-5-sonnet-20240620"The id of the Anthropic Claude model to use
namestr"Claude"The name of the model
providerstr"Anthropic"The provider of the model
max_tokensOptional[int]1024Maximum number of tokens to generate in the chat completion
temperatureOptional[float]NoneControls randomness in the model's output
stop_sequencesOptional[List[str]]NoneA list of strings that the model should stop generating text at
top_pOptional[float]NoneControls diversity via nucleus sampling
top_kOptional[int]NoneControls diversity via top-k sampling
request_paramsOptional[Dict[str, Any]]NoneAdditional parameters to include in the request
api_keyOptional[str]NoneThe API key for authenticating with Anthropic
client_paramsOptional[Dict[str, Any]]NoneAdditional parameters for client configuration
clientOptional[AnthropicClient]NoneA pre-configured instance of the Anthropic client