Calling Anthropic API: messages
Use the Anthropic messages API: differences from OpenAI, system prompt placement, and Claude-specific best practices.
Why Anthropic?
Claude models often have stronger instruction-following, better tool use, and longer context windows than equivalent OpenAI models — and are sometimes cheaper.
Most production agents support both providers as a fallback.
Install the SDK
# pip install anthropic
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from envAll lessons in this course
- Calling OpenAI API: chat.completions
- Calling Anthropic API: messages
- Streaming Responses (SSE)
- Cost Awareness: Token Counting and Budgets