รูปแบบ Anthropic
POST /v1/messages รับคำขอในรูปแบบ Anthropic Messages และตอบกลับในรูปแบบเดียวกัน ทั้งแบบสตรีมและไม่สตรีม ใช้ได้กับ Anthropic SDK และเครื่องมือที่สร้างบนมัน เช่น Claude Code: ตั้งค่า base URL ใช้ Shannon API key ของคุณ และระบุ model id ของ Shannon
POST https://api.shannon-ai.com/v1/messages
ชี้ Anthropic SDK ไปที่ base URL ของ Shannon 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."}]
}' คำตอบคือ message ที่ content เป็นรายการของบล็อก ให้หาบล็อกจาก type ของมัน: เมื่อโมเดลให้เหตุผล บล็อกแรกจะเป็น 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 key ของคุณ ใช้ 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 ของคำขอที่คุณกำหนดเอง จะถูกส่งกลับมาในคำตอบโดยไม่เปลี่ยนแปลง หากไม่ระบุ คำตอบจะมี id ที่เป็นเลขฐานสิบหก 12 ตัวอักษร |
ฟิลด์คำขอ
ต้องระบุเฉพาะ messages คอลัมน์ ใช้โดย ระบุโมเดลที่ฟิลด์นั้นเปลี่ยนคำตอบได้ โมเดล open-weight ที่โฮสต์คือ id ทั้งสิบสองตัวในรายการโมเดล ส่วนตระกูล Shannon 3 คือ shannon-3, shannon-3-pro, shannon-3.1 และ shannon-3.1-pro โมเดลและราคา
| ฟิลด์ | ประเภท | ค่าเริ่มต้น | คำอธิบาย | ใช้โดย |
|---|---|---|---|---|
model | string | shannon-1.6-lite | model id ของ Shannon จากรายการโมเดล ส่งมาทุกคำขอ การจับคู่ไม่สนใจตัวพิมพ์เล็กใหญ่ ชื่ออื่นใดจะคืน 400 unknown model ดังนั้นเครื่องมือที่ส่งชื่อโมเดลของตัวเองต้องถูกตั้งค่าให้ใช้ id ของ Shannon | ทุกโมเดล |
messages | array | จำเป็น บทสนทนา เรียงจากข้อความเก่าสุดก่อน โดยมี role เป็น user และ assistant ดู ข้อความและบล็อกเนื้อหา ด้านล่าง | ทุกโมเดล | |
system | string | array | คำสั่งสำหรับโมเดล: สตริง หรืออาร์เรย์ของบล็อกข้อความ ดู System prompt ด้านล่าง | โมเดล open-weight ที่โฮสต์, shannon-1.6-*, shannon-2-*, shannon-coder-1 | |
max_tokens | integer | 4096 | ขีดจำกัดสูงสุดของคำตอบ เป็นหน่วย tokens ไม่บังคับบน endpoint นี้ แต่ 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 ดู การสตรีม ด้านล่าง | ทุกโมเดล |
temperature | number | Sampling temperature บนโมเดล open-weight ที่โฮสต์ ค่าจะถูกจำกัดให้อยู่ระหว่าง 0 ถึง 2 | โมเดล open-weight ที่โฮสต์, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | |
top_p | number | Nucleus sampling | โมเดล open-weight ที่โฮสต์ | |
stop_sequences | array | สตริงได้สูงสุด 4 ตัว คำตอบจะจบก่อนสตริงแรกที่ปรากฏ stop_reason ยังคงเป็น end_turn | โมเดล open-weight ที่โฮสต์ | |
tools | array | tools ที่โมเดลเรียกใช้ได้ แต่ละตัวอยู่ในรูป {"name", "description", "input_schema"} ดู Tools ด้านล่าง | ทุกโมเดล | |
tool_choice | object | {"type": "auto"} ให้โมเดลตัดสินใจเอง, {"type": "any"} บังคับให้เรียก tool, {"type": "tool", "name": "…"} บังคับให้เรียก tool นั้น | โมเดล open-weight ที่โฮสต์ | |
thinking | object | โมเดลให้เหตุผลมากเพียงใดก่อนตอบ ดู Thinking ด้านล่าง | โมเดล open-weight ที่โฮสต์ | |
web_search | boolean | false | ส่วนเพิ่มเติมของ Shannon ในรูปแบบนี้: true ให้โมเดลค้นหาเว็บก่อนตอบ | shannon-1.6-*, shannon-2-*, ตระกูล Shannon 3 |
หากไม่ระบุ max_tokens ค่าจะเป็น 4,096 และเป็น 65,536 บน shannon-coder-1
ระบบรับ metadata, top_k, service_tier และเครื่องหมาย cache_control บนบล็อก เพื่อให้โค้ดไคลเอนต์เดิมทำงานได้โดยไม่ต้องแก้ ค่าเหล่านี้ไม่เปลี่ยนคำตอบ ส่วน prompt caching บนโมเดล open-weight ที่โฮสต์ทำงานอัตโนมัติ
การขอคำตอบ JSON ตามสคีมาทำผ่าน response_format บน Chat Completions และผ่าน text.format บน Responses เอาต์พุตแบบมีโครงสร้าง
คำขอที่มี 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 จะรายงาน tokens ที่อ่านจาก prompt cache แยกจาก input tokens อื่นๆ
{
"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 กับ id ในตระกูล Shannon 3 ให้ใส่คำสั่งที่ต้องคงไว้ลงในข้อความของผู้ใช้
ข้อความและบล็อกเนื้อหา
ข้อความมี 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": "…"}} | เอกสาร (PDF, Word, PowerPoint หรือ Excel) ในข้อความ user ส่งเป็น base64 หรือผ่าน URL | ตระกูล Shannon 3 |
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} | ในข้อความ assistant: การเรียก tool ที่โมเดลทำในคำตอบก่อนหน้า | ทุกโมเดล |
{"type": "tool_result", "tool_use_id": "toolu_…", "content": "…"} | ในข้อความ user: ผลลัพธ์ของการเรียกนั้น content เป็นสตริง หรือรายการของบล็อกข้อความ | ทุกโมเดล |
คุณส่ง content ของคำตอบก่อนหน้ากลับมาตามเดิมได้: บล็อก text และ tool_use จะถูกอ่าน ส่วนบล็อก thinking จะถูกข้าม
บนระดับ Shannon รูปภาพและเอกสารจะถูกอ่านจากข้อความ user ล่าสุด ขนาดและข้อจำกัดมีหน้าของตัวเอง รูปภาพและไฟล์
Thinking
โมเดล open-weight ที่โฮสต์จะแปลง thinking เป็นระดับความพยายามในการให้เหตุผล หากไม่ระบุฟิลด์นี้ ระดับจะเป็นสูง
| รูปแบบ | budget_tokens | ผล |
|---|---|---|
{"type": "disabled"} | ไม่ให้เหตุผล คำตอบไม่มีบล็อก thinking | |
{"type": "enabled", "budget_tokens": 2048} | ≤ 2,048 | ความพยายามต่ำ |
{"type": "enabled", "budget_tokens": 8192} | ≤ 8,192 | ความพยายามปานกลาง |
{"type": "enabled", "budget_tokens": 16000} | > 8,192 | ความพยายามสูง |
โมเดลที่ให้เหตุผลจะคืนการให้เหตุผลเป็นบล็อก {"type": "thinking", "thinking": "…"} ก่อนข้อความ ระดับ Shannon ที่ให้เหตุผลได้ก็ส่งเช่นกัน
ระดับความพยายามอธิบายไว้ในหน้าของตัวเอง ระดับความพยายามในการให้เหตุผล
Tools
tool คือฟังก์ชันที่โค้ดของคุณเป็นผู้รัน อธิบายแต่ละตัวด้วย name, description และ input_schema เมื่อโมเดลต้องการ tool คำตอบจะมีบล็อก tool_use และ stop_reason เป็น tool_use
นิยาม tool ใน tools:
[
{
"name": "get_weather",
"description": "Current weather for a city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
]
}
}
] content ของคำตอบที่เรียก tool นั้น:
[
{
"type": "text",
"text": ""
},
{
"type": "tool_use",
"id": "toolu_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
"name": "get_weather",
"input": {
"city": "Paris"
}
}
] รัน tool แล้วส่งคำขอใหม่อีกครั้งโดยเพิ่มการเรียกและบล็อก tool_result ลงใน 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
| รูปแบบ | ผล | ใช้โดย |
|---|---|---|
{"type": "auto"} | โมเดลตัดสินใจเองว่าจะเรียก tool หรือไม่ นี่คือค่าเริ่มต้น | ทุกโมเดล |
{"type": "any"} | โมเดลต้องเรียก tool ตัวใดตัวหนึ่ง | โมเดล open-weight ที่โฮสต์ |
{"type": "tool", "name": "…"} | โมเดลต้องเรียก tool ที่ระบุชื่อ | โมเดล open-weight ที่โฮสต์ |
ระบบอ่านเฉพาะ tools ที่มี input_schema การค้นหาเว็บไม่ใช่ tool บน endpoint นี้: ให้ตั้งค่าฟิลด์ web_search
ลูปของ tool อธิบายไว้ครบถ้วนในหน้าของตัวเอง การเรียกฟังก์ชัน
คำตอบ
| ฟิลด์ | ประเภท | คำอธิบาย | ส่งโดย |
|---|---|---|---|
id | string | msg_ ตามด้วยอักขระเลขฐานสิบหก 32 ตัว | ทุกโมเดล |
type | string | เป็น message เสมอ | ทุกโมเดล |
role | string | เป็น assistant เสมอ | ทุกโมเดล |
model | string | id มาตรฐานของโมเดลที่ตอบ | ทุกโมเดล |
content | array | บล็อกของคำตอบ เรียงตามลำดับนี้: thinking เมื่อโมเดลให้เหตุผล, text แล้วตามด้วย tool_use หนึ่งบล็อกต่อการเรียก tool หนึ่งครั้ง | ทุกโมเดล |
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": "…"} | การให้เหตุผลของโมเดล ไม่มีสมาชิก signature |
{"type": "text", "text": "…"} | ข้อความคำตอบ อาจว่างเปล่าได้เมื่อคำตอบเป็นการเรียก tool |
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} | การเรียก tool โดย input เป็นออบเจกต์ JSON ส่งผลลัพธ์กลับด้วย id เดียวกัน |
stop_reason
| stop_reason | คำอธิบาย | ส่งโดย |
|---|---|---|
end_turn | โมเดลตอบจบแล้ว หรือมี stop_sequences ตัวใดตัวหนึ่งของคุณปรากฏขึ้น | ทุกโมเดล |
tool_use | คำตอบมีการเรียก tool อย่างน้อยหนึ่งครั้ง | ทุกโมเดล |
max_tokens | คำตอบถูกตัดที่ขีดจำกัดของเอาต์พุต | ตระกูล Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 ในโหมดสตรีม |
การสตรีม
ตั้งค่า stream เป็น true เพื่อรับ server-sent events แต่ละเฟรมมีบรรทัด event: ที่ระบุชื่ออีเวนต์ และบรรทัด data: ที่เป็นออบเจกต์ JSON ซึ่งมีชื่อซ้ำใน type ตัวช่วยสตรีมของ Anthropic SDK จะอ่านอีเวนต์เหล่านี้ให้คุณ:
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, role, โมเดล, content ที่ว่างเปล่า และ usage ที่เริ่มจากศูนย์ |
content_block_start | index, content_block | บล็อกเปิดขึ้น content_block เป็นบล็อก text หรือ thinking ที่ว่างเปล่า หรือบล็อก tool_use พร้อม id และ name |
content_block_delta | index, delta {"type": "thinking_delta", "thinking"} | ส่วนหนึ่งของการให้เหตุผล สำหรับบล็อก thinking |
content_block_delta | index, delta {"type": "text_delta", "text"} | ส่วนหนึ่งของคำตอบ สำหรับบล็อก text |
content_block_delta | index, delta {"type": "input_json_delta", "partial_json"} | อาร์กิวเมนต์ของการเรียก tool ซึ่งมาครบใน delta เดียว สำหรับบล็อก tool_use |
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 | อีเวนต์ ping ที่มีข้อมูล {"type": "ping"} ทุก 15 วินาที |
| โมเดล open-weight ที่โฮสต์ | บรรทัดคอมเมนต์ : keepalive ทุก 15 วินาทีขณะที่โมเดลทำงาน |
สตรีมที่ล้มเหลว
ความล้มเหลวหลังสตรีมเริ่มแล้วจะเป็นอีเวนต์ error ที่มี body เหมือนคำตอบข้อผิดพลาด: {"type": "error", "error": {"type", "message"}} อีเวนต์ปิดท้ายอย่าง message_delta และ message_stop ยังคงตามมา ให้ถือว่าคำตอบล้มเหลวและส่งคำขอใหม่อีกครั้ง
ข้อผิดพลาด
ข้อผิดพลาดใช้ error body แบบ Anthropic: type เป็น error และออบเจกต์ error มี type กับ message ตารางแสดงสิ่งที่ endpoint นี้คืนบ่อยที่สุด รายการทั้งหมดพร้อมวิธีตัดสินใจว่าควรลองใหม่หรือไม่มีหน้าของตัวเอง การจัดการข้อผิดพลาด
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "unknown model: no-such-model"
}
} | สถานะ | ประเภท | ข้อความ | เมื่อไร |
|---|---|---|---|
401 | authentication_error | Missing authenticationInvalid API key | ไม่ได้ส่ง API key มา หรือคีย์ไม่รู้จักหรือถูกเพิกถอนแล้ว |
400 | invalid_request_error | unknown model: <id> | model ไม่ใช่ model id ของ Shannon |
400 | invalid_request_error | No user message provided | ระดับ Shannon: คำขอไม่มีข้อความของผู้ใช้และไม่มี 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: ใช้การเรียก Shannon Coder ตามแผนของคุณครบแล้วสำหรับช่วง 4 ชั่วโมงปัจจุบัน |
500 | server_error | The model backend failed to answer. Please retry. | โมเดลไม่ได้สร้างคำตอบ ส่งคำขอใหม่อีกครั้ง |
502 | api_error | The model backend failed to answer. Please retry. | โมเดลไม่ได้สร้างคำตอบ ส่งคำขอใหม่อีกครั้ง |
การนับ tokens
POST /v1/messages/count_tokens รับ body เดียวกับคำขอ message (model, system, messages, tools) และคืนค่า {"input_tokens": n} ซึ่งเป็นจำนวน input tokens ที่คำขอนั้นจะถูกเรียกเก็บ ใช้ได้กับโมเดล 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} การนับมีหน้าของตัวเอง พร้อม endpoint แบบข้อความธรรมดาและข้อจำกัด การนับ token