Tlola ho ea ho litaba
Responses API

Responses API

E ntjha

POST /v1/responses e amohela litaelo le lenane la lintho tsa input mme e khutlisa ntho ea karabo e entsoeng ka lintho tsa output, ka sebopeho sa OpenAI Responses. E sebelise le responses API ea SDK ea OpenAI le lisebelisoa tse hahiloeng ho eona, tse kang Codex CLI. Endpoint ha e boloke state: romela moqoqo oohle le kopo e 'ngoe le e 'ngoe.

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

Kopo e nyane ka ho fetisisa ke id ea model le mongolo. Karabo ha e etse streaming ntle le haeba u e kopa.

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)

Karabo ke ntho ea karabo. output ea eona e na le reasoning, ha model e nahanne, le molaetsa:

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

Li-field tsa kopo

model le input ke tseo kopo e li hlokang. 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 E hlokahala. Id ho tsoa lenaneng la li-model. Ho lekanya ha ho tsotelle litlhaku tse kholo le tse nyane. Id e sieo kapa e sa phatlalalitsoang e khutlisa 400 unknown model. Li-model tsohle
input string | array String, e baloang e le molaetsa o le mong oa user, kapa array ea lintho tsa input. Bona Lintho tsa input ka tlase. Li-model tsohle
instructions string Litaelo tsa model, system prompt ea sebopeho sena. Li-model tse hosted tsa open-weight, shannon-1.6-*, shannon-2-*, shannon-coder-1
stream boolean false true e romela karabo e le server-sent events. Bona Streaming ka tlase. Li-model tsohle
max_output_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 limit ka tlase. Li-model tse hosted tsa open-weight, shannon-1.6-*, shannon-2-*, shannon-coder-1
temperature number Sampling temperature. Ho li-model tse hosted tsa open-weight litekanyo li bolokoa pakeng tsa 0 le 2. Li-model tse hosted tsa open-weight; shannon-1.6-*, shannon-2-* le shannon-coder-1 likarabong tse se nang streaming
top_p number Nucleus sampling. Litekanyo li bolokoa pakeng tsa 0 le 1. Li-model tse hosted tsa open-weight
tools array Li-function tseo model e ka li bitsang, ka sebopeho se sephara sa sebopeho sena: {"type": "function", "name", "description", "parameters"}. Bona Tools ka tlase. 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", "name": "…"} e e qobella ho bitsa tool eo. Li-model tse hosted tsa open-weight
reasoning object {"effort": "…"} le off, low, medium kapa high. Boleng bo bong bofe bo khutlisa 400. Li-model tse hosted tsa open-weight
text object {"format": {…}} e kopa karabo ea JSON. Bona Structured output ka tlase. Li-tier tsohle tsa Shannon; li-model tse hosted tsa open-weight joalo ka ha li thathamisitsoe ka id

previous_response_id, store, metadata, parallel_tool_calls, truncation, include, user le prompt_cache_key lia amohelwa e le hore code ea moreki e teng e sebetse ntle le phetoho. Ha li fetole karabo. Kaha ha ho moqoqo o bolokiloeng, kopo e latelang e nka li-turn tse fetileng ho input.

Lintho tsa input

Ntho ea input ke molaetsa, o nang le role le content, kapa ntho e nang le mofuta e nkang kopo ea tool kapa sephetho sa eona. content ke string kapa array ea likarolo.

Ntho Tlhaloso E sebelisoa ke
{"role": "user", "content": …} Seo u se botsang. content ke string, kapa likarolo tsa input_text le input_image. Li-model tsohle
{"role": "assistant", "content": …} Karabo e fetileng ea model. content ke string, kapa likarolo tsa output_text. Li-model tsohle
{"role": "system", "content": …}
{"role": "developer", "content": …}
Litaelo ka hare ho moqoqo. Li-model tse hosted tsa open-weight
{"type": "function_call", "call_id": "…", "name": "…", "arguments": "…"} Kopo ea tool eo model e e entseng karabong e fetileng. arguments ke string ea JSON. Li-model tsohle
{"type": "function_call_output", "call_id": "…", "output": "…"} Sephetho sa kopo eo. call_id ke id ea kopo mme output ke sephetho e le string. Li-model tsohle

Kenya litaelo ho field ea instructions. Ka id ea lelapa la Shannon 3, kenya litaelo tse lokelang ho latelloa molaetsa oa user.

Lintho tsa output ea karabo li ka khutlela ho input joalo ka ha li le: lintho tsa message le function_call lia baloa, lintho tsa reasoning lia tlolloa.

Likarolo tsa litaba

Karolo Tlhaloso E fumaneha ho
{"type": "input_text", "text": "…"} Mongolo oa molaetsa oa user. Li-model tsohle
{"type": "output_text", "text": "…"} Mongolo oa molaetsa oa assistant. Li-model tsohle
{"type": "input_image", "image_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": "input_file", "file_data": "data:application/pdf;base64,…"} Tokomane (PDF, Word, PowerPoint kapa Excel): file_data e na le URL ea data:, kapa file_url e na le URL ea http(s). Lelapa la Shannon 3

Ho li-tier tsa Shannon litšoantšo le lifaele li baloa ho ntho ea ho qetela ea user ea input. Boholo le meeli li na le leqephe la tsona. Litšoantšo le lifaele

Kopo e nang le litaelo le likhetho

Kopo ena e romela litaelo, moqoqo e le lintho tsa input, moeli oa output, temperature 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.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)

Karabo ea model e hosted ea open-weight e na le id, object, model, created_at, status, output le usage. usage ea eona e eketsa tokens tse baloang ho cache le tokens tse sebelisitsoeng ho 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
  }
}

Ntho ea karabo

id, object, status, output le usage li ho karabo e 'ngoe le e 'ngoe. Aha code ea hau holim'a tsena.

Field Mofuta Tlhaloso E rometsoe ke
id string resp_ e latelwa ke litlhaku tse 32 tsa hexadecimal. Li-model tsohle
object string Kamehla ke response. Li-model tsohle
status string completed. Ho stream pele ke in_progress, mme ke failed ho event ea response.failed. Li-model tsohle
output array Lintho tsa output ka tatellano eo model e li hlahisitseng ka eona: reasoning, message, function_call. Li-model tsohle
usage object input_tokens, output_tokens le total_tokens. Li-model tsohle
usage.input_tokens_details object cached_tokens: input tokens tse baloang ho prompt cache. Li-model tse hosted tsa open-weight
usage.output_tokens_details object reasoning_tokens: output tokens tse sebelisitsoeng ho reasoning. Li-model tse hosted tsa open-weight
model string Id ea canonical ea model e arabileng. Lelapa la Shannon 3, li-model tse hosted tsa open-weight
created_at integer Nako ea karabo, ka metsotsoana ea Unix. Lelapa la Shannon 3, li-model tse hosted tsa open-weight
instructions, tools, temperature, … instructions, tools le temperature li pheta kopo. error le incomplete_details ke null, metadata ke {}, parallel_tool_calls ke true, tool_choice ke auto mme top_p ke null. Lelapa la Shannon 3

Lintho tsa output

Ntho Tlhaloso
{"id": "rs_…", "type": "reasoning", "summary": [{"type": "summary_text", "text": "…"}]} Reasoning ea model e le karolo e le 'ngoe ea summary_text. E teng feela ha model e nahanne.
{"id": "msg_…", "type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "…"}]} Karabo: karolo e le 'ngoe ea output_text e nang le mongolo.
{"id": "fc_…", "type": "function_call", "call_id": "call_…", "name": "…", "arguments": "…"} Kopo ea tool. arguments ke string ea JSON. Romela sephetho hape ka call_id e tšoanang.

Li-SDK tsa OpenAI li u kopanyetsa mongolo oa molaetsa ho response.output_text.

Streaming

Beha stream ho true bakeng sa server-sent events. Frame e 'ngoe le e 'ngoe e na le mohala oa event: o nang le lebitso la event le mohala oa data: o nang le ntho ea JSON; ntho e pheta lebitso ho type. Amanya li-delta le ntho ea tsona ka output_index.

Ka SDK ea OpenAI, bala li-event ka type ea tsona:

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

Li-event li fihla ka tatellano ena. Lihlopha tsa reasoning, molaetsa le likopo tsa tool li hlaha feela ha karabo e na le tsona.

Event Payload Neng
response.created response Kamehla ke ea pele. response.status ke in_progress mme response.output ha e na letho.
response.in_progress response Kamehla ke ea bobeli, e nang le ntho e tšoanang.
response.output_item.added output_index, item Reasoning e qala: ntho ea reasoning e nang le summary e se nang letho.
response.reasoning_summary_text.delta output_index, summary_index, delta Sekhechana sa reasoning.
response.reasoning_summary_text.done output_index, summary_index, text Reasoning e phethahetse: text ea eona eohle.
response.output_item.done output_index, item Ntho e phethiloeng ea reasoning.
response.output_item.added output_index, item Karabo e qala: ntho ea message e nang le boemo in_progress le ntle le litaba.
response.content_part.added output_index, content_index, part Karolo e se nang letho ea output_text e buleha.
response.output_text.delta output_index, content_index, delta Sekhechana sa karabo.
response.output_text.done output_index, content_index, text Karabo e phethahetse: text ea eona eohle.
response.content_part.done output_index, content_index, part Karolo e phethiloeng ea output_text.
response.output_item.done output_index, item Ntho e phethiloeng ea message, e nang le boemo completed.
response.output_item.added output_index, item Kopo ea tool e qala: ntho ea function_call e nang le call_id, name le arguments e se nang letho.
response.function_call_arguments.delta output_index, delta Li-argument tsa kopo, li felletse delta e le 'ngoe.
response.function_call_arguments.done output_index, arguments Li-argument tse tšoanang, e le arguments.
response.output_item.done output_index, item Ntho e phethiloeng ea function_call.
response.completed response Kamehla ke ea ho qetela ha ho atlehile: ntho eohle ea karabo e nang le output le 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 e hlolehang

Ho li-tier tsa Shannon karabo e hlolehileng e fela ka response.failed sebakeng sa response.completed. response.status ea eona ke failed mme response.error e na le code, rate_limit_exceeded kapa server_error, le message.

Ho li-model tse hosted tsa open-weight ho hloleha ke event ea error e nang le code api_error le message. response.completed e ntse e e latela.

Nka stream e le e hlolehileng ha e na le event ea response.failed kapa error, mme u romele kopo hape.

Tools

Tool ke function eo code ea hau e e etsang. E hlalose ho tools; ha model e e batla, karabo e na le ntho ea function_call sebakeng sa, kapa haufi le, molaetsa.

Tlhaloso ea tool ho tools:

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

output ea karabo e e bitsang:

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

Etsa function, ebe u romela kopo hape le kopo le sephetho sa eona li kentsoe ho 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\"}"
  }
]

Ke lisebelisoa feela tsa mofuta function tse baloang. Ho shannon-1.6-*, shannon-2-* le shannon-coder-1 schema ea parameters e fokotsoa ho mantsoe a tloaelehileng a JSON Schema: oneOf e baloa e le anyOf, mme mantsoe a kang $ref, additionalProperties, const, default le title ha a fetisetsoe ho model.

Litekanyo tsa tool_choice required le function e rehiloeng li sebelisoa ke li-model tse hosted tsa open-weight.

Tool loop e hlalositsoe ka botlalo leqepheng la eona. Mekhosi ya mesebetsi

Structured output

Sebopeho sena se ngola structured output e le text.format. Schema e ho format ka ho toba, haufi le name le strict, eseng tlasa setho sa json_schema joalo ka ho Chat Completions.

  • {"type": "json_object"} e kopa ntho efe kapa efe ea JSON.
  • {"type": "json_schema", "name", "schema", "strict"} e kopa JSON e latelang schema ea hau. strict ke true ha u e siea ka ntle.
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 e fihla e le mongolo karolong ea output_text ea molaetsa; e parse ka bouena. Model e hosted ea open-weight e se nang structured output e khutlisa 400.

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

Hore na model efe e amohela sebopeho sefe e thathamisitsoe leqepheng la eona. Diphumo tse hlophisitsoeng

Reasoning

Model e nahanang e khutlisa reasoning ea eona e le ntho ea output ea mofuta reasoning, pele ho molaetsa. Ho stream e fihla e le li-event tsa response.reasoning_summary_text.delta.

Li-model tse hosted tsa open-weight li sebelisa reasoning.effort: off, low, medium kapa high, le high ha u sa romele letho. off ha e khutlise ntho ea reasoning. E romele e le ntho; string e hlakileng ha e baloe ho endpoint ena.

Li-effort li hlalositsoe leqepheng la tsona. Effort ea reasoning

Output limit

max_output_tokens ke 4,096 ha u sa e romele. 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 seo kopo e se sebelisitseng. Boleng bo sa keneng ho balance ea hau e setseng bo khutlisa 429 Quota exceeded.

E lekanyetsa bolelele ba karabo ho shannon-1.6-*, shannon-2-* le shannon-coder-1, le bolelele ba mongolo oa karabo ho li-model tse hosted tsa open-weight.

Ho endpoint ena shannon-coder-1 e lefisoa ka tokens ho tsoa ho balance ea hau, joalo ka model e 'ngoe le e 'ngoe.

Body ea kopo e ka ba 32 MiB. Meeli le balance

Liphoso

Liphoso li sebelisa body ea phoso ea OpenAI: ntho ea error e nang le type le message; tse ling li boetse li nka code le param le boleng null. 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

Boemo Mofuta Molaetsa Neng
401 authentication_error Missing authentication
Invalid 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 ha e eo kapa hase id e phatlalalitsoeng.
400 invalid_request_error No user message provided. Li-tier tsa Shannon: input ha e na mongolo oa user.
400 invalid_request_error <id> does not accept image input Setšoantšo se 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 text.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: … Body ke JSON e nepahetseng empa field e na le mofuta o fosahetseng.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan max_output_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 api_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 li-model tse hosted tsa open-weight.
504 api_error upstream timed out Model e hosted ea open-weight e nkile nako e telele ho feta moeli oa nako oa karabo e se nang streaming. E romele ka stream e behiloeng ho true.