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-5", // specify a model
});

Anthropic Chat By Model

ts
const llm = useLlm("anthropic.claude-sonnet-5", {
  // other options,
  // no model needed, using claude-sonnet-5
});
INFO
You can use the following models using this shorthand:
  • anthropic.claude-fable-5
  • anthropic.claude-opus-5
  • anthropic.claude-opus-4-8
  • anthropic.claude-sonnet-5
  • anthropic.claude-opus-4-7
  • anthropic.claude-sonnet-4-6
  • anthropic.claude-opus-4-5
  • anthropic.claude-haiku-4-5
  • anthropic.claude-sonnet-4-5
  • anthropic.claude-opus-4-6deprecated
    Shorthand "anthropic.claude-opus-4-6" is deprecated and may be removed in a future release.
  • anthropic.claude-3-7-sonnetdeprecated
    Shorthand "anthropic.claude-3-7-sonnet" is deprecated and may be removed in a future release.
  • anthropic.claude-3-5-sonnetdeprecated
    Shorthand "anthropic.claude-3-5-sonnet" is deprecated and may be removed in a future release.
  • anthropic.claude-3-5-haikudeprecated
    Shorthand "anthropic.claude-3-5-haiku" is deprecated and may be removed in a future release.
  • anthropic.claude-3-opusdeprecated
    Shorthand "anthropic.claude-3-opus" is deprecated and may be removed in a future release.
Deprecated shorthands still resolve and will continue to work for now, but the underlying provider may stop accepting them at any time. Migrate to a current shorthand when you can.

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. Raised to 65536 when unset on the escalated effort path (Opus 4.7 / 4.8 high). See the effort note below.
effortstringundefinedMaps to reasoning effort / thinking. See the effort note below.
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

NOTE

Sampling parameter restrictions: claude-opus-4-7, claude-opus-4-8, claude-opus-5, claude-sonnet-5, and claude-fable-5 reject requests that include temperature, topP, or topK — llm-exe silently drops these for those models. For other Claude 4.x models, topP is silently dropped when temperature is also set, because the Anthropic API does not allow both simultaneously.

effort: Accepts minimal/low/medium/high (silently ignored on models that do not support reasoning, e.g. Claude 3.x). For the adaptive generation (Opus 4.6 / 4.7 / 4.8 / 5, Sonnet 4.6 / 5, Fable 5) it sets output_config.effort and adaptive thinking; high escalates to xhigh on Opus 4.7 / 4.8, and in that escalated case, if you do not pass maxTokens, its default is raised from 4096 to 65536 so adaptive thinking is not truncated (an explicit maxTokens is always honored). For the 4.5 generation it sets extended-thinking budget_tokens and raises max_tokens above the budget.

How effort maps per model: On the adaptive-thinking models (Opus 4.6 / 4.7 / 4.8 / 5, Sonnet 4.6 / 5, Fable 5) llm-exe sends thinking: { type: "adaptive" } and maps minimal/low to low, medium to medium, and high to high (except Opus 4.7 / 4.8, where high escalates to xhigh as described above; Opus 5 is deliberately not escalated, since Anthropic recommends starting at high there). On the 4.5 generation (claude-opus-4-5, claude-sonnet-4-5, claude-haiku-4-5) it instead sends an explicit thinking budget of 1024 / 4096 / 10240 / 32768 tokens for minimal / low / medium / high, raising maxTokens above that budget when needed, since Anthropic counts thinking tokens against max_tokens. On any other model effort is ignored.

Timeout on the escalated path: the raised 65536 ceiling lets an xhigh run generate for much longer, and llm-exe does not stream, so the whole response must complete within timeout (default 30000ms). A long generation can exceed it, and a timeout is retried (default numOfAttempts 2), costing a second billed attempt. Raise timeout when using effort: "high" on Opus 4.7 / 4.8.

Because effort enables thinking, and Anthropic disallows sampling parameters while thinking is active, llm-exe drops temperature and topK, and drops topP unless it is >= 0.95, whenever effort enables thinking — so the request stays valid.

A forced tool_choice (functionCall: "any" or a named tool) is incompatible with extended thinking (the 4.5 enabled path); llm-exe throws a clear error rather than send a request the API rejects. Adaptive thinking (4.6+/5) permits forced tool use, so it is allowed.

Anthropic Docs: link