tutorialpython
Using the Anthropic Python SDK with claudeapi.cheap
Complete guide to using the official Anthropic Python SDK with our discounted proxy. 2 lines of code to save 50%.
Installation
Install the official Anthropic SDK:
pip install anthropicBasic Usage
Just two changes from the official setup: base_url and api_key.
from anthropic import Anthropic
client = Anthropic(
base_url="https://claudeapi.cheap/api/proxy",
api_key="sk-cc-your-api-key"
)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "What is machine learning?"}
]
)
print(message.content[0].text)Streaming
with client.messages.stream(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a haiku about coding"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)System Prompts
message = client.messages.create(
model="claude-opus-4-6",
max_tokens=2048,
system="You are a senior Python developer. Be concise.",
messages=[
{"role": "user", "content": "Review this code: def add(a,b): return a+b"}
]
)Environment Variables
For cleaner code, set environment variables:
export ANTHROPIC_API_KEY="sk-cc-your-api-key"
export ANTHROPIC_BASE_URL="https://claudeapi.cheap/api/proxy"Then your code is identical to official usage:
client = Anthropic() # reads from env varsError Handling
from anthropic import APIError, RateLimitError
try:
message = client.messages.create(...)
except RateLimitError:
print("Rate limited, retrying...")
except APIError as e:
print(f"API error: {e.message}")All Models Available
claude-opus-4-6 â Most powerfulclaude-sonnet-4-6 â Best balanceclaude-haiku-4-5 â Fastest & cheapest