Anthropic provides a number of chat based models under the Claude moniker. Note that a Claude Pro membership does not give you the ability to call models via the API; instead, you will need to sign up (and pay for) a developer account.
chat_anthropic(
system_prompt = NULL,
params = NULL,
max_tokens = deprecated(),
model = NULL,
api_args = list(),
base_url = "https://api.anthropic.com/v1",
beta_headers = character(),
api_key = anthropic_key(),
api_headers = character(),
echo = NULL
)
models_anthropic(
base_url = "https://api.anthropic.com/v1",
api_key = anthropic_key()
)A system prompt to set the behavior of the assistant.
Common model parameters, usually created by params().
Maximum number of tokens to generate before stopping.
The model to use for the chat (defaults to "claude-sonnet-4-20250514").
We regularly update the default, so we strongly recommend explicitly specifying a model for anything other than casual use.
Use models_anthropic() to see all options.
Named list of arbitrary extra arguments appended to the body
of every chat API call. Combined with the body object generated by ellmer
with modifyList().
The base URL to the endpoint; the default uses OpenAI.
Optionally, a character vector of beta headers to opt-in claude features that are still in beta.
API key to use for authentication.
You generally should not supply this directly, but instead set the ANTHROPIC_API_KEY environment variable.
The best place to set this is in .Renviron,
which you can easily edit by calling usethis::edit_r_environ().
Named character vector of arbitrary extra headers appended to every chat API call.
One of the following options:
none: don't emit any output (default when running in a function).
output: echo text and tool-calling output as it streams in (default
when running at the console).
all: echo all input and output.
Note this only affects the chat() method.
A Chat object.
Other chatbots:
chat_aws_bedrock(),
chat_azure_openai(),
chat_cloudflare(),
chat_databricks(),
chat_deepseek(),
chat_github(),
chat_google_gemini(),
chat_groq(),
chat_huggingface(),
chat_mistral(),
chat_ollama(),
chat_openai(),
chat_openrouter(),
chat_perplexity(),
chat_portkey()
chat <- chat_anthropic()
#> Using model = "claude-sonnet-4-20250514".
chat$chat("Tell me three jokes about statisticians")
#> Here are three jokes about statisticians:
#>
#> 1. **The Drowning Statistician**
#> A statistician can have his head in an oven and his feet in ice, and he'll say
#> that on average, he feels fine.
#>
#> 2. **The Hiring Process**
#> How do you tell the difference between an introverted statistician and an
#> extroverted statistician? The introverted one looks at his own shoes when
#> talking to you. The extroverted one looks at *your* shoes.
#>
#> 3. **The Wedding Anniversary**
#> A statistician's wife is having a baby. The statistician is pacing in the
#> hospital corridor when the nurse comes out and says, "Congratulations! You're
#> the father of beautiful twins!" The statistician replies, "Well, I suppose
#> that's close to the national average."