AG2B

Anthropic

Synchronous Stream Reasoning

AnthropicProvider connects the agent to Anthropic's Messages /v1/messages API and maps to AG2B's normalized messages.

Usage

import { Agent, AnthropicProvider } from '@ag2b/core';

const agent = new Agent({
  provider: new AnthropicProvider({
    baseURL: '/api/llm',
    model: 'claude-sonnet-4-6',
    maxTokens: 1024,
  }),
});

Reasoning

Pass thinking: { enabled: true, budgetTokens: N } to turn on Claude's extended thinking.

new AnthropicProvider({
  baseURL: '/api/llm',
  model: 'claude-sonnet-4-6',
  maxTokens: 4096,
  thinking: { enabled: true, budgetTokens: 2048 },
});

Anthropic requires signed thinking blocks to be echoed back on turns that also produce tool calls — the provider handles this for you via message metadata.

Configuration

baseURL

baseURL: string

URL the provider POSTs to.

fetch

fetch: typeof fetch | undefined

Never embed API keys in the client

The provider runs in the user's browser — anything you put into baseURL, fetch headers, or environment-substituted strings ships in your bundle to every user.

Treat your LLM API key like a database password: keep it on a server, point baseURL at your own proxy, and let the proxy attach auth on the way out.

Custom fetch implementation. Defaults to globalThis.fetch. See Custom Fetch for a wrapper example.

model

model: string | undefined

Model name sent in the request body's model field (e.g. 'claude-sonnet-4-6'). When omitted, no model field is sent.
A proxy endpoint may inject it. Direct calls to Anthropic's API will be rejected.

maxTokens

maxTokens: number | undefined

Sent in the request body's max_tokens field. When omitted, no max_tokens field is sent.
A proxy endpoint may inject it. Direct calls to Anthropic's API will be rejected.

thinking

thinking: { enabled: boolean; budgetTokens: number } | undefined

See Reasoning.

On this page