Anthropic ફોર્મેટ
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 હેડરમાં મોકલે છે.
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."}]
}' જવાબ એક મેસેજ છે જેનો content બ્લોક્સની યાદી છે. બ્લોક્સને તેમના type થી શોધો: મોડેલે reasoning કર્યું હોય ત્યારે પહેલો બ્લોક thinking હોય છે અને ટેક્સ્ટ તેની પછી આવે છે.
{
"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
}
} હેડર્સ
| હેડર | મૂલ્ય | વર્ણન |
|---|---|---|
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 ભૂમિકાઓ સાથે. નીચે મેસેજ અને કન્ટેન્ટ બ્લોક્સ જુઓ. | બધા મોડેલ્સ | |
system | string | array | મોડેલ માટે સૂચનાઓ: સ્ટ્રિંગ, અથવા ટેક્સ્ટ બ્લોક્સની એરે. નીચે System prompt જુઓ. | હોસ્ટેડ open-weight મોડેલ્સ, shannon-1.6-*, shannon-2-*, shannon-coder-1 | |
max_tokens | integer | 4096 | જવાબની ઉપલી મર્યાદા, ટોકન્સમાં. આ એન્ડપોઇન્ટ પર વૈકલ્પિક; 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 સેમ્પલિંગ. | હોસ્ટેડ open-weight મોડેલ્સ | |
stop_sequences | array | વધુમાં વધુ 4 સ્ટ્રિંગ. જે પહેલી દેખાય તેની પહેલાં જવાબ પૂરો થાય છે. stop_reason end_turn જ રહે છે. | હોસ્ટેડ open-weight મોડેલ્સ | |
tools | array | મોડેલ જે ટૂલ્સ કોલ કરી શકે, દરેક {"name", "description", "input_schema"} તરીકે. નીચે Tools જુઓ. | બધા મોડેલ્સ | |
tool_choice | object | {"type": "auto"} મોડેલને નક્કી કરવા દે છે, {"type": "any"} તેને ટૂલ કોલ કરાવે છે, {"type": "tool", "name": "…"} તેને તે જ ટૂલ કોલ કરાવે છે. | હોસ્ટેડ 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 અને બ્લોક્સ પરના 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) 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?"}]
}' હોસ્ટેડ open-weight મોડેલ્સ પર usage prompt cache માંથી વંચાયેલા ટોકન્સને અન્ય ઇનપુટ ટોકન્સથી અલગ જણાવે છે.
{
"usage": {
"input_tokens": 31,
"cache_read_input_tokens": 0,
"cache_creation_input_tokens": 0,
"output_tokens": 62
}
} System prompt
system સ્ટ્રિંગ છે, અથવા [{"type": "text", "text": "…"}] સ્વરૂપમાં ટેક્સ્ટ બ્લોક્સની એરે. બ્લોક્સના ટેક્સ્ટ લાઇન બ્રેકથી જોડાય છે.
તે હોસ્ટેડ open-weight મોડેલ્સ, shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro અને shannon-coder-1 દ્વારા લાગુ કરાય છે. Shannon 3 ફેમિલી id સાથે, જે સૂચનાઓ પળાવી જ જોઈએ તે user મેસેજમાં મૂકો.
મેસેજ અને કન્ટેન્ટ બ્લોક્સ
મેસેજમાં role હોય છે, user અથવા assistant, અને એક content. content સ્ટ્રિંગ હોય છે, અથવા બ્લોક્સની એરે.
| બ્લોક | વર્ણન | ક્યાં ઉપલબ્ધ |
|---|---|---|
{"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 મોડેલ્સ |
{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} | user મેસેજમાં ડોક્યુમેન્ટ (PDF, Word, PowerPoint અથવા Excel), base64 તરીકે અથવા URL દ્વારા. | Shannon 3 ફેમિલી |
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} | assistant મેસેજમાં: અગાઉના જવાબમાં મોડેલે કરેલો ટૂલ કોલ. | બધા મોડેલ્સ |
{"type": "tool_result", "tool_use_id": "toolu_…", "content": "…"} | user મેસેજમાં: તે કોલનું પરિણામ. content સ્ટ્રિંગ હોય છે, અથવા ટેક્સ્ટ બ્લોક્સની યાદી. | બધા મોડેલ્સ |
તમે અગાઉના જવાબનો content જેમ છે તેમ પાછો મોકલી શકો છો: text અને tool_use બ્લોક્સ વંચાય છે, thinking બ્લોક્સ છોડી દેવાય છે.
Shannon ટિયર પર ઇમેજ અને ડોક્યુમેન્ટ છેલ્લા user મેસેજમાંથી વંચાય છે. કદ અને મર્યાદાઓનું પોતાનું પેજ છે. ઇમેજ અને ફાઇલ્સ
Thinking
હોસ્ટેડ open-weight મોડેલ્સ thinking ને reasoning effort સાથે જોડે છે. ફીલ્ડ વિના effort ઊંચો હોય છે.
| સ્વરૂપ | budget_tokens | અસર |
|---|---|---|
{"type": "disabled"} | કોઈ reasoning નહીં. જવાબમાં thinking બ્લોક નથી. | |
{"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 ટેક્સ્ટની આગળ {"type": "thinking", "thinking": "…"} બ્લોક તરીકે પાછું આપે છે. reasoning કરતા Shannon ટિયર પણ તે મોકલે છે.
effort નું વર્ણન તેમના પોતાના પેજ પર છે. Reasoning effort
ટૂલ્સ
ટૂલ એ ફંક્શન છે જે તમારો કોડ ચલાવે છે. દરેકને name, description અને input_schema થી વર્ણવો. જ્યારે મોડેલને ટૂલ જોઈએ, ત્યારે જવાબમાં tool_use બ્લોક હોય છે અને stop_reason tool_use હોય છે.
tools માં ટૂલની વ્યાખ્યા:
[
{
"name": "get_weather",
"description": "Current weather for a city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
]
}
}
] તેને કોલ કરતા જવાબનો content:
[
{
"type": "text",
"text": ""
},
{
"type": "tool_use",
"id": "toolu_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
"name": "get_weather",
"input": {
"city": "Paris"
}
}
] ટૂલ ચલાવો, પછી કોલ અને messages માં ઉમેરેલા tool_result બ્લોક સાથે રિક્વેસ્ટ ફરી મોકલો:
[
{
"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"} | ટૂલ કોલ કરવો કે નહીં તે મોડેલ નક્કી કરે છે. આ ડિફોલ્ટ છે. | બધા મોડેલ્સ |
{"type": "any"} | મોડેલે કોઈ એક ટૂલ કોલ કરવું જ પડે. | હોસ્ટેડ open-weight મોડેલ્સ |
{"type": "tool", "name": "…"} | મોડેલે નામ આપેલ ટૂલ કોલ કરવું જ પડે. | હોસ્ટેડ open-weight મોડેલ્સ |
માત્ર input_schema વાળા ટૂલ્સ જ વંચાય છે. આ એન્ડપોઇન્ટ પર વેબ સર્ચ ટૂલ નથી: web_search ફીલ્ડ સેટ કરો.
ટૂલ લૂપનું સંપૂર્ણ વર્ણન તેના પોતાના પેજ પર છે. ફંક્શન કોલિંગ
જવાબ
| ફીલ્ડ | પ્રકાર | વર્ણન | કોણ મોકલે છે |
|---|---|---|---|
id | string | msg_ પછી 32 હેક્સાડેસિમલ અક્ષરો. | બધા મોડેલ્સ |
type | string | હંમેશા message. | બધા મોડેલ્સ |
role | string | હંમેશા assistant. | બધા મોડેલ્સ |
model | string | જવાબ આપનાર મોડેલનું કેનોનિકલ id. | બધા મોડેલ્સ |
content | array | જવાબના બ્લોક્સ, આ ક્રમમાં: મોડેલે reasoning કર્યું હોય તો thinking, text, પછી દરેક ટૂલ કોલ દીઠ એક tool_use. | બધા મોડેલ્સ |
stop_reason | string | જવાબ શા માટે પૂરો થયો. નીચેની કિંમતો જુઓ. | બધા મોડેલ્સ |
usage | object | input_tokens અને output_tokens. | બધા મોડેલ્સ |
sources | array | ફક્ત web_search: true વાળી એવી રિક્વેસ્ટ પર જેની શોધમાં કંઈક મળ્યું હોય: મોડેલને મળેલાં પરિણામો, દરેક index, title અને url સાથે. જવાબમાં [1] એટલે index 1 વાળી એન્ટ્રી. સ્ટ્રીમમાં તે message_delta ઇવેન્ટ સાથે આવે છે. | shannon-1.6-*, shannon-2-*, Shannon 3 ફેમિલી |
usage.cache_read_input_tokens | integer | cache_read_input_tokens એ prompt નો કેશમાંથી વંચાયેલો ભાગ છે; input_tokens બાકીનો ભાગ છે. cache_creation_input_tokens હંમેશા 0 હોય છે. | હોસ્ટેડ open-weight મોડેલ્સ |
જવાબના બ્લોક્સ
| બ્લોક | વર્ણન |
|---|---|
{"type": "thinking", "thinking": "…"} | મોડેલનું reasoning. તેમાં signature સભ્ય નથી. |
{"type": "text", "text": "…"} | જવાબનો ટેક્સ્ટ. જવાબ ટૂલ કોલ હોય ત્યારે તે ખાલી હોઈ શકે. |
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} | ટૂલ કોલ. input JSON ઓબ્જેક્ટ છે. પરિણામ એ જ id સાથે પાછું મોકલો. |
stop_reason
| stop_reason | વર્ણન | કોણ મોકલે છે |
|---|---|---|
end_turn | મોડેલે જવાબ પૂરો કર્યો, અથવા તમારી કોઈ stop_sequences દેખાઈ. | બધા મોડેલ્સ |
tool_use | જવાબમાં એક કે વધુ ટૂલ કોલ છે. | બધા મોડેલ્સ |
max_tokens | જવાબ આઉટપુટ મર્યાદાએ કાપી નાખવામાં આવ્યો. | Shannon 3 ફેમિલી, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1, સ્ટ્રીમમાં |
Streaming
server-sent events માટે stream ને true સેટ કરો. દરેક ફ્રેમમાં ઇવેન્ટના નામ સાથેની event: લાઇન અને JSON ઓબ્જેક્ટ સાથેની data: લાઇન હોય છે, જે type માં નામ પુનરાવર્તિત કરે છે. Anthropic SDK ના stream helpers આ ઇવેન્ટ્સ તમારા માટે વાંચે છે:
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."}]
}' ઇવેન્ટ્સ, જે ક્રમમાં તે આવે છે:
| ઇવેન્ટ | ડેટા | ક્યારે |
|---|---|---|
message_start | message | હંમેશા પહેલો. message માં id, ભૂમિકા, મોડેલ, ખાલી content અને શૂન્યથી શરૂ થતો usage હોય છે. |
content_block_start | index, content_block | બ્લોક ખૂલે છે. content_block ખાલી text અથવા thinking બ્લોક છે, અથવા તેના id અને name સાથેનો tool_use બ્લોક. |
content_block_delta | index, delta {"type": "thinking_delta", "thinking"} | thinking બ્લોક માટે reasoning નો એક ટુકડો. |
content_block_delta | index, delta {"type": "text_delta", "text"} | text બ્લોક માટે જવાબનો એક ટુકડો. |
content_block_delta | index, delta {"type": "input_json_delta", "partial_json"} | tool_use બ્લોક માટે ટૂલ કોલના આર્ગ્યુમેન્ટ્સ, એક જ delta માં સંપૂર્ણ. |
content_block_stop | index | આ index વાળો બ્લોક પૂરો થયો. |
message_delta | delta {stop_reason, stop_sequence}, usage | જવાબનો અંત: delta.stop_reason, અને રિક્વેસ્ટનો usage. |
message_stop | હંમેશા છેલ્લો. |
બ્લોક્સ ખૂલવાના ક્રમમાં index થી ક્રમાંકિત થાય છે, અને એક બ્લોક પૂરો થયા પછી જ આગલો ખૂલે છે. દરેક બ્લોકને તેના પ્રકારથી વાંચો, ક્રમાંકથી નહીં: સ્ટ્રીમ પહેલા ખાલી text બ્લોક ખોલી શકે, પછી thinking બ્લોક, અને જવાબ પછીના text બ્લોકમાં આપી શકે.
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 | ડેટા {"type": "ping"} સાથેની ping ઇવેન્ટ, દર 15 સેકન્ડે. |
| હોસ્ટેડ open-weight મોડેલ્સ | કોમેન્ટ લાઇન : keepalive, મોડેલ કામ કરતું હોય ત્યારે દર 15 સેકન્ડે. |
નિષ્ફળ જતો સ્ટ્રીમ
સ્ટ્રીમ શરૂ થયા પછીની નિષ્ફળતા એ error ઇવેન્ટ છે જેનો બોડી એરર જવાબ જેવો જ હોય છે: {"type": "error", "error": {"type", "message"}}. અંતિમ ઇવેન્ટ્સ, message_delta અને message_stop, હજી પણ પછી આવે છે. જવાબને નિષ્ફળ ગણો અને રિક્વેસ્ટ ફરી મોકલો.
એરર્સ
એરર Anthropic એરર બોડીનો ઉપયોગ કરે છે: type એ error છે, અને error ઓબ્જેક્ટમાં type અને message હોય છે. ટેબલ આ એન્ડપોઇન્ટ સૌથી વધુ વાર શું પાછું આપે છે તે બતાવે છે. કઈ એરર ફરી અજમાવવી તે સાથેની સંપૂર્ણ યાદીનું પોતાનું પેજ છે. ભૂલ સંભાળ
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "unknown model: no-such-model"
}
} | સ્ટેટસ | પ્રકાર | મેસેજ | ક્યારે |
|---|---|---|---|
401 | authentication_error | Missing authenticationInvalid API key | કોઈ API કી મોકલાઈ નથી, અથવા કી અજાણી અથવા રદ કરેલી છે. |
400 | invalid_request_error | unknown model: <id> | model Shannon મોડેલ id નથી. |
400 | invalid_request_error | No user message provided | Shannon ટિયર: રિક્વેસ્ટમાં કોઈ user ટેક્સ્ટ નથી અને કોઈ tools નથી. |
400 | invalid_request_error | <id> does not accept image input | ઇમેજ ઇનપુટ વિનાના હોસ્ટેડ open-weight મોડેલને ઇમેજ મોકલવામાં આવી. |
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} પાછું આપે છે: રિક્વેસ્ટ માટે જેટલા ઇનપુટ ટોકન્સનો ચાર્જ લાગે તેટલી સંખ્યા. તે હોસ્ટેડ 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) 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} ગણતરીનું પોતાનું પેજ છે, જેમાં plain-text એન્ડપોઇન્ટ અને મર્યાદાઓ છે. ટોકન ગણતરી