ຂ້າມໄປຫາເນື້ອຫາ
Anthropic

Anthropic

POST /v1/messages ຮັບຄຳຮ້ອງຂໍໃນຮູບແບບ Anthropic Messages ແລະ ຕອບໃນຮູບແບບດຽວກັນ, ແບບ stream ຫຼື ບໍ່ stream. ໃຊ້ກັບ Anthropic SDK ແລະ ເຄື່ອງມືທີ່ສ້າງຈາກມັນ ເຊັ່ນ Claude Code: ຕັ້ງ base URL, ໃຊ້ Shannon API key ຂອງທ່ານ ແລະ ລະບຸ Shannon model id.

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

ຊີ້ Anthropic SDK ໄປທີ່ base URL ຂອງ Shannon. SDK ຈະເພີ່ມ /v1/messages ແລະ ສົ່ງ key ຂອງທ່ານໃນ 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)

ຄຳຕອບແມ່ນຂໍ້ຄວາມທີ່ content ເປັນລາຍການຂອງ block. ຊອກຫາ block ຈາກ type ຂອງມັນ: ເມື່ອ model ໄດ້ຄິດຫາເຫດຜົນ, block ທຳອິດແມ່ນ thinking ແລະ ຂໍ້ຄວາມຢູ່ຖັດຈາກນັ້ນ.

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

Headers

Header ຄ່າ ຄຳອະທິບາຍ
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 ຕົວ.

Request fields

ຕ້ອງມີພຽງ messages. ຄໍລຳ ໃຊ້ໂດຍ ລະບຸ model ທີ່ຟີວນັ້ນປ່ຽນຄຳຕອບ. Hosted open-weight models ແມ່ນສິບສອງ id ໃນລາຍການ model; ຕະກູນ Shannon 3 ແມ່ນ shannon-3, shannon-3-pro, shannon-3.1 ແລະ shannon-3.1-pro. Model ແລະ ລາຄາ

ຟີວ ປະເພດ ຄ່າເລີ່ມຕົ້ນ ຄຳອະທິບາຍ ໃຊ້ໂດຍ
model string shannon-1.6-lite model id ຂອງ Shannon ຈາກລາຍການ model. ສົ່ງມັນໃນທຸກຄຳຮ້ອງຂໍ. ການຈັບຄູ່ບໍ່ແຍກຕົວພິມໃຫຍ່-ນ້ອຍ. ຊື່ອື່ນໃດຈະສົ່ງຄືນ 400 unknown model, ດັ່ງນັ້ນເຄື່ອງມືທີ່ສົ່ງຊື່ model ຂອງຕົນເອງຕ້ອງຖືກຕັ້ງເປັນ Shannon id. ທຸກ model
messages array ຕ້ອງມີ. ບົດສົນທະນາ, ຂໍ້ຄວາມເກົ່າສຸດກ່ອນ, ດ້ວຍ role user ແລະ assistant. ເບິ່ງ Messages ແລະ content blocks ຂ້າງລຸ່ມ. ທຸກ model
system string | array ຄຳແນະນຳສຳລັບ model: string ຫຼື array ຂອງ text block. ເບິ່ງ System prompt ຂ້າງລຸ່ມ. Hosted open-weight models, shannon-1.6-*, shannon-2-*, shannon-coder-1
max_tokens integer 4096 ຂີດຈຳກັດສູງສຸດຂອງຄຳຕອບ, ເປັນ tokens. ບໍ່ບັງຄັບໃນ endpoint ນີ້; Anthropic SDK ສົ່ງມັນສະເໝີ. ຄ່າທີ່ຢູ່ນອກຊ່ວງ 1 ຫາ 65,536 ຈະຖືກປັບເຂົ້າຊ່ວງນັ້ນ. ມັນຍັງເປັນຈຳນວນທີ່ກັນໄວ້ຈາກຍອດເງິນຂອງທ່ານໃນຂະນະທີ່ຄຳຮ້ອງຂໍກຳລັງເຮັດວຽກ. Hosted open-weight models, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
stream boolean false true ສົ່ງຄຳຕອບເປັນ server-sent events. ເບິ່ງ Streaming ຂ້າງລຸ່ມ. ທຸກ model
temperature number Sampling temperature. ໃນ hosted open-weight models ຄ່າຈະຖືກຮັກສາໄວ້ລະຫວ່າງ 0 ແລະ 2. Hosted open-weight models, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
top_p number Nucleus sampling. Hosted open-weight models
stop_sequences array ສູງສຸດ 4 string. ຄຳຕອບຈະຈົບກ່ອນອັນທຳອິດທີ່ປະກົດ. stop_reason ຍັງເປັນ end_turn. Hosted open-weight models
tools array tools ທີ່ model ເອີ້ນໃຊ້ໄດ້, ແຕ່ລະອັນເປັນ {"name", "description", "input_schema"}. ເບິ່ງ Tools ຂ້າງລຸ່ມ. ທຸກ model
tool_choice object {"type": "auto"} ໃຫ້ model ຕັດສິນໃຈເອງ, {"type": "any"} ບັງຄັບໃຫ້ເອີ້ນ tool, {"type": "tool", "name": "…"} ບັງຄັບໃຫ້ເອີ້ນ tool ນັ້ນ. Hosted open-weight models
thinking object model ໃຊ້ reasoning ຫຼາຍປານໃດກ່ອນຕອບ. ເບິ່ງ Thinking ຂ້າງລຸ່ມ. Hosted open-weight models
web_search boolean false ສ່ວນເພີ່ມຂອງ Shannon ໃນຮູບແບບນີ້: true ໃຫ້ model ຄົ້ນຫາເວັບກ່ອນຕອບ. shannon-1.6-*, shannon-2-*, ຕະກູນ Shannon 3

ຖ້າບໍ່ມີ max_tokens ຄ່າແມ່ນ 4,096, ແລະ 65,536 ໃນ shannon-coder-1.

marker metadata, top_k, service_tier ແລະ cache_control ໃນ block ຖືກຮັບໄວ້ເພື່ອໃຫ້ໂຄ້ດ client ເດີມເຮັດວຽກໄດ້ໂດຍບໍ່ຕ້ອງແກ້. ມັນບໍ່ປ່ຽນຄຳຕອບ; prompt caching ໃນ hosted open-weight models ເປັນອັດຕະໂນມັດ.

ຄຳຕອບ JSON ຕາມ schema ຂໍດ້ວຍ response_format ໃນ Chat Completions ແລະ ດ້ວຍ text.format ໃນ Responses. ຜົນອອກມີໂຄງສ້າງ

ຄຳຮ້ອງຂໍທີ່ມີ system prompt ແລະ thinking

ຄຳຮ້ອງຂໍນີ້ສົ່ງ system prompt, thinking budget, temperature ແລະ stop sequence. ມັນໃຊ້ hosted open-weight model ເຊິ່ງນຳໃຊ້ຄ່າທັງໝົດນີ້ໄດ້.

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)

ໃນ hosted open-weight models usage ລາຍງານ tokens ທີ່ອ່ານຈາກ prompt cache ແຍກຈາກ input tokens ອື່ນໆ.

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

System prompt

system ເປັນ string, ຫຼື array ຂອງ text block ໃນຮູບແບບ [{"type": "text", "text": "…"}]. ຂໍ້ຄວາມຂອງ block ຕ່າງໆຈະຖືກຕໍ່ກັນດ້ວຍການຂຶ້ນແຖວໃໝ່.

ໃຊ້ໂດຍ hosted open-weight models, shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro ແລະ shannon-coder-1. ກັບ id ໃນຕະກູນ Shannon 3, ໃຫ້ໃສ່ຄຳແນະນຳທີ່ຕ້ອງຖືກປະຕິບັດໄວ້ໃນຂໍ້ຄວາມຂອງ user.

ຂໍ້ຄວາມ ແລະ content blocks

ຂໍ້ຄວາມມີ role ເປັນ user ຫຼື assistant, ແລະ content. content ເປັນ string ຫຼື array ຂອງ block.

Block ຄຳອະທິບາຍ ໃຊ້ໄດ້ໃນ
{"type": "text", "text": "…"} ຂໍ້ຄວາມ. ທຸກ model
{"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, ແລະ hosted open-weight models ທີ່ລະບຸວ່າຮັບຮູບພາບເປັນ input
{"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 ທີ່ model ໄດ້ເຮັດໃນຄຳຕອບກ່ອນໜ້າ. ທຸກ model
{"type": "tool_result", "tool_use_id": "toolu_…", "content": "…"} ໃນຂໍ້ຄວາມ user: ຜົນຂອງການເອີ້ນນັ້ນ. content ເປັນ string ຫຼື ລາຍການຂອງ text block. ທຸກ model

ທ່ານສົ່ງ content ຂອງຄຳຕອບກ່ອນໜ້າກັບຄືນໄດ້ຕາມເດີມ: block text ແລະ tool_use ຈະຖືກອ່ານ, block thinking ຈະຖືກຂ້າມ.

ໃນ Shannon tiers ຮູບພາບ ແລະ ເອກະສານຈະຖືກອ່ານຈາກຂໍ້ຄວາມ user ສຸດທ້າຍ. ຂະໜາດ ແລະ ຂີດຈຳກັດມີໜ້າຂອງຕົນເອງ. ຮູບພາບ ແລະ ໄຟລ໌

Thinking

Hosted open-weight models ແປງ thinking ເປັນລະດັບ reasoning effort. ຖ້າບໍ່ມີຟີວນີ້ ລະດັບ effort ແມ່ນສູງ.

ຮູບແບບ budget_tokens ຜົນ
{"type": "disabled"} ບໍ່ມີ reasoning. ຄຳຕອບບໍ່ມີ block 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 ສູງ.

model ທີ່ຄິດຫາເຫດຜົນຈະສົ່ງ reasoning ຂອງມັນຄືນເປັນ block {"type": "thinking", "thinking": "…"} ກ່ອນຂໍ້ຄວາມ. Shannon tiers ທີ່ຄິດຫາເຫດຜົນກໍສົ່ງມັນເຊັ່ນກັນ.

ລະດັບ effort ຕ່າງໆອະທິບາຍໄວ້ໃນໜ້າຂອງຕົນເອງ. Reasoning effort

Tools

tool ແມ່ນ function ທີ່ໂຄ້ດຂອງທ່ານເປັນຜູ້ຣັນ. ອະທິບາຍແຕ່ລະອັນດ້ວຍ name, description ແລະ input_schema. ເມື່ອ model ຕ້ອງການ tool, ຄຳຕອບຈະມີ block tool_use ແລະ stop_reason ເປັນ tool_use.

ຄຳນິຍາມ tool ໃນ tools:

tools
[
  {
    "name": "get_weather",
    "description": "Current weather for a city.",
    "input_schema": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        }
      },
      "required": [
        "city"
      ]
    }
  }
]

content ຂອງຄຳຕອບທີ່ເອີ້ນມັນ:

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

ຣັນ tool, ແລ້ວສົ່ງຄຳຮ້ອງຂໍອີກຄັ້ງ ໂດຍເພີ່ມການເອີ້ນນັ້ນ ແລະ block tool_result ເຂົ້າໃນ 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

ຮູບແບບ ຜົນ ໃຊ້ໂດຍ
{"type": "auto"} model ຕັດສິນໃຈເອງວ່າຈະເອີ້ນ tool ຫຼືບໍ່. ນີ້ແມ່ນຄ່າເລີ່ມຕົ້ນ. ທຸກ model
{"type": "any"} model ຕ້ອງເອີ້ນ tool ໃດໜຶ່ງ. Hosted open-weight models
{"type": "tool", "name": "…"} model ຕ້ອງເອີ້ນ tool ທີ່ລະບຸຊື່. Hosted open-weight models

ອ່ານສະເພາະ tools ທີ່ມີ input_schema. ການຄົ້ນຫາເວັບບໍ່ແມ່ນ tool ໃນ endpoint ນີ້: ໃຫ້ຕັ້ງຟີວ web_search.

tool loop ອະທິບາຍຢ່າງເຕັມໃນໜ້າຂອງຕົນເອງ. ການເອີ້ນຟັງຊັນ

ຄຳຕອບ

ຟີວ ປະເພດ ຄຳອະທິບາຍ ສົ່ງໂດຍ
id string msg_ ຕາມດ້ວຍຕົວອັກສອນເລກຖານສິບຫົກ 32 ຕົວ. ທຸກ model
type string ເປັນ message ສະເໝີ. ທຸກ model
role string ເປັນ assistant ສະເໝີ. ທຸກ model
model string id ມາດຕະຖານຂອງ model ທີ່ຕອບ. ທຸກ model
content array block ຕ່າງໆຂອງຄຳຕອບ, ຕາມລຳດັບນີ້: thinking ເມື່ອ model ໄດ້ຄິດຫາເຫດຜົນ, text, ແລ້ວຕາມດ້ວຍ tool_use ໜຶ່ງອັນຕໍ່ການເອີ້ນ tool ໜຶ່ງຄັ້ງ. ທຸກ model
stop_reason string ເຫດຜົນທີ່ຄຳຕອບສິ້ນສຸດ. ເບິ່ງຄ່າຕ່າງໆຂ້າງລຸ່ມ. ທຸກ model
usage object input_tokens ແລະ output_tokens. ທຸກ model
sources array ມີສະເພາະໃນຄຳຮ້ອງຂໍທີ່ມີ web_search: true ເຊິ່ງການຄົ້ນຫາພົບບາງຢ່າງ: ຜົນລັບທີ່ model ໄດ້ຮັບ, ແຕ່ລະອັນມີ index, title ແລະ url. [1] ໃນຄຳຕອບແມ່ນລາຍການທີ່ມີ index ເປັນ 1. ໃນ stream ມັນມາພ້ອມກັບ event message_delta. shannon-1.6-*, shannon-2-*, ຕະກູນ Shannon 3
usage.cache_read_input_tokens integer cache_read_input_tokens ແມ່ນສ່ວນຂອງ prompt ທີ່ອ່ານຈາກ cache; input_tokens ແມ່ນສ່ວນທີ່ເຫຼືອ. cache_creation_input_tokens ເປັນ 0 ສະເໝີ. Hosted open-weight models

Reply blocks

Block ຄຳອະທິບາຍ
{"type": "thinking", "thinking": "…"} ການຄິດຫາເຫດຜົນຂອງ model. ບໍ່ມີ member ຊື່ signature.
{"type": "text", "text": "…"} ຂໍ້ຄວາມຄຳຕອບ. ອາດຫວ່າງໄດ້ເມື່ອຄຳຕອບເປັນການເອີ້ນ tool.
{"type": "tool_use", "id": "toolu_…", "name": "…", "input": {…}} ການເອີ້ນ tool. input ເປັນ JSON object. ສົ່ງຜົນກັບຄືນດ້ວຍ id ດຽວກັນ.

stop_reason

stop_reason ຄຳອະທິບາຍ ສົ່ງໂດຍ
end_turn model ຕອບຈົບແລ້ວ, ຫຼື ມີ stop_sequences ຂອງທ່ານອັນໃດອັນໜຶ່ງປະກົດຂຶ້ນ. ທຸກ model
tool_use ຄຳຕອບມີການເອີ້ນ tool ໜຶ່ງຄັ້ງ ຫຼື ຫຼາຍກວ່ານັ້ນ. ທຸກ model
max_tokens ຄຳຕອບຖືກຕັດທີ່ຂີດຈຳກັດຂອງ output. ຕະກູນ Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1, ໃນ stream

Streaming

ຕັ້ງ stream ເປັນ true ເພື່ອຮັບ server-sent events. ແຕ່ລະ frame ມີແຖວ event: ທີ່ບອກຊື່ event ແລະ ແຖວ data: ທີ່ເປັນ JSON object ເຊິ່ງມີຊື່ຊ້ຳໃນ type. stream helper ຂອງ Anthropic SDK ອ່ານ event ເຫຼົ່ານີ້ໃຫ້ທ່ານ:

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)

event ຕ່າງໆ, ຕາມລຳດັບທີ່ມາຮອດ:

Event ຂໍ້ມູນ ເມື່ອໃດ
message_start message ມາກ່ອນສະເໝີ. message ມີ id, role, model, content ຫວ່າງ ແລະ usage ທີ່ເລີ່ມຈາກສູນ.
content_block_start index, content_block block ເປີດ. content_block ເປັນ block text ຫຼື thinking ທີ່ຫວ່າງ, ຫຼື block tool_use ພ້ອມ id ແລະ name ຂອງມັນ.
content_block_delta index, delta {"type": "thinking_delta", "thinking"} ສ່ວນໜຶ່ງຂອງການຄິດຫາເຫດຜົນ, ສຳລັບ block thinking.
content_block_delta index, delta {"type": "text_delta", "text"} ສ່ວນໜຶ່ງຂອງຄຳຕອບ, ສຳລັບ block text.
content_block_delta index, delta {"type": "input_json_delta", "partial_json"} arguments ຂອງການເອີ້ນ tool, ຄົບໃນ delta ດຽວ, ສຳລັບ block tool_use.
content_block_stop index block ທີ່ມີ index ນີ້ສຳເລັດແລ້ວ.
message_delta delta {stop_reason, stop_sequence}, usage ທ້າຍຄຳຕອບ: delta.stop_reason, ແລະ usage ຂອງຄຳຮ້ອງຂໍ.
message_stop ມາສຸດທ້າຍສະເໝີ.

block ຖືກໝາຍເລກດ້ວຍ index ຕາມລຳດັບທີ່ເປີດ, ແລະ block ໜຶ່ງຈະສຳເລັດກ່ອນ block ຕໍ່ໄປຈະເປີດ. ອ່ານແຕ່ລະ block ຈາກປະເພດຂອງມັນ, ບໍ່ແມ່ນຈາກເລກ: stream ອາດເປີດ block text ຫວ່າງກ່ອນ, ແລ້ວຈຶ່ງ block thinking, ແລະ ສົ່ງຄຳຕອບໃນ block text ທີ່ມາທີຫຼັງ.

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

Keep-alive

ສົ່ງໂດຍ ຄຳອະທິບາຍ
ຕະກູນ Shannon 3, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 event ping ທີ່ມີຂໍ້ມູນ {"type": "ping"}, ທຸກ 15 ວິນາທີ.
Hosted open-weight models ແຖວ comment : keepalive, ທຸກ 15 ວິນາທີໃນຂະນະທີ່ model ກຳລັງເຮັດວຽກ.

stream ທີ່ລົ້ມເຫຼວ

ຄວາມລົ້ມເຫຼວຫຼັງຈາກ stream ເລີ່ມແລ້ວແມ່ນ event error ທີ່ມີ body ດຽວກັນກັບຄຳຕອບຂໍ້ຜິດພາດ: {"type": "error", "error": {"type", "message"}}. event ປິດທ້າຍ, message_delta ແລະ message_stop, ຍັງຈະຕາມມາ. ໃຫ້ຖືວ່າຄຳຕອບລົ້ມເຫຼວ ແລະ ສົ່ງຄຳຮ້ອງຂໍອີກຄັ້ງ.

ຂໍ້ຜິດພາດ

ຂໍ້ຜິດພາດໃຊ້ error body ຂອງ Anthropic: type ເປັນ error, ແລະ object error ມີ type ແລະ message. ຕາຕະລາງລະບຸສິ່ງທີ່ endpoint ນີ້ສົ່ງຄືນເລື້ອຍທີ່ສຸດ. ລາຍການທັງໝົດ ພ້ອມສິ່ງທີ່ຄວນລອງໃໝ່ ມີໜ້າຂອງຕົນເອງ. ການຈັດການຂໍ້ຜິດພາດ

400 JSON
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "unknown model: no-such-model"
  }
}
ສະຖານະ ປະເພດ ຂໍ້ຄວາມ ເມື່ອໃດ
401 authentication_error Missing authentication
Invalid API key
ບໍ່ໄດ້ສົ່ງ API key, ຫຼື key ບໍ່ຮູ້ຈັກ ຫຼື ຖືກຖອນແລ້ວ.
400 invalid_request_error unknown model: <id> model ບໍ່ແມ່ນ model id ຂອງ Shannon.
400 invalid_request_error No user message provided Shannon tiers: ຄຳຮ້ອງຂໍບໍ່ມີຂໍ້ຄວາມຂອງ user ແລະ ບໍ່ມີ tools.
400 invalid_request_error <id> does not accept image input ສົ່ງຮູບພາບໄປຫາ hosted open-weight model ທີ່ບໍ່ຮອງຮັບຮູບພາບເປັນ input.
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. model ບໍ່ໄດ້ສ້າງຄຳຕອບ. ສົ່ງຄຳຮ້ອງຂໍອີກຄັ້ງ.
502 api_error The model backend failed to answer. Please retry. model ບໍ່ໄດ້ສ້າງຄຳຕອບ. ສົ່ງຄຳຮ້ອງຂໍອີກຄັ້ງ.

ການນັບ tokens

POST /v1/messages/count_tokens ຮັບ body ດຽວກັນກັບຄຳຮ້ອງຂໍຂໍ້ຄວາມ (model, system, messages, tools) ແລະ ສົ່ງຄືນ {"input_tokens": n}: ຈຳນວນ input tokens ທີ່ຄຳຮ້ອງຂໍນັ້ນຈະຖືກຄິດເງິນ. ມັນນັບໃຫ້ hosted open-weight models, ບໍ່ເສຍຄ່າ ແລະ ບໍ່ຖືກນັບໃນ 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)

ການນັບມີໜ້າຂອງຕົນເອງ, ພ້ອມ endpoint ແບບ plain-text ແລະ ຂີດຈຳກັດ. ການນັບ token