Documentation Index Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
Use this file to discover all available pages before exploring further.
نظرة عامة
يدعم TokenLab مسار Anthropic الأصلي Messages API ، لذا يمكنك استخدام Anthropic SDK الرسمي مباشرةً مع نماذج Claude.
بالنسبة إلى Anthropic SDK، استخدم https://api.tokenlab.sh كعنوان URL الأساسي، من دون إضافة /v1 بنفسك.
النوع : SDK أصليالمسار الرئيسي : Anthropic-nativeمستوى الدعم : مسار أصلي قوي
من بين مسارات SDK الموثقة، يُعد هذا أحد أكثر مسارات TokenLab دعماً للميزات الأصلية لـ Claude.
التثبيت
تهيئة العميل
from anthropic import Anthropic
client = Anthropic(
api_key = "sk-your-tokenlab-key" ,
base_url = "https://api.tokenlab.sh" ,
)
الاستخدام الأساسي
message = client.messages.create(
model = "claude-sonnet-4-6" ,
max_tokens = 1024 ,
messages = [
{ "role" : "user" , "content" : "Explain TokenLab in one sentence." }
]
)
print (message.content[ 0 ].text)
البث
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 )
الرؤية
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)
التفكير الموسّع
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)
نماذج Claude الموصى بها
النموذج الأفضل لـ claude-opus-4-6الاستدلال العميق، والتحليل المطوّل claude-sonnet-4-6البرمجة، ومهام المساعد العامة claude-haiku-4-5استجابات سريعة وخفيفة
استكشاف الأخطاء وإصلاحها
استخدم https://api.tokenlab.sh
لا تضف /v1 يدويًا عند تهيئة Anthropic SDK
تحقق من أن مفتاح TokenLab API الخاص بك يبدأ بـ sk-
تأكد من أن المفتاح نشط في لوحة تحكم TokenLab
دع Anthropic SDK يدير ترويسة المصادقة بدلًا من إضافة ترويسات مخصصة يدويًا
تحقق من اسم نموذج Claude بشكل مطابق تمامًا
راجع التوفر الحالي في فهرس نماذج TokenLab