منځپانګې ته ټوپ ووهئ
انتروپيک بڼه

انتروپيک بڼه

POST /v1/messages د Anthropic Messages په بڼه غوښتنه اخلي او په همدې بڼه ځواب ورکوي، streamed یا نه. دا د Anthropic SDK او هغو وسیلو سره وکاروئ چې پر هغه جوړې شوې، لکه Claude Code: base URL وټاکئ، خپله Shannon API کیلي وکاروئ او د Shannon ماډل id نوم واخلئ.

POST https://api.shannon-ai.com/v1/messages

Anthropic SDK د Shannon base URL ته په نښه کړئ. SDK /v1/messages زیاتوي او ستاسو کیلي د x-api-key header کې لیږي.

import anthropic

client = anthropic.Anthropic(
    api_key="YOUR_API_KEY",
    base_url="https://api.shannon-ai.com",
)

message = client.messages.create(
    model="shannon-3",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)

for block in message.content:
    if block.type == "text":
        print(block.text)

ځواب یو message دی چې content یې د blocks لیست دی. blocks د هغوی د type له مخې ومومئ: کله چې ماډل reasoning کړی وي، لومړی block thinking وي او متن ورپسې راځي.

200 JSON
{
  "id": "msg_5f0c1e7a9b3d4c62a8e1f07d2b46c9a3",
  "type": "message",
  "role": "assistant",
  "model": "shannon-3",
  "content": [
    {
      "type": "thinking",
      "thinking": "The user wants a greeting in one sentence. Keep it short and friendly."
    },
    {
      "type": "text",
      "text": "Hello, it is good to meet you."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 1184,
    "output_tokens": 46
  }
}

Headers

Header ارزښت تشریح
x-api-key YOUR_API_KEY ستاسو API کیلي. Authorization: Bearer YOUR_API_KEY د هغې پر ځای منل کیږي.
content-type application/json اړین.
anthropic-version 2023-06-01 منل کیږي، اړین نه دی. Anthropic SDK 2023-06-01 لیږي؛ ځواب د ارزښت پروا پرته همدا بڼه لري.
anthropic-beta منل کیږي، اړین نه دی.
x-request-id اختیاري. د غوښتنې لپاره ستاسو خپل id. دا په ځواب کې بې بدلونه بیرته راځي؛ پرته له دې ځواب د 12 هیکساډیسیمل حروفو id لري.

د غوښتنې ساحې

یوازې messages اړین دی. د پلي کوونکی ستون هغه ماډلونه نوموي چې په هغوی کې یوه ساحه ځواب بدلوي. کوربه شوي open-weight ماډلونه د ماډل لیست دولس id ګانې دي؛ د Shannon 3 کورنۍ shannon-3، shannon-3-pro، shannon-3.1 او shannon-3.1-pro ده. ماډلونه او بیې

ساحه ډول تلواله تشریح پلي کوونکی
model string shannon-1.6-lite د ماډل لیست څخه د Shannon ماډل id. له هرې غوښتنې سره یې واستوئ. مطابقت د توریزو په لوی کوچنۍ حساس نه دی. هر بل نوم 400 unknown model بیرته ورکوي، نو هغه وسیله چې خپل ماډل نومونه لیږي باید د Shannon id ته تنظیم شي. ټول ماډلونه
messages array اړین. خبرې اترې، زوړ پیغام لومړی، د user او assistant رولونو سره. لاندې پیغامونه او د منځپانګې blocks وګورئ. ټول ماډلونه
system string | array ماډل ته لارښوونې: یو string، یا د متن blocks array. لاندې System prompt وګورئ. کوربه شوي open-weight ماډلونه، shannon-1.6-*، shannon-2-*، shannon-coder-1
max_tokens integer 4096 د ځواب پورتنۍ حد، په ټوکنونو. په دې endpoint کې اختیاري؛ Anthropic SDK تل یې لیږي. له 1 څخه تر 65,536 بهر ارزښت دې حد ته راوړل کیږي. دا هغه اندازه هم ده چې د غوښتنې د چلیدو پر مهال ستاسو له بیلانس څخه ایښودل کیږي. کوربه شوي open-weight ماډلونه، shannon-1.6-lite، shannon-1.6-pro، shannon-coder-1
stream boolean false true ځواب د server-sent events په توګه لیږي. لاندې Streaming وګورئ. ټول ماډلونه
temperature number د نمونې اخیستنې temperature. په کوربه شوو open-weight ماډلونو کې ارزښتونه د 0 او 2 ترمنځ ساتل کیږي. کوربه شوي open-weight ماډلونه، shannon-1.6-lite، shannon-1.6-pro، shannon-coder-1
top_p number Nucleus sampling. کوربه شوي open-weight ماډلونه
stop_sequences array تر 4 پورې strings. ځواب د لومړي هغه څخه مخکې پای ته رسیږي چې څرګندیږي. stop_reason end_turn پاتې کیږي. کوربه شوي open-weight ماډلونه
tools array هغه tools چې ماډل یې راوغوښتلی شي، هر یو د {"name", "description", "input_schema"} په بڼه. لاندې Tools وګورئ. ټول ماډلونه
tool_choice object {"type": "auto"} ماډل ته پریږدي چې پرېکړه وکړي، {"type": "any"} یې دې ته اړ باسي چې یو tool راوغواړي، {"type": "tool", "name": "…"} یې اړ باسي چې همدا tool راوغواړي. کوربه شوي open-weight ماډلونه
thinking object ماډل د ځواب ورکولو دمخه څومره reasoning کوي. لاندې Thinking وګورئ. کوربه شوي open-weight ماډلونه
web_search boolean false د بڼې لپاره د Shannon اضافه: true ماډل ته اجازه ورکوي چې د ځواب دمخه ویب وپلټي. shannon-1.6-*، shannon-2-*، د Shannon 3 کورنۍ

پرته له max_tokens ارزښت 4,096 دی، او په shannon-coder-1 کې 65,536.

metadata، top_k، service_tier او په blocks کې cache_control نښې منل کیږي ترڅو موجود کلاینټ کوډ بدلون پرته چلیږي. دا ځواب نه بدلوي؛ په کوربه شوو open-weight ماډلونو کې prompt caching اتومات دی.

د schema مطابق JSON ځواب په Chat Completions کې د response_format او په Responses کې د text.format سره غوښتل کیږي. جوړښت شوي محصولات

د system prompt او thinking سره غوښتنه

دا غوښتنه system prompt، thinking budget، temperature او یو stop sequence لیږي. دا یو کوربه شوی open-weight ماډل کاروي، چې ټول پلي کوي.

import anthropic

client = anthropic.Anthropic(
    api_key="YOUR_API_KEY",
    base_url="https://api.shannon-ai.com",
)

message = client.messages.create(
    model="DeepSeek-V4-Flash-0731-W4A16-AUTOROUND-REAP",
    max_tokens=4096,
    system="You are a physics teacher. Answer in two sentences.",
    thinking={"type": "enabled", "budget_tokens": 2048},
    temperature=0.3,
    stop_sequences=["\n\n"],
    messages=[{"role": "user", "content": "Why is the sky blue?"}],
)

for block in message.content:
    if block.type == "thinking":
        print("reasoning:", block.thinking)
    elif block.type == "text":
        print("answer:", block.text)
print(message.usage)

په کوربه شوو open-weight ماډلونو کې usage هغه ټوکنونه چې د prompt cache څخه لوستل شوي د نورو input ټوکنونو څخه جلا راپور ورکوي.

200 JSON
{
  "usage": {
    "input_tokens": 31,
    "cache_read_input_tokens": 0,
    "cache_creation_input_tokens": 0,
    "output_tokens": 62
  }
}

System prompt

system یو string دی، یا د متن blocks لیست په دې بڼه [{"type": "text", "text": "…"}]. د blocks متنونه د کرښې ماتوالي سره یوځای کیږي.

دا د کوربه شوو open-weight ماډلونو، shannon-1.6-lite، shannon-1.6-pro، shannon-2-lite، shannon-2-pro او shannon-coder-1 لخوا پلي کیږي. د Shannon 3 کورنۍ id سره، هغه لارښوونې چې باید وساتل شي د user message کې ولیکئ.

پیغامونه او د منځپانګې blocks

پیغام یو role لري، user یا assistant، او یو content. content یو string دی، یا د blocks array.

Block تشریح شتون لري په
{"type": "text", "text": "…"} متن. ټول ماډلونه
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "…"}}
{"type": "image", "source": {"type": "url", "url": "…"}}
یو انځور په user پیغام کې، د base64 په توګه یا د URL له لارې. د Shannon 3 کورنۍ، shannon-1.6-lite، shannon-1.6-pro، او کوربه شوي open-weight ماډلونه چې انځور input لیست کوي
{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} یو سند (PDF، Word، PowerPoint یا Excel) په user پیغام کې، د base64 په توګه یا د URL له لارې. د Shannon 3 کورنۍ
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} په assistant پیغام کې: هغه tool غوښتنه چې ماډل په پخواني ځواب کې کړې وه. ټول ماډلونه
{"type": "tool_result", "tool_use_id": "toolu_…", "content": "…"} په user پیغام کې: د هغې غوښتنې پایله. content یو string دی، یا د متن blocks لیست. ټول ماډلونه

تاسو کولی شئ د پخواني ځواب content هماغسې بیرته واستوئ: text او tool_use blocks لوستل کیږي، thinking blocks پریښودل کیږي.

د Shannon په کچو کې انځورونه او اسناد د وروستي user پیغام څخه لوستل کیږي. اندازې او حدونه خپله پاڼه لري. انځورونه او فایلونه

Thinking

کوربه شوي open-weight ماډلونه thinking د reasoning effort سره تړي. پرته له دې ساحې effort لوړ وي.

بڼه budget_tokens اغېز
{"type": "disabled"} reasoning نشته. ځواب thinking block نه لري.
{"type": "enabled", "budget_tokens": 2048} ≤ 2,048 ټیټ effort.
{"type": "enabled", "budget_tokens": 8192} ≤ 8,192 منځنی effort.
{"type": "enabled", "budget_tokens": 16000} > 8,192 لوړ effort.

هغه ماډل چې reasoning کوي خپل reasoning د متن په مخ کې د block په توګه {"type": "thinking", "thinking": "…"} بیرته ورکوي. د Shannon هغه کچې چې reasoning کوي دا هم لیږي.

efforts په خپل جلا پاڼه کې بیان شوي. د reasoning effort

Tools

Tool یوه function ده چې ستاسو کوډ یې چلوي. هر یو د name، description او input_schema سره بیان کړئ. کله چې ماډل tool غواړي، ځواب tool_use block لري او stop_reason tool_use وي.

په tools کې د tool تعریف:

tools
[
  {
    "name": "get_weather",
    "description": "Current weather for a city.",
    "input_schema": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        }
      },
      "required": [
        "city"
      ]
    }
  }
]

د هغه ځواب content چې tool غواړي:

200 content
[
  {
    "type": "text",
    "text": ""
  },
  {
    "type": "tool_use",
    "id": "toolu_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
    "name": "get_weather",
    "input": {
      "city": "Paris"
    }
  }
]

tool چلوئ، بیا غوښتنه بیا ولیږئ او call او tool_result block messages ته اضافه کړئ:

messages
[
  {
    "role": "user",
    "content": "What is the weather in Paris?"
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "tool_use",
        "id": "toolu_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
        "name": "get_weather",
        "input": {
          "city": "Paris"
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "tool_use_id": "toolu_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
        "content": "{\"temperature_c\": 18, \"sky\": \"cloudy\"}"
      }
    ]
  }
]

tool_choice

بڼه اغېز پلي کوونکی
{"type": "auto"} ماډل پریکړه کوي چې tool وغواړي که نه. دا ډیفالټ دی. ټول ماډلونه
{"type": "any"} ماډل باید یو له tools څخه وغواړي. کوربه شوي open-weight ماډلونه
{"type": "tool", "name": "…"} ماډل باید نومول شوی tool وغواړي. کوربه شوي open-weight ماډلونه

یوازې هغه tools لوستل کیږي چې input_schema لري. Web search پدې endpoint کې tool نه دی: د web_search ساحه وټاکئ.

د tool loop بشپړ تشریح په خپله جلا پاڼه کې دی. فنکشن زنګ وهل

ځواب

ساحه ډول تشریح لیږونکی
id string msg_ وروسته 32 هیکساډیسیمل حروف. ټول ماډلونه
type string تل message. ټول ماډلونه
role string تل assistant. ټول ماډلونه
model string د هغه ماډل canonical id چې ځواب یې ورکړ. ټول ماډلونه
content array د ځواب blocks، په دې ترتیب: thinking کله چې ماډل reasoning کړی وي، text، بیا د هرې tool غوښتنې لپاره یو tool_use. ټول ماډلونه
stop_reason string ولې ځواب پای ته ورسید. لاندې ارزښتونه وګورئ. ټول ماډلونه
usage object input_tokens او output_tokens. ټول ماډلونه
sources array یوازې په هغه غوښتنه کې چې web_search: true لري او لټون یې یو څه موندلي: هغه پایلې چې ماډل ته ورکړل شوې، هر یو د index، title او url سره. په ځواب کې [1] هغه ننوتنه ده چې index یې 1 دی. په stream کې دا د message_delta پیښې سره راځي. shannon-1.6-*، shannon-2-*، د Shannon 3 کورنۍ
usage.cache_read_input_tokens integer cache_read_input_tokens د prompt هغه برخه ده چې له cache څخه لوستل شوې؛ input_tokens پاتې برخه ده. cache_creation_input_tokens تل 0 وي. کوربه شوي open-weight ماډلونه

د ځواب blocks

Block تشریح
{"type": "thinking", "thinking": "…"} د ماډل reasoning. هیڅ signature غړی نشته.
{"type": "text", "text": "…"} د ځواب متن. کله چې ځواب د tool غوښتنه وي دا کیدی شي خالي وي.
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} د tool غوښتنه. input د JSON شی دی. پایله د همدې id سره بیرته واستوئ.

stop_reason

stop_reason تشریح لیږونکی
end_turn ماډل خپل ځواب پای ته ورساوه، یا ستاسو یو stop_sequences څرګند شو. ټول ماډلونه
tool_use ځواب یو یا ډیر tool calls لري. ټول ماډلونه
max_tokens ځواب د output حد کې پرې شو. د Shannon 3 کورنۍ، shannon-1.6-lite، shannon-1.6-pro، shannon-coder-1، په streams کې

Streaming

د server-sent events لپاره stream په true وټاکئ. هر frame د event نوم سره یوه event: کرښه او د JSON څیز سره یوه data: کرښه لري چې نوم په type کې تکراروي. د Anthropic SDK stream helpers دا events ستاسو لپاره لولي:

import anthropic

client = anthropic.Anthropic(
    api_key="YOUR_API_KEY",
    base_url="https://api.shannon-ai.com",
)

with client.messages.stream(
    model="shannon-3",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain server-sent events in three sentences."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    message = stream.get_final_message()

print()
print(message.stop_reason, message.usage)

Events، په هغه ترتیب چې رارسیږي:

پیښه معلومات کله
message_start message تل لومړی. message id، role، ماډل، خالي content او usage لري چې له صفر پیلیږي.
content_block_start index, content_block یو block پرانیستل کیږي. content_block خالي text یا thinking block دی، یا د id او name سره tool_use block.
content_block_delta index, delta {"type": "thinking_delta", "thinking"} د reasoning یوه ټوټه، د thinking block لپاره.
content_block_delta index, delta {"type": "text_delta", "text"} د ځواب یوه ټوټه، د text block لپاره.
content_block_delta index, delta {"type": "input_json_delta", "partial_json"} د tool call آرګومنټونه، په یوه delta کې بشپړ، د tool_use block لپاره.
content_block_stop index هغه block چې دا index لري بشپړ شو.
message_delta delta {stop_reason, stop_sequence}, usage د ځواب پای: delta.stop_reason، او د غوښتنې usage.
message_stop تل وروستی.

Blocks د index له مخې په هماغه ترتیب شمیرل کیږي چې پرانیستل کیږي، او یو block مخکې بشپړیږي چې بل پرانیستل شي. هر block د ډول له مخې ولولئ، نه د شمیرې له مخې: یو stream کولی شي لومړی خالي text block پرانیزي، بیا thinking block، او ځواب په وروستي text block کې وسپاري.

200 text/event-stream
event: message_start
data: {"type":"message_start","message":{"id":"msg_5f0c…","type":"message","role":"assistant","model":"shannon-3","content":[],"usage":{"input_tokens":0,"output_tokens":0}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: content_block_start
data: {"type":"content_block_start","index":1,"content_block":{"type":"thinking","thinking":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":1,"delta":{"type":"thinking_delta","thinking":"Three sentences: what it is, how it is framed, why it is used."}}

event: ping
data: {"type": "ping"}

event: content_block_stop
data: {"type":"content_block_stop","index":1}

event: content_block_start
data: {"type":"content_block_start","index":2,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":2,"delta":{"type":"text_delta","text":"Server-sent events let a server push text over one HTTP reply."}}

event: content_block_stop
data: {"type":"content_block_stop","index":2}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":1190,"output_tokens":84}}

event: message_stop
data: {"type":"message_stop"}

Keep-alive

لیږونکی تشریح
د Shannon 3 کورنۍ، shannon-1.6-lite، shannon-1.6-pro، shannon-coder-1 یو ping event د {"type": "ping"} data سره، هر 15 ثانیې وروسته.
کوربه شوي open-weight ماډلونه د تبصرې کرښه : keepalive، هر 15 ثانیې وروسته پداسې حال کې چې ماډل کار کوي.

stream چې ناکامیږي

هغه ناکامي چې وروسته له دې رامنځته شي چې stream پیل شوی، یو error event دی چې بدنه یې د تېروتنې د ځواب په څیر ده: {"type": "error", "error": {"type", "message"}}. وروستي events، message_delta او message_stop، بیا هم ورپسې راځي. ځواب ناکام وګڼئ او غوښتنه بیا ولیږئ.

تېروتنې

تېروتنې د Anthropic د تېروتنې بدنه کاروي: type دی error، او error شی یو type او یو message لري. جدول هغه څه لیست کوي چې دا endpoint تر ټولو ډېر بیرته ورکوي. بشپړ لیست، د بیا هڅې سره، خپله پاڼه لري. د تېروتنې اداره کول

400 JSON
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "unknown model: no-such-model"
  }
}
حالت ډول پیغام کله
401 authentication_error Missing authentication
Invalid API key
هیڅ API کیلي نه وه لیږل شوې، یا کیلي نامعلومه یا لغوه شوې ده.
400 invalid_request_error unknown model: <id> model د Shannon ماډل id نه دی.
400 invalid_request_error No user message provided د Shannon کچې: غوښتنه هیڅ د کارونکي متن نه لري او هیڅ tools نه لري.
400 invalid_request_error <id> does not accept image input یو انځور هغه کوربه شوي open-weight ماډل ته ولیږل شو چې انځور input نه مني.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … messages نشته، یا یوه ساحه د JSON ناسم ډول لري.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan max_tokens ستاسو د بیلانس له پاتې اندازې څخه لوی دی.
429 rate_limit_error Too many requests. Retry in <n>s. Flood protection: په یوه دقیقه کې ستاسو په حساب له 120 زیاتې غوښتنې.
429 rate_limit_error Shannon Coder call quota reached. Upgrade your plan at shannon-ai.com/plan shannon-coder-1: د اوسنۍ 4-ساعتي کړکۍ لپاره ستاسو د پلان Shannon Coder غوښتنې خلاصې شوې.
500 server_error The model backend failed to answer. Please retry. ماډل ځواب نه تولید کړ. غوښتنه بیا واستوئ.
502 api_error The model backend failed to answer. Please retry. ماډل ځواب نه تولید کړ. غوښتنه بیا واستوئ.

د ټوکنونو شمېرل

POST /v1/messages/count_tokens د پیغام غوښتنې هماغه بدنه اخلي (model، system، messages، tools) او {"input_tokens": n} بیرته ورکوي: د input ټوکنونو شمېر چې د غوښتنې لپاره به محاسبه شي. دا د کوربه شوو open-weight ماډلونو لپاره شمیرل کیږي، وړیا ده او د flood protection له خوا نه شمیرل کیږي.

import anthropic

client = anthropic.Anthropic(
    api_key="YOUR_API_KEY",
    base_url="https://api.shannon-ai.com",
)

count = client.messages.count_tokens(
    model="DeepSeek-V4-Flash-0731-W4A16-AUTOROUND-REAP",
    system="You are a physics teacher. Answer in two sentences.",
    messages=[{"role": "user", "content": "Why is the sky blue?"}],
)

print(count.input_tokens)

شمېرنه خپله پاڼه لري، د ساده متن endpoint او حدونو سره. د ټوکنونو شمېرنه