Store Chat Messages & State Without Managing Infrastructure.Check Out DialogueDB
Skip to content

Anthropic

When using Anthropic models, llm-exe will make POST requests to https://api.anthropic.com/v1/messages.

Setup

Anthropic Chat

ts
const llm = useLlm("anthropic.chat.v1", {
  model: "claude-sonnet-4-6", // specify a model
});

Anthropic Chat By Model

ts
const llm = useLlm("anthropic.claude-sonnet-4-6", {
  // other options,
  // no model needed, using claude-sonnet-4-6
});
INFO
You can use the following models using this shorthand:
  • anthropic.claude-opus-4-6
  • anthropic.claude-sonnet-4-6
  • anthropic.claude-sonnet-4
  • anthropic.claude-opus-4
  • anthropic.claude-3-7-sonnet
  • anthropic.claude-3-5-sonnet
  • anthropic.claude-3-5-haiku

Authentication

To authenticate, you need to provide an Anthropic API Key. You can either provide the API key various ways, depending on your use case.

  • Pass in as execute options using anthropicApiKey
  • Pass in as setup options using anthropicApiKey
  • Use a default key by setting an environment variable of ANTHROPIC_API_KEY

Basic Usage

Generally you pass the LLM instance off to an LLM Executor and call that. However, it is possible to interact with the LLM object directly, if you wanted.

ts
// given array of chat messages, calls chat completion
await llm.call([]);

// given string prompt, calls completion
await llm.call("");

Anthropic-Specific Options

OptionTypeDefaultDescription
anthropicApiKeystringundefinedAPI key for Anthropic. Optionally can be set using process.env.ANTHROPIC_API_KEY
modelstringThe model to use. Must be specified when using anthropic.chat.v1.
temperaturenumberundefinedMaps to temperature. See Anthropic Docs
maxTokensnumber4096Maps to max_tokens. See Anthropic Docs
topPnumberundefinedMaps to top_p. See Anthropic Docs
topKnumberundefinedMaps to top_k. See Anthropic Docs
stopSequencesarrayundefinedMaps to stop_sequences. See Anthropic Docs
streambooleanundefinedNote: Not supported yet.
metadataobjectundefinedMaps to metadata. See Anthropic Docs
serviceTierstringundefinedMaps to service_tier. See Anthropic Docs

Anthropic Docs: link