English
中文
English
Client SDKs
中文
Client SDKs
English
Anthropic provides official SDKs to simplify API integration for Python, TypeScript, Java, and Go. We recommend using an SDK for most API interactions.
中文
Anthropic 提供官方 SDK 以簡化 Python、TypeScript、Java 和 Go 的 API 整合。我們建議在大多數 API 互動中使用 SDK。
English
Python SDK
中文
Python SDK
English
Install with pip:
中文
使用 pip 安裝:
bash
pip install anthropic
English
Usage example:
中文
使用範例:
python
from anthropic import Anthropic
client = Anthropic() # Reads ANTHROPIC_API_KEY from environment
message = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude"}]
)
print(message.content)
English
TypeScript SDK
中文
TypeScript SDK
English
Install with npm:
中文
使用 npm 安裝:
bash
npm install @anthropic-ai/sdk
English
Usage example:
中文
使用範例:
typescript
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic(); // Reads ANTHROPIC_API_KEY from environment
const message = await client.messages.create({
model: 'claude-sonnet-4-5',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }]
});
console.log(message.content);
English
Java SDK
中文
Java SDK
English
Add to your project with Gradle:
中文
使用 Gradle 新增至專案:
groovy
implementation 'com.anthropic:anthropic-sdk-java:latest'
English
Go SDK
中文
Go SDK
English
Install with go get:
中文
使用 go get 安裝:
bash
go get github.com/anthropics/anthropic-sdk-go
English
SDK Benefits
中文
SDK 優點
English
- Automatic header management (x-api-key, anthropic-version, content-type)
- Type-safe request and response handling
- Built-in retry logic and error handling
- Streaming support
- Request timeouts and connection management
中文
- 自動管理標頭(x-api-key、anthropic-version、content-type)
- 型別安全的請求和回應處理
- 內建重試邏輯和錯誤處理
- 串流支援
- 請求逾時和連線管理