---
title: Anthropic
description: anthropic() — Claude provider via @anthropic-ai/sdk. Lazy-loaded peer-dep; install when you use it.
---

> 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.

## Install

```bash
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.

`anthropic()` is imported from the `agentfootprint/llm-providers` subpath (the `agentfootprint/providers` alias also works), NOT the main `agentfootprint` barrel. Vendor-SDK-backed providers live on that subpath so bundlers walking the main entry never touch the optional peer-dep requires — automatic tree-shaking. (The main barrel only re-exports the zero-peer-dep providers: `mock`, `browserAnthropic`, `browserOpenai`, `createProvider`.)

## Use

```ts
import { Agent } from 'agentfootprint';
import { anthropic } from 'agentfootprint/llm-providers';

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.

## Tools (native function calling)

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.

## Streaming

`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.

## Production patterns

Wrap with resilience decorators for production:

```ts
import { withRetry, withFallback } from 'agentfootprint/resilience';
import { anthropic, openai } from 'agentfootprint/llm-providers';

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

See [Resilience guide](/agentfootprint/guides/resilience/).

## Browser variant

For browser environments where the Anthropic Node SDK doesn't bundle cleanly, use `BrowserAnthropicProvider` — `fetch`-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.

## Limitations

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

## Next steps

- [Resilience](/agentfootprint/guides/resilience/) — wrap with `withRetry` / `withFallback`
- [Streaming](/agentfootprint/guides/streaming/) — token-by-token UI rendering
