Anthropic Claude
Use Anthropic Claude models with PraisonAI Agents
Environment Variables
Setting MODEL_NAME=anthropic/claude-3-5-sonnet is enough — no need to set OPENAI_BASE_URL. The ANTHROPIC_API_KEY environment variable is consulted; OPENAI_API_KEY is not used as a fallback.
If you just want the Anthropic default, setting ANTHROPIC_API_KEY alone is enough — no MODEL_NAME, no llm=. Agent(...) picks anthropic/claude-3-5-sonnet-latest and routes it through litellm. See Provider Auto-Detection.
import os
from praisonaiagents import Agent
os.environ["MODEL_NAME"] = "anthropic/claude-3-5-sonnet"
os.environ["ANTHROPIC_API_KEY"] = "your-anthropic-key"
agent = Agent(name="Claude", instructions="You are Claude")Models
- Recommended:
claude-3-5-sonnet-20241022(best balance) - Fast/Cheap:
claude-3-5-haiku-20241022(fastest, affordable) - Advanced:
claude-3-opus-20240229(highest capability) - Latest:
claude-sonnet-4-5,claude-haiku-4-5(newest)
Routed model formats
Claude reached through Bedrock, Vertex AI, or OpenRouter is now detected as Anthropic — not misrouted to the OpenAI adapter — so async streaming works for these prefixes too.
| Routed model id | Detected provider | Async streaming |
|---|---|---|
bedrock/anthropic.claude-3-5-sonnet-v1:0 | Anthropic | ✅ supported |
vertex_ai/claude-3-5-sonnet@20240620 | Anthropic | ✅ supported |
openrouter/anthropic/claude-3.5-sonnet | Anthropic | ✅ supported |
See Routed model provider detection for the full detection rules.
Python
# export ANTHROPIC_API_KEY=your-api-key
from praisonaiagents import Agent
agent = Agent(
instructions="You are a helpful assistant",
llm="claude-3-5-sonnet-20241022"
)
agent.start("Explain quantum computing simply")With Tools
# export ANTHROPIC_API_KEY=your-api-key
from praisonaiagents import Agent
def calculate(expression: str) -> str:
"""Evaluate a math expression."""
return str(eval(expression))
agent = Agent(
instructions="You are a math assistant",
llm="claude-3-5-haiku-20241022",
tools=[calculate]
)
agent.start("What is 25 * 17 + 89?")Multi-Agent
# export ANTHROPIC_API_KEY=your-api-key
from praisonaiagents import Agent, Task, AgentTeam
analyst = Agent(
instructions="You analyze data and find insights",
llm="claude-3-5-sonnet-20241022"
)
reporter = Agent(
instructions="You write clear reports",
llm="claude-3-5-haiku-20241022"
)
task1 = Task(description="Analyze market trends", agent=analyst)
task2 = Task(description="Write executive summary", agent=reporter)
agents = AgentTeam(agents=[analyst, reporter], tasks=[task1, task2])
agents.start()CLI
export ANTHROPIC_API_KEY=your-api-key
# Basic prompt
python -m praisonai "Explain AI" --llm claude-3-5-sonnet-20241022
# With temperature
python -m praisonai "Write a story" --llm claude-3-5-sonnet-20241022 --temperature 0.8
# Run agents.yaml
python -m praisonaiYAML
framework: praisonai
topic: Analyze business strategy
agents:
analyst:
role: Business Analyst
goal: Analyze market opportunities
instructions: You are an expert business analyst
llm:
model: claude-3-5-sonnet-20241022
tasks:
analysis_task:
description: Analyze current market trends and opportunities
expected_output: Detailed market analysis report
strategist:
role: Strategy Consultant
goal: Develop actionable recommendations
instructions: You create strategic business plans
llm:
model: claude-3-5-haiku-20241022
tasks:
strategy_task:
description: Create strategic recommendations based on analysis
expected_output: Strategic action plan