Yiya kumxholo
Ubume beAnthropic

Ubume beAnthropic

I-POST /v1/messages ithatha isicelo kwifomethi ye-Anthropic Messages kwaye iphendula ngefomethi enye, nge-stream okanye ngaphandle kwayo. Yisebenzise ne-Anthropic SDK nezixhobo ezakhelwe kuyo, ezifana neClaude Code: seta i-base URL, sebenzisa i-Shannon API key yakho uze ubize i-id yemodeli yeShannon.

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

Lathisa i-Anthropic SDK kwi-base URL yeShannon. I-SDK yongeza i-/v1/messages kwaye ithumela isitshixo sakho kwi-header ye-x-api-key.

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)

Impendulo ngumyalezo onoluhlu lweeblock kwi-content. Fumana iiblock nge-type yazo: xa imodeli iqiqile, i-block yokuqala yi-thinking kwaye umbhalo ulandela emva kwayo.

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
  }
}

Ii-header

Header Ixabiso Inkcazelo
x-api-key YOUR_API_KEY I-API key yakho. I-Authorization: Bearer YOUR_API_KEY iyamkelwa endaweni yayo.
content-type application/json Iyafuneka.
anthropic-version 2023-06-01 Iyamkelwa, ayinyanzelekanga. I-Anthropic SDK ithumela i-2023-06-01; impendulo inefomethi enye nokuba lithini ixabiso.
anthropic-beta Iyamkelwa, ayinyanzelekanga.
x-request-id Ayinyanzelekanga. I-id yakho yesicelo. Ibuya ingatshintshanga kwimpendulo; ngaphandle kwayo impendulo ibamba i-id enoonobumba abayi-12 be-hexadecimal.

Iintsimi zesicelo

I-messages kuphela efunekayo. Ikholamu ethi Isebenza kwi ibiza iimodeli apho intsimi itshintsha impendulo. Iimodeli ze-open-weight ezisingathiweyo ziii-id ezilishumi elinambini zoluhlu lweemodeli; intsapho yeShannon 3 yi-shannon-3, shannon-3-pro, shannon-3.1 kunye ne-shannon-3.1-pro. Iimodeli namaxabiso

Intsimi Uhlobo Okuqhelekileyo Inkcazelo Isebenza kwi
model string shannon-1.6-lite I-id yemodeli yeShannon ekuluhlu lweemodeli. Yithumele kunye nesicelo ngasinye. Ukuthelekisa akuhoyi bukhulu boonobumba. Nalo naliphi na elinye igama libuyisa 400 unknown model, ngoko isixhobo esithumela amagama aso semodeli kufuneka sisetwe kwi-id yeShannon. Zonke iimodeli
messages array Iyafuneka. Incoko, umyalezo omdala kuqala, ngeeroli ze-user ne-assistant. Jonga Imiyalezo neeblock zomxholo ngezantsi. Zonke iimodeli
system string | array Imiyalelo yemodeli: intambo yoonobumba, okanye uluhlu lweeblock zokubhaliweyo. Jonga i-System prompt ngezantsi. Iimodeli ze-open-weight ezisingathiweyo, shannon-1.6-*, shannon-2-*, shannon-coder-1
max_tokens integer 4096 Umda ophezulu wempendulo, kwii-token. Ayinyanzelekanga kule endpoint; i-Anthropic SDK isoloko iyithumela. Ixabiso elingaphandle kwe-1 ukuya kwi-65,536 lisiwa kolo luhlu. Ngumyinge obekelwe bucala kwibhalansi yakho ngoxa isicelo sisaqhubeka. Iimodeli ze-open-weight ezisingathiweyo, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
stream boolean false I-true ithumela impendulo njengemisitho ethunyelwe yi-server. Jonga i-Streaming ngezantsi. Zonke iimodeli
temperature number Itemperatyhuri yokukhetha. Kwiimodeli ze-open-weight ezisingathiweyo amaxabiso agcinwa phakathi kwe-0 ne-2. Iimodeli ze-open-weight ezisingathiweyo, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
top_p number I-nucleus sampling. Iimodeli ze-open-weight ezisingathiweyo
stop_sequences array Ukuya kwiintambo ezi-4. Impendulo iphela phambi kokuqala ebonakalayo. I-stop_reason ihlala i-end_turn. Iimodeli ze-open-weight ezisingathiweyo
tools array Ii-tool imodeli engazibiza, nganye njenge-{"name", "description", "input_schema"}. Jonga i-Tools ngezantsi. Zonke iimodeli
tool_choice object {"type": "auto"} ivumela imodeli ukuba izikhethele, {"type": "any"} iyenza ibize i-tool, {"type": "tool", "name": "…"} iyenza ibize loo tool. Iimodeli ze-open-weight ezisingathiweyo
thinking object Ukuba imodeli iqiqa kangakanani phambi kokuphendula. Jonga i-Thinking ngezantsi. Iimodeli ze-open-weight ezisingathiweyo
web_search boolean false Isongezo seShannon kwifomethi: i-true ivumela imodeli ukuba ifune kwiwebhu phambi kokuphendula. shannon-1.6-*, shannon-2-*, intsapho yeShannon 3

Ngaphandle kwe-max_tokens ixabiso li-4,096, kwaye li-65,536 kwi-shannon-coder-1.

Iimaka ze-metadata, top_k, service_tier ne-cache_control kwiiblock zamkelwa ukuze ikhowudi ye-client ekhoyo isebenze ngaphandle kotshintsho. Azitshintshi mpendulo; i-prompt caching kwiimodeli ze-open-weight ezisingathiweyo ngokuzenzekelayo.

Impendulo ye-JSON ngokwe-schema iyacelwa nge-response_format kwi-Chat Completions nge-text.format kwi-Responses. Iziphumo ezicwangcisiweyo

Isicelo esine-system prompt ne-thinking

Esi sicelo sithumela i-system prompt, ibhajethi ye-thinking, itemperatyhuri kunye ne-stop sequence. Sisebenzisa imodeli ye-open-weight esingathiweyo, ezisebenzisa zonke.

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)

Kwiimodeli ze-open-weight ezisingathiweyo i-usage ixela ii-token ezifundwe kwi-prompt cache ngaphandle kwezinye ii-input token.

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

I-System prompt

I-system yintambo yoonobumba, okanye uluhlu lweeblock zokubhaliweyo ngefom [{"type": "text", "text": "…"}]. Imibhalo yeeblock idityaniswa ngomgca omtsha.

Isetyenziswa ziimodeli ze-open-weight ezisingathiweyo, shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro kunye ne-shannon-coder-1. Ngokusebenzisa i-id yentsapho yeShannon 3, faka imiyalelo ekufuneka ihlale ikhona kumyalezo womsebenzisi.

Imiyalezo neeblock zomxholo

Umyalezo uneroli ye-role, i-user okanye i-assistant, kunye ne-content. I-content yintambo yoonobumba, okanye uluhlu lweeblock.

Block Inkcazelo Iyafumaneka kwi
{"type": "text", "text": "…"} Okubhaliweyo. Zonke iimodeli
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "…"}}
{"type": "image", "source": {"type": "url", "url": "…"}}
Umfanekiso kumyalezo we-user, njenge-base64 okanye nge-URL. Intsapho yeShannon 3, shannon-1.6-lite, shannon-1.6-pro, neemodeli ze-open-weight ezisingathiweyo ezidwelisa i-image input
{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} Uxwebhu (PDF, Word, PowerPoint okanye Excel) kumyalezo we-user, njenge-base64 okanye nge-URL. Intsapho yeShannon 3
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} Kumyalezo we-assistant: ubizo lwe-tool olwenziwe yimodeli kwimpendulo yangaphambili. Zonke iimodeli
{"type": "tool_result", "tool_use_id": "toolu_…", "content": "…"} Kumyalezo we-user: umphumo wobo bizo. I-content yintambo yoonobumba, okanye uluhlu lweeblock zokubhaliweyo. Zonke iimodeli

Ungayithumela kwakhona i-content yempendulo yangaphambili njengoko injalo: iiblock ze-text ne-tool_use ziyafundwa, iiblock ze-thinking ziyatsitywa.

Kumanqanaba eShannon imifanekiso noxwebhu ifundwa kumyalezo wokugqibela we-user. Ubungakanani nemida inephepha layo. Imifanekiso neefayile

I-Thinking

Iimodeli ze-open-weight ezisingathiweyo zimapa i-thinking kwi-effort yokuqiqa. Ngaphandle kwentsimi i-effort iphezulu.

Ifom budget_tokens Isiphumo
{"type": "disabled"} Akukho kuqiqa. Impendulo ayinayo i-block ye-thinking.
{"type": "enabled", "budget_tokens": 2048} ≤ 2,048 I-effort ephantsi.
{"type": "enabled", "budget_tokens": 8192} ≤ 8,192 I-effort ephakathi.
{"type": "enabled", "budget_tokens": 16000} > 8,192 I-effort ephezulu.

Imodeli eqiqayo ibuyisa ukuqiqa kwayo njenge-block {"type": "thinking", "thinking": "…"} phambi kombhalo. Amanqanaba eShannon aqiqayo ayithumela naye.

Ii-effort zichazwe kwiphepha lazo. I-effort yokuqiqa

Ii-tool

I-tool ngumsebenzi osetyenziswa yikhowudi yakho. Chaza nganye nge-name, i-description ne-input_schema. Xa imodeli ifuna i-tool, impendulo ibamba i-block ye-tool_use kwaye i-stop_reason yi-tool_use.

Inkcazo ye-tool kwi-tools:

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

I-content yempendulo ebiza yona:

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

Qhuba i-tool, emva koko uthumele isicelo kwakhona nobizo kunye ne-block ye-tool_result ongezwe kwi-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

Ifom Isiphumo Isebenza kwi
{"type": "auto"} Imodeli ikhetha ukuba ibize i-tool okanye hayi. Oku kuyinto eqhelekileyo. Zonke iimodeli
{"type": "any"} Imodeli kufuneka ibize enye yee-tool. Iimodeli ze-open-weight ezisingathiweyo
{"type": "tool", "name": "…"} Imodeli kufuneka ibize i-tool ebizwe ngegama. Iimodeli ze-open-weight ezisingathiweyo

Zifundwa kuphela ii-tool ezine-input_schema. Ukufuna kwiwebhu akuyiyo i-tool kule endpoint: seta intsimi ye-web_search.

Iluphu ye-tool ichazwe ngokupheleleyo kwiphepha layo. Umsebenzi Ukufowuna

Impendulo

Intsimi Uhlobo Inkcazelo Ithunyelwe ngu
id string msg_ ilandelwa ziinhlobo ezingama-32 ze-hexadecimal. Zonke iimodeli
type string Ihlala i-message. Zonke iimodeli
role string Ihlala i-assistant. Zonke iimodeli
model string I-id eyiyo yemodeli ephendulileyo. Zonke iimodeli
content array Iiblock zempendulo, ngolu landelelwano: i-thinking xa imodeli iqiqile, i-text, emva koko i-tool_use enye kubizo ngalunye lwe-tool. Zonke iimodeli
stop_reason string Isizathu sokuphela kwempendulo. Jonga amaxabiso ngezantsi. Zonke iimodeli
usage object input_tokens kunye ne-output_tokens. Zonke iimodeli
sources array Kuphela kwisicelo esine-web_search: true esikhangelo salo sifumene into: iziphumo ezinikwe imodeli, nganye kunye ne-index, i-title kunye ne-url. I-[1] kwimpendulo yiyo into ene-index 1. Kwi-stream ifika kunye nomsitho we-message_delta. shannon-1.6-*, shannon-2-*, intsapho yeShannon 3
usage.cache_read_input_tokens integer I-cache_read_input_tokens yinxalenye ye-prompt efundwe kwi-cache; i-input_tokens ngumahluko osele. I-cache_creation_input_tokens ihlala i-0. Iimodeli ze-open-weight ezisingathiweyo

Iiblock zempendulo

Block Inkcazelo
{"type": "thinking", "thinking": "…"} Ukuqiqa kwemodeli. Akukho nxalenye ye-signature.
{"type": "text", "text": "…"} Umbhalo wempendulo. Ingaze ibe nto xa impendulo ingubizo lwe-tool.
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} Ubizo lwe-tool. I-input yi-JSON object. Buyisa umphumo nge-id enye.

stop_reason

stop_reason Inkcazelo Ithunyelwe ngu
end_turn Imodeli iyigqibile impendulo yayo, okanye enye yee-stop_sequences zakho ivele. Zonke iimodeli
tool_use Impendulo ibamba ubizo lwe-tool olunye okanye ngaphezulu. Zonke iimodeli
max_tokens Impendulo inqunyulwe kumda we-output. Intsapho yeShannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1, kwii-stream

I-Streaming

Seta i-stream ibe yi-true ukuze ufumane imisitho ethunyelwe yi-server. I-frame nganye inomgca we-event: onegama lesiganeko nomgca we-data: one-JSON object ephindaphinda igama kwi-type. Abancedisi be-stream be-Anthropic SDK bafunda ezi siganeko ngenxa yakho:

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)

Iziganeko, ngokolandelelwano zifika ngalo:

Isiganeko Idatha Xa
message_start message Ihlala ikuqala. I-message ibamba i-id, iroli, imodeli, i-content engenanto kunye ne-usage eqala kwi-zero.
content_block_start index, content_block I-block iyavuleka. I-content_block yi-block ye-text okanye ye-thinking engenanto, okanye i-block ye-tool_use ene-id ne-name yayo.
content_block_delta index, delta {"type": "thinking_delta", "thinking"} Iqhekeza lokuqiqa, kwi-block ye-thinking.
content_block_delta index, delta {"type": "text_delta", "text"} Iqhekeza lempendulo, kwi-block ye-text.
content_block_delta index, delta {"type": "input_json_delta", "partial_json"} Ii-argument zobizo lwe-tool, ezipheleleyo kwi-delta enye, kwi-block ye-tool_use.
content_block_stop index I-block enale-index igqityiwe.
message_delta delta {stop_reason, stop_sequence}, usage Isiphelo sempendulo: i-delta.stop_reason, kunye ne-usage yesicelo.
message_stop Ihlala ikokugqibela.

Iiblock zinikwa amanani nge-index ngokolandelelwano zivuleka ngalo, kwaye i-block enye iyagqitywa phambi kokuba elandelayo ivuleke. Funda i-block nganye ngohlobo lwayo, hayi ngenombolo yayo: i-stream inokuvula kuqala i-block ye-text engenanto, emva koko i-block ye-thinking, kwaye ithumele impendulo kwi-block ye-text kamva.

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

Ithunyelwe ngu Inkcazelo
Intsapho yeShannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 Isiganeko se-ping esinedatha {"type": "ping"}, rhoqo kwimizuzwana eyi-15.
Iimodeli ze-open-weight ezisingathiweyo Umgca wokuphawula othi : keepalive, rhoqo kwimizuzwana eyi-15 ngoxa imodeli isebenza.

I-stream engaphumeleliyo

Ukusilela emva kokuba i-stream iqalile sisiganeko se-error esinomzimba ofanayo nowempendulo yempazamo: {"type": "error", "error": {"type", "message"}}. Iziganeko zokuvala, i-message_delta ne-message_stop, zisalandela. Yithathe impendulo njengengaphumelelanga uze uthumele isicelo kwakhona.

Iimpazamo

Iimpazamo zisebenzisa umzimba wempazamo we-Anthropic: i-type yi-error, kwaye into ye-error ibamba i-type ne-message. Itheyibhile idwelisa oko le endpoint ikubuyisa rhoqo. Uluhlu olupheleleyo, kunye nezinto ekufuneka uzame kwakhona, lunephepha lalo. Ukuphatha imposiso

400 JSON
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "unknown model: no-such-model"
  }
}
Isimo Uhlobo Umyalezo Xa
401 authentication_error Missing authentication
Invalid API key
Akukho API key ithunyelweyo, okanye isitshixo asaziwa okanye sirhoxisiwe.
400 invalid_request_error unknown model: <id> I-model ayiyiyo i-id yemodeli yeShannon.
400 invalid_request_error No user message provided Amanqanaba eShannon: isicelo asinalo mbhalo womsebenzisi kwaye asinayo i-tools.
400 invalid_request_error <id> does not accept image input Umfanekiso uthunyelwe kwimodeli ye-open-weight esingathiweyo engenayo i-image input.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … I-messages ilahlekile, okanye intsimi inohlobo olungalunganga lwe-JSON.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan I-max_tokens inkulu kunokushiyekileyo kwibhalansi yakho.
429 rate_limit_error Too many requests. Retry in <n>s. I-flood protection: izicelo ezingaphezu kwe-120 kumzuzu omnye kwiakhawunti yakho.
429 rate_limit_error Shannon Coder call quota reached. Upgrade your plan at shannon-ai.com/plan shannon-coder-1: ubizo lwakho lweShannon Coder lwefestile yeeyure ezi-4 yangoku lusetyenzisiwe.
500 server_error The model backend failed to answer. Please retry. Imodeli ayivelisanga mpendulo. Thumela isicelo kwakhona.
502 api_error The model backend failed to answer. Please retry. Imodeli ayivelisanga mpendulo. Thumela isicelo kwakhona.

Ukubala ii-token

POST /v1/messages/count_tokens ithatha umzimba ofanayo nesicelo somyalezo (model, system, messages, tools) kwaye ibuyisa {"input_tokens": n}: inani lee-input token ekuya kuhlawulwa ngazo isicelo. Ibala iimodeli ze-open-weight ezisingathiweyo, ayibizi nto kwaye ayibalwa yi-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)

Ukubala kunephepha lako, elinendlela yombhalo oqhelekileyo nemida. Ukubala ii-token