English
中文
English

API Overview

中文

API 總覽

English

The Claude API is a RESTful API at https://api.anthropic.com that provides programmatic access to Claude models.

中文

Claude API 是位於 https://api.anthropic.com 的 RESTful API,提供對 Claude 模型的程式化存取。

English

Prerequisites

中文

先決條件

English

To use the Claude API, you'll need:

中文

要使用 Claude API,你需要:

English
  • An Anthropic Console account
  • An API key
中文
  • 一個 Anthropic Console 帳戶
  • 一個 API 金鑰
English

Available APIs

中文

可用的 API

English

The Claude API includes the following APIs:

中文

Claude API 包含以下 API:

English

General Availability:

中文

正式版(GA):

English
  • Messages API: Send messages to Claude for conversational interactions (POST /v1/messages)
  • Message Batches API: Process large volumes of Messages requests asynchronously with 50% cost reduction
  • Token Counting API: Count tokens in a message before sending to manage costs and rate limits
  • Models API: List available Claude models and their details
中文
  • Messages API:向 Claude 發送訊息進行對話互動(POST /v1/messages)
  • Message Batches API:非同步處理大量 Messages 請求,可節省 50% 成本
  • Token Counting API:發送前計算訊息中的 token 數量,以管理成本和速率限制
  • Models API:列出可用的 Claude 模型及其詳細資訊
English

Beta:

中文

測試版(Beta):

English
  • Files API: Upload and manage files for use across multiple API calls
  • Skills API: Create and manage custom agent skills
中文
  • Files API:上傳和管理可跨多個 API 呼叫使用的檔案
  • Skills API:建立和管理自訂 agent 技能
English

Authentication

中文

驗證

English

All requests to the Claude API must include these headers:

中文

所有對 Claude API 的請求都必須包含以下標頭:

English
Header Value Required
x-api-key Your API key from Console Yes
anthropic-version API version (e.g., 2023-06-01) Yes
content-type application/json Yes
中文
標頭 必填
x-api-key 從 Console 取得的 API 金鑰
anthropic-version API 版本(例如 2023-06-01)
content-type application/json
English

Client SDKs

中文

Client SDKs

English

Anthropic provides official SDKs that simplify API integration by handling authentication, request formatting, error handling, and more.

中文

Anthropic 提供官方 SDK,透過處理驗證、請求格式化、錯誤處理等功能來簡化 API 整合。

English

Benefits:

中文

優點:

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)
  • 型別安全的請求和回應處理
  • 內建重試邏輯和錯誤處理
  • 串流支援
  • 請求逾時和連線管理
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"}]
)
English

Claude API vs Third-Party Platforms

中文

Claude API vs 第三方平台

English

Claude is available through Anthropic's direct API and through partner platforms. Choose based on your infrastructure, compliance requirements, and pricing preferences.

中文

Claude 可透過 Anthropic 的直接 API 和合作夥伴平台使用。請根據你的基礎架構、合規要求和定價偏好做選擇。

English
Platform Provider Documentation
Amazon Bedrock AWS Claude on Amazon Bedrock
Vertex AI Google Cloud Claude on Vertex AI
Azure AI Microsoft Azure Claude on Azure AI
中文
平台 供應商 文件
Amazon Bedrock AWS Claude on Amazon Bedrock
Vertex AI Google Cloud Claude on Vertex AI
Azure AI Microsoft Azure Claude on Azure AI
English

Request Size Limits

中文

請求大小限制

English
Endpoint Maximum Size
Standard endpoints (Messages, Token Counting) 32 MB
Batch API 256 MB
Files API 500 MB
中文
端點 最大大小
標準端點(Messages、Token Counting) 32 MB
Batch API 256 MB
Files API 500 MB
English

Basic Example

中文

基本範例

English

Here's a minimal request using the Messages API:

中文

以下是使用 Messages API 的最小範例請求:

bash
curl https://api.anthropic.com/v1/messages \
  --header "x-api-key: $ANTHROPIC_API_KEY" \
  --header "anthropic-version: 2023-06-01" \
  --header "content-type: application/json" \
  --data '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello, Claude"}
    ]
  }'