Anthropic Python SDK
Official Python SDK for the Anthropic API providing access to Claude models. Current version is 0.84.0 (Feb 2026). Releases approximately weekly. Two separate packages exist: anthropic (core SDK) and claude-agent-sdk-python (agent workflows).
Common errors
-
ModuleNotFoundError: No module named 'anthropic'
cause The 'anthropic' package is not installed in the Python environment.fixInstall the package using 'pip install anthropic'. -
ImportError: cannot import name 'Anthropic' from 'anthropic'
cause The import statement is incorrect; 'Anthropic' is not a valid import from the 'anthropic' package.fixUse 'from anthropic import AnthropicClient' instead. -
AttributeError: module 'anthropic' has no attribute 'Anthropic'
cause The 'Anthropic' class does not exist in the 'anthropic' module.fixInstantiate the client with 'client = anthropic.AnthropicClient()'. -
TypeError: __init__() missing 1 required positional argument: 'api_key'
cause The 'AnthropicClient' class requires an 'api_key' argument during initialization.fixInitialize with 'client = anthropic.AnthropicClient(api_key="your_api_key")'. -
ValueError: Invalid API key provided
cause The provided API key is incorrect or malformed.fixEnsure the API key is correct and properly formatted.
Warnings
- breaking anthropic.Client() is removed. Use anthropic.Anthropic() instead.
- gotcha SDK releases weekly. Pin your version in production or expect frequent behaviour changes.
- gotcha message.content is a list, not a string. Access text via message.content[0].text.
- gotcha max_tokens is required. No default value. Omitting raises a validation error.
- deprecated claude-agent-sdk-python no longer requires Claude Code to be installed separately. It is bundled.
- breaking The package `claude-agent-sdk` is not a valid PyPI package and cannot be found. If you are trying to install the main Anthropic SDK, use `anthropic`. If you are looking for an agent-specific SDK, you might be looking for `claude-agent-sdk-python`.
- breaking Failed to authenticate due to missing API key. Ensure `api_key` is passed during client initialization or set the `ANTHROPIC_API_KEY` environment variable.
Install
-
pip install anthropic -
pip install claude-agent-sdk -
npm install @anthropic-ai/sdk
Imports
- Anthropic
import anthropic; anthropic.Client(api_key=...)
from anthropic import Anthropic
- AsyncAnthropic
import anthropic; anthropic.AsyncClient()
from anthropic import AsyncAnthropic
Quickstart
from anthropic import Anthropic
client = Anthropic() # reads ANTHROPIC_API_KEY from env
message = client.messages.create(
model='claude-opus-4-6',
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude"}
]
)
print(message.content[0].text)