Skip to content

Anthropic Provider

Set your Anthropic API key:

Terminal window
export ANTHROPIC_API_KEY=sk-ant-...

llmist will automatically discover and use Anthropic.

ModelAliasBest For
claude-opus-4-5opusComplex reasoning, creative tasks
claude-sonnet-4-5sonnetBalanced performance (recommended)
claude-haiku-4-5haikuFast, cost-effective tasks
import { LLMist } from 'llmist';
const answer = await LLMist.createAgent()
.withModel('sonnet')
.askAndCollect('Write a haiku about TypeScript');

All Claude 4+ models support extended thinking (reasoning). llmist maps ReasoningEffort to Anthropic’s thinking.budget_tokens:

EffortBudget Tokens
"none"1024 (minimum)
"low"2048
"medium"8192
"high"16384
"maximum"32768
const answer = await LLMist.createAgent()
.withModel('opus')
.withReasoning('high')
.askAndCollect('Explain the Riemann hypothesis.');

You can also specify an explicit token budget:

.withReasoning({ enabled: true, budgetTokens: 10000 })

For multi-turn tool use conversations, enable interleaved thinking so the model can reason between tool calls:

.withReasoning({ enabled: true, effort: 'high', interleaved: true })

See the Reasoning Models guide for full details.

Anthropic’s prompt caching reduces cost and latency by reusing previously computed context across requests. llmist enables caching automatically by adding cache_control markers to system prompts and the last user message.

No configuration needed — caching is on by default:

// Caching is automatic — repeated context is served from cache
const agent = LLMist.createAgent()
.withModel('sonnet')
.withSystem(largeSystemPrompt) // Cached automatically
.ask('Analyze this...');

To disable caching (removes all cache_control markers):

const agent = LLMist.createAgent()
.withModel('sonnet')
.withoutCaching() // No cache_control markers sent
.ask('Quick question');

Claude models support image input:

import { LLMist, imageFromBuffer } from 'llmist';
import { readFileSync } from 'fs';
const imageBuffer = readFileSync('diagram.png');
const answer = await LLMist.createAgent()
.withModel('sonnet')
.askWithImage(
'Describe this diagram',
imageFromBuffer(imageBuffer, 'image/png')
)
.askAndCollect();

Supported image formats: JPEG, PNG, GIF, WebP

Claude Opus 4.5 Most Capable

Section titled “Claude Opus 4.5 ”
  • Best for complex reasoning and creative tasks
  • Highest quality outputs
  • Higher latency and cost
  • 200K context window

Claude Sonnet 4.5 Recommended

Section titled “Claude Sonnet 4.5 ”
  • Best balance of capability and speed
  • Great for coding, analysis, and general tasks
  • Good cost efficiency
  • 200K context window
  • Fastest response times
  • Lowest cost
  • Good for simple tasks and high-volume use
  • 200K context window
import { LLMist, AnthropicMessagesProvider } from 'llmist';
const client = new LLMist({
autoDiscoverProviders: false,
adapters: [
new AnthropicMessagesProvider({
apiKey: process.env.ANTHROPIC_API_KEY,
baseUrl: 'https://api.anthropic.com', // Custom endpoint
}),
],
});
  1. Use Sonnet as default - Best balance for most tasks
  2. Reserve Opus for complex reasoning - When quality matters more than speed
  3. Use Haiku for high-volume - Simple tasks, classification, summarization
  4. Leverage long context - Claude handles 200K tokens well
for await (const event of agent.run()) {
if (event.type === 'llm_call_complete') {
console.log('Input tokens:', event.usage?.promptTokens);
console.log('Output tokens:', event.usage?.completionTokens);
console.log('Estimated cost:', event.cost);
}
}