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# 和其他用戶端程式庫的參考文件。
Was this page helpful?