Tool Use
Define functions in JSON schema. Claude decides when to call them; you execute and return.
If you just want to do a thing once, claude.ai is faster.
export ANTHROPIC_API_KEY=sk-ant-… (Mac/Linux) or setx ANTHROPIC_API_KEY "sk-ant-…" (Windows).pip install anthropic or npm install @anthropic-ai/sdk.import anthropic
client = anthropic.Anthropic()
msg = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude."}],
)
print(msg.content[0].text)
user and assistant turns. Each is text, images, documents, or tool calls/results.text block. Tool-using replies may have tool_use blocks you execute and feed back.Pick the model with model="claude-…". As of May 2026 the latest 4.x family includes Opus 4.7, Sonnet 4.6, Haiku 4.5. Default to Sonnet for cost-quality balance.
Define functions in JSON schema. Claude decides when to call them; you execute and return.
Mark long, repeated context (system prompt, big documents) as cacheable. ~90% cost reduction on cache hits.
Give Claude a thinking budget. Better answers on hard reasoning.
Pass documents in; Claude grounds its answer with span-level citations.
Drop images in messages. Claude reads them as content.
Upload once, reference by ID across calls. Pairs with caching for big PDFs.
Half-price async lane. Submit a batch, pick it up later. Great for backfills.
Screenshots in, mouse/keyboard out. Drives apps that have no API.
stream=True) so users see typing instead of waiting.max_tokens low for tool-driven loops; raise it only for the final synthesis turn.response.usage on every call. Build a dashboard in week one, not month six.