Claude API 快速入门
5 分钟上手 Claude API
3 步上手 Claude API
调用 Claude API 非常简单。
1. 获取 API Key
前往 Anthropic Console 创建账号并获取 API Key。
2. 安装 SDK
# Python
pip install anthropic
# Node.js
npm install @anthropic-ai/sdk
3. 写代码调用
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[
{"role": "user", "content": "你好,Claude!"}
]
)
print(message.content[0].text)
⚠️API Key 建议存在环境变量 ANTHROPIC_API_KEY 中,SDK 会自动读取。不要把 Key 写在代码里。