Neidio i'r cynnwys
Responses API

Responses API

Newydd

Mae POST /v1/responses yn cymryd cyfarwyddiadau a rhestr o eitemau mewnbwn ac yn dychwelyd gwrthrych ymateb wedi'i wneud o eitemau allbwn, yn fformat OpenAI Responses. Defnyddiwch ef gyda'r API responses yn SDK OpenAI a chydag offer sydd wedi'u hadeiladu arno, fel Codex CLI. Nid yw'r pwynt terfyn yn cadw cyflwr: anfonwch y sgwrs gyfan gyda phob cais.

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

Y cais lleiaf yw id model a thestun. Nid yw'r ateb yn cael ei ffrydio oni ofynnwch amdano.

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)

Gwrthrych ymateb yw'r ateb. Mae ei output yn dal y rhesymu, pan fu'r model yn rhesymu, a'r neges:

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

Meysydd cais

model ac input yw'r hyn sydd ei angen ar gais. Mae'r golofn Wedi'i gymhwyso gan yn enwi'r modelau lle mae maes yn newid yr ateb. Y modelau pwysau agored a gynhelir yw deuddeg id y rhestr fodelau; teulu Shannon 3 yw shannon-3, shannon-3-pro, shannon-3.1 a shannon-3.1-pro. Modelau a phrisiau

Maes Math Rhagosodiad Disgrifiad Wedi'i gymhwyso gan
model string Gofynnol. Id o'r rhestr fodelau. Nid yw'r paru yn sensitif i briflythrennau. Mae id coll neu heb ei gyhoeddi yn dychwelyd 400 unknown model. Pob model
input string | array Llinyn, a ddarllenir fel un neges defnyddiwr, neu arae o eitemau mewnbwn. Gweler Eitemau mewnbwn isod. Pob model
instructions string Cyfarwyddiadau i'r model, system prompt y fformat hwn. Modelau pwysau agored a gynhelir, shannon-1.6-*, shannon-2-*, shannon-coder-1
stream boolean false Mae true yn anfon yr ateb fel digwyddiadau a anfonir gan y gweinydd. Gweler Ffrydio isod. Pob model
max_output_tokens integer 4096 Terfyn uchaf yr ateb, mewn tokenau. Symudir gwerth y tu allan i 1 i 65,536 i mewn i'r ystod honno. Hefyd dyma'r swm a neilltuir o'ch balans tra bydd y cais yn rhedeg. Gweler Terfyn allbwn isod. Modelau pwysau agored a gynhelir, shannon-1.6-*, shannon-2-*, shannon-coder-1
temperature number Tymheredd samplu. Ar y modelau pwysau agored a gynhelir cedwir y gwerthoedd rhwng 0 a 2. Modelau pwysau agored a gynhelir; shannon-1.6-*, shannon-2-* a shannon-coder-1 ar atebion heb eu ffrydio
top_p number Samplu cnewyllyn. Cedwir y gwerthoedd rhwng 0 a 1. Modelau pwysau agored a gynhelir
tools array Y ffwythiannau y caiff y model eu galw, yn ffurf wastad y fformat hwn: {"type": "function", "name", "description", "parameters"}. Gweler Offer isod. Pob model
tool_choice string | object auto Mae "auto" yn gadael i'r model benderfynu. Mae "required" yn gwneud iddo alw offeryn. Mae {"type": "function", "name": "…"} yn gwneud iddo alw'r offeryn hwnnw. Modelau pwysau agored a gynhelir
reasoning object {"effort": "…"} gydag off, low, medium neu high. Mae unrhyw werth arall yn dychwelyd 400. Modelau pwysau agored a gynhelir
text object Mae {"format": {…}} yn gofyn am ateb JSON. Gweler Allbwn strwythuredig isod. Pob haen Shannon; modelau pwysau agored a gynhelir fel y rhestrir fesul id

Derbynnir previous_response_id, store, metadata, parallel_tool_calls, truncation, include, user a prompt_cache_key fel bod cod cleient presennol yn rhedeg heb newid. Nid ydynt yn newid yr ateb. Gan na chaiff unrhyw sgwrs ei storio, mae cais dilynol yn cario'r troeon cynharach yn input.

Eitemau mewnbwn

Mae eitem fewnbwn naill ai'n neges, gyda role a content, neu'n eitem fathedig sy'n cario galwad offeryn neu ei chanlyniad. Llinyn neu arae o rannau yw content.

Eitem Disgrifiad Wedi'i gymhwyso gan
{"role": "user", "content": …} Yr hyn a ofynnwch. Mae content yn llinyn, neu'n rhannau input_text ac input_image. Pob model
{"role": "assistant", "content": …} Ateb cynharach gan y model. Mae content yn llinyn, neu'n rhannau output_text. Pob model
{"role": "system", "content": …}
{"role": "developer", "content": …}
Cyfarwyddiadau y tu mewn i'r sgwrs. Modelau pwysau agored a gynhelir
{"type": "function_call", "call_id": "…", "name": "…", "arguments": "…"} Galwad offeryn a wnaeth y model mewn ateb cynharach. Llinyn JSON yw arguments. Pob model
{"type": "function_call_output", "call_id": "…", "output": "…"} Canlyniad yr alwad honno. call_id yw id yr alwad ac output y canlyniad fel llinyn. Pob model

Rhowch gyfarwyddiadau yn y maes instructions. Gydag id yn nheulu Shannon 3, rhowch gyfarwyddiadau y mae'n rhaid iddynt ddal yn y neges user.

Gall eitemau output ateb fynd yn ôl i input fel y maent: darllenir eitemau message a function_call, hepgorir eitemau reasoning.

Rhannau cynnwys

Rhan Disgrifiad Ar gael ar
{"type": "input_text", "text": "…"} Testun neges defnyddiwr. Pob model
{"type": "output_text", "text": "…"} Testun neges assistant. Pob model
{"type": "input_image", "image_url": "…"} Delwedd, fel URL data: gyda chynnwys base64 neu fel URL http(s). Teulu Shannon 3, shannon-1.6-lite, shannon-1.6-pro, a'r modelau pwysau agored a gynhelir sy'n rhestru mewnbwn delwedd
{"type": "input_file", "file_data": "data:application/pdf;base64,…"} Dogfen (PDF, Word, PowerPoint neu Excel): mae file_data yn dal URL data:, neu file_url URL http(s). Teulu Shannon 3

Ar haenau Shannon darllenir delweddau a ffeiliau o'r eitem user olaf yn input. Mae gan feintiau a therfynau eu tudalen eu hunain. Delweddau a ffeiliau

Cais gyda chyfarwyddiadau ac opsiynau

Mae'r cais hwn yn anfon cyfarwyddiadau, sgwrs fel eitemau mewnbwn, terfyn allbwn, tymheredd ac ymdrech resymu. Mae'n defnyddio model pwysau agored a gynhelir, sy'n cymhwyso pob un ohonynt.

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)

Mae gan ateb model pwysau agored a gynhelir id, object, model, created_at, status, output a usage. Mae ei usage yn ychwanegu'r tokenau a ddarllenwyd o'r cache a'r tokenau a dreuliwyd ar resymu:

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

Y gwrthrych ymateb

Mae id, object, status, output a usage ar bob ateb. Adeiladwch eich cod ar y rheini.

Maes Math Disgrifiad Anfonwyd gan
id string resp_ ac yna 32 nod hecsadegol. Pob model
object string Bob amser yn response. Pob model
status string completed. Mewn ffrwd mae'n in_progress yn gyntaf, ac yn failed mewn digwyddiad response.failed. Pob model
output array Yr eitemau allbwn yn y drefn y cynhyrchodd y model hwy: reasoning, message, function_call. Pob model
usage object input_tokens, output_tokens a total_tokens. Pob model
usage.input_tokens_details object cached_tokens: y tokenau mewnbwn a ddarllenwyd o'r prompt cache. Modelau pwysau agored a gynhelir
usage.output_tokens_details object reasoning_tokens: y tokenau allbwn a dreuliwyd ar resymu. Modelau pwysau agored a gynhelir
model string Id canonaidd y model a atebodd. Teulu Shannon 3, modelau pwysau agored a gynhelir
created_at integer Amser yr ateb, mewn eiliadau Unix. Teulu Shannon 3, modelau pwysau agored a gynhelir
instructions, tools, temperature, … Mae instructions, tools a temperature yn ailadrodd y cais. Mae error ac incomplete_details yn null, mae metadata yn {}, mae parallel_tool_calls yn true, mae tool_choice yn auto ac mae top_p yn null. Teulu Shannon 3

Eitemau allbwn

Eitem Disgrifiad
{"id": "rs_…", "type": "reasoning", "summary": [{"type": "summary_text", "text": "…"}]} Rhesymu'r model fel un rhan summary_text. Yn bresennol dim ond pan fu'r model yn rhesymu.
{"id": "msg_…", "type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "…"}]} Yr ateb: un rhan output_text gyda'r testun.
{"id": "fc_…", "type": "function_call", "call_id": "call_…", "name": "…", "arguments": "…"} Galwad offeryn. Llinyn JSON yw arguments. Anfonwch y canlyniad yn ôl gyda'r un call_id.

Mae SDKs OpenAI yn uno testun y neges i chi yn response.output_text.

Ffrydio

Gosodwch stream i true ar gyfer digwyddiadau a anfonir gan y gweinydd. Mae gan bob ffrâm linell event: gydag enw'r digwyddiad a llinell data: gyda gwrthrych JSON; mae'r gwrthrych yn ailadrodd yr enw yn type. Paru deltâu â'u heitem yn ôl output_index.

Gyda SDK OpenAI, darllenwch y digwyddiadau yn ôl eu type:

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

Mae'r digwyddiadau'n cyrraedd yn y drefn hon. Mae'r grwpiau ar gyfer rhesymu, y neges a galwadau offer yn ymddangos dim ond pan fo'r ateb yn eu cynnwys.

Digwyddiad Llwyth Pryd
response.created response Bob amser yn gyntaf. Mae response.status yn in_progress ac mae response.output yn wag.
response.in_progress response Bob amser yn ail, gyda'r un gwrthrych.
response.output_item.added output_index, item Mae'r rhesymu yn dechrau: eitem reasoning gyda summary gwag.
response.reasoning_summary_text.delta output_index, summary_index, delta Darn o'r rhesymu.
response.reasoning_summary_text.done output_index, summary_index, text Mae'r rhesymu yn gyflawn: ei text cyfan.
response.output_item.done output_index, item Yr eitem reasoning gorffenedig.
response.output_item.added output_index, item Mae'r ateb yn dechrau: eitem message gyda statws in_progress a dim cynnwys.
response.content_part.added output_index, content_index, part Mae rhan output_text wag yn agor.
response.output_text.delta output_index, content_index, delta Darn o'r ateb.
response.output_text.done output_index, content_index, text Mae'r ateb yn gyflawn: ei text cyfan.
response.content_part.done output_index, content_index, part Y rhan output_text gorffenedig.
response.output_item.done output_index, item Yr eitem message gorffenedig, gyda statws completed.
response.output_item.added output_index, item Mae galwad offeryn yn dechrau: eitem function_call gyda call_id, name ac arguments gwag.
response.function_call_arguments.delta output_index, delta Dadleuon yr alwad, yn gyflawn mewn un delta.
response.function_call_arguments.done output_index, arguments Yr un dadleuon, fel arguments.
response.output_item.done output_index, item Yr eitem function_call gorffenedig.
response.completed response Bob amser yn olaf ar lwyddiant: y gwrthrych ymateb cyfan gydag output a 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}, …}}

Ffrwd sy'n methu

Ar haenau Shannon mae ateb a fethodd yn gorffen gyda response.failed yn lle response.completed. Ei response.status yw failed ac mae response.error yn dal code, rate_limit_exceeded neu server_error, a message.

Ar y modelau pwysau agored a gynhelir, digwyddiad error yw methiant gyda code api_error a message. Mae response.completed yn dal i'w ddilyn.

Trinnwch ffrwd fel un a fethodd pan fo'n dal response.failed neu ddigwyddiad error, ac anfonwch y cais eto.

Offer

Ffwythiant y mae eich cod yn ei redeg yw offeryn. Disgrifiwch ef yn tools; pan fo'r model ei eisiau, mae'r ateb yn dal eitem function_call yn lle'r neges, neu wrth ei hymyl.

Diffiniad offeryn yn tools:

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

output ateb sy'n ei alw:

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

Rhedwch y ffwythiant, yna anfonwch y cais eto gyda'r alwad a'i chanlyniad wedi'u hychwanegu at 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\"}"
  }
]

Darllenir offer o'r math function yn unig. Ar shannon-1.6-*, shannon-2-* a shannon-coder-1 caiff y sgema parameters ei leihau i allweddeiriau cyffredin JSON Schema: darllenir oneOf fel anyOf, ac nid yw allweddeiriau fel $ref, additionalProperties, const, default a title yn cael eu trosglwyddo i'r model.

Mae'r modelau pwysau agored a gynhelir yn cymhwyso gwerthoedd tool_choice required a ffwythiant a enwir.

Disgrifir y ddolen offer yn llawn ar ei thudalen ei hun. Galw swyddogaeth

Allbwn strwythuredig

Mae'r fformat hwn yn sillafu allbwn strwythuredig fel text.format. Mae'r sgema yn eistedd yn uniongyrchol yn format, wrth ymyl name a strict, nid o dan aelod json_schema fel ar Chat Completions.

  • Mae {"type": "json_object"} yn gofyn am unrhyw wrthrych JSON.
  • Mae {"type": "json_schema", "name", "schema", "strict"} yn gofyn am JSON sy'n dilyn eich sgema. Mae strict yn true pan fyddwch yn ei adael allan.
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"
        ]
      }
    }
  }
}

Mae'r JSON yn cyrraedd fel testun yn rhan output_text y neges; dadansoddwch ef eich hun. Mae model pwysau agored a gynhelir heb allbwn strwythuredig yn dychwelyd 400.

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

Rhestrir pa fodel sy'n cymryd pa ffurf ar ei dudalen ei hun. Allbynnau strwythuredig

Rhesymu

Mae model sy'n rhesymu yn dychwelyd ei resymu fel eitem allbwn o'r math reasoning, cyn y neges. Mewn ffrwd mae'n cyrraedd fel digwyddiadau response.reasoning_summary_text.delta.

Mae'r modelau pwysau agored a gynhelir yn cymhwyso reasoning.effort: off, low, medium neu high, gyda high pan na anfonwch ddim. Nid yw off yn dychwelyd eitem reasoning. Anfonwch ef fel gwrthrych; ni ddarllenir llinyn noeth ar y pwynt terfyn hwn.

Disgrifir yr ymdrechion ar eu tudalen eu hunain. Ymdrech rhesymu

Terfyn allbwn

Mae max_output_tokens yn 4,096 pan na anfonwch ef. Dyna nifer y tokenau a neilltuir o'ch balans pan fo'r cais yn dechrau; pan fo'r ateb yn gyflawn, caiff y swm hwnnw ei ddisodli gan yr hyn a ddefnyddiodd y cais. Mae gwerth nad yw'n ffitio i'ch balans sy'n weddill yn dychwelyd 429 Quota exceeded.

Mae'n cyfyngu hyd yr ateb ar shannon-1.6-*, shannon-2-* a shannon-coder-1, a hyd testun yr ateb ar y modelau pwysau agored a gynhelir.

Ar y pwynt terfyn hwn codir shannon-coder-1 mewn tokenau o'ch balans, fel pob model arall.

Gall corff cais fod hyd at 32 MiB. Terfynau a balans

Gwallau

Mae gwallau'n defnyddio corff gwall OpenAI: gwrthrych error gyda type a message; mae rhai hefyd yn cario code a param gyda'r gwerth null. Mae'r tabl yn rhestru'r hyn y mae'r pwynt terfyn hwn yn ei ddychwelyd amlaf. Mae gan y rhestr lawn, gyda'r hyn i'w ailgeisio, ei thudalen ei hun. Rheoli gwallau

Statws Math Neges Pryd
401 authentication_error Missing authentication
Invalid API key
Ni anfonwyd allwedd API, neu mae'r allwedd yn anhysbys neu wedi'i dirymu.
400 invalid_request_error unknown model: <id> Mae model ar goll neu nid yw'n id cyhoeddedig.
400 invalid_request_error No user message provided. Haenau Shannon: nid yw input yn dal testun defnyddiwr.
400 invalid_request_error <id> does not accept image input Anfonwyd delwedd i fodel pwysau agored a gynhelir heb fewnbwn delwedd.
400 invalid_request_error <id> does not accept response_format Anfonwyd text.format i fodel pwysau agored a gynhelir heb allbwn strwythuredig.
400 invalid_request_error unknown reasoning effort '<value>'; expected off, low, medium or high Mae reasoning.effort yn dal gwerth y tu allan i'r rhestr.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … Mae'r corff yn JSON dilys ond mae gan faes y math anghywir.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan Mae max_output_tokens yn fwy na'r hyn sy'n weddill o'ch balans.
429 rate_limit_error Too many requests. Retry in <n>s. Amddiffyniad rhag llifogydd: mwy na 120 cais mewn un funud ar eich cyfrif.
500 api_error The model backend failed to answer. Please retry. Ni chynhyrchodd y model ateb. Anfonwch y cais eto.
502 api_error The model backend failed to answer. Please retry. Yr un peth, ar y modelau pwysau agored a gynhelir.
504 api_error upstream timed out Cymerodd model pwysau agored a gynhelir yn hirach na therfyn amser ateb heb ei ffrydio. Anfonwch ef gyda stream wedi'i osod i true.