Cruth anthropic
Gabhaidh POST /v1/messages ri iarrtas ann an cruth Anthropic Messages agus freagraidh e san aon chruth, le streaming no às aonais. Cleachd e leis an SDK Anthropic agus le innealan a tha stèidhichte air, leithid Claude Code: suidhich am base URL, cleachd d’ iuchair API Shannon agus ainmich id modail Shannon.
POST https://api.shannon-ai.com/v1/messages
Nochd an SDK Anthropic air base URL Shannon. Cuiridh an SDK /v1/messages ris agus cuiridh e d’ iuchair sa header 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."}]
}' Is e teachdaireachd a th’ sa fhreagairt le content na liosta de bhlocaichean. Lorg na blocaichean a-rèir an type: nuair a rinn am modail reusanachadh, is e thinking a’ chiad bhloc agus thig an teacsa na dhèidh.
{
"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 | Luach | Tuairisgeul |
|---|---|---|
x-api-key | YOUR_API_KEY | D’ iuchair API. Thèid Authorization: Bearer YOUR_API_KEY aontachadh na àite. |
content-type | application/json | Riatanach. |
anthropic-version | 2023-06-01 | Air aontachadh, chan eil e riatanach. Cuiridh an SDK Anthropic 2023-06-01; tha an aon chruth air a’ fhreagairt ge bith dè an luach. |
anthropic-beta | Air aontachadh, chan eil e riatanach. | |
x-request-id | Roghainneil. D’ id fhèin airson an iarrtais. Thig e air ais gun atharrachadh air a’ fhreagairt; às aonais tha id de 12 caractaran sia-deugach sa fhreagairt. |
Raointean an iarrtais
Chan eil ach messages riatanach. Ainmichidh a’ cholbh Air a chur an sàs le na modailean air an atharraich raon am freagairt. Is e na modailean open-weight hosted an dusan id air liosta nam modailean; is e teaghlach Shannon 3 shannon-3, shannon-3-pro, shannon-3.1 agus shannon-3.1-pro. Modailean & prìsean
| Raon | Seòrsa | Bun-roghainn | Tuairisgeul | Air a chur an sàs le |
|---|---|---|---|---|
model | string | shannon-1.6-lite | Id modail Shannon bho liosta nam modailean. Cuir e leis gach iarrtas. Chan eil an t-eadar-dhealachadh eadar litrichean mòra is beaga a’ cunntadh. Tillidh ainm sam bith eile 400 unknown model, agus mar sin feumaidh inneal a chuireas a ainmean modail fhèin a bhith air a shuidheachadh gu id Shannon. | A h-uile modail |
messages | array | Riatanach. An còmhradh, an teachdaireachd as sine an toiseach, leis na dreuchdan user agus assistant. Faic Teachdaireachdan agus blocaichean susbaint gu h-ìosal. | A h-uile modail | |
system | string | array | Stiùireadh dhan mhodail: sreang, no array de bhlocaichean teacsa. Faic System prompt gu h-ìosal. | Modailean open-weight hosted, shannon-1.6-*, shannon-2-*, shannon-coder-1 | |
max_tokens | integer | 4096 | Crìoch àrd a’ fhreagairt, ann an tokens. Roghainneil air an endpoint seo; bidh an SDK Anthropic ga chur an-còmhnaidh. Thèid luach taobh a-muigh 1 gu 65,536 a ghluasad dhan raon sin. Is e cuideachd an t-suim a thèid a chur an dàrna taobh bhon balance agad fhad ‘s a tha an t-iarrtas a’ ruith. | Modailean open-weight hosted, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 |
stream | boolean | false | Cuiridh true am freagairt mar server-sent events. Faic Streaming gu h-ìosal. | A h-uile modail |
temperature | number | Teòthachd samplaidh. Air na modailean open-weight hosted thèid luachan a chumail eadar 0 agus 2. | Modailean open-weight hosted, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | |
top_p | number | Samplachadh nucleus. | Modailean open-weight hosted | |
stop_sequences | array | Suas gu 4 sreangan. Thig am freagairt gu crìch ron chiad tè a nochdas. Fanaidh stop_reason mar end_turn. | Modailean open-weight hosted | |
tools | array | Na h-innealan a dh’fhaodas am modail a ghairm, gach fear mar {"name", "description", "input_schema"}. Faic Tools gu h-ìosal. | A h-uile modail | |
tool_choice | object | Leigidh {"type": "auto"} leis a’ mhodail co-dhùnadh, thèid aige air inneal a ghairm le {"type": "any"}, agus bidh aige ris an inneal sin a ghairm le {"type": "tool", "name": "…"}. | Modailean open-weight hosted | |
thinking | object | Dè cho mòr ‘s a bhios am modail a’ reusanachadh mus freagair e. Faic Thinking gu h-ìosal. | Modailean open-weight hosted | |
web_search | boolean | false | Cur-ris Shannon dhan chruth: leigidh true leis a’ mhodail an lìon a rannsachadh mus freagair e. | shannon-1.6-*, shannon-2-*, teaghlach Shannon 3 |
Às aonais max_tokens is e 4,096 an luach, agus 65,536 air shannon-coder-1.
Thèid metadata, top_k, service_tier agus comharran cache_control air blocaichean aontachadh gus an ruith còd client a th’ ann mar a tha e. Chan atharraich iad am freagairt; tha prompt caching air na modailean open-weight hosted fèin-obrachail.
Thèid freagairt JSON a-rèir schema iarraidh le response_format air Chat Completions agus le text.format air Responses. Toraidhean structarail
Iarrtas le system prompt agus thinking
Cuiridh an t-iarrtas seo system prompt, buidseat thinking, teòthachd agus stop sequence. Cleachdaidh e modail open-weight hosted, a chuireas an sàs iad uile.
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?"}]
}' Air na modailean open-weight hosted bheir usage cunntas air na tokens a chaidh a leughadh bhon prompt cache air leth bho na input tokens eile.
{
"usage": {
"input_tokens": 31,
"cache_read_input_tokens": 0,
"cache_creation_input_tokens": 0,
"output_tokens": 62
}
} System prompt
Is e system sreang, no array de bhlocaichean teacsa san fhoirm [{"type": "text", "text": "…"}]. Thèid teacsaichean nam blocaichean a cheangal le briseadh loidhne.
Thèid a chur an sàs leis na modailean open-weight hosted, shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro agus shannon-coder-1. Le id à teaghlach Shannon 3, cuir na stiùiridhean a dh’fheumas a bhith ann dhan teachdaireachd neach-cleachdaidh.
Teachdaireachdan agus blocaichean susbaint
Tha role aig teachdaireachd, user no assistant, agus content. Is e content sreang, no array de bhlocaichean.
| Block | Tuairisgeul | Ri fhaighinn air |
|---|---|---|
{"type": "text", "text": "…"} | Teacsa. | A h-uile modail |
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "…"}}{"type": "image", "source": {"type": "url", "url": "…"}} | Dealbh ann an teachdaireachd user, mar base64 no le URL. | Teaghlach Shannon 3, shannon-1.6-lite, shannon-1.6-pro, agus na modailean open-weight hosted a tha a’ liostadh input dealbh |
{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} | Sgrìobhainn (PDF, Word, PowerPoint no Excel) ann an teachdaireachd user, mar base64 no le URL. | Teaghlach Shannon 3 |
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} | Ann an teachdaireachd assistant: gairm inneil a rinn am modail ann am freagairt roimhe. | A h-uile modail |
{"type": "tool_result", "tool_use_id": "toolu_…", "content": "…"} | Ann an teachdaireachd user: toradh a’ ghairm sin. Is e content sreang, no liosta de bhlocaichean teacsa. | A h-uile modail |
’S urrainn dhut content freagairt a bh’ ann roimhe a chur air ais mar a tha e: thèid blocaichean text agus tool_use a leughadh, thèid blocaichean thinking a leum thairis.
Air ìrean Shannon thèid dealbhan is sgrìobhainnean a leughadh bhon teachdaireachd user mu dheireadh. Tha duilleag fhèin aig meudan is crìochan. Dealbhan agus faidhlichean
Thinking
Bidh na modailean open-weight hosted a’ mapadh thinking gu oidhirp reusanachaidh. Às aonais an raoin tha an oidhirp àrd.
| Cruth | budget_tokens | Buaidh |
|---|---|---|
{"type": "disabled"} | Gun reusanachadh. Chan eil bloc thinking sa fhreagairt. | |
{"type": "enabled", "budget_tokens": 2048} | ≤ 2,048 | Oidhirp ìosal. |
{"type": "enabled", "budget_tokens": 8192} | ≤ 8,192 | Oidhirp mheadhanach. |
{"type": "enabled", "budget_tokens": 16000} | > 8,192 | Oidhirp àrd. |
Tillidh modail a nì reusanachadh a reusanachadh mar bhloc {"type": "thinking", "thinking": "…"} ron teacsa. Cuiridh na h-ìrean Shannon a nì reusanachadh e cuideachd.
Tha na h-oidhirpean air an tuairisgeul air an duilleag fhèin. Oidhirp reusanachaidh
Innealan
Is e inneal function a ruitheas an còd agad. Mìnich gach fear le name, description agus input_schema. Nuair a tha inneal a dhìth air a’ mhodail, tha bloc tool_use sa fhreagairt agus is e tool_use an stop_reason.
Mìneachadh inneil ann an tools:
[
{
"name": "get_weather",
"description": "Current weather for a city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
]
}
}
] content freagairt a ghairmeas e:
[
{
"type": "text",
"text": ""
},
{
"type": "tool_use",
"id": "toolu_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
"name": "get_weather",
"input": {
"city": "Paris"
}
}
] Ruith an t-inneal, an uair sin cuir an t-iarrtas a-rithist leis a’ ghairm agus bloc tool_result air a chur ri 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
| Cruth | Buaidh | Air a chur an sàs le |
|---|---|---|
{"type": "auto"} | Cho-dhùineas am modail an gairm e inneal. Is e seo a’ bhun-roghainn. | A h-uile modail |
{"type": "any"} | Feumaidh am modail aon dhe na h-innealan a ghairm. | Modailean open-weight hosted |
{"type": "tool", "name": "…"} | Feumaidh am modail an t-inneal ainmichte a ghairm. | Modailean open-weight hosted |
Cha tèid ach innealan le input_schema a leughadh. Chan e inneal a th’ ann an rannsachadh lìn air an endpoint seo: suidhich an raon web_search.
Tha an lùb innealan air a mhìneachadh gu h-iomlan air an duilleag fhèin. Call gnìomh
Am freagairt
| Raon | Seòrsa | Tuairisgeul | Air a chur le |
|---|---|---|---|
id | string | msg_ agus an uair sin 32 caractar sia-deugach. | A h-uile modail |
type | string | An-còmhnaidh message. | A h-uile modail |
role | string | An-còmhnaidh assistant. | A h-uile modail |
model | string | Id canonical a’ mhodail a fhreagair. | A h-uile modail |
content | array | Blocaichean an fhreagairt, san òrdugh seo: thinking nuair a rinn am modail reusanachadh, text, an uair sin aon tool_use airson gach gairm inneil. | A h-uile modail |
stop_reason | string | Carson a thàinig am freagairt gu crìch. Faic na luachan gu h-ìosal. | A h-uile modail |
usage | object | input_tokens agus output_tokens. | A h-uile modail |
sources | array | Air iarrtas le web_search: true a lorg rannsachadh rudeigin a-mhàin: na toraidhean a fhuair am modail, gach fear le index, title agus url. Is e [1] san fhreagairt an inntrigeadh aig a bheil index 1. Ann an stream thig e leis an tachartas message_delta. | shannon-1.6-*, shannon-2-*, teaghlach Shannon 3 |
usage.cache_read_input_tokens | integer | Is e cache_read_input_tokens a’ phàirt dhen prompt a chaidh a leughadh bhon cache; is e input_tokens an còrr. Tha cache_creation_input_tokens 0 an-còmhnaidh. | Modailean open-weight hosted |
Blocaichean freagairt
| Block | Tuairisgeul |
|---|---|
{"type": "thinking", "thinking": "…"} | Reusanachadh a’ mhodail. Chan eil ball signature ann. |
{"type": "text", "text": "…"} | Teacsa an fhreagairt. Faodaidh e a bhith falamh nuair as e gairm inneil am freagairt. |
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} | Gairm inneil. Is e nì JSON a th’ ann an input. Cuir an toradh air ais leis an aon id. |
stop_reason
| stop_reason | Tuairisgeul | Air a chur le |
|---|---|---|
end_turn | Chrìochnaich am modail am freagairt, no nochd fear de na stop_sequences agad. | A h-uile modail |
tool_use | Tha gairm inneil no barrachd sa fhreagairt. | A h-uile modail |
max_tokens | Chaidh am freagairt a ghearradh aig crìoch an output. | Teaghlach Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1, ann an streams |
Streaming
Suidhich stream gu true airson server-sent events. Tha loidhne event: aig gach frèam le ainm an tachartais agus loidhne data: le nì JSON a bheir an t-ainm a-rithist ann an type. Leughaidh luchd-cuideachaidh stream an SDK Anthropic na tachartasan seo dhut:
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."}]
}' Na tachartasan, san òrdugh anns an tig iad:
| Tachartas | Dàta | Cuin |
|---|---|---|
message_start | message | An-còmhnaidh an toiseach. Tha an id, an dreuchd, am modail, content falamh agus usage a thòisicheas aig neoni ann an message. |
content_block_start | index, content_block | Bidh bloc a’ fosgladh. Is e content_block bloc text no thinking falamh, no bloc tool_use le id agus name. |
content_block_delta | index, delta {"type": "thinking_delta", "thinking"} | Pìos dhen reusanachadh, airson bloc thinking. |
content_block_delta | index, delta {"type": "text_delta", "text"} | Pìos dhen fhreagairt, airson bloc text. |
content_block_delta | index, delta {"type": "input_json_delta", "partial_json"} | Argamaidean gairm inneil, coileanta ann an aon delta, airson bloc tool_use. |
content_block_stop | index | Tha am bloc leis an index seo coileanta. |
message_delta | delta {stop_reason, stop_sequence}, usage | Deireadh an fhreagairt: delta.stop_reason, agus usage an iarrtais. |
message_stop | An-còmhnaidh mu dheireadh. |
Tha na blocaichean air an àireamhachadh le index san òrdugh anns an fhosgail iad, agus bidh aon bhloc coileanta mus fosgail am fear ùr. Leugh gach bloc a-rèir an t-seòrsa, chan ann a-rèir an àireamh: faodaidh stream bloc text falamh fhosgladh an toiseach, an uair sin am bloc thinking, agus am freagairt a lìbhrigeadh ann am bloc text nas fhaide air adhart.
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
| Air a chur le | Tuairisgeul |
|---|---|
Teaghlach Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | Tachartas ping leis an dàta {"type": "ping"}, gach 15 diogan. |
| Modailean open-weight hosted | Loidhne bheachd : keepalive, gach 15 diogan fhad ‘s a tha am modail ag obair. |
Stream a dh’fhailicheas
Is e tachartas error a th’ ann an fàilligeadh às dèidh dha an stream tòiseachadh, leis an aon bhodhaig ri freagairt mearachd: {"type": "error", "error": {"type", "message"}}. Thig na tachartasan dùnaidh, message_delta agus message_stop, fhathast às a dhèidh. Làimhsich am freagairt mar fhàilligeadh agus cuir an t-iarrtas a-rithist.
Mearachdan
Bidh mearachdan a’ cleachdadh bodhaig mearachd Anthropic: is e type error, agus tha type agus message san nì error. Tha an clàr a’ liostadh na tha an endpoint seo a’ tilleadh as trice. Tha duilleag fhèin aig an liosta slàn, le na ghabhas feuchainn a-rithist. Làimhseachadh mearachd
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "unknown model: no-such-model"
}
} | Staid | Seòrsa | Teachdaireachd | Cuin |
|---|---|---|---|
401 | authentication_error | Missing authenticationInvalid API key | Cha deach iuchair API a chur, no chan eil an iuchair aithnichte no chaidh a cur à bith. |
400 | invalid_request_error | unknown model: <id> | Chan e id modail Shannon a th’ ann an model. |
400 | invalid_request_error | No user message provided | Ìrean Shannon: chan eil teacsa neach-cleachdaidh no tools san iarrtas. |
400 | invalid_request_error | <id> does not accept image input | Chaidh dealbh a chur gu modail open-weight hosted gun input dealbh. |
422 | invalid_request_error | Failed to deserialize the JSON body into the target type: … | Chan eil messages ann, no tha seòrsa JSON ceàrr air raon. |
429 | rate_limit_error | Quota exceeded. Upgrade your plan at shannon-ai.com/plan | Tha max_tokens nas motha na tha air fhàgail dhen balance agad. |
429 | rate_limit_error | Too many requests. Retry in <n>s. | Dìon thar-thuiltidh: còrr air 120 iarrtas ann am mionaid air a’ chunntas agad. |
429 | rate_limit_error | Shannon Coder call quota reached. Upgrade your plan at shannon-ai.com/plan | shannon-coder-1: chaidh gairmean Shannon Coder a’ phlana agad airson na h-uinneige làithrich 4 uairean a thìde a chleachdadh. |
500 | server_error | The model backend failed to answer. Please retry. | Cha tug am modail freagairt. Cuir an t-iarrtas a-rithist. |
502 | api_error | The model backend failed to answer. Please retry. | Cha tug am modail freagairt. Cuir an t-iarrtas a-rithist. |
Cunntadh tokens
Gabhaidh POST /v1/messages/count_tokens an aon bhodhaig ri iarrtas teachdaireachd (model, system, messages, tools) agus tillidh e {"input_tokens": n}: an àireamh de input tokens a thèid iarraidh air an iarrtas. Obraichidh e airson nam modailean open-weight hosted, tha e an-asgaidh agus cha tèid a chunntadh leis an dìon thar-thuiltidh.
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} Tha duilleag fhèin aig cunntadh, leis an endpoint teacsa shlàn agus na crìochan. Cunntadh tokens