Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
设置您的 API 密钥
将您的 API 密钥导出为环境变量。SDK 会自动读取 ANTHROPIC_API_KEY。
export ANTHROPIC_API_KEY="your-api-key-here"创建项目并安装 SDK
mkdir claude-quickstart && cd claude-quickstart
python3 -m venv .venv && source .venv/bin/activate
pip install anthropic编写代码
创建一个名为 quickstart.py 的文件:
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-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)运行代码
python quickstart.pyHere are some effective search strategies to find the latest developments in renewable energy:
## General Search Terms
- "Renewable energy news 2025"
- ...您已经完成了第一次 API 调用。接下来,学习您将在每个 Claude 集成中使用的 Messages API 模式。
学习多轮对话、系统提示、停止原因以及其他核心模式。
熟悉基础知识后,可以进一步探索:
按能力和成本比较 Claude 模型。
浏览 Claude 的所有功能:工具、上下文管理、结构化输出等。
Python、TypeScript、C# 及其他客户端库的参考文档。
比较 API 密钥和 Workload Identity Federation,并设置密钥过期时间。
Was this page helpful?