Tổng quan
LemonData hỗ trợ đường dẫn Messages API gốc của Anthropic, vì vậy bạn có thể sử dụng trực tiếp Anthropic SDK chính thức cho các model Claude.
Đối với Anthropic SDK, hãy sử dụng https://api.lemondata.cc làm base URL, không tự thêm /v1.
Loại : SDK nativeĐường chính : Anthropic-nativeMức hỗ trợ : Đường native mạnh
Among the documented SDK routes, this is one of the strongest-supported LemonData paths for Claude-native features.
Cài đặt
Cấu hình Client
from anthropic import Anthropic
client = Anthropic(
api_key = "sk-your-lemondata-key" ,
base_url = "https://api.lemondata.cc" ,
)
Cách sử dụng cơ bản
message = client.messages.create(
model = "claude-sonnet-4-6" ,
max_tokens = 1024 ,
messages = [
{ "role" : "user" , "content" : "Explain LemonData in one sentence." }
]
)
print (message.content[ 0 ].text)
Streaming
with client.messages.stream(
model = "claude-sonnet-4-6" ,
max_tokens = 1024 ,
messages = [{ "role" : "user" , "content" : "Write a short poem about coding." }]
) as stream:
for text in stream.text_stream:
print (text, end = "" , flush = True )
Vision
import base64
message = client.messages.create(
model = "claude-sonnet-4-6" ,
max_tokens = 1024 ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "What's in this image?" },
{
"type" : "image" ,
"source" : {
"type" : "url" ,
"url" : "https://example.com/image.jpg"
}
}
]
}]
)
with open ( "image.png" , "rb" ) as f:
image_data = base64.b64encode(f.read()).decode()
message = client.messages.create(
model = "claude-sonnet-4-6" ,
max_tokens = 1024 ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "Describe this image" },
{
"type" : "image" ,
"source" : {
"type" : "base64" ,
"media_type" : "image/png" ,
"data" : image_data
}
}
]
}]
)
message = client.messages.create(
model = "claude-sonnet-4-6" ,
max_tokens = 1024 ,
tools = [{
"name" : "get_weather" ,
"description" : "Get the weather for a location" ,
"input_schema" : {
"type" : "object" ,
"properties" : {
"location" : { "type" : "string" }
},
"required" : [ "location" ]
}
}],
messages = [{ "role" : "user" , "content" : "What's the weather in Tokyo?" }]
)
for block in message.content:
if block.type == "tool_use" :
print (block.name)
print (block.input)
Extended Thinking
message = client.messages.create(
model = "claude-opus-4-6" ,
max_tokens = 16000 ,
thinking = {
"type" : "enabled" ,
"budget_tokens" : 10000
},
messages = [{ "role" : "user" , "content" : "Solve this complex problem step by step." }]
)
for block in message.content:
if block.type == "thinking" :
print (block.thinking)
elif block.type == "text" :
print (block.text)
Các Model Claude được khuyến nghị
Model Phù hợp nhất cho claude-opus-4-6Suy luận chuyên sâu, phân tích dạng dài claude-sonnet-4-6Lập trình, các tác vụ trợ lý tổng quát claude-haiku-4-5Phản hồi nhanh, gọn nhẹ
Khắc phục sự cố
Sử dụng https://api.lemondata.cc
Không tự thêm /v1 khi cấu hình Anthropic SDK
Kiểm tra rằng API key LemonData của bạn bắt đầu bằng sk-
Xác nhận key đang hoạt động trong dashboard LemonData
Hãy để Anthropic SDK quản lý auth header thay vì tự thêm custom header theo cách thủ công
Xác minh chính xác tên model Claude
Kiểm tra tính khả dụng hiện tại trong danh mục model của LemonData