Skip to main content

Anthropic Provider

Use Anthropic’s Claude models including Claude 4, Claude 3.5 Sonnet, and Claude 3 Opus.

Environment Variables

export ANTHROPIC_API_KEY=sk-ant-...
VariableRequiredDescription
ANTHROPIC_API_KEYYesYour Anthropic API key

Supported Modalities

ModalitySupported
Text/Chat
Embeddings
Image
Audio
Speech
Tools

Quick Start

import { Agent } from 'praisonai';

const agent = new Agent({
  name: 'Claude',
  instructions: 'You are a helpful assistant.',
  llm: 'anthropic/claude-sonnet-4-20250514'
});

const response = await agent.chat('Hello!');
console.log(response);

Available Models

ModelDescriptionContext
claude-sonnet-4-20250514Latest Claude 4 Sonnet200K
claude-opus-4-5Most capable200K
claude-3-5-sonnet-20241022Claude 3.5 Sonnet200K
claude-3-opus-20240229Claude 3 Opus200K
claude-3-haiku-20240307Fast, efficient200K

Advanced Configuration

import { Agent } from 'praisonai';

const agent = new Agent({
  name: 'AnalystClaude',
  instructions: 'You are an expert analyst.',
  llm: 'anthropic/claude-sonnet-4-20250514',
  llmConfig: {
    temperature: 0.7,
    maxTokens: 8192,
  }
});

With Tools

import { Agent } from 'praisonai';

const calculatorTool = {
  name: 'calculator',
  description: 'Perform calculations',
  parameters: {
    type: 'object',
    properties: {
      expression: { type: 'string', description: 'Math expression' }
    },
    required: ['expression']
  },
  execute: async ({ expression }) => {
    return eval(expression).toString();
  }
};

const agent = new Agent({
  name: 'MathClaude',
  instructions: 'Help with calculations.',
  llm: 'anthropic/claude-sonnet-4-20250514',
  tools: [calculatorTool]
});

Vision (Image Input)

import { Agent } from 'praisonai';

const agent = new Agent({
  name: 'VisionClaude',
  instructions: 'Analyze images.',
  llm: 'anthropic/claude-sonnet-4-20250514'
});

const response = await agent.chat({
  content: 'What is in this image?',
  images: ['https://example.com/image.jpg']
});

Streaming

import { Agent } from 'praisonai';

const agent = new Agent({
  name: 'StreamClaude',
  instructions: 'You are helpful.',
  llm: 'anthropic/claude-sonnet-4-20250514'
});

for await (const chunk of agent.stream('Tell me a story')) {
  process.stdout.write(chunk);
}

Multi-Agent Workflow

import { Agent, Agents } from 'praisonai';

const researcher = new Agent({
  name: 'Researcher',
  instructions: 'Research topics thoroughly.',
  llm: 'anthropic/claude-sonnet-4-20250514'
});

const writer = new Agent({
  name: 'Writer',
  instructions: 'Write clear summaries.',
  llm: 'anthropic/claude-3-haiku-20240307'
});

const agents = new Agents({
  agents: [researcher, writer],
  tasks: [
    { agent: researcher, description: 'Research {topic}' },
    { agent: writer, description: 'Summarize the research' }
  ]
});

const result = await agents.start({ topic: 'quantum computing' });

Troubleshooting

Invalid API Key

Error: Authentication failed
Solution: Verify your ANTHROPIC_API_KEY starts with sk-ant-.

Rate Limits

Error: Rate limit exceeded
Solution: Implement retry logic or contact Anthropic for higher limits.

Model Not Found

Error: Model not found
Solution: Check the model name includes the date suffix (e.g., claude-sonnet-4-20250514).