Ruka hadi kwenye maudhui
Responses API

Responses API

Mpya

POST /v1/responses inapokea instructions na orodha ya input items na kurudisha kitu cha response kilichoundwa na output items, kwa umbizo la OpenAI Responses. Itumie na responses API ya SDK ya OpenAI na tools zilizojengwa juu yake, kama Codex CLI. Endpoint haihifadhi hali: tuma mazungumzo yote kwa kila ombi.

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

Ombi dogo zaidi ni model id na maandishi. Jibu halina stream usipoliomba.

from openai import OpenAI

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

response = client.responses.create(
    model="shannon-3",
    input="Say hello in one sentence.",
)

print(response.output_text)

Jibu ni kitu cha response. output yake ina reasoning, model ilipofikiri, na ujumbe:

200 JSON
{
  "id": "resp_5f0c1e7a9b3d4c62a8e1f07d2b46c9a3",
  "object": "response",
  "created_at": 1791625200,
  "model": "shannon-3",
  "status": "completed",
  "error": null,
  "incomplete_details": null,
  "instructions": null,
  "metadata": {},
  "parallel_tool_calls": true,
  "temperature": null,
  "tool_choice": "auto",
  "tools": [],
  "top_p": null,
  "output": [
    {
      "id": "rs_8a2e6c1f4b7d4e03b9c5a1d70f3e2b64",
      "type": "reasoning",
      "summary": [
        {
          "type": "summary_text",
          "text": "The user wants a greeting in one sentence. Keep it short and friendly."
        }
      ]
    },
    {
      "id": "msg_1c7b9e3a5d2f4a86b0e4c8d19a6f7e25",
      "type": "message",
      "role": "assistant",
      "status": "completed",
      "content": [
        {
          "type": "output_text",
          "text": "Hello, it is good to meet you.",
          "annotations": []
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 1184,
    "output_tokens": 46,
    "total_tokens": 1230
  }
}

Fields za ombi

model na input ndivyo ombi linahitaji. Safu ya Inatumiwa na inataja model ambazo field inabadilisha jibu juu yake. Model za open-weight zinazopangishwa ni id kumi na mbili za orodha ya model; familia ya Shannon 3 ni shannon-3, shannon-3-pro, shannon-3.1 na shannon-3.1-pro. Model na bei

Field Aina Chaguo-msingi Maelezo Inatumiwa na
model string Inahitajika. Id kutoka kwenye orodha ya model. Ulinganishaji hauangalii herufi kubwa na ndogo. Id iliyokosekana au isiyochapishwa hurudisha 400 unknown model. Model zote
input string | array String, inayosomwa kama ujumbe mmoja wa user, au array ya input items. Tazama Input items hapa chini. Model zote
instructions string Maagizo kwa model, system prompt ya umbizo hili. Model za open-weight zinazopangishwa, shannon-1.6-*, shannon-2-*, shannon-coder-1
stream boolean false true hutuma jibu kama server-sent events. Tazama Streaming hapa chini. Model zote
max_output_tokens integer 4096 Kikomo cha juu cha jibu, kwa tokens. Thamani iliyo nje ya 1 hadi 65,536 huhamishiwa ndani ya masafa hayo. Pia ni kiasi kinachotengwa kutoka kwenye salio lako wakati ombi linaendelea. Tazama Kikomo cha output hapa chini. Model za open-weight zinazopangishwa, shannon-1.6-*, shannon-2-*, shannon-coder-1
temperature number Sampling temperature. Kwenye model za open-weight zinazopangishwa thamani huwekwa kati ya 0 na 2. Model za open-weight zinazopangishwa; shannon-1.6-*, shannon-2-* na shannon-coder-1 kwenye majibu yasiyo ya stream
top_p number Nucleus sampling. Thamani huwekwa kati ya 0 na 1. Model za open-weight zinazopangishwa
tools array Functions ambazo model inaweza kuita, kwa umbo bapa la umbizo hili: {"type": "function", "name", "description", "parameters"}. Tazama Tools hapa chini. Model zote
tool_choice string | object auto "auto" huiacha model iamue. "required" huifanya iite tool. {"type": "function", "name": "…"} huifanya iite tool hiyo. Model za open-weight zinazopangishwa
reasoning object {"effort": "…"} na off, low, medium au high. Thamani nyingine yoyote hurudisha 400. Model za open-weight zinazopangishwa
text object {"format": {…}} huomba jibu la JSON. Tazama Matokeo yaliyopangwa hapa chini. Viwango vyote vya Shannon; model za open-weight zinazopangishwa kama zilivyoorodheshwa kwa kila id

previous_response_id, store, metadata, parallel_tool_calls, truncation, include, user na prompt_cache_key zinakubaliwa ili code ya client iliyopo ifanye kazi bila mabadiliko. Hazibadilishi jibu. Kwa sababu hakuna mazungumzo yanayohifadhiwa, ombi linalofuata hubeba zamu za awali kwenye input.

Input items

Input item ni ujumbe, wenye role na content, au item yenye aina inayobeba wito wa tool au matokeo yake. content ni string au array ya sehemu.

Item Maelezo Inatumiwa na
{"role": "user", "content": …} Unachouliza. content ni string, au sehemu za input_text na input_image. Model zote
{"role": "assistant", "content": …} Jibu la awali la model. content ni string, au sehemu za output_text. Model zote
{"role": "system", "content": …}
{"role": "developer", "content": …}
Maagizo ndani ya mazungumzo. Model za open-weight zinazopangishwa
{"type": "function_call", "call_id": "…", "name": "…", "arguments": "…"} Wito wa tool ambao model ilifanya kwenye jibu la awali. arguments ni JSON string. Model zote
{"type": "function_call_output", "call_id": "…", "output": "…"} Matokeo ya wito huo. call_id ni id ya wito na output ni matokeo kama string. Model zote

Weka maagizo kwenye field ya instructions. Ukiwa na id ya familia ya Shannon 3, weka maagizo yanayopaswa kushikilia kwenye ujumbe wa user.

Items za output ya jibu zinaweza kurudi kwenye input kama zilivyo: items za message na function_call husomwa, items za reasoning huruka.

Sehemu za maudhui

Sehemu Maelezo Inapatikana kwenye
{"type": "input_text", "text": "…"} Maandishi ya ujumbe wa user. Model zote
{"type": "output_text", "text": "…"} Maandishi ya ujumbe wa assistant. Model zote
{"type": "input_image", "image_url": "…"} Picha, kama URL ya data: yenye maudhui ya base64 au kama URL ya http(s). Familia ya Shannon 3, shannon-1.6-lite, shannon-1.6-pro, na model za open-weight zinazopangishwa zinazoorodhesha input ya picha
{"type": "input_file", "file_data": "data:application/pdf;base64,…"} Hati (PDF, Word, PowerPoint au Excel): file_data ina URL ya data:, au file_url ina URL ya http(s). Familia ya Shannon 3

Kwenye viwango vya Shannon picha na mafaili husomwa kutoka kwenye item ya mwisho ya user ya input. Ukubwa na mipaka vina ukurasa wake. Picha na mafaili

Ombi lenye instructions na options

Ombi hili linatuma instructions, mazungumzo kama input items, kikomo cha output, temperature na reasoning effort. Linatumia model ya open-weight inayopangishwa, ambayo huzitumia zote.

from openai import OpenAI

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

response = client.responses.create(
    model="DeepSeek-V4-Flash-0731-W4A16-AUTOROUND-REAP",
    instructions="You are a physics teacher. Answer in two sentences.",
    input=[
        {"role": "user", "content": "Why is the sky blue?"},
        {"role": "assistant", "content": "Air scatters blue light more than red light."},
        {"role": "user", "content": "And why are sunsets red?"},
    ],
    max_output_tokens=512,
    temperature=0.3,
    reasoning={"effort": "low"},
)

for item in response.output:
    if item.type == "reasoning":
        print("reasoning:", item.summary[0].text)
    elif item.type == "message":
        print("answer:", item.content[0].text)
print(response.usage)

Jibu la model ya open-weight inayopangishwa lina id, object, model, created_at, status, output na usage. usage yake huongeza tokens zilizosomwa kutoka cache na tokens zilizotumika kwa reasoning:

200 JSON
{
  "usage": {
    "input_tokens": 58,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens": 67,
    "output_tokens_details": {
      "reasoning_tokens": 19
    },
    "total_tokens": 125
  }
}

Kitu cha response

id, object, status, output na usage ziko kwenye kila jibu. Jenga code yako juu ya hizo.

Field Aina Maelezo Hutumwa na
id string resp_ ikifuatiwa na herufi 32 za hexadecimal. Model zote
object string Daima response. Model zote
status string completed. Kwenye stream kwanza ni in_progress, na failed kwenye tukio la response.failed. Model zote
output array Output items kwa mpangilio model ilivyozizalisha: reasoning, message, function_call. Model zote
usage object input_tokens, output_tokens na total_tokens. Model zote
usage.input_tokens_details object cached_tokens: tokens za input zilizosomwa kutoka prompt cache. Model za open-weight zinazopangishwa
usage.output_tokens_details object reasoning_tokens: tokens za output zilizotumika kwa reasoning. Model za open-weight zinazopangishwa
model string Id rasmi ya model iliyojibu. Familia ya Shannon 3, model za open-weight zinazopangishwa
created_at integer Wakati wa jibu, kwa sekunde za Unix. Familia ya Shannon 3, model za open-weight zinazopangishwa
instructions, tools, temperature, … instructions, tools na temperature hurudia ombi. error na incomplete_details ni null, metadata ni {}, parallel_tool_calls ni true, tool_choice ni auto na top_p ni null. Familia ya Shannon 3

Output items

Item Maelezo
{"id": "rs_…", "type": "reasoning", "summary": [{"type": "summary_text", "text": "…"}]} Reasoning ya model kama sehemu moja ya summary_text. Ipo tu wakati model ilifikiri.
{"id": "msg_…", "type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "…"}]} Jibu: sehemu moja ya output_text yenye maandishi.
{"id": "fc_…", "type": "function_call", "call_id": "call_…", "name": "…", "arguments": "…"} Wito wa tool. arguments ni JSON string. Tuma matokeo nyuma kwa call_id ile ile.

SDK za OpenAI huunganisha maandishi ya ujumbe kwa ajili yako kwenye response.output_text.

Streaming

Weka stream kuwa true kupata server-sent events. Kila frame ina mstari wa event: wenye jina la tukio na mstari wa data: wenye kitu cha JSON; kitu hurudia jina kwenye type. Linganisha deltas na item yake kwa output_index.

Ukiwa na SDK ya OpenAI, soma matukio kwa type yake:

from openai import OpenAI

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

stream = client.responses.create(
    model="shannon-3",
    input="Explain server-sent events in three sentences.",
    stream=True,
)

for event in stream:
    kind = getattr(event, "type", "error")     # an event without a type is an error event
    if kind == "response.reasoning_summary_text.delta":
        pass                                   # a piece of reasoning: event.delta
    elif kind == "response.output_text.delta":
        print(event.delta, end="", flush=True)
    elif kind == "response.output_item.done" and event.item.type == "function_call":
        print("\ntool call:", event.item.name, event.item.arguments)
    elif kind == "response.completed":
        print("\n", event.response.usage)
    elif kind in ("response.failed", "error"):
        raise RuntimeError("the stream failed, send the request again")

Matukio hufika kwa mpangilio huu. Makundi ya reasoning, ujumbe na wito wa tools yanaonekana tu jibu likiwa nayo.

Tukio Payload Lini
response.created response Daima ya kwanza. response.status ni in_progress na response.output ni tupu.
response.in_progress response Daima ya pili, na kitu kile kile.
response.output_item.added output_index, item Reasoning inaanza: item ya reasoning yenye summary tupu.
response.reasoning_summary_text.delta output_index, summary_index, delta Kipande cha reasoning.
response.reasoning_summary_text.done output_index, summary_index, text Reasoning imekamilika: text yake yote.
response.output_item.done output_index, item Item ya reasoning iliyokamilika.
response.output_item.added output_index, item Jibu linaanza: item ya message yenye hali in_progress na bila maudhui.
response.content_part.added output_index, content_index, part Sehemu tupu ya output_text inafunguka.
response.output_text.delta output_index, content_index, delta Kipande cha jibu.
response.output_text.done output_index, content_index, text Jibu limekamilika: text yake yote.
response.content_part.done output_index, content_index, part Sehemu ya output_text iliyokamilika.
response.output_item.done output_index, item Item ya message iliyokamilika, yenye hali completed.
response.output_item.added output_index, item Wito wa tool unaanza: item ya function_call yenye call_id, name na arguments tupu.
response.function_call_arguments.delta output_index, delta Arguments za wito, kamili katika delta moja.
response.function_call_arguments.done output_index, arguments Arguments zile zile, kama arguments.
response.output_item.done output_index, item Item ya function_call iliyokamilika.
response.completed response Daima ya mwisho kwenye mafanikio: kitu kizima cha response chenye output na usage.
200 text/event-stream
event: response.created
data: {"type":"response.created","response":{"id":"resp_5f0c…","object":"response","status":"in_progress","output":[], …}}

event: response.in_progress
data: {"type":"response.in_progress","response":{"id":"resp_5f0c…","object":"response","status":"in_progress","output":[], …}}

event: response.output_item.added
data: {"type":"response.output_item.added","output_index":0,"item":{"id":"msg_1c7b…","type":"message","role":"assistant","status":"in_progress","content":[]}}

event: response.content_part.added
data: {"type":"response.content_part.added","output_index":0,"content_index":0,"part":{"type":"output_text","text":""}}

event: response.output_text.delta
data: {"type":"response.output_text.delta","output_index":0,"content_index":0,"delta":"Server-sent"}

event: response.output_text.delta
data: {"type":"response.output_text.delta","output_index":0,"content_index":0,"delta":" events let a server push text over one HTTP reply."}

event: response.output_text.done
data: {"type":"response.output_text.done","output_index":0,"content_index":0,"text":"Server-sent events let a server push text over one HTTP reply."}

event: response.content_part.done
data: {"type":"response.content_part.done","output_index":0,"content_index":0,"part":{"type":"output_text","text":"Server-sent events let a server push text over one HTTP reply."}}

event: response.output_item.done
data: {"type":"response.output_item.done","output_index":0,"item":{"id":"msg_1c7b…","type":"message","role":"assistant","status":"completed","content":[{"type":"output_text","text":"Server-sent events let a server push text over one HTTP reply.","annotations":[]}]}}

event: response.completed
data: {"type":"response.completed","response":{"id":"resp_5f0c…","object":"response","status":"completed","output":[…],"usage":{"input_tokens":1190,"output_tokens":18,"total_tokens":1208}, …}}

Stream inayoshindwa

Kwenye viwango vya Shannon jibu lililoshindwa huisha na response.failed badala ya response.completed. response.status yake ni failed na response.error ina code, rate_limit_exceeded au server_error, na message.

Kwenye model za open-weight zinazopangishwa kushindwa ni tukio la error lenye code api_error na message. response.completed bado inalifuata.

Chukulia stream kama iliyoshindwa inapokuwa na response.failed au tukio la error, na utume ombi tena.

Tools

Tool ni function ambayo code yako inaendesha. Ieleze kwenye tools; model inapoitaka, jibu lina item ya function_call badala ya, au kando ya, ujumbe.

Ufafanuzi wa tool kwenye tools:

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

output ya jibu linaloiita:

200 output
[
  {
    "id": "call_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
    "type": "function_call",
    "name": "get_weather",
    "call_id": "call_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
    "arguments": "{\"city\":\"Paris\"}"
  }
]

Endesha function, kisha tuma ombi tena na wito na matokeo yake yaliyoongezwa kwenye input:

input
[
  {
    "role": "user",
    "content": "What is the weather in Paris?"
  },
  {
    "type": "function_call",
    "call_id": "call_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
    "name": "get_weather",
    "arguments": "{\"city\":\"Paris\"}"
  },
  {
    "type": "function_call_output",
    "call_id": "call_3d9a7c1e5b2f4a60c8e1d7f09b24a6c5",
    "output": "{\"temperature_c\": 18, \"sky\": \"cloudy\"}"
  }
]

Ni tools za aina function pekee zinazosomwa. Kwenye shannon-1.6-*, shannon-2-* na shannon-coder-1 schema ya parameters hupunguzwa hadi keywords za kawaida za JSON Schema: oneOf husomwa kama anyOf, na keywords kama $ref, additionalProperties, const, default na title hazipitishwi kwa model.

Thamani za tool_choice required na function iliyotajwa zinatumiwa na model za open-weight zinazopangishwa.

Mzunguko wa tool umeelezwa kikamilifu kwenye ukurasa wake. Uitoaji wa kazi

Matokeo yaliyopangwa

Umbizo hili huandika matokeo yaliyopangwa kama text.format. Schema iko moja kwa moja kwenye format, kando ya name na strict, si chini ya member ya json_schema kama kwenye Chat Completions.

  • {"type": "json_object"} huomba kitu chochote cha JSON.
  • {"type": "json_schema", "name", "schema", "strict"} huomba JSON inayofuata schema yako. strict ni true ukiiacha nje.
POST /v1/responses
{
  "model": "shannon-1.6-lite",
  "input": "Extract the city and the date: 'The conference opens in Lisbon on 12 May 2027.'",
  "text": {
    "format": {
      "type": "json_schema",
      "name": "event",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          },
          "date": {
            "type": "string",
            "description": "ISO 8601 date"
          }
        },
        "required": [
          "city",
          "date"
        ]
      }
    }
  }
}

JSON hufika kama maandishi kwenye sehemu ya output_text ya ujumbe; ichanganue (parse) mwenyewe. Model ya open-weight inayopangishwa isiyo na matokeo yaliyopangwa hurudisha 400.

output_text
{"city": "Lisbon", "date": "2027-05-12"}

Model ipi inakubali umbo lipi imeorodheshwa kwenye ukurasa wake. Matokeo yaliyopangwa

Reasoning

Model inayofikiri hurudisha reasoning yake kama output item ya aina reasoning, kabla ya ujumbe. Kwenye stream hufika kama matukio ya response.reasoning_summary_text.delta.

Model za open-weight zinazopangishwa hutumia reasoning.effort: off, low, medium au high, na high usipotuma chochote. off haitoi reasoning item. Itume kama kitu; string pekee haisomwi kwenye endpoint hii.

Efforts zimeelezwa kwenye ukurasa wake. Reasoning effort

Kikomo cha output

max_output_tokens ni 4,096 usipoituma. Ni idadi ya tokens inayotengwa kutoka kwenye salio lako ombi linapoanza; jibu likikamilika, kiasi hicho hubadilishwa na kile ambacho ombi lilitumia. Thamani isiyoingia kwenye salio lako lililobaki hurudisha 429 Quota exceeded.

Inapunguza urefu wa jibu kwenye shannon-1.6-*, shannon-2-* na shannon-coder-1, na urefu wa maandishi ya jibu kwenye model za open-weight zinazopangishwa.

Kwenye endpoint hii shannon-coder-1 hutozwa kwa tokens kutoka kwenye salio lako, kama kila model nyingine.

Mwili wa ombi unaweza kuwa hadi 32 MiB. Mipaka na salio

Makosa

Makosa hutumia mwili wa kosa wa OpenAI: kitu cha error chenye type na message; baadhi pia hubeba code na param zenye thamani null. Jedwali linaorodhesha kile ambacho endpoint hii hurudisha mara nyingi zaidi. Orodha kamili, pamoja na yapi ya kujaribu tena, ina ukurasa wake. Ushughulikiaji wa Makosa

Hali Aina Ujumbe Lini
401 authentication_error Missing authentication
Invalid API key
Hakuna API key iliyotumwa, au key haijulikani au imebatilishwa.
400 invalid_request_error unknown model: <id> model haipo au si id iliyochapishwa.
400 invalid_request_error No user message provided. Viwango vya Shannon: input haina maandishi ya user.
400 invalid_request_error <id> does not accept image input Picha ilitumwa kwa model ya open-weight inayopangishwa isiyo na input ya picha.
400 invalid_request_error <id> does not accept response_format text.format ilitumwa kwa model ya open-weight inayopangishwa isiyo na matokeo yaliyopangwa.
400 invalid_request_error unknown reasoning effort '<value>'; expected off, low, medium or high reasoning.effort ina thamani iliyo nje ya orodha.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … Mwili ni JSON halali lakini field ina aina isiyo sahihi.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan max_output_tokens ni kubwa kuliko kilichobaki kwenye salio lako.
429 rate_limit_error Too many requests. Retry in <n>s. Flood protection: maombi zaidi ya 120 ndani ya dakika moja kwenye akaunti yako.
500 api_error The model backend failed to answer. Please retry. Model haikutoa jibu. Tuma ombi tena.
502 api_error The model backend failed to answer. Please retry. Vivyo hivyo, kwenye model za open-weight zinazopangishwa.
504 api_error upstream timed out Model ya open-weight inayopangishwa ilichukua muda mrefu kuliko kikomo cha muda cha jibu lisilo la stream. Litume na stream iliyowekwa kuwa true.