Peke ki ngā ihirangi
Chat Completions

Chat Completions

Ka tango te POST /v1/chat/completions i tētahi kōrero ka whakahoki i te karere e whai ake nei a te model i te hōputu OpenAI Chat Completions. Whakamahia mai i tētahi SDK OpenAI, mā te HTTP kau rānei; ko tēnei whārangi te tohutoro āpure-ki-te-āpure.

POST https://api.shannon-ai.com/v1/chat/completions

Ko te tono iti rawa he model id me tētahi karere kaiwhakamahi kotahi.

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.shannon-ai.com/v1",
)

response = client.chat.completions.create(
    model="shannon-3",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)

print(response.choices[0].message.content)

He JSON object kotahi te whakautu:

200 JSON
{
  "id": "chatcmpl-5f0c1e7a9b3d4c62a8e1f07d2b46c9a3",
  "object": "chat.completion",
  "created": 1791625200,
  "model": "shannon-3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello, it is good to meet you.",
        "reasoning_content": "The user wants a greeting in one sentence. Keep it short and friendly."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 1184,
    "completion_tokens": 46,
    "total_tokens": 1230
  }
}

Ngā header

Ngā header tono

Header Uara Whakaahuatanga
Authorization Bearer YOUR_API_KEY Tō API key. Ka whakaaetia te x-api-key: YOUR_API_KEY hei whakakapi i ia endpoint.
Content-Type application/json Hiahiatia. Ka whakahoki tētahi atu uara i te 415.
x-request-id Kōwhiringa. Tō ake id mō te tono. Ka hoki mai kāore i huri i te whakautu.

Ngā header whakautu

Header Whakaahuatanga
x-request-id I ia whakautu, tae atu ki ngā hapa me ngā stream: te uara i tukuna e koe, he 12 tohu hekihekimara rānei ina kāore koe i tuku. Whakahuatia ina pūrongo koe i tētahi raruraru.
content-type application/json, he text/event-stream rānei ina he true te stream.

Ngā āpure tono

Ko te messages anake te mea e hiahiatia ana. Ko te pou Whakamahia e e ingoa ana i ngā model e huri ai te whakautu mā tētahi āpure. Ko ngā model open-weight hosted ko ngā id tekau mā rua o te rārangi model; ko te whānau Shannon 3 ko shannon-3, shannon-3-pro, shannon-3.1 me shannon-3.1-pro. Ngā model me ngā utu

Āpure Momo Taunoa Whakaahuatanga Whakamahia e
model string shannon-1.6-lite Te model e whakautu ana: he id mai i te rārangi model. Tukuna i ia tono. Kāore e aro ki te rahi o ngā reta. Ka whakahoki tētahi id kāore i whakaputaina i te 400 unknown model. Ngā model katoa
messages array Hiahiatia. Te kōrero, te karere tawhito rawa i te tuatahi. Tirohia Messages i raro nei. Ngā model katoa
stream boolean false Ka tuku te true i te whakautu hei server-sent events i te wā e tuhia ana. Ngā model katoa
max_tokens integer 4096 Te tepe o runga o te whakautu, i roto i ngā tokens. Ka nekehia he uara i waho i te 1 ki te 65,536 ki roto i taua whānui. Koia hoki te nui ka wehea mai i tō toenga i te wā e rere ana te tono. Tirohia Output length i raro nei. Ngā model open-weight hosted, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
max_completion_tokens integer Ōrite ki te max_tokens. Ina tukuna e rua, ka whakamahia te max_tokens. Ngā model open-weight hosted, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
temperature number Te pāmahana tauira. I runga i ngā model open-weight hosted ko te taunoa he 1, ā, ka mau ngā uara ki waenga i te 0 me te 2. Ngā model open-weight hosted, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1
top_p number 0.95 Nucleus sampling. Ka mau ngā uara ki waenga i te 0 me te 1. Ngā model open-weight hosted
seed integer Te seed o te sampler, tētahi tau tōpū ahakoa tehea. Mēnā kāore, ka puta te seed mai i te model me te kōrero, nō reira ka whakamahi te tono ōrite i tukuna e rua i te seed ōrite. Ngā model open-weight hosted
stop string | array He rārangi tuhi, he rārangi o ngā rārangi tuhi rānei. Ka whakamahia tae atu ki te 4. Ka mutu te whakautu i mua i te tuatahi e puta ana; kāore te kuputuhi stop ake e whakahokia. Ngā model open-weight hosted
reasoning_effort string high Te nui o te reasoning a te model i mua i tana whakautu: off, low, medium he high rānei. Ko te none me te minimal te tikanga off, ko te default te tikanga medium, ko te max te tikanga high. Ka whakahoki tētahi atu uara i te 400. Ngā model open-weight hosted
reasoning object Te tautuhinga ōrite i te āhua object: {"effort": "low"}. Ina tukuna e rua, ka whakamahia te reasoning_effort. Ngā model open-weight hosted
tools array Ngā function ka taea e te model te karanga, ia tētahi hei {"type": "function", "function": {"name", "description", "parameters"}}. Ka hoki mai ngā karanga a te model i te tool_calls; ka whakahaere tō code i a rātou. Ngā model katoa
tool_choice string | object auto Mā te "auto" e whakatau te model. Mā te "required" e karanga ia i tētahi tool. Mā te {"type": "function", "function": {"name": "…"}} e karanga ia i taua tool. Ngā model open-weight hosted
response_format object {"type": "json_object"} mō tētahi whakautu JSON, {"type": "json_schema", "json_schema": {…}} rānei mō tētahi whakautu e whai ana i tō schema. Ngā taumata Shannon katoa; ngā model open-weight hosted pērā i te rārangi mō ia id
web_search boolean false Mā te true e rapu te model i te tukutuku i mua i tana whakautu. shannon-1.6-*, shannon-2-*, te whānau Shannon 3

Ka whakaaetia ētahi atu āpure OpenAI, pērā i te n, user, stream_options, parallel_tool_calls, presence_penalty, frequency_penalty, logit_bias, logprobs, metadata, store me prompt_cache_key, kia kore ai e huri te code kiritaki o nāianei. Kāore ō rātou pānga ki te whakautu: kotahi tonu te choice, ā, ka mutu tonu tētahi stream me te usage.

Ka whakahoki tētahi āpure he hē te momo JSON, hei tauira "max_tokens": "100", i te 422. Pērā hoki te tono kāore he messages.

He whārangi motuhake tō ngā tools, te output whakatakoto, te reasoning me te rapu tukutuku: Karanga ā‑mahi, Putanga hanganga, Reasoning effort, Rapu paetukutuku.

He tono me ngā kōwhiringa

Ka tautuhi tēnei tono i tētahi karere system, i ngā āpure sampling me te reasoning effort. Ka whakamahi i tētahi model open-weight hosted, ka whakamahi i te katoa.

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.shannon-ai.com/v1",
)

response = client.chat.completions.create(
    model="DeepSeek-V4-Flash-0731-W4A16-AUTOROUND-REAP",
    messages=[
        {"role": "system", "content": "You are a physics teacher. Answer in two sentences."},
        {"role": "user", "content": "Why is the sky blue?"},
    ],
    max_tokens=512,
    temperature=0.3,
    top_p=0.9,
    seed=7,
    stop=["\n\n"],
    reasoning_effort="low",
)

message = response.choices[0].message
print(message.reasoning_content)  # the reasoning
print(message.content)            # the answer
print(response.usage)

He āhua ōrite te whakautu ki runga ake nei. Ka tāpiri tōna usage e rua ngā taipitopito i runga i ngā model open-weight hosted: ngā prompt tokens i pānuitia mai i te cache me ngā tokens i whakapaua ki te reasoning.

200 JSON
{
  "usage": {
    "prompt_tokens": 31,
    "completion_tokens": 62,
    "total_tokens": 93,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 21
    }
  }
}

Te roa o te output

E rua ngā mahi a te max_tokens. Tuatahi, ko te maha o ngā tokens ka wehea mai i tō toenga ina tīmata te tono. Ina oti te whakautu, ka whakakapia taua nui e ngā tokens i whakamahia e te tono. Mēnā he nui ake te max_tokens i te toenga o tō toenga, ka whakahoki te tono i te 429 Quota exceeded ahakoa ka tau te whakautu ake. Tukuna he max_tokens iti ake kia iti iho te wehenga.

Ka tatauria te shannon-coder-1 i tētahi tikanga rerekē i runga i tēnei endpoint: he karanga Shannon Coder o tō mahere te tono kotahi, ā, kāore he tokens e wehea mō taua tono. Ngā tepe me te toenga

Tuarua, ka whakawhāiti i te roa o te whakautu i runga i ēnei model:

Ngā model Te mahi a te max_tokens
shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 Ka mutu te whakautu ina eke ki te tepe. Ka mutu tētahi stream ki te finish_reason length.
Ngā model open-weight hosted Ka mutu te kuputuhi whakautu i te max_tokens. Kāore te reasoning e tatauria ki a ia. Ko ngā uara iti iho i te 256 ka mahi pēnei i te 256.

Mēnā kāore he max_tokens he max_completion_tokens rānei, ko te uara 4,096. I runga i te shannon-coder-1 ko 65,536.

Ngā karere

He object ia karere me tētahi role me tētahi content. Ko te content he rārangi tuhi, he rārangi wāhanga rānei ina nui ake te kawe a te karere i te kuputuhi.

Role Whakaahuatanga Whakamahia e
system Ngā tohutohu mō te model. Whakaurua tuatahi. I runga i ngā taumata Shannon ko te karere system tuatahi te mea ka whakamahia. Ngā model open-weight hosted, shannon-1.6-*, shannon-2-*, shannon-coder-1
developer Ka pānuitia hei system. Ngā model open-weight hosted
user Tā koe e pātai ai. I runga i ngā taumata Shannon ko te karere user whakamutunga te prompt, ā, ko ngā karere i mua i a ia te hītori. Ngā model katoa
assistant Ngā whakautu o mua a te model. Pupurihia ōna tool_calls ina tukuna e koe tētahi hua tool i muri i a ia. Ngā model katoa
tool Te hua o tētahi tool call: kei te tool_call_id te id o te karanga, kei te content te hua hei rārangi tuhi. Ngā model katoa

Me tētahi id o te whānau Shannon 3, whakatōngia ngā tohutohu me mau ki roto i te karere user.

I runga i ngā taumata Shannon ka whakahoki te tono kāore he kuputuhi kaiwhakamahi, kāore he tools i te 400 No user message provided.

Ngā wāhanga ihirangi

Wāhanga Whakaahuatanga Kei
{"type": "text", "text": "…"} Kuputuhi māmā. Ngā model katoa
{"type": "image_url", "image_url": {"url": "…"}} He whakaahua, hei URL data: me te ihirangi base64, hei URL http(s) rānei. Te whānau Shannon 3, shannon-1.6-lite, shannon-1.6-pro, me ngā model open-weight hosted e rārangi ana i te input whakaahua
{"type": "file", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} He tuhinga (PDF, Word, PowerPoint, Excel rānei), hei base64, mā te URL rānei. Te whānau Shannon 3

He whārangi motuhake tō ngā rahi, ngā tepe me te rārangi katoa o ngā āhua. Ngā whakaahua me ngā kōnae

Te object whakautu

Āpure Momo Whakaahuatanga
id string chatcmpl- ka whai i te 32 tohu hekihekimara.
object string Ko chat.completion i ngā wā katoa.
created integer Te wā o te whakautu, i ngā hekona Unix.
model string Te id ōkawa o te model nāna i whakautu. Ka rerekē pea te tuhi i te id i tukuna e koe.
choices array Kotahi tonu te choice, me te index 0.
choices[0].message.role string Ko assistant i ngā wā katoa.
choices[0].message.content string | null Te kuputuhi whakautu. Me ngā tool_calls he null i runga i ngā taumata Shannon; ka taea e ngā model open-weight hosted te tuku kuputuhi i te taha o ngā karanga.
choices[0].message.reasoning_content string | null Te reasoning i tuhia e te model i mua i te whakautu, he null rānei ina kāore he.
choices[0].message.tool_calls array Kei reira ina karanga anake te model i ngā tools. He id tō ia urunga, he type function, me tētahi function me te name me ngā arguments hei rārangi tuhi JSON.
choices[0].message.annotations array I runga anake i tētahi tono me te web_search: true i kitea he mea e tana rapu. Kotahi te url_citation mō ia pūtake e ingoatia ana e tētahi tohu i te content, me te url, te title, te start_index me te end_index (te tūnga o te tohu, e tātaihia ana ki ngā tohu tuhi, kāore te mutunga e whakaurua).
choices[0].finish_reason string Te take i mutu ai te whakautu. Tirohia Ngā take mutunga.
usage object Ngā tokens o te tono. Tirohia Usage.
sources array I runga anake i tētahi tono me te web_search: true i kitea he mea e tana rapu: ngā hua i hoatu ki te model, he index, he title me he url ō ia tētahi. Ko te [1] i te whakautu te tāurunga whai index 1.

Ngā take mutunga

finish_reason Whakaahuatanga
stop Kua oti i te model tana whakautu, kua puta rānei tētahi rārangi tuhi stop.
tool_calls Ka karanga te model i tētahi tool neke atu rānei. Whakahaerea rātou ka tuku i ngā hua ki ngā karere tool.
length I tapahia te whakautu i te tepe output. Ka pūrongotia i ngā stream o shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 me te whānau Shannon 3.

Ka pūrongo te whakautu kāore i stream i te stop he tool_calls rānei.

Usage

Āpure Momo Whakaahuatanga Kei
usage.prompt_tokens integer Input tokens. Ngā model katoa
usage.completion_tokens integer Output tokens: te reasoning, te whakautu me ngā tool call tahi. Ngā model katoa
usage.total_tokens integer Te prompt_tokens me te completion_tokens. Ngā model katoa
usage.prompt_tokens_details.cached_tokens integer Te wāhanga o te prompt_tokens i pānuitia mai i te prompt cache. Ngā model open-weight hosted
usage.completion_tokens_details.reasoning_tokens integer Te wāhanga o te completion_tokens i whakapaua ki te reasoning. Ngā model open-weight hosted

I runga i ngā model open-weight hosted, ko te prompt_tokens ō karere me ō tautuhinga tool kua tatauria ki te tokenizer ake a te model, tāpiri ngā tokens o ngā whakaahua. Ka whakahoki ngā endpoint tatau token i te tau ōrite i mua i tō tuku. Te tatau token

I runga i ngā taumata Shannon, ka tatau te prompt_tokens i ngā mea katoa i pānuitia e te model hei tuhi i te whakautu, nō reira he nui ake i te kuputuhi o ō karere anake.

Streaming

Ina tautuhia te stream ki te true ka tae mai te whakautu hei tuhinga chat.completion.chunk ka mutu me te data: [DONE]. Ka kawe te wāhanga whakamutunga i mua i a ia i te finish_reason me te usage; kāore he stream_options e hiahiatia. He whārangi motuhake tō ngā āhua wāhanga, ngā rārangi keep-alive me ngā hapa i roto i tētahi stream. Rere

Ngā hapa

He JSON object te hapa me tētahi mema error. Ka whakahaerea ngā tirotiro i tēnei raupapa: API key, tinana tono, model id, kātahi te toenga. Ka rārangi te ripanga i ngā mea e hoki mai ana i tēnei endpoint i te nuinga o te wā. He whārangi motuhake tō te rārangi katoa, me ngā mea hei whakamātau anō. Whakahaere hapa

400 JSON
{
  "error": {
    "type": "invalid_request_error",
    "message": "unknown model: no-such-model"
  }
}
Tūnga Momo Karere Āhea
401 authentication_error Missing authentication
Invalid API key
Kāore he API key i tukuna, kāore rānei i te mōhiotia te key, kua whakakorea rānei.
400 invalid_request_error unknown model: <id> Ehara te model i te id kua whakaputaina.
400 invalid_request_error No user message provided Ngā taumata Shannon: kāore he kuputuhi kaiwhakamahi me he tools i te tono.
400 invalid_request_error <id> does not accept image input I tukuna he wāhanga whakaahua ki tētahi model open-weight hosted kāore he input whakaahua.
400 invalid_request_error <id> does not accept response_format I tukuna te response_format ki tētahi model open-weight hosted kāore he output whakatakoto.
400 invalid_request_error unknown reasoning effort '<value>'; expected off, low, medium or high He uara kei te reasoning_effort kei waho i te rārangi.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … Kua ngaro te messages, he hē rānei te momo JSON o tētahi āpure.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan He nui ake te max_tokens i te toenga o tō toenga.
429 rate_limit_error Too many requests. Retry in <n>s. Flood protection: neke atu i te 120 tono i roto i te meneti kotahi i tō pūkete.
500 server_error The model backend failed to answer. Please retry. Kāore te model i hanga whakautu. Tukuna anō te tono.
502 api_error The model backend failed to answer. Please retry. Ōrite tonu, i runga i te whānau Shannon 3 me ngā model open-weight hosted.