Anthropic Provider
Use Anthropic Claude models with PraisonAI TypeScript
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-...| Variable | Required | Description |
|---|---|---|
ANTHROPIC_API_KEY | Yes | Your Anthropic API key |
Supported Modalities
| Modality | Supported |
|---|---|
| Text/Chat | ✅ |
| Embeddings | ❌ |
| Image | ✅ |
| Audio | ❌ |
| Speech | ❌ |
| Tools | ✅ |
Quick Start
- Simple Usage
typescript 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); - With Configuration
Adjust provider credentials and model settings for production — see the sections above.
Available Models
| Model | Description | Context |
|---|---|---|
claude-sonnet-4-20250514 | Latest Claude 4 Sonnet | 200K |
claude-opus-4-5 | Most capable | 200K |
claude-3-5-sonnet-20241022 | Claude 3.5 Sonnet | 200K |
claude-3-opus-20240229 | Claude 3 Opus | 200K |
claude-3-haiku-20240307 | Fast, efficient | 200K |
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, AgentTeam } 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 AgentTeam({
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 failedSolution: Verify your ANTHROPIC_API_KEY starts with sk-ant-.
Rate Limits
Error: Rate limit exceededSolution: Implement retry logic or contact Anthropic for higher limits.
Model Not Found
Error: Model not foundSolution: Check the model name includes the date suffix (e.g., claude-sonnet-4-20250514).