Careeroza
Setup and API Key
Install the SDK
Example
Inside your virtual environment:
pip install anthropic python-dotenvExample output
Successfully installed anthropic-1.x ...
# .env
ANTHROPIC_API_KEY=sk-ant-api03-xxxxxxxxxxxxxxxxfrom dotenv import load_dotenv
import anthropic
load_dotenv() # loads ANTHROPIC_API_KEY from .env
client = anthropic.Anthropic() # picks up ANTHROPIC_API_KEY automaticallyWhat the SDK Sends
Example
The SDK is a convenient wrapper around one HTTPS request: POST https://api.anthropic.com/v1/messages with a JSON body. Building that request yourself shows there is no magic (this does not send anything):
import json
api_key = "sk-ant-api03-demo-key-1234"
headers = {
"x-api-key": api_key[:10] + "...", # masked for printing
"anthropic-version": "2023-06-01",
"content-type": "application/json",
}
body = {
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello, Claude"}],
}
print("POST https://api.anthropic.com/v1/messages")
for k, v in headers.items():
print(f"{k}: {v}")
print()
print(json.dumps(body, indent=2))Output
POST https://api.anthropic.com/v1/messages
x-api-key: sk-ant-api...
anthropic-version: 2023-06-01
content-type: application/json
{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Hello, Claude"
}
]
}Example
The same call with curl:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-opus-5-5", "max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello, Claude"}]}'