Eqa uye okuqukethwe
Anthropic

Anthropic

I-POST /v1/messages yamukela isicelo ngefomethi ye-Anthropic Messages bese iphendula ngefomethi efanayo, isakazwa noma ingasakazwa. Yisebenzise ne-Anthropic SDK namathuluzi akhelwe kuyo, njenge-Claude Code: setha i-base URL, sebenzisa i-API key yakho ye-Shannon bese uqamba i-id ye-model ye-Shannon.

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

Khomba i-Anthropic SDK ku-base URL ye-Shannon. I-SDK yengeza i-/v1/messages bese ithumela i-key yakho ku-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 ingumlayezo onokuthi i-content yawo uhlu lwama-block. Thola ama-block nge-type yawo: uma i-model icabangile, i-block yokuqala ithi thinking bese umbhalo ulandela.

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

Ama-header

I-header Inani Incazelo
x-api-key YOUR_API_KEY I-API key yakho. I-Authorization: Bearer YOUR_API_KEY iyamukelwa esikhundleni sayo.
content-type application/json Iyadingeka.
anthropic-version 2023-06-01 Iyamukelwa, ayiphoqelekile. I-Anthropic SDK ithumela i-2023-06-01; impendulo inefomethi efanayo noma ngabe yinaphi inani.
anthropic-beta Iyamukelwa, ayiphoqelekile.
x-request-id Ayiphoqelekile. I-id yakho yesicelo. Ibuya ingashintshiwe empendulweni; ngaphandle kwayo impendulo ine-id yezinhlamvu ze-hexadecimal ezingu-12.

Ama-field esicelo

I-messages kuphela edingekayo. Ikholomu ethi Kusebenza ku- ibala ama-model lapho i-field ishintsha khona impendulo. Ama-model e-open-weight ahlinzekiwe ama-id ayishumi nambili osukwini lwama-model; umndeni we-Shannon 3 ngu-shannon-3, shannon-3-pro, shannon-3.1 no-shannon-3.1-pro. Ama-model namanani

I-field Uhlobo Okuzenzakalelayo Incazelo Kusebenza ku-
model string shannon-1.6-lite I-id ye-model ye-Shannon evela ohlwini lwama-model. Ithumele kuso sonke isicelo. Ukufanisa akunaki ukuhluka phakathi kwezinhlamvu ezinkulu nezincane. Noma yiliphi elinye igama libuyisela 400 unknown model, ngakho ithuluzi elithumela amagama alo e-model kufanele lisethwe ku-id ye-Shannon. Wonke ama-model
messages array Iyadingeka. Ingxoxo, umlayezo omdala kuqala, ngezindima ze-user ne-assistant. Bheka Imilayezo nama-block okuqukethwe ngezansi. Wonke ama-model
system string | array Imiyalo ye-model: i-string, noma uhlu lwama-block ombhalo. Bheka i-System prompt ngezansi. Ama-model e-open-weight ahlinzekiwe, shannon-1.6-*, shannon-2-*, shannon-coder-1
max_tokens integer 4096 Umkhawulo ophezulu wempendulo, ngama-token. Akuphoqelekile kule endpoint; i-Anthropic SDK iyayithumela njalo. Inani elingaphandle kwe-1 kuya ku-65,536 lisondezwa kulelo cala. Futhi yilona nani elibekelwa eceleni ku-balance yakho ngenkathi isicelo sisebenza. Ama-model e-open-weight ahlinzekiwe, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
stream boolean false I-true ithumela impendulo njenge-server-sent events. Bheka i-Streaming ngezansi. Wonke ama-model
temperature number Izinga lokushisa lokuhlola (sampling temperature). Kuma-model e-open-weight ahlinzekiwe amanani agcinwa phakathi kuka-0 no-2. Ama-model e-open-weight ahlinzekiwe, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
top_p number I-nucleus sampling. Ama-model e-open-weight ahlinzekiwe
stop_sequences array Kufika kuma-string angu-4. Impendulo iphela ngaphambi kokuqala okubonakala. I-stop_reason ihlala ithi end_turn. Ama-model e-open-weight ahlinzekiwe
tools array Amathuluzi i-model engawabiza, ngalinye njenge-{"name", "description", "input_schema"}. Bheka i-Tools ngezansi. Wonke ama-model
tool_choice object I-{"type": "auto"} ivumela i-model ukuthi inqume, i-{"type": "any"} iyiphoqa ukuthi ibize ithuluzi, i-{"type": "tool", "name": "…"} iyiphoqa ukuthi ibize lelo thuluzi. Ama-model e-open-weight ahlinzekiwe
thinking object Ukuthi i-model icabanga kangakanani ngaphambi kokuphendula. Bheka i-Thinking ngezansi. Ama-model e-open-weight ahlinzekiwe
web_search boolean false Isengezo se-Shannon kufomethi: i-true ivumela i-model ukuthi isesha kuwebhu ngaphambi kokuphendula. shannon-1.6-*, shannon-2-*, umndeni we-Shannon 3

Ngaphandle kwe-max_tokens inani lingu-4,096, futhi lingu-65,536 ku-shannon-coder-1.

Ama-marker e-metadata, top_k, service_tier ne-cache_control kuma-block ayamukelwa ukuze ikhodi yeklayenti esekhona isebenze ngaphandle kokushintshwa. Awashintshi impendulo; i-prompt caching kuma-model e-open-weight ahlinzekiwe iyazenzakalela.

Impendulo ye-JSON ngokwe-schema icelwa nge-response_format ku-Chat Completions nge-text.format ku-Responses. Imiphumela ehlanganisiwe

Isicelo esinesistimu prompt ne-thinking

Lesi sicelo sithumela i-system prompt, isabelomali se-thinking, izinga lokushisa ne-stop sequence. Sisebenzisa i-model ye-open-weight ehlinzekiwe, esebenzisa zonke lezi.

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)

Kuma-model e-open-weight ahlinzekiwe i-usage ibika ama-token afundwe ku-prompt cache ngokwehlukana namanye ama-token okufakwayo.

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

I-System prompt

I-system iyi-string, noma uhlu lwama-block ombhalo ngefomu elithi [{"type": "text", "text": "…"}]. Imibhalo yama-block ihlanganiswa ngomugqa omusha.

Isetshenziswa ngama-model e-open-weight ahlinzekiwe, i-shannon-1.6-lite, i-shannon-1.6-pro, i-shannon-2-lite, i-shannon-2-pro ne-shannon-coder-1. Nge-id yomndeni we-Shannon 3, faka imiyalo okufanele ilandelwe emlayezweni womsebenzisi.

Imilayezo nama-block okuqukethwe

Umlayezo unalo i-role, i-user noma i-assistant, kanye ne-content. I-content iyisikhwama sombhalo, noma uhlu lwama-block.

I-block Incazelo Kuyatholakala ku-
{"type": "text", "text": "…"} Umbhalo. Wonke ama-model
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "…"}}
{"type": "image", "source": {"type": "url", "url": "…"}}
Isithombe emlayezweni we-user, nge-base64 noma nge-URL. Umndeni we-Shannon 3, shannon-1.6-lite, shannon-1.6-pro, nama-model e-open-weight ahlinzekiwe abala okufakwayo kwezithombe
{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} Idokhumenti (PDF, Word, PowerPoint noma Excel) emlayezweni we-user, nge-base64 noma nge-URL. Umndeni we-Shannon 3
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} Emlayezweni we-assistant: ukubiza ithuluzi i-model ekwenze empendulweni yangaphambilini. Wonke ama-model
{"type": "tool_result", "tool_use_id": "toolu_…", "content": "…"} Emlayezweni we-user: umphumela walowo mbiza. I-content iyisikhwama sombhalo, noma uhlu lwama-block ombhalo. Wonke ama-model

Ungathumela futhi i-content yempendulo yangaphambilini njengoba injalo: ama-block e-text ne-tool_use ayafundwa, ama-block e-thinking ayeqiwa.

Emazingeni e-Shannon izithombe namadokhumenti kufundwa emlayezweni wokugcina we-user. Osayizi nemikhawulo banekhasi labo. Izithombe namafayela

I-Thinking

Ama-model e-open-weight ahlinzekiwe ahambisanisa i-thinking nomzamo wokucabanga. Ngaphandle kwe-field umzamo uphezulu.

Ifomu budget_tokens Umphumela
{"type": "disabled"} Akukho kucabanga. Impendulo ayinayo i-block ye-thinking.
{"type": "enabled", "budget_tokens": 2048} ≤ 2,048 Umzamo ophansi.
{"type": "enabled", "budget_tokens": 8192} ≤ 8,192 Umzamo ophakathi nendawo.
{"type": "enabled", "budget_tokens": 16000} > 8,192 Umzamo ophezulu.

I-model ecabangayo ibuyisela ukucabanga kwayo njenge-block {"type": "thinking", "thinking": "…"} ngaphambi kombhalo. Amazinga e-Shannon acabangayo nawo ayakuthumela.

Imizamo ichazwe ekhasini layo. Umzamo wokucabanga

Amathuluzi

Ithuluzi ngumsebenzi osetshenziswa yikhodi yakho. Chaza ngalinye nge-name, i-description ne-input_schema. Uma i-model idinga ithuluzi, impendulo iqukethe i-block ye-tool_use futhi i-stop_reason ithi tool_use.

Incazelo yethuluzi ku-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 ithuluzi:

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

Sebenzisa ithuluzi, bese uthumela isicelo futhi nokubiza kanye ne-block ye-tool_result eyengeziwe ku-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

Ifomu Umphumela Kusebenza ku-
{"type": "auto"} I-model inquma ukuthi ibize ithuluzi yini. Lokhu kuyisimiso. Wonke ama-model
{"type": "any"} I-model kufanele ibize elinye lamathuluzi. Ama-model e-open-weight ahlinzekiwe
{"type": "tool", "name": "…"} I-model kufanele ibize ithuluzi elinegama elidingiwe. Ama-model e-open-weight ahlinzekiwe

Amathuluzi kuphela anale input_schema ayafundwa. Ukusesha kuwebhu akulona ithuluzi kule endpoint: setha i-field ye-web_search.

Isiyingi sethuluzi sichazwe ngokugcwele ekhasini laso. Ukubiza umsebenzi

Impendulo

I-field Uhlobo Incazelo Kuthunyelwe ngu-
id string I-msg_ elandelwa yizinhlamvu ze-hexadecimal ezingu-32. Wonke ama-model
type string Njalo message. Wonke ama-model
role string Njalo assistant. Wonke ama-model
model string I-id ye-canonical ye-model ephendulile. Wonke ama-model
content array Ama-block empendulo, ngalolu hlelo: i-thinking uma i-model icabangile, i-text, bese i-tool_use eyodwa ekubizeni ithuluzi ngalinye. Wonke ama-model
stop_reason string Isizathu sokuthi impendulo iphele. Bheka amanani ngezansi. Wonke ama-model
usage object I-input_tokens ne-output_tokens. Wonke ama-model
sources array Kuphela esicelweni esine-web_search: true okusesha kwaso kuthole okuthile: imiphumela i-model eyinikeziwe, ngayinye ine-index, title ne-url. I-[1] empendulweni yilokho okufakiwe okune-index 1. Ku-stream ifika nomcimbi we-message_delta. shannon-1.6-*, shannon-2-*, umndeni we-Shannon 3
usage.cache_read_input_tokens integer I-cache_read_input_tokens yingxenye ye-prompt efundwe ku-cache; i-input_tokens yinsalela. I-cache_creation_input_tokens njalo ngu-0. Ama-model e-open-weight ahlinzekiwe

Ama-block empendulo

I-block Incazelo
{"type": "thinking", "thinking": "…"} Ukucabanga kwe-model. Akukho ilungu le-signature.
{"type": "text", "text": "…"} Umbhalo wempendulo. Ungase ungabi nalutho uma impendulo iwukubiza ithuluzi.
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} Ukubiza ithuluzi. I-input iyinto ye-JSON. Thumela umphumela futhi nge-id efanayo.

stop_reason

stop_reason Incazelo Kuthunyelwe ngu-
end_turn I-model iqedile impendulo yayo, noma enye yama-stop_sequences akho ivelile. Wonke ama-model
tool_use Impendulo iqukethe ukubiza ithuluzi eyodwa noma ngaphezulu. Wonke ama-model
max_tokens Impendulo inqunyiwe emkhawulweni wokuphumayo. Umndeni we-Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1, kuma-stream

I-Streaming

Setha i-stream ibe true ukuthola ama-server-sent events. I-frame ngayinye inomugqa we-event: onegama lomcimbi nomugqa we-data: one-JSON object ephindaphinda igama ku-type. Abasizi be-stream be-Anthropic SDK bayawafunda lama-event ngawe:

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)

Imicimbi, ngokulandelana efika ngakho:

Umcimbi Idatha Nini
message_start message Njalo kuqala. I-message iqukethe i-id, indima, i-model, i-content engenalutho ne-usage eqala ku-zero.
content_block_start index, content_block I-block iyavuleka. I-content_block iyi-block ye-text noma ye-thinking engenalutho, noma i-block ye-tool_use ene-id ne-name yayo.
content_block_delta index, delta {"type": "thinking_delta", "thinking"} Ucezu lokucabanga, lwe-block ye-thinking.
content_block_delta index, delta {"type": "text_delta", "text"} Ucezu lwempendulo, lwe-block ye-text.
content_block_delta index, delta {"type": "input_json_delta", "partial_json"} Izimpikiswano zokubiza ithuluzi, ziphelele ku-delta eyodwa, ku-block ye-tool_use.
content_block_stop index I-block enale index isiphelile.
message_delta delta {stop_reason, stop_sequence}, usage Ukuphela kwempendulo: i-delta.stop_reason, ne-usage yesicelo.
message_stop Njalo kugcina.

Ama-block abalwa nge-index ngokulandelana avuleka ngakho, futhi i-block eyodwa iyaqeda ngaphambi kokuvuleka kwelandelayo. Funda i-block ngayinye ngohlobo lwayo, hhayi ngenombolo yayo: i-stream ingase ivule kuqala i-block ye-text engenalutho, bese i-block ye-thinking, bese iletha impendulo ku-block ye-text yakamuva.

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

I-Keep-alive

Kuthunyelwe ngu- Incazelo
Umndeni we-Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 Umcimbi we-ping onedatha {"type": "ping"}, njalo emizuzwana engu-15.
Ama-model e-open-weight ahlinzekiwe Umugqa wokuphawula : keepalive, njalo emizuzwana engu-15 ngenkathi i-model isebenza.

I-stream ehlulekayo

Ukohluleka ngemva kokuqala kwe-stream kuwumcimbi we-error onomzimba ofanayo nempendulo yephutha: {"type": "error", "error": {"type", "message"}}. Imicimbi yokuvala, i-message_delta ne-message_stop, isalandela. Thatha impendulo njengehlulekile bese uthumela isicelo futhi.

Amaphutha

Amaphutha asebenzisa umzimba wephutha we-Anthropic: i-type ithi error, nento ye-error iqukethe i-type ne-message. ithebula lokho lesi sihlokwana ebuyisela kaningi. Uhlu olugcwele, nalokho okufanele kuzanywe futhi, lunekhasi lalo. Ukuphathwa kwamaphutha

400 JSON
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "unknown model: no-such-model"
  }
}
Isimo Uhlobo Umlayezo Nini
401 authentication_error Missing authentication
Invalid API key
Ayikho i-API key ethunyelwe, noma i-key ayaziwa noma ihoxisiwe.
400 invalid_request_error unknown model: <id> I-model ayiyona i-id ye-model ye-Shannon.
400 invalid_request_error No user message provided Amazinga e-Shannon: isicelo asinawo umbhalo womsebenzisi futhi asinawo ama-tools.
400 invalid_request_error <id> does not accept image input Isithombe sithunyelwe ku-model ye-open-weight ehlinzekiwe engenakho ukufakwa kwezithombe.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … I-messages ilahlekile, noma i-field inohlobo olungalungile lwe-JSON.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan I-max_tokens inkulu kunalokho okusele ku-balance yakho.
429 rate_limit_error Too many requests. Retry in <n>s. I-flood protection: izicelo ezingaphezu kwe-120 ngomzuzu owodwa ku-akhawunti yakho.
429 rate_limit_error Shannon Coder call quota reached. Upgrade your plan at shannon-ai.com/plan shannon-coder-1: izicelo ze-Shannon Coder zepulani yakho zewindi lamahora angu-4 lamanje sezisetshenzisiwe.
500 server_error The model backend failed to answer. Please retry. I-model ayikhiqizanga mpendulo. Thumela isicelo futhi.
502 api_error The model backend failed to answer. Please retry. I-model ayikhiqizanga mpendulo. Thumela isicelo futhi.

Ukubala ama-token

I-POST /v1/messages/count_tokens yamukela umzimba ofanayo nesicelo somlayezo (model, system, messages, tools) futhi ibuyisela {"input_tokens": n}: inani lama-token okufakwayo isicelo esizobiziswa ngawo. Ibala kuma-model e-open-weight ahlinzekiwe, ayibizi futhi 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 kunekhasi lakho, elinendawo yokugcina yombhalo olula nemikhawulo. Ukubala ama-token