Call Claude with the official Anthropic SDK (Python and TypeScript)
Install the anthropic / @anthropic-ai/sdk package, set ANTHROPIC_API_KEY and send your first Messages API request to Claude Opus 5.5, following Anthropic's official Get started page.
Verification
- Test environment
- Unknown
- Tested on
- Unknown
- Last updated
- 2026-11-11
Related models: Claude Haiku 5.5, Claude Opus 5.5, Claude Sonnet 5.5
This guide follows Anthropic's official Get started with Claude page. The code below is copied from that page; we have not run it ourselves.
1. Get an API key
Create an API key in the Claude Console. The SDKs read it from the ANTHROPIC_API_KEY environment variable:
export ANTHROPIC_API_KEY="your-api-key-here"
For local development, Anthropic also offers the ant CLI: after ant auth login, the SDKs pick up your credentials automatically, so you don't need to store a key in your shell.
2. Python
mkdir claude-quickstart && cd claude-quickstart
python3 -m venv .venv && source .venv/bin/activate
pip install anthropic
Save this as quickstart.py:
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1000,
messages=[
{
"role": "user",
"content": "What should I search for to find the latest developments in renewable energy?",
}
],
)
for block in message.content:
if block.type == "text":
print(block.text)
Run it with python quickstart.py.
3. TypeScript
mkdir claude-quickstart && cd claude-quickstart
npm init -y
npm pkg set type=module
npm install @anthropic-ai/sdk
Save this as quickstart.ts and run npx tsx quickstart.ts:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const message = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 1000,
messages: [
{
role: "user",
content: "What should I search for to find the latest developments in renewable energy?"
}
]
});
for (const block of message.content) {
if (block.type === "text") {
console.log(block.text);
}
}
4. Read the response
The response content is a list of blocks, which is why both samples loop and print only text blocks. The JSON also carries stop_reason (for example end_turn) and usage with input_tokens and output_tokens, which is what you are billed for.
If you call the HTTP API directly instead of using an SDK, send the x-api-key header and the anthropic-version header; the Get started page currently uses anthropic-version: 2026-10-21.
5. Pick a model
The quickstart uses claude-opus-5-5. You can swap in another model ID from the same family:
- Claude Opus 5.5:
claude-opus-5-5 - Claude Sonnet 5.5:
claude-sonnet-5-5 - Claude Haiku 5.5:
claude-haiku-5-5
Compare what each one costs for your workload on the Pricing page before you choose.
Next steps
- Stream long answers instead of waiting for the full message (see the streaming guide on this site).
- Cache long, repeated prompts with
cache_controlto cut input costs (see the prompt caching guide).
Further reading
- ChatGPT Plus vs Claude Pro: A Month of Token Usage Compared: the site owner's month of Claude Code and Codex usage, priced at API rates.
Sources
- Get started with Claude (Anthropic docs)platform
.claude .com (opens in a new tab) · checked 2026-11-11 - ChatGPT Plus vs Claude Pro: A Month of Token Usage Compared (XMLans blog)en
.xmlans .com (opens in a new tab) · checked 2026-11-11 - ChatGPT vs Claude 20刀订阅大横评(星梦博客)www
.xmlans .com (opens in a new tab) · checked 2026-11-11