pip install anthropic★Official Python SDK. Also@anthropic-ai/sdk(TS), plus Go/Java/Ruby/C#/PHP.import anthropic client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY★The zero-arg client resolves credentials from the environment (ANTHROPIC_API_KEY, or anant auth loginprofile) — don't hardcode keys.anthropic.AsyncAnthropic()for asyncio.export ANTHROPIC_API_KEY="sk-ant-..."Get a key from console.anthropic.com. The SDK auto-retries 429/5xx/network errors (max_retries=2default) with backoff.# Bedrock / Vertex / Foundry: use the platform client class anthropic.AnthropicVertex(project_id="...", region="...")Samemessages.createsurface on Amazon Bedrock, Google Vertex AI, and Microsoft Foundry via their dedicated client classes (partner pricing).
resp = client.messages.create( model="claude-opus-5", max_tokens=16000, messages=[{"role":"user", "content":"What is the capital of France?"}])★The one call you use everywhere.messagesis a list of{"role","content"}(rolesuser/assistant).max_tokensis required.for block in resp.content: if block.type == "text": print(block.text)★resp.contentis a list of content blocks (text,thinking,tool_use, ...). Check.typebefore reading — don't assumecontent[0].text.resp.stop_reason · resp.usage.input_tokens / .output_tokens★stop_reason:end_turn,max_tokens,tool_use,refusal,pause_turn.usagereports billed tokens.# don't lowball max_tokens — hitting the cap truncates mid-thoughttipDefault ~16000 for non-streaming, ~64000 for streaming; use ~256 only for classification. Hitting the cap givesstop_reason: "max_tokens".
"claude-opus-5" # 1M ctx · $5 / $25 per 1M · the default★Anthropic's flagship general model — use it unless you have a reason not to. Thinking is on by default."claude-sonnet-5" # 1M ctx · $2 / $10 · high-volume workhorse★Cheaper, still very capable — good for production volume."claude-haiku-4-5"(200K, $1/$5) for simple, speed-critical tasks."claude-fable-5-1" # 1M ctx · $10 / $50 · most capableThe most capable widely-released model for the hardest reasoning/agentic work — different API behavior & higher price than Opus."claude-opus-4-8"is the prior Opus.client.models.list() · client.models.retrieve("claude-opus-5")Live capability lookup:max_input_tokens(context window),max_tokens,capabilities. ⚠️ Model IDs are complete — never append a date suffix.