Skip to content

Anthropic

The Anthropic SDK is the production path for Claude. agentfootprint’s anthropic() factory wraps it as an LLMProvider — same interface as mock(), so the rest of your agent code is identical between dev and prod.

Terminal window
npm install @anthropic-ai/sdk

The SDK is a peer dependency declared in peerDependenciesMeta with optional: true — npm doesn’t auto-install it. Lazy-required at first call; friendly install hint if missing.

import { Agent, anthropic } from 'agentfootprint';
const provider = anthropic({
apiKey: process.env.ANTHROPIC_API_KEY!,
// defaultModel: 'claude-sonnet-4-5-20250929', // optional, used when Agent doesn't override
});
const agent = Agent.create({
provider,
model: 'claude-sonnet-4-5-20250929',
}).build();

Model strings need date suffixes (claude-sonnet-4-5-20250929, claude-haiku-4-5-20251001) — Anthropic’s API requires the explicit version for stability.

Anthropic’s Messages API has native tool_use blocks. The provider translates the agent’s Tool[] into the API’s tool format and round-trips assistant tool_calls via LLMMessage.toolCalls. ReAct correctness preserved across multi-iteration runs.

provider.stream(req) uses the SDK’s native iterator; chunks land as they arrive. Final chunk carries the full LLMResponse (toolCalls + usage + stopReason) — single round-trip serves UI tokens AND ReAct decisioning.

Wrap with resilience decorators for production:

import { withRetry, withFallback, anthropic, openai } from 'agentfootprint';
const provider = withRetry(
withFallback(
anthropic({ apiKey: process.env.ANTHROPIC_API_KEY! }),
openai({ apiKey: process.env.OPENAI_API_KEY! }),
),
{ maxAttempts: 5 },
);

See Resilience guide.

For browser environments where the Anthropic Node SDK doesn’t bundle cleanly, use BrowserAnthropicProviderfetch-based, zero peer deps. Requires the anthropic-dangerous-direct-browser-access: true header (which the provider sets automatically). Production browser apps should proxy through a backend.

  • Multi-modal content (images, video) not supported — LLMMessage.content is string.
  • responseFormat (JSON-Schema-coerced output) not exposed yet — pass schema instructions via systemPrompt.