Tsallake zuwa abun ciki
Responses API

Responses API

Sabo

POST /v1/responses yana karɓar umarni da jerin input items kuma yana mayar da response object da aka yi da output items, a tsarin OpenAI Responses. Ku yi amfani da shi da responses API na OpenAI SDK da kayan da aka gina a kansa, kamar Codex CLI. Endpoint ɗin ba ya riƙe state: ku aika dukan tattaunawar da kowace request.

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

Mafi ƙanƙantar request id ne na model da rubutu. Ba a yin streaming na amsar sai kun nema.

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)

Amsar object ce na response. output ɗinta yana ɗauke da reasoning, idan model ya yi reasoning, da saƙon:

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 na request

model da input ne abin da request ke buƙata. Ginshiƙin Wanda ke aiwatarwa yana sunayen models da field ke canza amsa a kansu. Hosted open-weight models su ne ids goma sha biyu na jerin models; iyalin Shannon 3 su ne shannon-3, shannon-3-pro, shannon-3.1 da shannon-3.1-pro. Models & farashi

Field Nau'i Na asali Bayani Wanda ke aiwatarwa
model string Wajibi. Id daga jerin models. Ba a bambanta manyan haruffa da ƙanana. Id da ya ɓace ko wanda ba a wallafa ba yana mayar da 400 unknown model. Duk models
input string | array String, wanda ake karantawa a matsayin saƙon mai amfani ɗaya, ko array na input items. Duba Input items a ƙasa. Duk models
instructions string Umarni ga model, system prompt na wannan tsari. Hosted open-weight models, shannon-1.6-*, shannon-2-*, shannon-coder-1
stream boolean false true yana aika amsar a matsayin server-sent events. Duba Streaming a ƙasa. Duk models
max_output_tokens integer 4096 Iyakar amsa, a tokens. Ƙimar da ta wuce 1 zuwa 65,536 ana mayar da ita cikin wannan kewayon. Hakanan shi ne adadin da ake ware daga balance ɗinku yayin da request yake gudana. Duba Iyakar output a ƙasa. Hosted open-weight models, shannon-1.6-*, shannon-2-*, shannon-coder-1
temperature number Sampling temperature. A hosted open-weight models ana riƙe ƙimomi tsakanin 0 da 2. Hosted open-weight models; shannon-1.6-*, shannon-2-* da shannon-coder-1 a amsoshin da ba streaming ba
top_p number Nucleus sampling. Ana riƙe ƙimomi tsakanin 0 da 1. Hosted open-weight models
tools array Functions da model zai iya kira, a siffar lebur ta wannan tsari: {"type": "function", "name", "description", "parameters"}. Duba Tools a ƙasa. Duk models
tool_choice string | object auto "auto" yana barin model ya yanke shawara. "required" yana tilasta masa kiran tool. {"type": "function", "name": "…"} yana tilasta masa kiran wannan tool ɗin. Hosted open-weight models
reasoning object {"effort": "…"} da off, low, medium ko high. Duk wata ƙima tana mayar da 400. Hosted open-weight models
text object {"format": {…}} yana neman amsar JSON. Duba Structured output a ƙasa. Duk matakan Shannon; hosted open-weight models kamar yadda aka lissafa ga kowane id

Ana karɓar previous_response_id, store, metadata, parallel_tool_calls, truncation, include, user da prompt_cache_key don code na client da ke akwai ya yi aiki ba tare da canji ba. Ba sa canza amsar. Domin ba a adana tattaunawa, request na gaba yana ɗauke da turns na baya a input.

Input items

Input item ko saƙo ne, mai role da content, ko item mai nau'i da ke ɗauke da kiran tool ko sakamakonsa. content string ne ko array na sassa.

Item Bayani Wanda ke aiwatarwa
{"role": "user", "content": …} Abin da kuke tambaya. content string ne, ko sassan input_text da input_image. Duk models
{"role": "assistant", "content": …} Amsar model ta baya. content string ne, ko sassan output_text. Duk models
{"role": "system", "content": …}
{"role": "developer", "content": …}
Umarni a cikin tattaunawar. Hosted open-weight models
{"type": "function_call", "call_id": "…", "name": "…", "arguments": "…"} Kiran tool da model ya yi a amsa ta baya. arguments JSON string ne. Duk models
{"type": "function_call_output", "call_id": "…", "output": "…"} Sakamakon wannan kira. call_id shi ne id na kiran kuma output sakamakon a matsayin string. Duk models

Ku sa umarni a field na instructions. Da id na iyalin Shannon 3, ku saka umarnin da dole ya yi aiki a cikin saƙon user.

Ana iya mayar da items na output na amsa cikin input yadda suke: ana karanta items na message da function_call, ana tsallake items na reasoning.

Sassan abun ciki

Sashe Bayani Akwai a
{"type": "input_text", "text": "…"} Rubutun saƙon mai amfani. Duk models
{"type": "output_text", "text": "…"} Rubutun saƙon assistant. Duk models
{"type": "input_image", "image_url": "…"} Hoto, a matsayin data: URL mai abun ciki na base64 ko a matsayin URL na http(s). Iyalin Shannon 3, shannon-1.6-lite, shannon-1.6-pro, da hosted open-weight models da ke da image input
{"type": "input_file", "file_data": "data:application/pdf;base64,…"} Takarda (PDF, Word, PowerPoint ko Excel): file_data yana ɗauke da data: URL, ko file_url URL na http(s). Iyalin Shannon 3

A matakan Shannon ana karanta hotuna da fayiloli daga item na user na ƙarshe na input. Girma da iyakoki suna da shafinsu. Hotuna da fayiloli

Request mai instructions da zaɓuɓɓuka

Wannan request yana aika umarni, tattaunawa a matsayin items na input, iyakar output, temperature da effort na reasoning. Yana amfani da hosted open-weight model, wanda ke aiwatar da dukansu.

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)

Amsar hosted open-weight model tana da id, object, model, created_at, status, output da usage. usage ɗinta yana ƙara tokens da aka karanta daga cache da tokens da aka kashe a kan 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
  }
}

Response object

id, object, status, output da usage suna cikin kowace amsa. Ku gina code ɗinku a kansu.

Field Nau'i Bayani Wanda ya aika
id string resp_ sannan haruffan hexadecimal 32. Duk models
object string Koyaushe response. Duk models
status string completed. A cikin stream da farko yana in_progress, kuma failed a cikin event na response.failed. Duk models
output array Items na output bisa tsarin da model ya samar da su: reasoning, message, function_call. Duk models
usage object input_tokens, output_tokens da total_tokens. Duk models
usage.input_tokens_details object cached_tokens: tokens na input da aka karanta daga cache na prompt. Hosted open-weight models
usage.output_tokens_details object reasoning_tokens: tokens na output da aka kashe a kan reasoning. Hosted open-weight models
model string Id na asali na model da ya amsa. Iyalin Shannon 3, hosted open-weight models
created_at integer Lokacin amsar, a daƙiƙun Unix. Iyalin Shannon 3, hosted open-weight models
instructions, tools, temperature, … instructions, tools da temperature suna maimaita request ɗin. error da incomplete_details su ne null, metadata shi ne {}, parallel_tool_calls shi ne true, tool_choice shi ne auto kuma top_p shi ne null. Iyalin Shannon 3

Items na output

Item Bayani
{"id": "rs_…", "type": "reasoning", "summary": [{"type": "summary_text", "text": "…"}]} Reasoning na model a matsayin ɓangare ɗaya na summary_text. Yana nan ne kawai idan model ya yi reasoning.
{"id": "msg_…", "type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "…"}]} Amsar: ɓangare ɗaya na output_text mai rubutun.
{"id": "fc_…", "type": "function_call", "call_id": "call_…", "name": "…", "arguments": "…"} Kiran tool. arguments string ne na JSON. Ku mayar da sakamakon da call_id iri ɗaya.

OpenAI SDKs suna haɗa muku rubutun saƙon a cikin response.output_text.

Streaming

Ku saita stream zuwa true don server-sent events. Kowane frame yana da layin event: mai sunan event da layin data: mai object na JSON; object ɗin yana maimaita sunan a cikin type. Ku haɗa deltas da item ɗinsu ta output_index.

Da OpenAI SDK, ku karanta events ta type ɗinsu:

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

Events suna zuwa bisa wannan tsari. Rukunonin reasoning, saƙo da kiran tools suna bayyana ne kawai idan amsar tana da su.

Event Payload Lokaci
response.created response Koyaushe na farko. response.status shi ne in_progress kuma response.output babu komai.
response.in_progress response Koyaushe na biyu, da object iri ɗaya.
response.output_item.added output_index, item Reasoning ya fara: item na reasoning mai summary mara komai.
response.reasoning_summary_text.delta output_index, summary_index, delta Guntun reasoning.
response.reasoning_summary_text.done output_index, summary_index, text Reasoning ya cika: cikakken text ɗinsa.
response.output_item.done output_index, item Item ɗin reasoning da ya kammala.
response.output_item.added output_index, item Amsar ta fara: item na message mai status in_progress kuma babu content.
response.content_part.added output_index, content_index, part Ɓangaren output_text mara komai ya buɗe.
response.output_text.delta output_index, content_index, delta Guntun amsar.
response.output_text.done output_index, content_index, text Amsar ta cika: cikakken text ɗinta.
response.content_part.done output_index, content_index, part Ɓangaren output_text da ya kammala.
response.output_item.done output_index, item Item ɗin message da ya kammala, mai status completed.
response.output_item.added output_index, item Kiran tool ya fara: item na function_call mai call_id, name da arguments marasa komai.
response.function_call_arguments.delta output_index, delta Arguments na kiran, cikakku a delta ɗaya.
response.function_call_arguments.done output_index, arguments Arguments iri ɗaya, a matsayin arguments.
response.output_item.done output_index, item Item ɗin function_call da ya kammala.
response.completed response Koyaushe na ƙarshe idan an yi nasara: cikakken object na response mai output da 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 da ya gaza

A tiers na Shannon, amsar da ta gaza tana ƙarewa da response.failed maimakon response.completed. response.status ɗinta shi ne failed kuma response.error yana ɗauke da code, wato rate_limit_exceeded ko server_error, da message.

A hosted open-weight models, gazawa event ne na error mai code api_error da message. response.completed yana biyo bayansa duk da haka.

Ku ɗauki stream a matsayin wanda ya gaza idan yana ɗauke da event na response.failed ko error, sannan ku sake aika request ɗin.

Tools

Tool aiki ne da code ɗinku ke gudanarwa. Ku bayyana shi a cikin tools; idan model yana buƙatarsa, amsar tana ɗauke da item na function_call maimakon saƙon, ko kusa da shi.

Ma'anar tool a cikin tools:

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

output na amsar da ke kiran sa:

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

Ku gudanar da aikin, sannan ku sake aika request ɗin da kiran da sakamakonsa a ƙara cikin 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\"}"
  }
]

Ana karanta tools na nau'in function kawai. A shannon-1.6-*, shannon-2-* da shannon-coder-1 schema na parameters ana rage shi zuwa keywords na JSON Schema na gama gari: ana karanta oneOf a matsayin anyOf, kuma keywords kamar $ref, additionalProperties, const, default da title ba a mika su ga model ba.

Hosted open-weight models suna aiwatar da ƙimomin tool_choice required da aikin da aka ambaci suna.

An bayyana tool loop sosai a shafinsa na kansa. Kiran Aiki

Structured output

Wannan tsari yana rubuta structured output a matsayin text.format. Schema yana kai tsaye a cikin format, kusa da name da strict, ba a ƙarƙashin member na json_schema ba kamar a Chat Completions.

  • {"type": "json_object"} yana neman kowane object na JSON.
  • {"type": "json_schema", "name", "schema", "strict"} yana neman JSON da ke bin schema ɗinku. strict shi ne true idan kun bar shi.
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 yana zuwa a matsayin rubutu a ɓangaren output_text na saƙon; ku yi parse ɗinsa da kanku. Hosted open-weight model ba tare da structured output ba yana mayar da 400.

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

Wane model ke ɗaukar wane tsari an lissafa a shafinsa na kansa. Abubuwan da aka Tsara

Reasoning

Model da ke yin reasoning yana mayar da reasoning ɗinsa a matsayin item na output na nau'in reasoning, kafin saƙon. A cikin stream yana zuwa a matsayin events na response.reasoning_summary_text.delta.

Hosted open-weight models suna aiwatar da reasoning.effort: off, low, medium ko high, kuma high ne idan ba ku aika komai ba. off ba ya mayar da item na reasoning. Ku aika shi a matsayin object; ba a karanta string kaɗai a wannan endpoint ba.

An bayyana effort-effort a shafinsu na kansu. Reasoning effort

Iyakar output

max_output_tokens shi ne 4,096 idan ba ku aika shi ba. Shi ne adadin tokens da ake ware daga balance ɗinku lokacin da request ya fara; idan amsar ta cika, ana maye gurbin wannan adadi da abin da request ya yi amfani da shi. Ƙimar da ba ta shiga cikin balance ɗinku da ya rage tana mayar da 429 Quota exceeded.

Yana iyakance tsawon amsa a shannon-1.6-*, shannon-2-* da shannon-coder-1, da tsawon rubutun amsa a hosted open-weight models.

A wannan endpoint ana cajin shannon-coder-1 a tokens daga balance ɗinku, kamar kowane sauran model.

Jikin request na iya kaiwa 32 MiB. Iyakoki da balance

Kurakurai

Kurakurai suna amfani da jikin kuskure na OpenAI: object ɗin error mai type da message; wasu kuma suna ɗauke da code da param masu ƙimar null. Teburin yana lissafa abin da wannan endpoint ya fi mayarwa. Cikakken jerin, tare da abin da za a sake gwadawa, yana da shafinsa. Kuskuren Gudanarwa

Matsayi Nau'i Saƙo Lokaci
401 authentication_error Missing authentication
Invalid API key
Ba a aika maɓallin API ba, ko kuma maɓallin ba a san shi ba ko an soke shi.
400 invalid_request_error unknown model: <id> model ya ɓace ko ba id da aka wallafa ba ne.
400 invalid_request_error No user message provided. Matakan Shannon: input ba shi da rubutun mai amfani.
400 invalid_request_error <id> does not accept image input An aika hoto zuwa hosted open-weight model wanda ba shi da image input.
400 invalid_request_error <id> does not accept response_format An aika text.format zuwa hosted open-weight model wanda ba shi da structured output.
400 invalid_request_error unknown reasoning effort '<value>'; expected off, low, medium or high reasoning.effort yana ɗauke da ƙima a wajen jerin.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … Jikin JSON ne mai inganci amma wani field yana da nau'i mara kyau.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan max_output_tokens ya fi abin da ya rage a balance ɗinku girma.
429 rate_limit_error Too many requests. Retry in <n>s. Flood protection: fiye da requests 120 a cikin minti ɗaya a asusunku.
500 api_error The model backend failed to answer. Please retry. Model bai samar da amsa ba. Ku sake aika request ɗin.
502 api_error The model backend failed to answer. Please retry. Haka ma, a hosted open-weight models.
504 api_error upstream timed out Hosted open-weight model ya ɗauki fiye da iyakar lokacin amsar da ba streaming ba. Ku aika shi da stream an saita zuwa true.