跳轉到主要內容

概覽

此端點提供原生的 Anthropic Messages API 相容性。對於具備延伸思考等功能的 Claude 模型,請使用此端點。
Anthropic SDK 的 Base URL:https://api.lemondata.cc(不含 /v1 後綴)

請求標頭

x-api-key
string
必填
您的 LemonData API 金鑰。可作為 Bearer token 的替代方案。
anthropic-version
string
必填
Anthropic API 版本。請使用 2023-06-01

請求主體

model
string
必填
Claude 模型 ID(例如:claude-sonnet-4-6claude-opus-4-6)。
messages
array
必填
訊息物件陣列,包含 rolecontent
max_tokens
integer
必填
要生成的最大 token 數量。
system
string
System prompt(與 messages 陣列分開)。
temperature
number
預設值:"1"
取樣溫度(0-1)。
stream
boolean
預設值:"false"
啟用串流回應。
thinking
object
延伸思考設定(Claude Opus 4.5)。
  • type(string):設為 "enabled" 以啟用
  • budget_tokens(integer):思考可使用的 token 預算
tools
array
模型可用的工具。
tool_choice
object
模型應如何使用工具。選項:autoanytool(指定工具)。
top_p
number
Nucleus sampling 參數。請使用 temperature 或 top_p 其中之一,不要同時使用。
top_k
integer
每個 token 僅從前 K 個選項中取樣。
stop_sequences
array
自訂停止序列,當出現時模型將停止生成。
metadata
object
附加到請求上的中繼資料,用於追蹤目的。

回應

id
string
唯一的訊息識別碼。
type
string
一律為 message
role
string
一律為 assistant
content
array
內容區塊陣列(text、thinking、tool_use)。
model
string
所使用的模型。
stop_reason
string
生成停止的原因(end_turnmax_tokenstool_use)。
usage
object
Token 使用情況,包含 input_tokensoutput_tokens
curl -X POST "https://api.lemondata.cc/v1/messages" \
  -H "x-api-key: sk-your-api-key" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "system": "You are a helpful assistant.",
    "messages": [
      {"role": "user", "content": "Hello, Claude!"}
    ]
  }'
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "model": "claude-sonnet-4-6",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 15,
    "output_tokens": 10
  }
}

圖片輸入示例

對於支援視覺能力的 Claude 模型,請將圖片放在 messages[].content 中,作為結構化圖片內容區塊傳入。
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "請描述這張圖片。"
        },
        {
          "type": "image",
          "source": {
            "type": "url",
            "url": "https://example.com/demo.jpg"
          }
        }
      ]
    }
  ]
}
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "請描述這張圖片。"
        },
        {
          "type": "image",
          "source": {
            "type": "base64",
            "media_type": "image/jpeg",
            "data": "/9j/4AAQSkZJRgABAQ..."
          }
        }
      ]
    }
  ]
}

延伸思考範例

message = client.messages.create(
    model="claude-opus-4-6",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000
    },
    messages=[{"role": "user", "content": "Solve this math problem..."}]
)

for block in message.content:
    if block.type == "thinking":
        print(f"Thinking: {block.thinking}")
    elif block.type == "text":
        print(f"Response: {block.text}")

Anthropic Message Batches

LemonData 現在除了 /v1/messages 之外,也提供原生 Anthropic Message Batches 流程。 可用路由:
  • POST /v1/messages/batches
  • GET /v1/messages/batches
  • GET /v1/messages/batches/:message_batch_id
  • GET /v1/messages/batches/:message_batch_id/results
  • POST /v1/messages/batches/:message_batch_id/cancel
  • DELETE /v1/messages/batches/:message_batch_id
使用說明:
  • 使用同一把 LemonData API key 與 Anthropic 原生請求標頭。
  • 如果 batch item 引用了 file_id,也要加上 anthropic-beta: files-api-2025-04-14
  • Batch job 會維持 Anthropic 原生請求/回應格式,同時 LemonData 會追蹤其內部結算生命週期。