Langsung ke konten
Responses API

Responses API

Baru

POST /v1/responses menerima instruksi dan daftar item input lalu mengembalikan objek response yang terdiri dari item output, dalam format OpenAI Responses. Gunakan dengan API responses dari SDK OpenAI dan dengan tool yang dibangun di atasnya, seperti Codex CLI. Endpoint ini tidak menyimpan state: kirim seluruh percakapan pada setiap permintaan.

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

Permintaan terkecil adalah id model dan sebuah teks. Balasan tidak di-stream kecuali Anda memintanya.

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)

Balasan adalah objek response. output-nya berisi penalaran, jika model bernalar, dan pesan:

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

Field permintaan

model dan input adalah yang dibutuhkan permintaan. Kolom Applied by menyebutkan model tempat suatu field mengubah balasan. Model open-weight hosted adalah dua belas id dalam daftar model; keluarga Shannon 3 adalah shannon-3, shannon-3-pro, shannon-3.1, dan shannon-3.1-pro. Model & harga

Field Tipe Default Deskripsi Diterapkan oleh
model string Wajib. Id dari daftar model. Pencocokan tidak membedakan huruf besar dan kecil. Id yang hilang atau tidak dipublikasikan mengembalikan 400 unknown model. Semua model
input string | array String, yang dibaca sebagai satu pesan user, atau array item input. Lihat Input items di bawah. Semua model
instructions string Instruksi untuk model, system prompt dari format ini. Model open-weight hosted, shannon-1.6-*, shannon-2-*, shannon-coder-1
stream boolean false true mengirim balasan sebagai server-sent events. Lihat Streaming di bawah. Semua model
max_output_tokens integer 4096 Batas atas balasan, dalam token. Nilai di luar 1 sampai 65,536 dipindahkan ke rentang itu. Ini juga jumlah yang disisihkan dari saldo Anda selama permintaan berjalan. Lihat Output limit di bawah. Model open-weight hosted, shannon-1.6-*, shannon-2-*, shannon-coder-1
temperature number Temperature sampling. Pada model open-weight hosted, nilai dijaga di antara 0 dan 2. Model open-weight hosted; shannon-1.6-*, shannon-2-*, dan shannon-coder-1 pada balasan tanpa stream
top_p number Nucleus sampling. Nilai dijaga di antara 0 dan 1. Model open-weight hosted
tools array Fungsi yang boleh dipanggil model, dalam bentuk datar format ini: {"type": "function", "name", "description", "parameters"}. Lihat Tools di bawah. Semua model
tool_choice string | object auto "auto" membiarkan model memutuskan. "required" membuatnya memanggil tool. {"type": "function", "name": "…"} membuatnya memanggil tool tersebut. Model open-weight hosted
reasoning object {"effort": "…"} dengan off, low, medium, atau high. Nilai lain mengembalikan 400. Model open-weight hosted
text object {"format": {…}} meminta jawaban JSON. Lihat Structured output di bawah. Semua tier Shannon; model open-weight hosted sebagaimana tercantum per id

previous_response_id, store, metadata, parallel_tool_calls, truncation, include, user, dan prompt_cache_key diterima agar kode klien yang ada berjalan tanpa perubahan. Field-field itu tidak mengubah balasan. Karena tidak ada percakapan yang disimpan, permintaan lanjutan membawa giliran sebelumnya di input.

Item input

Item input adalah pesan, dengan role dan content, atau item bertipe yang membawa pemanggilan tool atau hasilnya. content adalah string atau array bagian.

Item Deskripsi Diterapkan oleh
{"role": "user", "content": …} Yang Anda tanyakan. content adalah string, atau bagian input_text dan input_image. Semua model
{"role": "assistant", "content": …} Balasan model sebelumnya. content adalah string, atau bagian output_text. Semua model
{"role": "system", "content": …}
{"role": "developer", "content": …}
Instruksi di dalam percakapan. Model open-weight hosted
{"type": "function_call", "call_id": "…", "name": "…", "arguments": "…"} Pemanggilan tool yang dibuat model pada balasan sebelumnya. arguments adalah string JSON. Semua model
{"type": "function_call_output", "call_id": "…", "output": "…"} Hasil dari panggilan itu. call_id adalah id panggilan dan output adalah hasilnya sebagai string. Semua model

Taruh instruksi di field instructions. Dengan id keluarga Shannon 3, taruh instruksi yang harus dipatuhi di pesan user.

Item dari output balasan dapat dikirim kembali ke input apa adanya: item message dan function_call dibaca, item reasoning dilewati.

Bagian konten

Bagian Deskripsi Tersedia di
{"type": "input_text", "text": "…"} Teks pesan user. Semua model
{"type": "output_text", "text": "…"} Teks pesan assistant. Semua model
{"type": "input_image", "image_url": "…"} Gambar, sebagai URL data: dengan konten base64 atau sebagai URL http(s). Keluarga Shannon 3, shannon-1.6-lite, shannon-1.6-pro, dan model open-weight hosted yang mencantumkan input gambar
{"type": "input_file", "file_data": "data:application/pdf;base64,…"} Dokumen (PDF, Word, PowerPoint, atau Excel): file_data berisi URL data:, atau file_url berisi URL http(s). Keluarga Shannon 3

Pada tier Shannon, gambar dan file dibaca dari item user terakhir di input. Ukuran dan batas memiliki halamannya sendiri. Gambar dan file

Permintaan dengan instruksi dan opsi

Permintaan ini mengirim instruksi, percakapan sebagai item input, batas output, temperature, dan reasoning effort. Permintaan ini memakai model open-weight hosted, yang menerapkan semuanya.

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)

Balasan model open-weight hosted memiliki id, object, model, created_at, status, output, dan usage. usage-nya menambahkan token yang dibaca dari cache dan token yang dipakai untuk penalaran:

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

Objek response

id, object, status, output, dan usage ada pada setiap balasan. Bangun kode Anda di atasnya.

Field Tipe Deskripsi Dikirim oleh
id string resp_ diikuti 32 karakter heksadesimal. Semua model
object string Selalu response. Semua model
status string completed. Dalam stream, awalnya in_progress, dan failed pada event response.failed. Semua model
output array Item output dalam urutan model menghasilkannya: reasoning, message, function_call. Semua model
usage object input_tokens, output_tokens, dan total_tokens. Semua model
usage.input_tokens_details object cached_tokens: token input yang dibaca dari cache prompt. Model open-weight hosted
usage.output_tokens_details object reasoning_tokens: token output yang dipakai untuk penalaran. Model open-weight hosted
model string Id kanonis model yang menjawab. Keluarga Shannon 3, model open-weight hosted
created_at integer Waktu balasan, dalam detik Unix. Keluarga Shannon 3, model open-weight hosted
instructions, tools, temperature, … instructions, tools, dan temperature mengulang isi permintaan. error dan incomplete_details adalah null, metadata adalah {}, parallel_tool_calls adalah true, tool_choice adalah auto, dan top_p adalah null. Keluarga Shannon 3

Item output

Item Deskripsi
{"id": "rs_…", "type": "reasoning", "summary": [{"type": "summary_text", "text": "…"}]} Penalaran model sebagai satu bagian summary_text. Hanya ada jika model bernalar.
{"id": "msg_…", "type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "…"}]} Jawabannya: satu bagian output_text berisi teks.
{"id": "fc_…", "type": "function_call", "call_id": "call_…", "name": "…", "arguments": "…"} Pemanggilan tool. arguments adalah string JSON. Kirim hasilnya kembali dengan call_id yang sama.

SDK OpenAI menggabungkan teks pesan untuk Anda di response.output_text.

Streaming

Setel stream ke true untuk server-sent events. Setiap frame memiliki baris event: berisi nama event dan baris data: berisi objek JSON; objek itu mengulang nama tersebut di type. Cocokkan delta dengan item-nya berdasarkan output_index.

Dengan SDK OpenAI, baca event berdasarkan type-nya:

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

Event datang dalam urutan ini. Kelompok untuk penalaran, pesan, dan pemanggilan tool hanya muncul jika balasan memilikinya.

Event Payload Kapan
response.created response Selalu pertama. response.status adalah in_progress dan response.output kosong.
response.in_progress response Selalu kedua, dengan objek yang sama.
response.output_item.added output_index, item Penalaran dimulai: item reasoning dengan summary kosong.
response.reasoning_summary_text.delta output_index, summary_index, delta Sepotong penalaran.
response.reasoning_summary_text.done output_index, summary_index, text Penalaran selesai: seluruh text-nya.
response.output_item.done output_index, item Item reasoning yang sudah selesai.
response.output_item.added output_index, item Jawaban dimulai: item message dengan status in_progress dan tanpa konten.
response.content_part.added output_index, content_index, part Bagian output_text kosong dibuka.
response.output_text.delta output_index, content_index, delta Sepotong jawaban.
response.output_text.done output_index, content_index, text Jawaban selesai: seluruh text-nya.
response.content_part.done output_index, content_index, part Bagian output_text yang sudah selesai.
response.output_item.done output_index, item Item message yang sudah selesai, dengan status completed.
response.output_item.added output_index, item Pemanggilan tool dimulai: item function_call dengan call_id, name, dan arguments kosong.
response.function_call_arguments.delta output_index, delta Argumen panggilan, lengkap dalam satu delta.
response.function_call_arguments.done output_index, arguments Argumen yang sama, sebagai arguments.
response.output_item.done output_index, item Item function_call yang sudah selesai.
response.completed response Selalu terakhir jika berhasil: seluruh objek response dengan output dan 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 yang gagal

Pada tier Shannon, balasan yang gagal berakhir dengan response.failed sebagai ganti response.completed. response.status-nya adalah failed dan response.error berisi code, yaitu rate_limit_exceeded atau server_error, dan sebuah message.

Pada model open-weight hosted, kegagalan berupa event error dengan code api_error dan sebuah message. response.completed tetap menyusul setelahnya.

Anggap stream gagal jika berisi event response.failed atau error, lalu kirim ulang permintaan.

Tool

Tool adalah fungsi yang dijalankan kode Anda. Deskripsikan di tools; ketika model menginginkannya, balasan berisi item function_call sebagai ganti, atau di samping, pesan.

Definisi tool di tools:

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

output balasan yang memanggilnya:

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

Jalankan fungsinya, lalu kirim permintaan lagi dengan panggilan dan hasilnya ditambahkan ke 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\"}"
  }
]

Hanya tool bertipe function yang dibaca. Pada shannon-1.6-*, shannon-2-*, dan shannon-coder-1, skema parameters diringkas menjadi kata kunci JSON Schema yang umum: oneOf dibaca sebagai anyOf, dan kata kunci seperti $ref, additionalProperties, const, default, dan title tidak diteruskan ke model.

Nilai tool_choice required dan fungsi bernama diterapkan oleh model open-weight hosted.

Loop tool dijelaskan lengkap di halamannya sendiri. Pemanggilan fungsi

Output terstruktur

Format ini menuliskan output terstruktur sebagai text.format. Skema berada langsung di format, di samping name dan strict, bukan di bawah anggota json_schema seperti pada Chat Completions.

  • {"type": "json_object"} meminta objek JSON apa pun.
  • {"type": "json_schema", "name", "schema", "strict"} meminta JSON yang mengikuti skema Anda. strict adalah true jika Anda menghilangkannya.
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 datang sebagai teks di bagian output_text pada pesan; parse sendiri. Model open-weight hosted tanpa output terstruktur mengembalikan 400.

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

Model mana yang menerima bentuk mana dicantumkan di halamannya sendiri. Output Terstruktur

Penalaran

Model yang bernalar mengembalikan penalarannya sebagai item output bertipe reasoning, sebelum pesan. Dalam stream, penalaran datang sebagai event response.reasoning_summary_text.delta.

Model open-weight hosted menerapkan reasoning.effort: off, low, medium, atau high, dengan high jika Anda tidak mengirim apa pun. off tidak mengembalikan item reasoning. Kirim sebagai objek; string saja tidak dibaca pada endpoint ini.

Level effort dijelaskan di halamannya sendiri. Reasoning effort

Batas output

max_output_tokens adalah 4,096 jika tidak Anda kirim. Itu adalah jumlah token yang disisihkan dari saldo Anda saat permintaan dimulai; ketika balasan selesai, jumlah itu diganti dengan yang dipakai permintaan. Nilai yang tidak muat dalam sisa saldo Anda mengembalikan 429 Quota exceeded.

Ia membatasi panjang balasan pada shannon-1.6-*, shannon-2-*, dan shannon-coder-1, serta panjang teks jawaban pada model open-weight hosted.

Pada endpoint ini, shannon-coder-1 ditagih dalam token dari saldo Anda, seperti model lainnya.

Body permintaan dapat berukuran hingga 32 MiB. Batas dan saldo

Error

Error memakai body error OpenAI: objek error dengan type dan message; sebagian juga membawa code dan param bernilai null. Tabel mencantumkan yang paling sering dikembalikan endpoint ini. Daftar lengkap, beserta mana yang perlu dicoba ulang, ada di halamannya sendiri. Penanganan kesalahan

Status Type Pesan Kapan
401 authentication_error Missing authentication
Invalid API key
Kunci API tidak dikirim, atau kunci tidak dikenal atau sudah dicabut.
400 invalid_request_error unknown model: <id> model hilang atau bukan id yang dipublikasikan.
400 invalid_request_error No user message provided. Tier Shannon: input tidak berisi teks user.
400 invalid_request_error <id> does not accept image input Gambar dikirim ke model open-weight hosted yang tidak mendukung input gambar.
400 invalid_request_error <id> does not accept response_format text.format dikirim ke model open-weight hosted tanpa output terstruktur.
400 invalid_request_error unknown reasoning effort '<value>'; expected off, low, medium or high reasoning.effort berisi nilai di luar daftar.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … Body adalah JSON valid tetapi sebuah field bertipe salah.
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan max_output_tokens lebih besar dari sisa saldo Anda.
429 rate_limit_error Too many requests. Retry in <n>s. Flood protection: lebih dari 120 permintaan dalam satu menit pada akun Anda.
500 api_error The model backend failed to answer. Please retry. Model tidak menghasilkan balasan. Kirim ulang permintaan.
502 api_error The model backend failed to answer. Please retry. Sama, pada model open-weight hosted.
504 api_error upstream timed out Model open-weight hosted memakan waktu lebih lama dari batas waktu balasan tanpa stream. Kirim dengan stream disetel ke true.