Environment:Anthropics Anthropic sdk python Python SDK Core Environment
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, API_Client |
| Last Updated | 2026-02-15 12:00 GMT |
Overview
Python >= 3.9 environment with httpx, pydantic, anyio, and supporting libraries for the Anthropic Python SDK (v0.79.0).
Description
This environment provides the core runtime for interacting with the Anthropic Messages API. It requires Python 3.9 or later and a set of mandatory dependencies including httpx for HTTP transport, pydantic (v1 or v2) for response modeling, anyio for async compatibility, and jiter for fast JSON parsing. The SDK supports both synchronous and asynchronous usage patterns across all major operating systems (Linux, macOS, Windows).
Usage
Use this environment for any workflow involving the Anthropic Python SDK, including basic message conversations, streaming, tool use, structured output extraction, extended thinking, and cloud provider integrations. This is the mandatory base environment for all SDK operations.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux, macOS, Windows | OS-independent; POSIX preferred |
| Python | >= 3.9 | Supports 3.9, 3.10, 3.11, 3.12, 3.13, 3.14 |
| Network | HTTPS outbound to api.anthropic.com | Port 443; configurable via ANTHROPIC_BASE_URL |
Dependencies
Python Packages (Required)
httpx>= 0.25.0, < 1pydantic>= 1.9.0, < 3typing-extensions>= 4.10, < 5anyio>= 3.5.0, < 5distro>= 1.7.0, < 2sniffiojiter>= 0.4.0, < 1docstring-parser>= 0.15, < 1
Python Packages (Optional)
aiohttp+httpx_aiohttp>= 0.1.9 (for improved async concurrency)
Credentials
The following environment variables are used for authentication:
ANTHROPIC_API_KEY: Primary API key for authenticating with the Anthropic API.ANTHROPIC_AUTH_TOKEN: Alternative bearer token authentication (mutually exclusive with API key).ANTHROPIC_BASE_URL: Override the default API base URL (defaults tohttps://api.anthropic.com).ANTHROPIC_LOG: Controls SDK logging level. Set to"debug"or"info"for diagnostics.DEFER_PYDANTIC_BUILD: Controls Pydantic model building timing (defaults to"true").
Quick Install
pip install anthropic
For optional aiohttp support:
pip install 'anthropic[aiohttp]'
Code Evidence
Dependency declarations from pyproject.toml:11-19:
dependencies = [
"httpx>=0.25.0, <1",
"pydantic>=1.9.0, <3",
"typing-extensions>=4.10, <5",
"anyio>=3.5.0, <5",
"distro>=1.7.0, <2",
"sniffio",
"jiter>=0.4.0, <1",
"docstring-parser>=0.15,<1",
]
Python version requirement from pyproject.toml:22:
requires-python = ">= 3.9"
Environment variable handling from _client.py:92-103:
if api_key is None:
api_key = os.environ.get("ANTHROPIC_API_KEY")
self.api_key = api_key
if auth_token is None:
auth_token = os.environ.get("ANTHROPIC_AUTH_TOKEN")
self.auth_token = auth_token
if base_url is None:
base_url = os.environ.get("ANTHROPIC_BASE_URL")
if base_url is None:
base_url = f"https://api.anthropic.com"
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
AuthenticationError (401) |
Missing or invalid API key | Set ANTHROPIC_API_KEY environment variable or pass api_key parameter
|
RateLimitError (429) |
Too many requests | SDK auto-retries with backoff; reduce request rate if persistent |
ValueError: Streaming is required for operations that may take longer than 10 minutes |
Non-streaming request with high max_tokens | Use stream=True or reduce max_tokens
|
MissingDependencyError |
Optional extra not installed | Run pip install anthropic[vertex] or anthropic[bedrock]
|
Compatibility Notes
- Pydantic v1 and v2: The SDK includes a compatibility layer (
_compat.py) that supports both Pydantic v1 (1.9.0+) and v2 (2.x). Method dispatch is performed at runtime. - Async Runtimes: Supports asyncio and other async runtimes via anyio. The
sniffiolibrary detects the active async library. - HTTP Client: Default is httpx; optional aiohttp backend via
httpx_aiohttpfor improved async concurrency. - Python 3.14: Supported per pyproject.toml classifiers.
Related Pages
- Implementation:Anthropics_Anthropic_sdk_python_Anthropic_Client_Init
- Implementation:Anthropics_Anthropic_sdk_python_Messages_Create
- Implementation:Anthropics_Anthropic_sdk_python_Messages_Stream
- Implementation:Anthropics_Anthropic_sdk_python_BetaToolRunner
- Implementation:Anthropics_Anthropic_sdk_python_Messages_Parse
- Implementation:Anthropics_Anthropic_sdk_python_Cloud_Provider_Auth
- Implementation:Anthropics_Anthropic_sdk_python_Cloud_Provider_Clients
- Implementation:Anthropics_Anthropic_sdk_python_Provider_Dependency_Install
- Implementation:Anthropics_Anthropic_sdk_python_Messages_Create_With_Thinking