namzu.aidocs

Anthropic Provider

Configure @namzu/anthropic for the Anthropic Messages API through Namzu.

@namzu/anthropic is the direct Anthropic integration for Namzu. It wraps the official Anthropic SDK and exposes the provider as the anthropic type in ProviderRegistry.

1. When to Use It

Choose this package when you want native Anthropic Messages API behavior instead of going through a compatibility layer.

2. When Not to Use It

Choose another provider when:

  • you need AWS-native auth and region semantics, in which case @namzu/bedrock is a better fit
  • your endpoint is only Anthropic-compatible over raw HTTP, in which case @namzu/http may be the simpler abstraction

3. Install

pnpm add @namzu/sdk @namzu/anthropic

4. Register and Create the Provider

import { ProviderRegistry } from '@namzu/sdk'
import { registerAnthropic } from '@namzu/anthropic'
 
registerAnthropic()
 
const { provider, capabilities } = ProviderRegistry.create({
  type: 'anthropic',
  apiKey: process.env.ANTHROPIC_API_KEY!,
  model: 'claude-sonnet-4-20250514',
  maxTokens: 4096,
})

5. Sanity-Check With a Direct Provider Call

const response = await provider.chat({
  model: 'claude-sonnet-4-20250514',
  messages: [{ role: 'user', content: 'Say hello in one sentence.' }],
  maxTokens: 1024,
})
 
console.log(response.message.content)

6. Use It With a Reactive Agent

import {
  ReactiveAgent,
  ToolRegistry,
  generateProjectId,
  generateSessionId,
  generateTenantId,
} from '@namzu/sdk'
 
const agent = new ReactiveAgent({
  id: 'anthropic-agent',
  name: 'Anthropic Agent',
  version: '1.0.0',
  category: 'docs',
  description: 'Provider documentation example.',
})
 
const result = await agent.run(
  {
    messages: [{ role: 'user', content: 'Say hello.' }],
    workingDirectory: process.cwd(),
  },
  {
    provider,
    tools: new ToolRegistry(),
    model: 'claude-sonnet-4-20250514',
    tokenBudget: 8_192,
    timeoutMs: 60_000,
    projectId: generateProjectId(),
    sessionId: generateSessionId(),
    tenantId: generateTenantId(),
  },
)

7. Configuration

FieldRequiredDescription
apiKeyYesAnthropic API key
modelNoDefault model for calls that omit params.model
baseURLNoOverride endpoint URL for a compatible proxy or gateway
timeoutNoRequest timeout in milliseconds
defaultHeadersNoExtra headers appended to every request
maxTokensNoDefault max_tokens value; Anthropic requires this field at request time

8. Capability Snapshot

The package exports ANTHROPIC_CAPABILITIES:

{
  supportsTools: true,
  supportsStreaming: true,
  supportsFunctionCalling: true,
}

9. Operational Notes

  • Anthropic requires max_tokens, so setting maxTokens at provider creation time is a good default.
  • baseURL can point at proxies or gateways, but for Bedrock-hosted Anthropic models @namzu/bedrock is the better fit.
  • The provider also implements listModels() and healthCheck().

10. Common Errors

ErrorMeaningFix
Unsupported provider type: anthropicregistration never happenedcall registerAnthropic() before create()
missing API key errorapiKey not providedpass a valid Anthropic API key
tool-rich calls fail unexpectedlymax_tokens handling was overlooked in direct callsset maxTokens at provider creation or per call

On this page