Chuyển đến nội dung chính
POST
/
v1
/
messages
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-5",
    "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-5",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 15,
    "output_tokens": 10
  }
}

Tổng quan

Endpoint này cung cấp khả năng tương thích gốc với Anthropic Messages API. Sử dụng endpoint này cho các mô hình Claude với các tính năng như suy nghĩ mở rộng (extended thinking).
Base URL cho Anthropic SDK: https://api.lemondata.cc (không có hậu tố /v1)

Request Headers

x-api-key
string
bắt buộc
API key LemonData của bạn. Giải pháp thay thế cho Bearer token.
anthropic-version
string
bắt buộc
Phiên bản Anthropic API. Sử dụng 2023-06-01.

Request Body

model
string
bắt buộc
ID mô hình Claude (ví dụ: claude-sonnet-4-5).
messages
array
bắt buộc
Mảng các đối tượng tin nhắn với rolecontent.
max_tokens
integer
bắt buộc
Số lượng token tối đa để tạo.
system
string
System prompt (tách biệt với mảng messages).
temperature
number
mặc định:"1"
Nhiệt độ lấy mẫu (0-1).
stream
boolean
mặc định:"false"
Bật phản hồi dạng luồng (streaming).
thinking
object
Cấu hình suy nghĩ mở rộng (Claude Opus 4.5).
  • type (string): "enabled" để kích hoạt
  • budget_tokens (integer): Ngân sách token cho việc suy nghĩ
tools
array
Các công cụ có sẵn cho mô hình.
tool_choice
object
Cách mô hình nên sử dụng các công cụ. Các tùy chọn: auto, any, tool (công cụ cụ thể).
top_p
number
Tham số lấy mẫu hạt nhân (nucleus sampling). Sử dụng temperature hoặc top_p, không sử dụng cả hai.
top_k
integer
Chỉ lấy mẫu từ K tùy chọn hàng đầu cho mỗi token.
stop_sequences
array
Các chuỗi dừng tùy chỉnh sẽ khiến mô hình ngừng tạo nội dung.
metadata
object
Metadata để đính kèm vào yêu cầu cho mục đích theo dõi.

Phản hồi

id
string
Định danh tin nhắn duy nhất.
type
string
Luôn là message.
role
string
Luôn là assistant.
content
array
Mảng các khối nội dung (text, thinking, tool_use).
model
string
Mô hình được sử dụng.
stop_reason
string
Lý do việc tạo nội dung dừng lại (end_turn, max_tokens, tool_use).
usage
object
Mức sử dụng token với 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-5",
    "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-5",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 15,
    "output_tokens": 10
  }
}

Ví dụ về Suy nghĩ Mở rộng

message = client.messages.create(
    model="claude-opus-4-5",
    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}")