Chat Completions
POST /v1/chat/completions e amohela moqoqo mme e khutlisa molaetsa o latelang oa model ka sebopeho sa OpenAI Chat Completions. E sebelise ho SDK efe kapa efe ea OpenAI kapa ka HTTP e hlakileng; leqephe lena ke tšupiso ea field ka field.
POST https://api.shannon-ai.com/v1/chat/completions
Kopo e nyane ka ho fetisisa ke id ea model le molaetsa o le mong oa user.
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."}]
}' Karabo ke ntho e le 'ngoe ea 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
}
} Li-header
Li-header tsa kopo
| Header | Boleng | Tlhaloso |
|---|---|---|
Authorization | Bearer YOUR_API_KEY | Senotlolo sa hau sa API. x-api-key: YOUR_API_KEY e amohelwa sebakeng sa sona ho endpoint e 'ngoe le e 'ngoe. |
Content-Type | application/json | E hlokahala. Boleng bo bong bofe bo khutlisa 415. |
x-request-id | Ha e hlokahale. Id ea hau ea kopo. E khutla e sa fetohang karabong. |
Li-header tsa karabo
| Header | Tlhaloso |
|---|---|
x-request-id | Ho karabo e 'ngoe le e 'ngoe, ho kenyelletsa liphoso le li-stream: boleng boo u bo romelitseng, kapa litlhaku tse 12 tsa hexadecimal ha u sa romele letho. E qotse ha u tlaleha bothata. |
content-type | application/json, kapa text/event-stream ha stream e le true. |
Li-field tsa kopo
messages feela e hlokahala. Kholomo ea E sebelisoa ke e reha li-model tseo field e fetolang karabo ho tsona. Li-model tse hosted tsa open-weight ke li-id tse leshome le metso e 'meli tsa lenane la li-model; lelapa la Shannon 3 ke shannon-3, shannon-3-pro, shannon-3.1 le shannon-3.1-pro. Li-model le litheko
| Field | Mofuta | Default | Tlhaloso | E sebelisoa ke |
|---|---|---|---|---|
model | string | shannon-1.6-lite | Model e arabang: id ho tsoa lenaneng la li-model. E romele ho kopo e 'ngoe le e 'ngoe. Ho lekanya ha ho tsotelle litlhaku tse kholo le tse nyane. Id e sa phatlalalitsoang e khutlisa 400 unknown model. | Li-model tsohle |
messages | array | E hlokahala. Moqoqo, molaetsa o moholo ka ho fetisisa pele. Bona Messages ka tlase. | Li-model tsohle | |
stream | boolean | false | true e romela karabo e le server-sent events ha e ntse e ngoloa. | Li-model tsohle |
max_tokens | integer | 4096 | Moeli o phahameng oa karabo, ka tokens. Boleng bo kantle ho 1 ho isa ho 65,536 bo fetoleloa ka har'a moeli oo. Ke hape palo e behelloang thoko ho balance ea hau ha kopo e ntse e sebetsa. Bona Output length ka tlase. | Li-model tse hosted tsa open-weight, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 |
max_completion_tokens | integer | E tšoana le max_tokens. Ha tsena ka bobeli li romeloa, max_tokens e a sebelisoa. | Li-model tse hosted tsa open-weight, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | |
temperature | number | Sampling temperature. Ho li-model tse hosted tsa open-weight default ke 1 mme litekanyo li bolokoa pakeng tsa 0 le 2. | Li-model tse hosted tsa open-weight, shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | |
top_p | number | 0.95 | Nucleus sampling. Litekanyo li bolokoa pakeng tsa 0 le 1. | Li-model tse hosted tsa open-weight |
seed | integer | Seed ea sampler, palo efe kapa efe e feletseng. Ntle le eona, seed e tsoa ho model le moqoqo, kahoo kopo e tšoanang e romeloang habeli e sebelisa seed e tšoanang. | Li-model tse hosted tsa open-weight | |
stop | string | array | String kapa array ea li-string. Ho fihlela ho tse 4 lia sebelisoa. Karabo e fela pele ho ea pele e hlahang; mongolo oa stop ka boeona ha o khutlisoe. | Li-model tse hosted tsa open-weight | |
reasoning_effort | string | high | Hore na model e nahana hakae pele e araba: off, low, medium kapa high. none le minimal li bolela off, default e bolela medium, max e bolela high. Boleng bo bong bofe bo khutlisa 400. | Li-model tse hosted tsa open-weight |
reasoning | object | Setting e tšoanang ka sebopeho sa ntho: {"effort": "low"}. Ha tsena ka bobeli li romeloa, reasoning_effort e a sebelisoa. | Li-model tse hosted tsa open-weight | |
tools | array | Li-function tseo model e ka li bitsang, e 'ngoe le e 'ngoe e le {"type": "function", "function": {"name", "description", "parameters"}}. Likopo tsa model li khutla ho tool_calls; code ea hau e li etsa. | Li-model tsohle | |
tool_choice | string | object | auto | "auto" e lumella model hore e iketsetse qeto. "required" e e qobella ho bitsa tool. {"type": "function", "function": {"name": "…"}} e e qobella ho bitsa tool eo. | Li-model tse hosted tsa open-weight |
response_format | object | {"type": "json_object"} bakeng sa karabo ea JSON, kapa {"type": "json_schema", "json_schema": {…}} bakeng sa karabo e latelang schema ea hau. | Li-tier tsohle tsa Shannon; li-model tse hosted tsa open-weight joalo ka ha li thathamisitsoe ka id | |
web_search | boolean | false | true e lumella model hore e batle webeng pele e araba. | shannon-1.6-*, shannon-2-*, lelapa la Shannon 3 |
Li-field tse ling tsa OpenAI, tse kang n, user, stream_options, parallel_tool_calls, presence_penalty, frequency_penalty, logit_bias, logprobs, metadata, store le prompt_cache_key, lia amohelwa e le hore code ea moreki e teng e sebetse ntle le phetoho. Ha li fetole karabo: kamehla ho na le choice e le 'ngoe, mme stream e lula e fela ka usage.
Field e nang le mofuta o fosahetseng oa JSON, mohlala "max_tokens": "100", e khutlisa 422. Kopo e se nang messages le eona e joalo.
Tools, structured output, reasoning le web search e 'ngoe le e 'ngoe e na le leqephe la eona: Mekhosi ya mesebetsi, Diphumo tse hlophisitsoeng, Effort ea reasoning, Patlo ya webe.
Kopo e nang le likhetho
Kopo ena e beha molaetsa oa system, li-field tsa sampling le reasoning effort. E sebelisa model e hosted ea open-weight, e sebelisang tsohle.
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"
}' Karabo e na le sebopeho se tšoanang le se ka holimo. usage ea eona e eketsa lintlha tse peli ho li-model tse hosted tsa open-weight: prompt tokens tse baloang ho cache le tokens tse sebelisitsoeng ho reasoning.
{
"usage": {
"prompt_tokens": 31,
"completion_tokens": 62,
"total_tokens": 93,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 21
}
}
} Bolelele ba output
max_tokens e etsa lintho tse peli. Ea pele, ke palo ea tokens e behelloang thoko ho balance ea hau ha kopo e qala. Ha karabo e phethahetse, palo eo e nkeloa sebaka ke tokens tseo kopo e li sebelisitseng. Haeba max_tokens e kholo ho feta se setseng ho balance ea hau, kopo e khutlisa 429 Quota exceeded esita le ha karabo ka boeona e ne e tla lekana. Romela max_tokens e tlase ho beha thoko tse fokolang.
shannon-coder-1 e baloa ka tsela e fapaneng endpoint-ng ena: kopo e 'ngoe le e 'ngoe ke e 'ngoe ea likopo tsa Shannon Coder tsa plan ea hau, mme ha ho tokens tse behelloang thoko bakeng sa eona. Meeli le balance
Ea bobeli, e fokotsa bolelele ba karabo ho li-model tsena:
| Li-model | Seo max_tokens e se etsang |
|---|---|
shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 | Karabo e emisa ha e fihla moeling. Stream e ntan e fela ka finish_reason length. |
| Li-model tse hosted tsa open-weight | Mongolo oa karabo o emisa ho max_tokens. Reasoning ha e baloe ho eona. Litekanyo tse ka tlase ho 256 li sebetsa e le 256. |
Ntle le max_tokens kapa max_completion_tokens, boleng ke 4,096. Ho shannon-coder-1 ke 65,536.
Melaetsa
Molaetsa o mong le o mong ke ntho e nang le role le content. content ke string, kapa array ea likarolo ha molaetsa o nka ho feta mongolo.
| Role | Tlhaloso | E sebelisoa ke |
|---|---|---|
system | Litaelo tsa model. E behe pele. Ho li-tier tsa Shannon molaetsa oa pele oa system ke oo o sebelisoang. | Li-model tse hosted tsa open-weight, shannon-1.6-*, shannon-2-*, shannon-coder-1 |
developer | E baloa e le system. | Li-model tse hosted tsa open-weight |
user | Seo u se botsang. Ho li-tier tsa Shannon molaetsa oa ho qetela oa user ke prompt mme melaetsa e fetileng ke history. | Li-model tsohle |
assistant | Likarabo tse fetileng tsa model. Boloka tool_calls ea eona ha u romela sephetho sa tool ka mor'a eona. | Li-model tsohle |
tool | Sephetho sa kopo ea tool: tool_call_id e na le id ea kopo mme content e na le sephetho e le string. | Li-model tsohle |
Ka id ea lelapa la Shannon 3, kenya litaelo tse lokelang ho latelloa molaetsa oa user.
Ho li-tier tsa Shannon kopo e se nang mongolo oa user kapa tools e khutlisa 400 No user message provided.
Likarolo tsa litaba
| Karolo | Tlhaloso | E fumaneha ho |
|---|---|---|
{"type": "text", "text": "…"} | Mongolo o hlakileng. | Li-model tsohle |
{"type": "image_url", "image_url": {"url": "…"}} | Setšoantšo, e le URL ea data: e nang le litaba tsa base64 kapa e le URL ea http(s). | Lelapa la Shannon 3, shannon-1.6-lite, shannon-1.6-pro, le li-model tse hosted tsa open-weight tse ngotsoeng input ea setšoantšo |
{"type": "file", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} | Tokomane (PDF, Word, PowerPoint kapa Excel), e le base64 kapa ka URL. | Lelapa la Shannon 3 |
Boholo, meeli le lenane le felletseng la mebopeho li na le leqephe la tsona. Litšoantšo le lifaele
Ntho ea karabo
| Field | Mofuta | Tlhaloso |
|---|---|---|
id | string | chatcmpl- e latelwa ke litlhaku tse 32 tsa hexadecimal. |
object | string | Kamehla ke chat.completion. |
created | integer | Nako ea karabo, ka metsotsoana ea Unix. |
model | string | Id ea canonical ea model e arabileng. E ka fapana ka mongolo le id eo u e rometseng. |
choices | array | Kamehla ke choice e le 'ngoe feela, e nang le index 0. |
choices[0].message.role | string | Kamehla ke assistant. |
choices[0].message.content | string | null | Mongolo oa karabo. Ka tool_calls ke null ho li-tier tsa Shannon; li-model tse hosted tsa open-weight li ka romela mongolo haufi le likopo. |
choices[0].message.reasoning_content | string | null | Reasoning eo model e e ngotseng pele ho karabo, kapa null ha ho e 'ngoe. |
choices[0].message.tool_calls | array | E teng feela ha model e bitsa tools. Entry e 'ngoe le e 'ngoe e na le id, type function, le function e nang le name le arguments e le string ea JSON. |
choices[0].message.annotations | array | Feela ho kopo e nang le web_search: true eo patlo ea eona e fumaneng eng kapa eng. url_citation e le 'ngoe bakeng sa mohloli o mong le o mong oo letšoao ho content le o rehang, e nang le url, title, start_index le end_index (sebaka sa letšoao, se balehiloeng ka litlhaku, qetello ha e kenyelletsoe). |
choices[0].finish_reason | string | Hobaneng karabo e felile. Bona Mabaka a ho fela. |
usage | object | Tokens tsa kopo. Bona Usage. |
sources | array | Feela ho kopo e nang le web_search: true eo patlo ea eona e fumaneng eng kapa eng: liphetho tseo model e li file, e 'ngoe le e 'ngoe e na le index, title le url. [1] karabong ke entry e nang le index 1. |
Mabaka a ho fela
| finish_reason | Tlhaloso |
|---|---|
stop | Model e qetile karabo ea eona, kapa string ea stop e hlahile. |
tool_calls | Model e bitsa tool e le 'ngoe kapa tse ngata. Li etse mme u romele liphetho melaetsa ea tool. |
length | Karabo e khaoloe moeling oa output. E tlalehoa ho li-stream tsa shannon-1.6-lite, shannon-1.6-pro, shannon-coder-1 le lelapa la Shannon 3. |
Karabo e se nang streaming e tlaleha stop kapa tool_calls.
Usage
| Field | Mofuta | Tlhaloso | E fumaneha ho |
|---|---|---|---|
usage.prompt_tokens | integer | Input tokens. | Li-model tsohle |
usage.completion_tokens | integer | Output tokens: reasoning, karabo le likopo tsa tool hammoho. | Li-model tsohle |
usage.total_tokens | integer | prompt_tokens hammoho le completion_tokens. | Li-model tsohle |
usage.prompt_tokens_details.cached_tokens | integer | Karolo ea prompt_tokens e baloang ho prompt cache. | Li-model tse hosted tsa open-weight |
usage.completion_tokens_details.reasoning_tokens | integer | Karolo ea completion_tokens e sebelisitsoeng ho reasoning. | Li-model tse hosted tsa open-weight |
Ho li-model tse hosted tsa open-weight, prompt_tokens ke melaetsa ea hau le litlhaloso tsa tool tse baloang ka tokenizer ea model ka boeona, hammoho le tokens tsa litšoantšo leha e le life. Li-endpoint tsa ho bala tokens li khutlisa palo e tšoanang pele u romela. Ho bala tokens
Ho li-tier tsa Shannon, prompt_tokens e bala tsohle tseo model e li balileng ho ngola karabo, kahoo e kholo ho feta mongolo oa melaetsa ea hau feela.
Streaming
Ha stream e behiloe ho true karabo e fihla e le li-event tsa chat.completion.chunk mme e fela ka data: [DONE]. Chunk ea ho qetela pele ho eona e nka finish_reason le usage; ha ho hlokahale stream_options. Mebopeho ea li-chunk, mela ea keep-alive le liphoso ka hare ho stream li na le leqephe la tsona. Phallela
Liphoso
Phoso ke ntho ea JSON e nang le setho sa error. Liphatlalatso li etsoa ka tatellano ena: senotlolo sa API, body ea kopo, id ea model, ebe balance. Tafole e thathamisa seo endpoint ena e se khutlisang hangata. Lenane le felletseng, le se ka lekoang hape, le na le leqephe la lona. Diphoso
{
"error": {
"type": "invalid_request_error",
"message": "unknown model: no-such-model"
}
} | Boemo | Mofuta | Molaetsa | Neng |
|---|---|---|---|
401 | authentication_error | Missing authenticationInvalid API key | Ha ho senotlolo sa API se rometsoeng, kapa senotlolo ha se tsejoe kapa se hlakotsoe. |
400 | invalid_request_error | unknown model: <id> | model hase id e phatlalalitsoeng. |
400 | invalid_request_error | No user message provided | Li-tier tsa Shannon: kopo ha e na mongolo oa user kapa tools. |
400 | invalid_request_error | <id> does not accept image input | Karolo ea setšoantšo e rometsoe ho model e hosted ea open-weight e se nang input ea setšoantšo. |
400 | invalid_request_error | <id> does not accept response_format | response_format e rometsoe ho model e hosted ea open-weight e se nang structured output. |
400 | invalid_request_error | unknown reasoning effort '<value>'; expected off, low, medium or high | reasoning_effort e na le boleng bo kantle ho lenane. |
422 | invalid_request_error | Failed to deserialize the JSON body into the target type: … | messages ha e eo, kapa field e na le mofuta o fosahetseng oa JSON. |
429 | rate_limit_error | Quota exceeded. Upgrade your plan at shannon-ai.com/plan | max_tokens e kholo ho feta se setseng ho balance ea hau. |
429 | rate_limit_error | Too many requests. Retry in <n>s. | Flood protection: likopo tse fetang 120 ka motsotso o le mong ho akhaonte ea hau. |
500 | server_error | The model backend failed to answer. Please retry. | Model ha ea ka ea hlahisa karabo. Romela kopo hape. |
502 | api_error | The model backend failed to answer. Please retry. | Ho tšoana, ho lelapa la Shannon 3 le li-model tse hosted tsa open-weight. |