Chat Completions
I-POST /v1/chat/completions ithatha incoko kwaye ibuyisa umyalezo olandelayo wemodeli kwifomethi ye-OpenAI Chat Completions. Yisebenzise kuyo nayiphi na i-SDK ye-OpenAI okanye nge-HTTP eqhelekileyo; eli phepha lisalathiso sentsimi ngentsimi.
POST https://api.shannon-ai.com/v1/chat/completions
Isicelo esincinci yi-id yemodeli nomyalezo omnye womsebenzisi.
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) import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com/v1",
});
const response = await client.chat.completions.create({
model: "shannon-3",
messages: [{ role: "user", content: "Say hello in one sentence." }],
});
console.log(response.choices[0].message.content); curl https://api.shannon-ai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "shannon-3",
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}' Impendulo yi-JSON object enye:
{
"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
}
} Ii-header
Ii-header zesicelo
| Header | Ixabiso | Inkcazelo |
|---|---|---|
Authorization | Bearer YOUR_API_KEY | I-API key yakho. I-x-api-key: YOUR_API_KEY iyamkelwa endaweni yayo kuyo yonke i-endpoint. |
Content-Type | application/json | Iyafuneka. Nawuphi na omnye ixabiso ubuyisa i-415. |
x-request-id | Ayinyanzelekanga. I-id yakho yesicelo. Ibuya ingatshintshanga kwimpendulo. |
Ii-header zempendulo
| Header | Inkcazelo |
|---|---|
x-request-id | Kuyo yonke impendulo, kubandakanywa iimpazamo nee-stream: ixabiso olithumeleyo, okanye iinhlobo ezili-12 ze-hexadecimal xa ungathumelanga nanye. Yicaphule xa uxela ingxaki. |
content-type | application/json, okanye text/event-stream xa i-stream yi-true. |
Iintsimi zesicelo
I-messages kuphela efunekayo. Ikholamu ethi Isebenza kwi ibiza iimodeli apho intsimi itshintsha impendulo. Iimodeli ze-open-weight ezisingathiweyo ziii-id ezilishumi elinambini zoluhlu lweemodeli; intsapho yeShannon 3 yi-shannon-3, shannon-3-pro, shannon-3.1 kunye ne-shannon-3.1-pro. Iimodeli namaxabiso
| Intsimi | Uhlobo | Okuqhelekileyo | Inkcazelo | Isebenza kwi |
|---|---|---|---|---|
model | string | shannon-1.6-lite | Imodeli ephendulayo: i-id ekuluhlu lweemodeli. Yithumele kunye nesicelo ngasinye. Ukuthelekisa akuhoyi bukhulu boonobumba. I-id engapapashwanga ibuyisa 400 unknown model. | Zonke iimodeli |
messages | array | Iyafuneka. Incoko, umyalezo omdala kuqala. Jonga Imiyalezo ngezantsi. | Zonke iimodeli | |
stream | boolean | false | I-true ithumela impendulo njengemisitho ethunyelwe yi-server ngoxa ibhalwa. | Zonke iimodeli |
max_tokens | integer | 4096 | Umda ophezulu wempendulo, kwii-token. Ixabiso elingaphandle kwe-1 ukuya kwi-65,536 lisiwa kolo luhlu. Ngumyinge obekelwe bucala kwibhalansi yakho ngoxa isicelo sisaqhubeka. Jonga Ubude be-output ngezantsi. | Iimodeli ze-open-weight ezisingathiweyo, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 |
max_completion_tokens | integer | Ifana ne-max_tokens. Xa zombini zithunyelwe, isetyenziswa i-max_tokens. | Iimodeli ze-open-weight ezisingathiweyo, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | |
temperature | number | Itemperatyhuri yesampling. Kwiimodeli ze-open-weight ezisingathiweyo ixabiso elingagqibekanga li-1 kwaye amaxabiso agcinwa phakathi kwe-0 ne-2. | Iimodeli ze-open-weight ezisingathiweyo, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | |
top_p | number | 0.95 | I-nucleus sampling. Amaxabiso agcinwa phakathi kwe-0 ne-1. | Iimodeli ze-open-weight ezisingathiweyo |
seed | integer | I-seed ye-sampler, nayiphi na inani elipheleleyo. Ngaphandle kwayo, i-seed ithathwa kwimodeli nakwincoko, ngoko isicelo esifanayo esithunyelwe kabini sisebenzisa i-seed efanayo. | Iimodeli ze-open-weight ezisingathiweyo | |
stop | string | array | Intambo yoonobumba okanye uluhlu lweentambo. Zisetyenziswa ukuya kuzi-4. Impendulo iphela phambi kokuqala ebonakalayo; umbhalo wokumisa ngokwawo awubuyiswa. | Iimodeli ze-open-weight ezisingathiweyo | |
reasoning_effort | string | high | Ukuba imodeli iqiqa kangakanani phambi kokuphendula: off, low, medium okanye high. I-none ne-minimal zithetha off, i-default ithetha medium, i-max ithetha high. Nawuphi na omnye ixabiso ubuyisa 400. | Iimodeli ze-open-weight ezisingathiweyo |
reasoning | object | Useto olufanayo ngefom ye-object: {"effort": "low"}. Xa zombini zithunyelwe, isetyenziswa i-reasoning_effort. | Iimodeli ze-open-weight ezisingathiweyo | |
tools | array | Imisebenzi imodeli engayibiza, nganye njenge-{"type": "function", "function": {"name", "description", "parameters"}}. Ubizo lwemodeli lubuya kwi-tool_calls; ikhowudi yakho iyaluqhuba. | Zonke iimodeli | |
tool_choice | string | object | auto | "auto" ivumela imodeli ukuba izikhethele. "required" iyenza ibize i-tool. {"type": "function", "function": {"name": "…"}} iyenza ibize loo tool. | Iimodeli ze-open-weight ezisingathiweyo |
response_format | object | {"type": "json_object"} kwimpendulo ye-JSON, okanye {"type": "json_schema", "json_schema": {…}} kwimpendulo elandela i-schema yakho. | Onke amanqanaba eShannon; iimodeli ze-open-weight ezisingathiweyo njengoko zidweliswe nge-id nganye | |
web_search | boolean | false | I-true ivumela imodeli ukuba ifune kwiwebhu phambi kokuphendula. | shannon-1.6-*, shannon-2-*, intsapho yeShannon 3 |
Ezinye iintsimi ze-OpenAI, ezifana ne-n, user, stream_options, parallel_tool_calls, presence_penalty, frequency_penalty, logit_bias, logprobs, metadata, store kunye ne-prompt_cache_key, ziyamkelwa ukuze ikhowudi ye-client ekhoyo isebenze ngaphandle kotshintsho. Azitshintshi mpendulo: ihlala ikho inketho enye, kwaye i-stream iphela ngokusetyenziswa.
Intsimi enohlobo olungalunganga lwe-JSON, umzekelo "max_tokens": "100", ibuyisa i-422. Isicelo esingenayo i-messages senza okufanayo.
Ii-tool, i-structured output, ukuqiqa nokufuna kwiwebhu nganye inephepha layo: Umsebenzi Ukufowuna, Iziphumo ezicwangcisiweyo, I-effort yokuqiqa, Uphendlo lwewebhu olwakhelwe ngaphakathi.
Isicelo esinezinketho
Esi sicelo sisetha umyalezo we-system, iintsimi zesampling ne-effort yokuqiqa. Sisebenzisa imodeli ye-open-weight esingathiweyo, ezisebenzisa zonke.
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) import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com/v1",
});
const response = await 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",
});
const message = response.choices[0].message;
console.log(message.reasoning_content); // the reasoning
console.log(message.content); // the answer
console.log(response.usage); curl https://api.shannon-ai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"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"
}' Impendulo inemo efanayo nale ingentla. I-usage yayo yongeza iinkcukacha ezimbini kwiimodeli ze-open-weight ezisingathiweyo: ii-prompt token ezifundwe kwi-cache nee-token ezisetyenziswe ekuqiqeni.
{
"usage": {
"prompt_tokens": 31,
"completion_tokens": 62,
"total_tokens": 93,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 21
}
}
} Ubude be-output
I-max_tokens yenza izinto ezimbini. Kuqala, linani lee-token elibekelwe bucala kwibhalansi yakho xa isicelo siqala. Xa impendulo igqityiwe, loo mbeko ithatyathelwa indawo ngee-token isicelo esizisebenzisileyo. Ukuba i-max_tokens inkulu kunokushiyekileyo kwibhalansi yakho, isicelo sibuyisa i-429 Quota exceeded nokuba impendulo ngokwayo ibiya kungena. Thumela i-max_tokens ephantsi ukuze ubeke bucala okuncinci.
I-shannon-coder-1 ibalwa ngokwahlukileyo kule endpoint: isicelo ngasinye siyyenye yobizo lweShannon Coder lweplani yakho, kwaye akukho ii-token zibekelwa bucala. Imida nebhalansi
Okwesibini, ikhawulela ubude bempendulo kwezi modeli:
| Iimodeli | Oko i-max_tokens ikwenzayo |
|---|---|
shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | Impendulo iyayeka xa ifikelela kumda. I-stream iphela ngelo xesha nge-finish_reason length. |
| Iimodeli ze-open-weight ezisingathiweyo | Umbhalo wempendulo uyayeka kwi-max_tokens. Ukuqiqa akubalwa kuyo. Amaxabiso angaphantsi kwe-256 asebenza njenge-256. |
Ngaphandle kwe-max_tokens okanye i-max_completion_tokens, ixabiso li-4,096. Kwi-shannon-coder-1 li-65,536.
Imiyalezo
Umyalezo ngamnye yi-object ene-role ne-content. I-content yintambo yoonobumba, okanye uluhlu lweendawo xa umyalezo uthwele okungaphezu kombhalo.
| Iroli | Inkcazelo | Isebenza kwi |
|---|---|---|
system | Imiyalelo yemodeli. Yibeke kuqala. Kumanqanaba eShannon umyalezo wokuqala we-system ngowo osetyenziswayo. | Iimodeli ze-open-weight ezisingathiweyo, shannon-1.6-*, shannon-2-*, shannon-coder-1 |
developer | Ifundwa njenge-system. | Iimodeli ze-open-weight ezisingathiweyo |
user | Oko ukubuzayo. Kumanqanaba eShannon umyalezo wokugqibela we-user yi-prompt kwaye imiyalezo ephambi kwawo yimbali. | Zonke iimodeli |
assistant | Iimpendulo zangaphambili zemodeli. Gcina i-tool_calls yayo xa uthumela umphumo we-tool emva kwayo. | Zonke iimodeli |
tool | Umphumo wobizo lwe-tool: i-tool_call_id ibamba i-id yobizo kwaye i-content ibamba umphumo njengentambo yoonobumba. | Zonke iimodeli |
Ngokusebenzisa i-id yentsapho yeShannon 3, faka imiyalelo ekufuneka ihlale ikhona kumyalezo we-user.
Kumanqanaba eShannon isicelo esingenambhalo womsebenzisi ne-tools sibuyisa i-400 No user message provided.
Iindawo zomxholo
| Inxalenye | Inkcazelo | Iyafumaneka kwi |
|---|---|---|
{"type": "text", "text": "…"} | Umbhalo oqhelekileyo. | Zonke iimodeli |
{"type": "image_url", "image_url": {"url": "…"}} | Umfanekiso, njenge-URL ye-data: enomxholo we-base64 okanye njenge-URL ye-http(s). | Intsapho yeShannon 3, shannon-1.6-lite, shannon-1.6-pro, neemodeli ze-open-weight ezisingathiweyo ezidwelisa i-image input |
{"type": "file", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} | Uxwebhu (PDF, Word, PowerPoint okanye Excel), njenge-base64 okanye nge-URL. | Intsapho yeShannon 3 |
Ubungakanani, imida noluhlu olupheleleyo lweefom zinephepha lazo. Imifanekiso neefayile
I-object yempendulo
| Intsimi | Uhlobo | Inkcazelo |
|---|---|---|
id | string | chatcmpl- ilandelwa ziinhlobo ezingama-32 ze-hexadecimal. |
object | string | Ihlala i-chat.completion. |
created | integer | Ixesha lempendulo, kwimizuzwana ye-Unix. |
model | string | I-id eyiyo yemodeli ephendulileyo. Inokwahluka ngokubhalwa kwi-id oyithumeleyo. |
choices | array | Ihlala inketho enye kanye, ene-index 0. |
choices[0].message.role | string | Ihlala i-assistant. |
choices[0].message.content | string | null | Umbhalo wempendulo. Nge-tool_calls yi-null kumanqanaba eShannon; iimodeli ze-open-weight ezisingathiweyo zinokuthumela umbhalo ecaleni kobizo. |
choices[0].message.reasoning_content | string | null | Ukuqiqa imodeli eqibhale phambi kwempendulo, okanye i-null xa kungekho. |
choices[0].message.tool_calls | array | Ikhona kuphela xa imodeli ibiza ii-tool. Into nganye ine-id, i-type function, kunye ne-function ene-name ne-arguments njengentambo ye-JSON. |
choices[0].message.annotations | array | Kuphela kwisicelo esine-web_search: true esikhangelo salo sifumene into. I-url_citation enye kumthombo ngamnye obhekiselwa kuwo uphawu kwi-content, kunye ne-url, i-title, i-start_index ne-end_index (indawo yophawu, ebalwa ngoonobumba, isiphelo asibandakanywa). |
choices[0].finish_reason | string | Isizathu sokuphela kwempendulo. Jonga Izizathu zokuphela. |
usage | object | Ii-token zesicelo. Jonga Ukusetyenziswa. |
sources | array | Kuphela kwisicelo esine-web_search: true esikhangelo salo sifumene into: iziphumo ezinikwe imodeli, nganye kunye ne-index, i-title kunye ne-url. I-[1] kwimpendulo yiyo into ene-index 1. |
Izizathu zokuphela
| finish_reason | Inkcazelo |
|---|---|
stop | Imodeli iyigqibile impendulo yayo, okanye intambo ye-stop ivele. |
tool_calls | Imodeli ibiza i-tool enye okanye ngaphezulu. Ziqhube uze uthumele iziphumo kwimiyalezo ye-tool. |
length | Impendulo inqunyulwe kumda we-output. Ixelwa kwii-stream ze-shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 nentsapho yeShannon 3. |
Impendulo engekho kwi-stream ixela i-stop okanye i-tool_calls.
Ukusetyenziswa
| Intsimi | Uhlobo | Inkcazelo | Iyafumaneka kwi |
|---|---|---|---|
usage.prompt_tokens | integer | Ii-input token. | Zonke iimodeli |
usage.completion_tokens | integer | Ii-output token: ukuqiqa, impendulo nobizo lwee-tool zidibene. | Zonke iimodeli |
usage.total_tokens | integer | I-prompt_tokens kunye ne-completion_tokens. | Zonke iimodeli |
usage.prompt_tokens_details.cached_tokens | integer | Inxalenye ye-prompt_tokens efundwe kwi-prompt cache. | Iimodeli ze-open-weight ezisingathiweyo |
usage.completion_tokens_details.reasoning_tokens | integer | Inxalenye ye-completion_tokens esetyenziswe ekuqiqeni. | Iimodeli ze-open-weight ezisingathiweyo |
Kwiimodeli ze-open-weight ezisingathiweyo, i-prompt_tokens yimiyalezo yakho nenkcazo zee-tool ezibalwe nge-tokenizer yemodeli ngokwayo, kunye nee-token zemifanekiso. Ii-endpoint zokubala ii-token zibuyisa inani elifanayo phambi kokuba uthumele. Ukubala ii-token
Kumanqanaba eShannon, i-prompt_tokens ibala yonke into imodeli eyifundileyo ukuze ibhale impendulo, ngoko inkulu kunombhalo wemiyalezo yakho kuphela.
I-Streaming
Xa i-stream isetwe ku-true impendulo ifika njengeziganeko ze-chat.completion.chunk kwaye iphela nge-data: [DONE]. I-chunk yokugqibela phambi kwayo ithwala i-finish_reason ne-usage; akukho ntsimi ye-stream_options efunekayo. Iimo ze-chunk, imigca ye-keep-alive neempazamo ngaphakathi kwe-stream zinephepha lazo. Umsinga
Iimpazamo
Impazamo yi-JSON object enelungu le-error. Ukuhlolwa kuqhutywa ngolu landelelwano: i-API key, umzimba wesicelo, i-id yemodeli, emva koko ibhalansi. Itheyibhile idwelisa oko le endpoint ikubuyisa rhoqo. Uluhlu olupheleleyo, kunye nezinto ekufuneka uzame kwakhona, lunephepha lalo. Ukuphatha imposiso
{
"error": {
"type": "invalid_request_error",
"message": "unknown model: no-such-model"
}
} | Isimo | Uhlobo | Umyalezo | Xa |
|---|---|---|---|
401 | authentication_error | Missing authenticationInvalid API key | Akukho API key ithunyelweyo, okanye isitshixo asaziwa okanye sirhoxisiwe. |
400 | invalid_request_error | unknown model: <id> | I-model ayiyiyo i-id epapashiweyo. |
400 | invalid_request_error | No user message provided | Amanqanaba eShannon: isicelo asinambhalo womsebenzisi kwaye asinayo i-tools. |
400 | invalid_request_error | <id> does not accept image input | Inxalenye yomfanekiso ithunyelwe kwimodeli ye-open-weight esingathiweyo engenayo i-image input. |
400 | invalid_request_error | <id> does not accept response_format | I-response_format ithunyelwe kwimodeli ye-open-weight esingathiweyo engenayo i-structured output. |
400 | invalid_request_error | unknown reasoning effort '<value>'; expected off, low, medium or high | I-reasoning_effort ibamba ixabiso elingaphandle koluhlu. |
422 | invalid_request_error | Failed to deserialize the JSON body into the target type: … | I-messages ilahlekile, okanye intsimi inohlobo olungalunganga lwe-JSON. |
429 | rate_limit_error | Quota exceeded. Upgrade your plan at shannon-ai.com/plan | I-max_tokens inkulu kunokushiyekileyo kwibhalansi yakho. |
429 | rate_limit_error | Too many requests. Retry in <n>s. | I-flood protection: izicelo ezingaphezu kwe-120 kumzuzu omnye kwiakhawunti yakho. |
500 | server_error | The model backend failed to answer. Please retry. | Imodeli ayivelisanga mpendulo. Thumela isicelo kwakhona. |
502 | api_error | The model backend failed to answer. Please retry. | Okufanayo, kwintsapho yeShannon 3 nakwiimodeli ze-open-weight ezisingathiweyo. |