Dumphani kupita ku zomwe zili
Responses API

Responses API

Chatsopano

POST /v1/responses imalandira malangizo ndi mndandanda wa ma input item ndikubweza response object yopangidwa ndi ma output item, mu mtundu wa OpenAI Responses. Igwiritseni ntchito ndi responses API ya OpenAI SDK komanso ndi ma tool omangidwa pa iyo, monga Codex CLI. Endpoint siisunga state: tumizani zokambirana zonse ndi pempho lililonse.

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

Pempho laling'ono kwambiri ndi model id ndi text. Yankho silichita stream pokhapokha mutapempha.

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)

Yankho ndi response object. output yake ili ndi reasoning, pamene model yaganiza, ndi message:

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

Ma field a pempho

model ndi input ndizo zomwe pempho limafuna. Column ya Imagwira ntchito pa imatchula ma model omwe field imasintha yankho. Hosted open-weight model ndi ma id khumi ndi awiri a mndandanda wa ma model; banja la Shannon 3 ndi shannon-3, shannon-3-pro, shannon-3.1 ndi shannon-3.1-pro. Ma model ndi mitengo

Field Mtundu Yokhazikika Kufotokozera Imagwira ntchito pa
model string Yofunika. Id yochokera mu mndandanda wa ma model. Kufanana sikusiyanitsa zilembo zazikulu ndi zazing'ono. Id yosowa kapena yosafalitsidwa imabweza 400 unknown model. Ma model onse
input string | array String, yomwe imawerengedwa ngati message imodzi ya user, kapena array ya ma input item. Onani Input items pansipa. Ma model onse
instructions string Malangizo a model, system prompt ya mtundu uwu. Hosted open-weight model, shannon-1.6-*, shannon-2-*, shannon-coder-1
stream boolean false true imatumiza yankho ngati server-sent events. Onani Streaming pansipa. Ma model onse
max_output_tokens integer 4096 Malire apamwamba a yankho, mu ma token. Mtengo wopitirira 1 mpaka 65,536 umasunthidwa kulowa mu malirewo. Ndi kuchuluka komwe kumasungidwa pa balance yanu pamene pempho likuyenda. Onani Output limit pansipa. Hosted open-weight model, shannon-1.6-*, shannon-2-*, shannon-coder-1
temperature number Sampling temperature. Pa hosted open-weight model mitengo imasungidwa pakati pa 0 ndi 2. Hosted open-weight model; shannon-1.6-*, shannon-2-* ndi shannon-coder-1 pa mayankho opanda stream
top_p number Nucleus sampling. Mitengo imasungidwa pakati pa 0 ndi 1. Hosted open-weight model
tools array Ma function omwe model ingayitane, mu mawonekedwe osalala a mtundu uwu: {"type": "function", "name", "description", "parameters"}. Onani Tools pansipa. Ma model onse
tool_choice string | object auto "auto" imalola model kusankha. "required" imaipangitsa kuyitana tool. {"type": "function", "name": "…"} imaipangitsa kuyitana tool imeneyo. Hosted open-weight model
reasoning object {"effort": "…"} ndi off, low, medium kapena high. Mtengo wina uliwonse umabweza 400. Hosted open-weight model
text object {"format": {…}} imapempha yankho la JSON. Onani Structured output pansipa. Ma tier onse a Shannon; hosted open-weight model monga mwalembedwera pa id iliyonse

previous_response_id, store, metadata, parallel_tool_calls, truncation, include, user ndi prompt_cache_key zimalandiridwa kuti code ya client yomwe ilipo igwire ntchito popanda kusintha. Sizisintha yankho. Chifukwa palibe zokambirana zomwe zimasungidwa, pempho lotsatira limanyamula ma turn akale mu input.

Input items

Input item ndi message, yokhala ndi role ndi content, kapena item yokhala ndi type yomwe imanyamula call ya tool kapena zotsatira zake. content ndi string kapena array ya ma part.

Item Kufotokozera Imagwira ntchito pa
{"role": "user", "content": …} Zomwe mukufunsa. content ndi string, kapena ma part a input_text ndi input_image. Ma model onse
{"role": "assistant", "content": …} Yankho lakale la model. content ndi string, kapena ma part a output_text. Ma model onse
{"role": "system", "content": …}
{"role": "developer", "content": …}
Malangizo mkati mwa zokambirana. Hosted open-weight model
{"type": "function_call", "call_id": "…", "name": "…", "arguments": "…"} Call ya tool yomwe model idapanga mu yankho lakale. arguments ndi JSON string. Ma model onse
{"type": "function_call_output", "call_id": "…", "output": "…"} Zotsatira za call imeneyo. call_id ndi id ya call ndipo output ndi zotsatira ngati string. Ma model onse

Ikani malangizo mu field ya instructions. Ndi id ya banja la Shannon 3, ikani malangizo omwe ayenera kutsatiridwa mu message ya user.

Ma item a output ya yankho amatha kubwerera mu input monga alili: ma item a message ndi function_call amawerengedwa, ma item a reasoning amadumphidwa.

Ma content part

Part Kufotokozera Ilipo pa
{"type": "input_text", "text": "…"} Text ya message ya user. Ma model onse
{"type": "output_text", "text": "…"} Text ya message ya assistant. Ma model onse
{"type": "input_image", "image_url": "…"} Chithunzi, ngati data: URL yokhala ndi zomwe zili mu base64 kapena ngati http(s) URL. Banja la Shannon 3, shannon-1.6-lite, shannon-1.6-pro, ndi hosted open-weight model zomwe zimalemba input ya zithunzi
{"type": "input_file", "file_data": "data:application/pdf;base64,…"} Chikalata (PDF, Word, PowerPoint kapena Excel): file_data ili ndi data: URL, kapena file_url ili ndi http(s) URL. Banja la Shannon 3

Pa ma tier a Shannon zithunzi ndi ma file zimawerengedwa kuchokera ku item yomaliza ya user ya input. Kukula ndi malire zili patsamba lawo. Zithunzi ndi ma file

Pempho lokhala ndi instructions ndi options

Pempho ili limatumiza instructions, zokambirana ngati ma input item, output limit, temperature ndi reasoning effort. Limagwiritsa ntchito hosted open-weight model, yomwe imagwiritsa ntchito zonsezo.

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)

Yankho la hosted open-weight model lili ndi id, object, model, created_at, status, output ndi usage. usage yake imawonjezera ma token owerengedwa kuchokera ku cache ndi ma token ogwiritsidwa ntchito pa 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
  }
}

Object ya response

id, object, status, output ndi usage zili pa yankho lililonse. Mangani code yanu pa izo.

Field Mtundu Kufotokozera Yotumizidwa ndi
id string resp_ yotsatiridwa ndi zilembo 32 za hexadecimal. Ma model onse
object string Nthawi zonse response. Ma model onse
status string completed. Mu stream imakhala in_progress poyamba, ndi failed mu event ya response.failed. Ma model onse
output array Ma output item motsatira momwe model idawapangira: reasoning, message, function_call. Ma model onse
usage object input_tokens, output_tokens ndi total_tokens. Ma model onse
usage.input_tokens_details object cached_tokens: ma input token owerengedwa kuchokera ku prompt cache. Hosted open-weight model
usage.output_tokens_details object reasoning_tokens: ma output token ogwiritsidwa ntchito pa reasoning. Hosted open-weight model
model string Id yovomerezeka ya model yomwe yayankha. Banja la Shannon 3, hosted open-weight model
created_at integer Nthawi ya yankho, mu masekondi a Unix. Banja la Shannon 3, hosted open-weight model
instructions, tools, temperature, … instructions, tools ndi temperature zimabwereza pempho. error ndi incomplete_details ndi null, metadata ndi {}, parallel_tool_calls ndi true, tool_choice ndi auto ndipo top_p ndi null. Banja la Shannon 3

Ma output item

Item Kufotokozera
{"id": "rs_…", "type": "reasoning", "summary": [{"type": "summary_text", "text": "…"}]} Reasoning ya model ngati part imodzi ya summary_text. Imakhalapo pokhapokha model itaganiza.
{"id": "msg_…", "type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "…"}]} Yankho: part imodzi ya output_text yokhala ndi text.
{"id": "fc_…", "type": "function_call", "call_id": "call_…", "name": "…", "arguments": "…"} Call ya tool. arguments ndi JSON string. Bwezerani zotsatira ndi call_id yomweyo.

Ma OpenAI SDK amalumikiza text ya message m'malo mwanu mu response.output_text.

Streaming

Khazikitsani stream kukhala true kuti mulandire server-sent events. Frame iliyonse ili ndi mzere wa event: wokhala ndi dzina la event ndi mzere wa data: wokhala ndi JSON object; object imabwereza dzinalo mu type. Fananizani ma delta ndi item yawo ndi output_index.

Ndi OpenAI SDK, werengani ma event ndi type yawo:

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

Ma event amafika motsatira dongosolo ili. Magulu a reasoning, message ndi ma call a tool amaoneka pokhapokha yankho lili nawo.

Event Payload Liti
response.created response Nthawi zonse yoyamba. response.status ndi in_progress ndipo response.output ilibe kanthu.
response.in_progress response Nthawi zonse yachiwiri, ndi object yomweyo.
response.output_item.added output_index, item Reasoning imayamba: item ya reasoning yokhala ndi summary yopanda kanthu.
response.reasoning_summary_text.delta output_index, summary_index, delta Chigawo cha reasoning.
response.reasoning_summary_text.done output_index, summary_index, text Reasoning yatha: text yake yonse.
response.output_item.done output_index, item Item ya reasoning yomalizidwa.
response.output_item.added output_index, item Yankho limayamba: item ya message yokhala ndi status in_progress ndi popanda zomwe zili mkati.
response.content_part.added output_index, content_index, part Part yopanda kanthu ya output_text imatsegulidwa.
response.output_text.delta output_index, content_index, delta Chigawo cha yankho.
response.output_text.done output_index, content_index, text Yankho latha: text yake yonse.
response.content_part.done output_index, content_index, part Part ya output_text yomalizidwa.
response.output_item.done output_index, item Item ya message yomalizidwa, yokhala ndi status completed.
response.output_item.added output_index, item Call ya tool imayamba: item ya function_call yokhala ndi call_id, name ndi arguments yopanda kanthu.
response.function_call_arguments.delta output_index, delta Ma argument a call, athunthu mu delta imodzi.
response.function_call_arguments.done output_index, arguments Ma argument omwewo, ngati arguments.
response.output_item.done output_index, item Item ya function_call yomalizidwa.
response.completed response Nthawi zonse yomaliza pakachita bwino: response object yonse ndi output ndi 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 yomwe yalephera

Pa ma tier a Shannon yankho lolephera limatha ndi response.failed m'malo mwa response.completed. response.status yake ndi failed ndipo response.error ili ndi code, rate_limit_exceeded kapena server_error, ndi message.

Pa hosted open-weight model cholakwika ndi event ya error yokhala ndi code api_error ndi message. response.completed imatsatirabe.

Ganizirani stream ngati yolephera ikakhala ndi event ya response.failed kapena error, ndipo tumizaninso pempho.

Ma tool

Tool ndi function yomwe code yanu imayendetsa. Ifotokozeni mu tools; model ikaifuna, yankho limakhala ndi item ya function_call m'malo mwa message kapena pambali pake.

Tanthauzo la tool mu tools:

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

output ya yankho lomwe limayitana tool:

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

Yendetsani function, kenako tumizaninso pempho ndi call ndi zotsatira zake zowonjezedwa ku 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\"}"
  }
]

Ma tool a type function okha ndi omwe amawerengedwa. Pa shannon-1.6-*, shannon-2-* ndi shannon-coder-1 schema ya parameters imachepetsedwa kufika pa ma keyword wamba a JSON Schema: oneOf imawerengedwa ngati anyOf, ndipo ma keyword monga $ref, additionalProperties, const, default ndi title sapatsidwa kwa model.

Mitengo ya tool_choice required ndi function yotchulidwa imagwiritsidwa ntchito ndi hosted open-weight model.

Tool loop yafotokozedwa mokwanira patsamba lake. Kuyitana mafunkseni

Structured output

Mtundu uwu umalemba structured output ngati text.format. Schema ili mwachindunji mu format, pambali pa name ndi strict, osati pansi pa member ya json_schema monga pa Chat Completions.

  • {"type": "json_object"} imapempha JSON object iliyonse.
  • {"type": "json_schema", "name", "schema", "strict"} imapempha JSON yotsatira schema yanu. strict ndi true mukapanda kuilemba.
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 imafika ngati text mu part ya output_text ya message; isanthuleni nokha. Hosted open-weight model yopanda structured output imabweza 400.

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

Model yomwe imalandira mtundu uti yalembedwa patsamba lake. Zotuluka zokonzedwa

Reasoning

Model yomwe imaganiza imabweza reasoning yake ngati output item ya type reasoning, patsogolo pa message. Mu stream imafika ngati ma event a response.reasoning_summary_text.delta.

Hosted open-weight model zimagwiritsa ntchito reasoning.effort: off, low, medium kapena high, ndi high mukapanda kutumiza kanthu. off simabweza reasoning item. Itumizeni ngati object; string yokha siiwerengedwa pa endpoint iyi.

Ma effort amafotokozedwa patsamba lawo. Reasoning effort

Output limit

max_output_tokens ndi 4,096 mukapanda kuitumiza. Ndi chiwerengero cha ma token chomwe chimasungidwa pa balance yanu pempho likayamba; yankho likatha, kuchuluka kumeneko kumasinthidwa ndi zomwe pempho lagwiritsa ntchito. Mtengo wosakwana mu balance yanu yotsala umabweza 429 Quota exceeded.

Imalepheretsa kutalika kwa yankho pa shannon-1.6-*, shannon-2-* ndi shannon-coder-1, ndi kutalika kwa text ya yankho pa hosted open-weight model.

Pa endpoint iyi shannon-coder-1 imaperekedwa mtengo mu ma token kuchokera ku balance yanu, monga model ina iliyonse.

Body ya pempho ikhoza kufika 32 MiB. Malire ndi balance

Zolakwika

Zolakwika zimagwiritsa ntchito body ya cholakwika ya OpenAI: object ya error yokhala ndi type ndi message; zina zimanyamulanso code ndi param ndi mtengo null. Table imalemba zomwe endpoint iyi imabweza kawirikawiri. Mndandanda wonse, ndi zoyenera kuyesanso, uli patsamba lake. Zolakwika

Status Type Message Liti
401 authentication_error Missing authentication
Invalid API key
API key sinatumizidwe, kapena kiyi siidziwika kapena yathetsedwa.
400 invalid_request_error unknown model: <id> model ikusowa kapena si id yofalitsidwa.
400 invalid_request_error No user message provided. Ma tier a Shannon: input ilibe text ya user.
400 invalid_request_error <id> does not accept image input Chithunzi chinatumizidwa ku hosted open-weight model yopanda input ya zithunzi.
400 invalid_request_error <id> does not accept response_format text.format inatumizidwa ku hosted open-weight model yopanda structured output.
400 invalid_request_error unknown reasoning effort '<value>'; expected off, low, medium or high reasoning.effort ili ndi mtengo wakunja kwa mndandanda.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … Body ndi JSON yovomerezeka koma field ili ndi type yolakwika.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan max_output_tokens ndi yayikulu kuposa zomwe zatsala pa balance yanu.
429 rate_limit_error Too many requests. Retry in <n>s. Flood protection: ma pempho opitirira 120 mu mphindi imodzi pa akaunti yanu.
500 api_error The model backend failed to answer. Please retry. Model sinapange yankho. Tumizaninso pempho.
502 api_error The model backend failed to answer. Please retry. Chimodzimodzi, pa hosted open-weight model.
504 api_error upstream timed out Hosted open-weight model inatenga nthawi yayitali kuposa malire a nthawi a yankho lopanda stream. Tumizani ndi stream yokhazikitsidwa kukhala true.