Anthropic
POST /v1/messages inapokea ombi kwa umbizo la Anthropic Messages na kujibu kwa umbizo lile lile, kwa streaming au bila. Itumie na SDK ya Anthropic na tools zilizojengwa juu yake, kama Claude Code: weka base URL, tumia API key yako ya Shannon na taja model id ya Shannon.
POST https://api.shannon-ai.com/v1/messages
Elekeza SDK ya Anthropic kwenye base URL ya Shannon. SDK huongeza /v1/messages na hutuma key yako kwenye header ya 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) import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com",
});
const message = await client.messages.create({
model: "shannon-3",
max_tokens: 1024,
messages: [{ role: "user", content: "Say hello in one sentence." }],
});
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
} curl https://api.shannon-ai.com/v1/messages \
-H "x-api-key: YOUR_API_KEY" \
-H "content-type: application/json" \
-d '{
"model": "shannon-3",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}' Jibu ni ujumbe ambao content yake ni orodha ya blocks. Tafuta blocks kwa type yake: wakati model ilifikiri, block ya kwanza ni thinking na maandishi yanakuja baada yake.
{
"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 | Thamani | Maelezo |
|---|---|---|
x-api-key | YOUR_API_KEY | API key yako. Authorization: Bearer YOUR_API_KEY inakubaliwa badala yake. |
content-type | application/json | Inahitajika. |
anthropic-version | 2023-06-01 | Inakubaliwa, haihitajiki. SDK ya Anthropic hutuma 2023-06-01; jibu lina umbizo lile lile bila kujali thamani. |
anthropic-beta | Inakubaliwa, haihitajiki. | |
x-request-id | Si lazima. Id yako mwenyewe ya ombi. Inarudi bila mabadiliko kwenye jibu; bila hiyo jibu hubeba id ya herufi 12 za hexadecimal. |
Fields za ombi
messages pekee ndiyo inahitajika. Safu ya Inatumiwa na inataja model ambazo field inabadilisha jibu juu yake. Model za open-weight zinazopangishwa ni id kumi na mbili za orodha ya model; familia ya Shannon 3 ni shannon-3, shannon-3-pro, shannon-3.1 na shannon-3.1-pro. Model na bei
| Field | Aina | Chaguo-msingi | Maelezo | Inatumiwa na |
|---|---|---|---|---|
model | string | shannon-1.6-lite | Model id ya Shannon kutoka kwenye orodha ya model. Itume na kila ombi. Ulinganishaji hauangalii herufi kubwa na ndogo. Jina lolote lingine hurudisha 400 unknown model, kwa hiyo tool inayotuma majina yake ya model lazima iwekwe kwenye id ya Shannon. | Model zote |
messages | array | Inahitajika. Mazungumzo, ujumbe wa zamani zaidi kwanza, yenye roles user na assistant. Tazama Ujumbe na content blocks hapa chini. | Model zote | |
system | string | array | Maagizo kwa model: string, au array ya blocks za maandishi. Tazama System prompt hapa chini. | Model za open-weight zinazopangishwa, shannon-1.6-*, shannon-2-*, shannon-coder-1 | |
max_tokens | integer | 4096 | Kikomo cha juu cha jibu, kwa tokens. Si lazima kwenye endpoint hii; SDK ya Anthropic daima huituma. Thamani iliyo nje ya 1 hadi 65,536 huhamishiwa ndani ya masafa hayo. Pia ni kiasi kinachotengwa kutoka kwenye salio lako wakati ombi linaendelea. | Model za open-weight zinazopangishwa, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 |
stream | boolean | false | true hutuma jibu kama server-sent events. Tazama Streaming hapa chini. | Model zote |
temperature | number | Sampling temperature. Kwenye model za open-weight zinazopangishwa thamani huwekwa kati ya 0 na 2. | Model za open-weight zinazopangishwa, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | |
top_p | number | Nucleus sampling. | Model za open-weight zinazopangishwa | |
stop_sequences | array | Hadi strings 4. Jibu huisha kabla ya ya kwanza inayoonekana. stop_reason hubaki end_turn. | Model za open-weight zinazopangishwa | |
tools | array | Tools ambazo model inaweza kuita, kila moja kama {"name", "description", "input_schema"}. Tazama Tools hapa chini. | Model zote | |
tool_choice | object | {"type": "auto"} huacha model iamue, {"type": "any"} huifanya iite tool, {"type": "tool", "name": "…"} huifanya iite tool hiyo. | Model za open-weight zinazopangishwa | |
thinking | object | Kiasi ambacho model hufikiri kabla ya kujibu. Tazama Thinking hapa chini. | Model za open-weight zinazopangishwa | |
web_search | boolean | false | Nyongeza ya Shannon kwenye umbizo: true huiruhusu model kutafuta kwenye wavuti kabla ya kujibu. | shannon-1.6-*, shannon-2-*, familia ya Shannon 3 |
Bila max_tokens thamani ni 4,096, na 65,536 kwenye shannon-coder-1.
metadata, top_k, service_tier na alama za cache_control kwenye blocks zinakubaliwa ili code ya client iliyopo ifanye kazi bila mabadiliko. Haziathiri jibu; prompt caching kwenye model za open-weight zinazopangishwa ni ya kiotomatiki.
Jibu la JSON kulingana na schema huombwa kwa response_format kwenye Chat Completions na kwa text.format kwenye Responses. Matokeo yaliyopangwa
Ombi lenye system prompt na thinking
Ombi hili linatuma system prompt, bajeti ya thinking, temperature na stop sequence. Linatumia model ya open-weight inayopangishwa, ambayo huzitumia zote.
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) import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com",
});
const message = await 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 (const block of message.content) {
if (block.type === "thinking") console.log("reasoning:", block.thinking);
if (block.type === "text") console.log("answer:", block.text);
}
console.log(message.usage); curl https://api.shannon-ai.com/v1/messages \
-H "x-api-key: YOUR_API_KEY" \
-H "content-type: application/json" \
-d '{
"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?"}]
}' Kwenye model za open-weight zinazopangishwa, usage huripoti tokens zilizosomwa kutoka prompt cache kando na tokens nyingine za input.
{
"usage": {
"input_tokens": 31,
"cache_read_input_tokens": 0,
"cache_creation_input_tokens": 0,
"output_tokens": 62
}
} System prompt
system ni string, au array ya blocks za maandishi kwa umbo [{"type": "text", "text": "…"}]. Maandishi ya blocks huunganishwa kwa kukatika kwa mstari.
Inatumiwa na model za open-weight zinazopangishwa, shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro na shannon-coder-1. Kwa id ya familia ya Shannon 3, weka maagizo yanayopaswa kushikilia kwenye ujumbe wa user.
Ujumbe na content blocks
Ujumbe una role, yaani user au assistant, na content. content ni string, au array ya blocks.
| Block | Maelezo | Inapatikana kwenye |
|---|---|---|
{"type": "text", "text": "…"} | Maandishi. | Model zote |
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "…"}}{"type": "image", "source": {"type": "url", "url": "…"}} | Picha kwenye ujumbe wa user, kama base64 au kwa URL. | Familia ya Shannon 3, shannon-1.6-lite, shannon-1.6-pro, na model za open-weight zinazopangishwa zinazoorodhesha input ya picha |
{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} | Hati (PDF, Word, PowerPoint au Excel) kwenye ujumbe wa user, kama base64 au kwa URL. | Familia ya Shannon 3 |
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} | Kwenye ujumbe wa assistant: wito wa tool ambao model ilifanya kwenye jibu la awali. | Model zote |
{"type": "tool_result", "tool_use_id": "toolu_…", "content": "…"} | Kwenye ujumbe wa user: matokeo ya wito huo. content ni string, au orodha ya blocks za maandishi. | Model zote |
Unaweza kutuma tena content ya jibu la awali kama ilivyo: blocks za text na tool_use husomwa, blocks za thinking huruka.
Kwenye viwango vya Shannon, picha na hati husomwa kutoka kwenye ujumbe wa mwisho wa user. Ukubwa na mipaka vina ukurasa wake. Picha na mafaili
Thinking
Model za open-weight zinazopangishwa huhusisha thinking na reasoning effort. Bila field hiyo, effort ni high.
| Umbo | budget_tokens | Athari |
|---|---|---|
{"type": "disabled"} | Hakuna reasoning. Jibu halina block ya thinking. | |
{"type": "enabled", "budget_tokens": 2048} | ≤ 2,048 | Effort ya chini. |
{"type": "enabled", "budget_tokens": 8192} | ≤ 8,192 | Effort ya wastani. |
{"type": "enabled", "budget_tokens": 16000} | > 8,192 | Effort ya juu. |
Model inayofikiri hurudisha reasoning yake kama block {"type": "thinking", "thinking": "…"} mbele ya maandishi. Viwango vya Shannon vinavyofikiri pia huituma.
Efforts zimeelezwa kwenye ukurasa wake. Reasoning effort
Tools
Tool ni function ambayo code yako inaendesha. Eleza kila moja kwa name, description na input_schema. Model inapotaka tool, jibu lina block ya tool_use na stop_reason ni tool_use.
Ufafanuzi wa tool kwenye tools:
[
{
"name": "get_weather",
"description": "Current weather for a city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
]
}
}
] content ya jibu linaloiita:
[
{
"type": "text",
"text": ""
},
{
"type": "tool_use",
"id": "toolu_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
"name": "get_weather",
"input": {
"city": "Paris"
}
}
] Endesha tool, kisha tuma ombi tena na wito huo na block ya tool_result iliyoongezwa kwenye 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
| Umbo | Athari | Inatumiwa na |
|---|---|---|
{"type": "auto"} | Model inaamua kama iite tool. Hii ndiyo chaguo-msingi. | Model zote |
{"type": "any"} | Model lazima iite moja ya tools. | Model za open-weight zinazopangishwa |
{"type": "tool", "name": "…"} | Model lazima iite tool iliyotajwa. | Model za open-weight zinazopangishwa |
Ni tools zenye input_schema pekee zinazosomwa. Web search si tool kwenye endpoint hii: weka field ya web_search.
Mzunguko wa tool umeelezwa kikamilifu kwenye ukurasa wake. Uitoaji wa kazi
Jibu
| Field | Aina | Maelezo | Hutumwa na |
|---|---|---|---|
id | string | msg_ ikifuatiwa na herufi 32 za hexadecimal. | Model zote |
type | string | Daima message. | Model zote |
role | string | Daima assistant. | Model zote |
model | string | Id rasmi ya model iliyojibu. | Model zote |
content | array | Blocks za jibu, kwa mpangilio huu: thinking wakati model ilifikiri, text, kisha tool_use moja kwa kila wito wa tool. | Model zote |
stop_reason | string | Kwa nini jibu liliisha. Tazama thamani hapa chini. | Model zote |
usage | object | input_tokens na output_tokens. | Model zote |
sources | array | Kwenye ombi lenye web_search: true pekee ambalo utafutaji wake ulipata kitu: matokeo ambayo model ilipewa, kila moja likiwa na index, title na url. [1] kwenye jibu ni kipengee chenye index 1. Kwenye stream huja na tukio la message_delta. | shannon-1.6-*, shannon-2-*, familia ya Shannon 3 |
usage.cache_read_input_tokens | integer | cache_read_input_tokens ni sehemu ya prompt iliyosomwa kutoka cache; input_tokens ni iliyobaki. cache_creation_input_tokens daima ni 0. | Model za open-weight zinazopangishwa |
Blocks za jibu
| Block | Maelezo |
|---|---|
{"type": "thinking", "thinking": "…"} | Reasoning ya model. Hakuna member ya signature. |
{"type": "text", "text": "…"} | Maandishi ya jibu. Yanaweza kuwa tupu wakati jibu ni wito wa tool. |
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} | Wito wa tool. input ni kitu cha JSON. Tuma matokeo nyuma kwa id ile ile. |
stop_reason
| stop_reason | Maelezo | Hutumwa na |
|---|---|---|
end_turn | Model imemaliza jibu lake, au moja ya stop_sequences zako imeonekana. | Model zote |
tool_use | Jibu lina wito mmoja au zaidi wa tool. | Model zote |
max_tokens | Jibu lilikatwa kwenye kikomo cha output. | Familia ya Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1, kwenye streams |
Streaming
Weka stream kuwa true kupata server-sent events. Kila frame ina mstari wa event: wenye jina la tukio na mstari wa data: wenye kitu cha JSON kinachorudia jina kwenye type. Stream helpers za SDK ya Anthropic husoma matukio haya kwa ajili yako:
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) import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com",
});
const stream = client.messages.stream({
model: "shannon-3",
max_tokens: 1024,
messages: [{ role: "user", content: "Explain server-sent events in three sentences." }],
});
stream.on("text", (text) => process.stdout.write(text));
const message = await stream.finalMessage();
console.log("\n", message.stop_reason, message.usage); curl -N https://api.shannon-ai.com/v1/messages \
-H "x-api-key: YOUR_API_KEY" \
-H "content-type: application/json" \
-d '{
"model": "shannon-3",
"max_tokens": 1024,
"stream": true,
"messages": [{"role": "user", "content": "Explain server-sent events in three sentences."}]
}' Matukio, kwa mpangilio yanavyofika:
| Tukio | Data | Lini |
|---|---|---|
message_start | message | Daima ya kwanza. message ina id, role, model, content tupu na usage inayoanza na sifuri. |
content_block_start | index, content_block | Block inafunguka. content_block ni block tupu ya text au thinking, au block ya tool_use yenye id na name yake. |
content_block_delta | index, delta {"type": "thinking_delta", "thinking"} | Kipande cha reasoning, kwa block ya thinking. |
content_block_delta | index, delta {"type": "text_delta", "text"} | Kipande cha jibu, kwa block ya text. |
content_block_delta | index, delta {"type": "input_json_delta", "partial_json"} | Arguments za wito wa tool, kamili katika delta moja, kwa block ya tool_use. |
content_block_stop | index | Block yenye index hii imekamilika. |
message_delta | delta {stop_reason, stop_sequence}, usage | Mwisho wa jibu: delta.stop_reason, na usage ya ombi. |
message_stop | Daima ya mwisho. |
Blocks zinahesabiwa kwa index kwa mpangilio zinavyofunguka, na block moja inakamilika kabla ya inayofuata kufunguka. Soma kila block kwa aina yake, si kwa namba yake: stream inaweza kufungua block tupu ya text kwanza, kisha block ya thinking, na kutoa jibu kwenye block ya text ya baadaye.
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
| Hutumwa na | Maelezo |
|---|---|
Familia ya Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | Tukio la ping lenye data {"type": "ping"}, kila sekunde 15. |
| Model za open-weight zinazopangishwa | Mstari wa maoni : keepalive, kila sekunde 15 wakati model inafanya kazi. |
Stream inayoshindwa
Hitilafu baada ya stream kuanza ni tukio la error lenye mwili ule ule kama jibu la kosa: {"type": "error", "error": {"type", "message"}}. Matukio ya kufunga, message_delta na message_stop, bado yanafuata. Chukulia jibu kama lililoshindwa na utume ombi tena.
Makosa
Makosa hutumia mwili wa kosa wa Anthropic: type ni error, na kitu cha error kina type na message. Jedwali linaorodhesha kile ambacho endpoint hii hurudisha mara nyingi zaidi. Orodha kamili, pamoja na yapi ya kujaribu tena, ina ukurasa wake. Ushughulikiaji wa Makosa
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "unknown model: no-such-model"
}
} | Hali | Aina | Ujumbe | Lini |
|---|---|---|---|
401 | authentication_error | Missing authenticationInvalid API key | Hakuna API key iliyotumwa, au key haijulikani au imebatilishwa. |
400 | invalid_request_error | unknown model: <id> | model si model id ya Shannon. |
400 | invalid_request_error | No user message provided | Viwango vya Shannon: ombi halina maandishi ya mtumiaji wala tools. |
400 | invalid_request_error | <id> does not accept image input | Picha ilitumwa kwa model ya open-weight inayopangishwa isiyo na input ya picha. |
422 | invalid_request_error | Failed to deserialize the JSON body into the target type: … | messages haipo, au field ina aina isiyo sahihi ya JSON. |
429 | rate_limit_error | Quota exceeded. Upgrade your plan at shannon-ai.com/plan | max_tokens ni kubwa kuliko kilichobaki kwenye salio lako. |
429 | rate_limit_error | Too many requests. Retry in <n>s. | Flood protection: maombi zaidi ya 120 ndani ya dakika moja kwenye akaunti yako. |
429 | rate_limit_error | Shannon Coder call quota reached. Upgrade your plan at shannon-ai.com/plan | shannon-coder-1: maombi ya Shannon Coder ya mpango wako kwa dirisha la sasa la saa 4 yametumika yote. |
500 | server_error | The model backend failed to answer. Please retry. | Model haikutoa jibu. Tuma ombi tena. |
502 | api_error | The model backend failed to answer. Please retry. | Model haikutoa jibu. Tuma ombi tena. |
Kuhesabu tokens
POST /v1/messages/count_tokens inapokea mwili ule ule wa ombi la ujumbe (model, system, messages, tools) na inarudisha {"input_tokens": n}: idadi ya tokens za input ambazo ombi lingetozwa. Inahesabu kwa model za open-weight zinazopangishwa, ni bure na haihesabiwi na 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) import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com",
});
const count = await client.messages.countTokens({
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?" }],
});
console.log(count.input_tokens); curl https://api.shannon-ai.com/v1/messages/count_tokens \
-H "x-api-key: YOUR_API_KEY" \
-H "content-type: application/json" \
-d '{
"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?"}]
}'
# {"input_tokens": 31} Kuhesabu kuna ukurasa wake, wenye endpoint ya maandishi matupu na mipaka. Kuhesabu tokens