Using the API

export ANTHROPIC_API_KEY="sk-ant-..."   # add to ~/.zshrc or ~/.bashrc
import anthropic
client = anthropic.Anthropic()   # reads ANTHROPIC_API_KEY automatically
response = client.messages.create(
    model="claude-opus-4-6",
    max_tokens=512,
    messages=[{"role": "user", "content": "How many rows are in a 10x10 grid?"}]
)
print(response.content[0].text)
import time
for attempt in range(5):
    try:
        response = client.messages.create(...)
        break
    except anthropic.RateLimitError:
        time.sleep(2 ** attempt)

Exercises