Anthropic
When using Anthropic models, llm-exe will make POST requests to https://api.anthropic.com/v1/messages.
Setup
Anthropic Chat
const llm = useLlm("anthropic.chat.v1", {
model: "claude-sonnet-5", // specify a model
});Anthropic Chat By Model
const llm = useLlm("anthropic.claude-sonnet-5", {
// other options,
// no model needed, using claude-sonnet-5
});anthropic.claude-fable-5anthropic.claude-opus-5anthropic.claude-opus-4-8anthropic.claude-sonnet-5anthropic.claude-opus-4-7anthropic.claude-sonnet-4-6anthropic.claude-opus-4-5anthropic.claude-haiku-4-5anthropic.claude-sonnet-4-5anthropic.claude-opus-4-6deprecatedanthropic.claude-3-7-sonnetdeprecatedanthropic.claude-3-5-sonnetdeprecatedanthropic.claude-3-5-haikudeprecatedanthropic.claude-3-opusdeprecated
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.
// given array of chat messages, calls chat completion
await llm.call([]);
// given string prompt, calls completion
await llm.call("");Anthropic-Specific Options
| Option | Type | Default | Description |
|---|---|---|---|
| anthropicApiKey | string | undefined | API key for Anthropic. Optionally can be set using process.env.ANTHROPIC_API_KEY |
| model | string | — | The model to use. Must be specified when using anthropic.chat.v1. |
| temperature | number | undefined | Maps to temperature. See Anthropic Docs |
| maxTokens | number | 4096 | Maps to max_tokens. Raised to 65536 when unset on the escalated effort path (Opus 4.7 / 4.8 high). See the effort note below. |
| effort | string | undefined | Maps to reasoning effort / thinking. See the effort note below. |
| topP | number | undefined | Maps to top_p. See Anthropic Docs |
| topK | number | undefined | Maps to top_k. See Anthropic Docs |
| stopSequences | array | undefined | Maps to stop_sequences. See Anthropic Docs |
| stream | boolean | undefined | Note: Not supported yet. |
| metadata | object | undefined | Maps to metadata. See Anthropic Docs |
| serviceTier | string | undefined | Maps 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
