ਸਮੱਗਰੀ ਤੇ ਜਾਓ
Responses API

Responses API

ਨਵਾਂ

POST /v1/responses ਹਦਾਇਤਾਂ ਅਤੇ ਇਨਪੁਟ ਆਈਟਮਾਂ ਦੀ ਸੂਚੀ ਲੈਂਦਾ ਹੈ ਅਤੇ OpenAI Responses ਫਾਰਮੈਟ ਵਿੱਚ ਆਉਟਪੁੱਟ ਆਈਟਮਾਂ ਦਾ ਬਣਿਆ response object ਵਾਪਸ ਕਰਦਾ ਹੈ। ਇਸ ਨੂੰ OpenAI SDK ਦੇ responses API ਨਾਲ ਅਤੇ ਇਸ ਉੱਤੇ ਬਣੇ ਟੂਲਾਂ, ਜਿਵੇਂ Codex CLI, ਨਾਲ ਵਰਤੋ। ਇਹ endpoint ਕੋਈ ਸਥਿਤੀ ਨਹੀਂ ਰੱਖਦਾ: ਹਰ ਰਿਕੁਐਸਟ ਨਾਲ ਪੂਰੀ ਗੱਲਬਾਤ ਭੇਜੋ।

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

ਸਭ ਤੋਂ ਛੋਟੀ ਰਿਕੁਐਸਟ ਇੱਕ ਮਾਡਲ id ਅਤੇ ਇੱਕ ਟੈਕਸਟ ਹੈ। ਜਵਾਬ ਸਟ੍ਰੀਮ ਨਹੀਂ ਹੁੰਦਾ ਜਦੋਂ ਤੱਕ ਤੁਸੀਂ ਇਸਦੀ ਮੰਗ ਨਾ ਕਰੋ।

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)

ਜਵਾਬ ਇੱਕ response object ਹੈ। ਇਸਦੇ output ਵਿੱਚ ਰੀਜ਼ਨਿੰਗ, ਜੇ ਮਾਡਲ ਨੇ ਕੀਤੀ ਹੋਵੇ, ਅਤੇ ਸੰਦੇਸ਼ ਹੁੰਦਾ ਹੈ:

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

ਰਿਕੁਐਸਟ ਫੀਲਡ

ਰਿਕੁਐਸਟ ਨੂੰ model ਅਤੇ input ਚਾਹੀਦੇ ਹਨ। Applied by ਕਾਲਮ ਉਹ ਮਾਡਲ ਦੱਸਦਾ ਹੈ ਜਿਨ੍ਹਾਂ ਉੱਤੇ ਕੋਈ ਫੀਲਡ ਜਵਾਬ ਬਦਲਦਾ ਹੈ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਮਾਡਲ ਸੂਚੀ ਦੀਆਂ ਬਾਰਾਂ ids ਹਨ; Shannon 3 ਪਰਿਵਾਰ shannon-3, shannon-3-pro, shannon-3.1 ਅਤੇ shannon-3.1-pro ਹੈ। ਮਾਡਲ ਅਤੇ ਕੀਮਤਾਂ

ਫੀਲਡ ਕਿਸਮ ਡਿਫੌਲਟ ਵੇਰਵਾ ਕੌਣ ਲਾਗੂ ਕਰਦਾ ਹੈ
model string ਲਾਜ਼ਮੀ। ਮਾਡਲ ਸੂਚੀ ਵਿੱਚੋਂ ਇੱਕ id। ਮਿਲਾਨ ਵਿੱਚ ਛੋਟੇ-ਵੱਡੇ ਅੱਖਰਾਂ ਦਾ ਫ਼ਰਕ ਨਹੀਂ ਪੈਂਦਾ। ਗੈਰਹਾਜ਼ਰ ਜਾਂ ਅਣਪ੍ਰਕਾਸ਼ਿਤ id 400 unknown model ਵਾਪਸ ਕਰਦੀ ਹੈ। ਸਾਰੇ ਮਾਡਲ
input string | array ਇੱਕ string, ਜੋ ਇੱਕ user message ਵਜੋਂ ਪੜ੍ਹੀ ਜਾਂਦੀ ਹੈ, ਜਾਂ ਇਨਪੁਟ ਆਈਟਮਾਂ ਦਾ array। ਹੇਠਾਂ ਇਨਪੁਟ ਆਈਟਮਾਂ ਵੇਖੋ। ਸਾਰੇ ਮਾਡਲ
instructions string ਮਾਡਲ ਲਈ ਹਦਾਇਤਾਂ, ਇਸ ਫਾਰਮੈਟ ਦਾ system prompt। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ, shannon-1.6-*, shannon-2-*, shannon-coder-1
stream boolean false true ਜਵਾਬ ਨੂੰ server-sent events ਵਜੋਂ ਭੇਜਦਾ ਹੈ। ਹੇਠਾਂ ਸਟ੍ਰੀਮਿੰਗ ਵੇਖੋ। ਸਾਰੇ ਮਾਡਲ
max_output_tokens integer 4096 ਜਵਾਬ ਦੀ ਉੱਪਰਲੀ ਹੱਦ, tokens ਵਿੱਚ। 1 ਤੋਂ 65,536 ਤੋਂ ਬਾਹਰ ਦਾ ਮੁੱਲ ਉਸ ਦਾਇਰੇ ਵਿੱਚ ਲਿਆਂਦਾ ਜਾਂਦਾ ਹੈ। ਰਿਕੁਐਸਟ ਚੱਲਣ ਦੌਰਾਨ ਤੁਹਾਡੇ ਬੈਲੇਂਸ ਵਿੱਚੋਂ ਇਹੀ ਰਕਮ ਵੱਖ ਰੱਖੀ ਜਾਂਦੀ ਹੈ। ਹੇਠਾਂ ਆਉਟਪੁੱਟ ਦੀ ਸੀਮਾ ਵੇਖੋ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ, shannon-1.6-*, shannon-2-*, shannon-coder-1
temperature number ਸੈਂਪਲਿੰਗ temperature। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲਾਂ ਉੱਤੇ ਮੁੱਲ 0 ਤੋਂ 2 ਦੇ ਵਿਚਕਾਰ ਰੱਖੇ ਜਾਂਦੇ ਹਨ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ; stream ਨਾ ਕੀਤੇ ਜਵਾਬਾਂ ਉੱਤੇ shannon-1.6-*, shannon-2-* ਅਤੇ shannon-coder-1
top_p number Nucleus ਸੈਂਪਲਿੰਗ। ਮੁੱਲ 0 ਤੋਂ 1 ਦੇ ਵਿਚਕਾਰ ਰੱਖੇ ਜਾਂਦੇ ਹਨ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
tools array ਉਹ ਫੰਕਸ਼ਨ ਜੋ ਮਾਡਲ ਕਾਲ ਕਰ ਸਕਦਾ ਹੈ, ਇਸ ਫਾਰਮੈਟ ਦੇ ਸਮਤਲ ਰੂਪ ਵਿੱਚ: {"type": "function", "name", "description", "parameters"}। ਹੇਠਾਂ ਟੂਲ ਵੇਖੋ। ਸਾਰੇ ਮਾਡਲ
tool_choice string | object auto "auto" ਮਾਡਲ ਨੂੰ ਫੈਸਲਾ ਕਰਨ ਦਿੰਦਾ ਹੈ। "required" ਉਸ ਤੋਂ ਟੂਲ ਕਾਲ ਕਰਵਾਉਂਦਾ ਹੈ। {"type": "function", "name": "…"} ਉਸ ਤੋਂ ਉਹੀ ਟੂਲ ਕਾਲ ਕਰਵਾਉਂਦਾ ਹੈ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
reasoning object off, low, medium ਜਾਂ high ਨਾਲ {"effort": "…"}। ਕੋਈ ਹੋਰ ਮੁੱਲ 400 ਵਾਪਸ ਕਰਦਾ ਹੈ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
text object {"format": {…}} JSON ਜਵਾਬ ਮੰਗਦਾ ਹੈ। ਹੇਠਾਂ ਸੰਗਠਿਤ ਆਉਟਪੁੱਟ ਵੇਖੋ। ਸਾਰੇ Shannon ਟੀਅਰ; ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਜਿਵੇਂ ਹਰ id ਲਈ ਸੂਚੀਬੱਧ ਹੈ

previous_response_id, store, metadata, parallel_tool_calls, truncation, include, user ਅਤੇ prompt_cache_key ਇਸ ਲਈ ਸਵੀਕਾਰ ਕੀਤੇ ਜਾਂਦੇ ਹਨ ਕਿ ਮੌਜੂਦਾ ਕਲਾਇੰਟ ਕੋਡ ਬਿਨਾਂ ਬਦਲਾਅ ਦੇ ਚੱਲੇ। ਉਹ ਜਵਾਬ ਨਹੀਂ ਬਦਲਦੇ। ਕਿਉਂਕਿ ਕੋਈ ਗੱਲਬਾਤ ਸਟੋਰ ਨਹੀਂ ਹੁੰਦੀ, ਅਗਲੀ ਰਿਕੁਐਸਟ ਪਿਛਲੇ turns ਨੂੰ input ਵਿੱਚ ਲੈ ਕੇ ਜਾਂਦੀ ਹੈ।

ਇਨਪੁਟ ਆਈਟਮਾਂ

ਇਨਪੁਟ ਆਈਟਮ ਜਾਂ ਤਾਂ role ਅਤੇ content ਵਾਲਾ ਇੱਕ message ਹੈ, ਜਾਂ ਕਿਸਮ ਵਾਲੀ ਆਈਟਮ ਜੋ ਟੂਲ ਕਾਲ ਜਾਂ ਉਸ ਦਾ ਨਤੀਜਾ ਲੈ ਕੇ ਜਾਂਦੀ ਹੈ। content ਇੱਕ string ਜਾਂ parts ਦਾ array ਹੈ।

ਆਈਟਮ ਵੇਰਵਾ ਕੌਣ ਲਾਗੂ ਕਰਦਾ ਹੈ
{"role": "user", "content": …} ਜੋ ਤੁਸੀਂ ਪੁੱਛਦੇ ਹੋ। content ਇੱਕ string ਹੈ, ਜਾਂ input_text ਅਤੇ input_image parts। ਸਾਰੇ ਮਾਡਲ
{"role": "assistant", "content": …} ਮਾਡਲ ਦਾ ਪਿਛਲਾ ਜਵਾਬ। content ਇੱਕ string ਹੈ, ਜਾਂ output_text parts। ਸਾਰੇ ਮਾਡਲ
{"role": "system", "content": …}
{"role": "developer", "content": …}
ਗੱਲਬਾਤ ਦੇ ਅੰਦਰ ਹਦਾਇਤਾਂ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
{"type": "function_call", "call_id": "…", "name": "…", "arguments": "…"} ਇੱਕ ਟੂਲ ਕਾਲ ਜੋ ਮਾਡਲ ਨੇ ਪਿਛਲੇ ਜਵਾਬ ਵਿੱਚ ਕੀਤੀ। arguments ਇੱਕ JSON string ਹੈ। ਸਾਰੇ ਮਾਡਲ
{"type": "function_call_output", "call_id": "…", "output": "…"} ਉਸ ਕਾਲ ਦਾ ਨਤੀਜਾ। call_id ਕਾਲ ਦੀ id ਹੈ ਅਤੇ output ਨਤੀਜਾ string ਵਜੋਂ। ਸਾਰੇ ਮਾਡਲ

ਹਦਾਇਤਾਂ ਨੂੰ instructions ਫੀਲਡ ਵਿੱਚ ਪਾਓ। Shannon 3 ਪਰਿਵਾਰ ਦੀ id ਨਾਲ, ਜੋ ਹਦਾਇਤਾਂ ਲਾਜ਼ਮੀ ਹਨ ਉਨ੍ਹਾਂ ਨੂੰ user message ਵਿੱਚ ਪਾਓ।

ਜਵਾਬ ਦੇ output ਦੀਆਂ ਆਈਟਮਾਂ ਜਿਉਂ ਦੀਆਂ ਤਿਉਂ input ਵਿੱਚ ਵਾਪਸ ਜਾ ਸਕਦੀਆਂ ਹਨ: message ਅਤੇ function_call ਆਈਟਮਾਂ ਪੜ੍ਹੀਆਂ ਜਾਂਦੀਆਂ ਹਨ, reasoning ਆਈਟਮਾਂ ਛੱਡ ਦਿੱਤੀਆਂ ਜਾਂਦੀਆਂ ਹਨ।

Content parts

ਹਿੱਸਾ ਵੇਰਵਾ ਕਿੱਥੇ ਉਪਲਬਧ
{"type": "input_text", "text": "…"} user message ਦਾ ਟੈਕਸਟ। ਸਾਰੇ ਮਾਡਲ
{"type": "output_text", "text": "…"} ਅਸਿਸਟੈਂਟ ਸੰਦੇਸ਼ ਦਾ ਟੈਕਸਟ। ਸਾਰੇ ਮਾਡਲ
{"type": "input_image", "image_url": "…"} ਇੱਕ ਇਮੇਜ, base64 ਸਮੱਗਰੀ ਵਾਲੇ data: URL ਵਜੋਂ ਜਾਂ http(s) URL ਵਜੋਂ। Shannon 3 ਪਰਿਵਾਰ, shannon-1.6-lite, shannon-1.6-pro, ਅਤੇ ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਜੋ ਇਮੇਜ ਇਨਪੁਟ ਸੂਚੀਬੱਧ ਕਰਦੇ ਹਨ
{"type": "input_file", "file_data": "data:application/pdf;base64,…"} ਇੱਕ ਦਸਤਾਵੇਜ਼ (PDF, Word, PowerPoint ਜਾਂ Excel): file_data ਵਿੱਚ data: URL ਹੁੰਦਾ ਹੈ, ਜਾਂ file_url ਵਿੱਚ http(s) URL। Shannon 3 ਪਰਿਵਾਰ

Shannon ਟੀਅਰਾਂ ਉੱਤੇ ਇਮੇਜਾਂ ਅਤੇ ਫਾਈਲਾਂ input ਦੀ ਆਖਰੀ user ਆਈਟਮ ਤੋਂ ਪੜ੍ਹੀਆਂ ਜਾਂਦੀਆਂ ਹਨ। ਆਕਾਰ ਅਤੇ ਸੀਮਾਵਾਂ ਦਾ ਆਪਣਾ ਪੰਨਾ ਹੈ। ਇਮੇਜਾਂ ਅਤੇ ਫਾਈਲਾਂ

ਹਦਾਇਤਾਂ ਅਤੇ ਵਿਕਲਪਾਂ ਵਾਲੀ ਰਿਕੁਐਸਟ

ਇਹ ਰਿਕੁਐਸਟ instructions, ਇਨਪੁਟ ਆਈਟਮਾਂ ਵਜੋਂ ਇੱਕ ਗੱਲਬਾਤ, ਆਉਟਪੁੱਟ ਦੀ ਸੀਮਾ, ਇੱਕ temperature ਅਤੇ ਇੱਕ reasoning effort ਭੇਜਦੀ ਹੈ। ਇਹ ਇੱਕ ਹੋਸਟ ਕੀਤਾ open-weight ਮਾਡਲ ਵਰਤਦੀ ਹੈ, ਜੋ ਇਨ੍ਹਾਂ ਸਭ ਨੂੰ ਲਾਗੂ ਕਰਦਾ ਹੈ।

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)

ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਦੇ ਜਵਾਬ ਵਿੱਚ id, object, model, created_at, status, output ਅਤੇ usage ਹੁੰਦੇ ਹਨ। ਇਸਦਾ usage ਕੈਸ਼ ਤੋਂ ਪੜ੍ਹੇ ਟੋਕਨ ਅਤੇ ਰੀਜ਼ਨਿੰਗ ਉੱਤੇ ਖਰਚ ਹੋਏ ਟੋਕਨ ਵੀ ਜੋੜਦਾ ਹੈ:

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 ਅਤੇ usage ਹਰ ਜਵਾਬ ਵਿੱਚ ਹੁੰਦੇ ਹਨ। ਆਪਣਾ ਕੋਡ ਇਨ੍ਹਾਂ ਉੱਤੇ ਬਣਾਓ।

ਫੀਲਡ ਕਿਸਮ ਵੇਰਵਾ ਕੌਣ ਭੇਜਦਾ ਹੈ
id string resp_ ਅਤੇ ਉਸ ਤੋਂ ਬਾਅਦ 32 ਹੈਕਸਾਡੈਸੀਮਲ ਅੱਖਰ। ਸਾਰੇ ਮਾਡਲ
object string ਹਮੇਸ਼ਾ response। ਸਾਰੇ ਮਾਡਲ
status string completed। ਸਟ੍ਰੀਮ ਵਿੱਚ ਇਹ ਪਹਿਲਾਂ in_progress ਹੁੰਦਾ ਹੈ, ਅਤੇ response.failed ਇਵੈਂਟ ਵਿੱਚ failed। ਸਾਰੇ ਮਾਡਲ
output array ਆਉਟਪੁੱਟ ਆਈਟਮ ਉਸ ਕ੍ਰਮ ਵਿੱਚ ਜਿਸ ਵਿੱਚ ਮਾਡਲ ਨੇ ਉਨ੍ਹਾਂ ਨੂੰ ਬਣਾਇਆ: reasoning, message, function_call। ਸਾਰੇ ਮਾਡਲ
usage object input_tokens, output_tokens ਅਤੇ total_tokens। ਸਾਰੇ ਮਾਡਲ
usage.input_tokens_details object cached_tokens: ਪ੍ਰੋਂਪਟ ਕੈਸ਼ ਤੋਂ ਪੜ੍ਹੇ ਗਏ ਇਨਪੁਟ ਟੋਕਨ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
usage.output_tokens_details object reasoning_tokens: ਰੀਜ਼ਨਿੰਗ ਉੱਤੇ ਖਰਚ ਹੋਏ ਆਉਟਪੁੱਟ ਟੋਕਨ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
model string ਜਵਾਬ ਦੇਣ ਵਾਲੇ ਮਾਡਲ ਦਾ canonical id। Shannon 3 ਪਰਿਵਾਰ, ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
created_at integer ਜਵਾਬ ਦਾ ਸਮਾਂ, Unix ਸਕਿੰਟਾਂ ਵਿੱਚ। Shannon 3 ਪਰਿਵਾਰ, ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
instructions, tools, temperature, … instructions, tools ਅਤੇ temperature ਰਿਕੁਐਸਟ ਨੂੰ ਦੁਹਰਾਉਂਦੇ ਹਨ। error ਅਤੇ incomplete_details null ਹਨ, metadata {} ਹੈ, parallel_tool_calls true ਹੈ, tool_choice auto ਹੈ ਅਤੇ top_p null ਹੈ। Shannon 3 ਪਰਿਵਾਰ

ਆਉਟਪੁੱਟ ਆਈਟਮ

ਆਈਟਮ ਵੇਰਵਾ
{"id": "rs_…", "type": "reasoning", "summary": [{"type": "summary_text", "text": "…"}]} ਮਾਡਲ ਦੀ ਰੀਜ਼ਨਿੰਗ ਇੱਕ summary_text ਹਿੱਸੇ ਵਜੋਂ। ਸਿਰਫ਼ ਤਾਂ ਹੀ ਹੁੰਦਾ ਹੈ ਜਦੋਂ ਮਾਡਲ ਨੇ ਰੀਜ਼ਨਿੰਗ ਕੀਤੀ ਹੋਵੇ।
{"id": "msg_…", "type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "…"}]} ਜਵਾਬ: ਟੈਕਸਟ ਵਾਲਾ ਇੱਕ output_text ਹਿੱਸਾ।
{"id": "fc_…", "type": "function_call", "call_id": "call_…", "name": "…", "arguments": "…"} ਇੱਕ ਟੂਲ ਕਾਲ। arguments ਇੱਕ JSON string ਹੈ। ਨਤੀਜਾ ਉਸੇ call_id ਨਾਲ ਵਾਪਸ ਭੇਜੋ।

OpenAI SDK ਸੰਦੇਸ਼ ਦਾ ਟੈਕਸਟ ਤੁਹਾਡੇ ਲਈ response.output_text ਵਿੱਚ ਜੋੜ ਦਿੰਦੇ ਹਨ।

ਸਟ੍ਰੀਮਿੰਗ

server-sent events ਲਈ stream ਨੂੰ true ਕਰੋ। ਹਰ ਫਰੇਮ ਵਿੱਚ ਇਵੈਂਟ ਦੇ ਨਾਮ ਵਾਲੀ ਇੱਕ event: ਲਾਈਨ ਅਤੇ JSON object ਵਾਲੀ ਇੱਕ data: ਲਾਈਨ ਹੁੰਦੀ ਹੈ; object type ਵਿੱਚ ਨਾਮ ਦੁਹਰਾਉਂਦਾ ਹੈ। deltas ਨੂੰ ਉਨ੍ਹਾਂ ਦੀ ਆਈਟਮ ਨਾਲ output_index ਰਾਹੀਂ ਮਿਲਾਓ।

OpenAI SDK ਨਾਲ ਇਵੈਂਟਾਂ ਨੂੰ ਉਨ੍ਹਾਂ ਦੇ 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")

ਇਵੈਂਟ ਇਸ ਕ੍ਰਮ ਵਿੱਚ ਆਉਂਦੇ ਹਨ। ਰੀਜ਼ਨਿੰਗ, ਸੰਦੇਸ਼ ਅਤੇ ਟੂਲ ਕਾਲਾਂ ਦੇ ਸਮੂਹ ਸਿਰਫ਼ ਤਾਂ ਹੀ ਆਉਂਦੇ ਹਨ ਜਦੋਂ ਜਵਾਬ ਵਿੱਚ ਉਹ ਹੋਣ।

Event Payload ਕਦੋਂ
response.created response ਹਮੇਸ਼ਾ ਪਹਿਲਾ। response.status in_progress ਹੁੰਦਾ ਹੈ ਅਤੇ response.output ਖਾਲੀ ਹੁੰਦਾ ਹੈ।
response.in_progress response ਹਮੇਸ਼ਾ ਦੂਜਾ, ਉਸੇ object ਨਾਲ।
response.output_item.added output_index, item ਰੀਜ਼ਨਿੰਗ ਸ਼ੁਰੂ ਹੁੰਦੀ ਹੈ: ਖਾਲੀ summary ਵਾਲੀ ਇੱਕ reasoning ਆਈਟਮ।
response.reasoning_summary_text.delta output_index, summary_index, delta ਰੀਜ਼ਨਿੰਗ ਦਾ ਇੱਕ ਟੁਕੜਾ।
response.reasoning_summary_text.done output_index, summary_index, text ਰੀਜ਼ਨਿੰਗ ਪੂਰੀ ਹੋ ਗਈ: ਇਸਦਾ ਪੂਰਾ text।
response.output_item.done output_index, item ਮੁਕੰਮਲ ਹੋਈ reasoning ਆਈਟਮ।
response.output_item.added output_index, item ਜਵਾਬ ਸ਼ੁਰੂ ਹੁੰਦਾ ਹੈ: ਸਟੇਟਸ in_progress ਅਤੇ ਬਿਨਾਂ ਸਮੱਗਰੀ ਵਾਲੀ ਇੱਕ message ਆਈਟਮ।
response.content_part.added output_index, content_index, part ਇੱਕ ਖਾਲੀ output_text ਹਿੱਸਾ ਖੁੱਲ੍ਹਦਾ ਹੈ।
response.output_text.delta output_index, content_index, delta ਜਵਾਬ ਦਾ ਇੱਕ ਟੁਕੜਾ।
response.output_text.done output_index, content_index, text ਜਵਾਬ ਪੂਰਾ ਹੋ ਗਿਆ: ਇਸਦਾ ਪੂਰਾ text।
response.content_part.done output_index, content_index, part ਮੁਕੰਮਲ ਹੋਇਆ output_text ਹਿੱਸਾ।
response.output_item.done output_index, item ਮੁਕੰਮਲ ਹੋਈ message ਆਈਟਮ, ਸਟੇਟਸ completed ਨਾਲ।
response.output_item.added output_index, item ਇੱਕ ਟੂਲ ਕਾਲ ਸ਼ੁਰੂ ਹੁੰਦੀ ਹੈ: call_id, name ਅਤੇ ਖਾਲੀ arguments ਵਾਲੀ ਇੱਕ function_call ਆਈਟਮ।
response.function_call_arguments.delta output_index, delta ਕਾਲ ਦੇ arguments, ਇੱਕ ਹੀ delta ਵਿੱਚ ਪੂਰੇ।
response.function_call_arguments.done output_index, arguments ਉਹੀ arguments, arguments ਵਜੋਂ।
response.output_item.done output_index, item ਮੁਕੰਮਲ ਹੋਈ function_call ਆਈਟਮ।
response.completed response ਸਫਲਤਾ ਉੱਤੇ ਹਮੇਸ਼ਾ ਆਖਰੀ: output ਅਤੇ usage ਸਮੇਤ ਪੂਰਾ response object।
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}, …}}

ਅਸਫਲ ਹੋਣ ਵਾਲੀ ਸਟ੍ਰੀਮ

Shannon ਟੀਅਰਾਂ ਉੱਤੇ ਅਸਫਲ ਜਵਾਬ response.completed ਦੀ ਥਾਂ response.failed ਨਾਲ ਖਤਮ ਹੁੰਦਾ ਹੈ। ਇਸਦਾ response.status failed ਹੁੰਦਾ ਹੈ ਅਤੇ response.error ਵਿੱਚ ਇੱਕ code, ਜੋ rate_limit_exceeded ਜਾਂ server_error ਹੈ, ਅਤੇ ਇੱਕ message ਹੁੰਦਾ ਹੈ।

ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲਾਂ ਉੱਤੇ ਅਸਫਲਤਾ ਇੱਕ error ਇਵੈਂਟ ਹੁੰਦੀ ਹੈ, ਜਿਸ ਵਿੱਚ code api_error ਅਤੇ ਇੱਕ message ਹੁੰਦਾ ਹੈ। ਇਸਦੇ ਬਾਅਦ ਵੀ response.completed ਆਉਂਦਾ ਹੈ।

ਜਦੋਂ ਸਟ੍ਰੀਮ ਵਿੱਚ response.failed ਜਾਂ error ਇਵੈਂਟ ਹੋਵੇ ਤਾਂ ਉਸਨੂੰ ਅਸਫਲ ਮੰਨੋ ਅਤੇ ਰਿਕੁਐਸਟ ਦੁਬਾਰਾ ਭੇਜੋ।

ਟੂਲ

ਟੂਲ ਇੱਕ ਫੰਕਸ਼ਨ ਹੈ ਜਿਸਨੂੰ ਤੁਹਾਡਾ ਕੋਡ ਚਲਾਉਂਦਾ ਹੈ। ਇਸਦਾ ਵੇਰਵਾ tools ਵਿੱਚ ਦਿਓ; ਜਦੋਂ ਮਾਡਲ ਨੂੰ ਇਹ ਚਾਹੀਦਾ ਹੋਵੇ, ਤਾਂ ਜਵਾਬ ਵਿੱਚ ਸੰਦੇਸ਼ ਦੀ ਥਾਂ, ਜਾਂ ਉਸਦੇ ਨਾਲ, ਇੱਕ function_call ਆਈਟਮ ਹੁੰਦੀ ਹੈ।

tools ਵਿੱਚ ਇੱਕ ਟੂਲ ਪਰਿਭਾਸ਼ਾ:

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

ਉਸਨੂੰ ਕਾਲ ਕਰਨ ਵਾਲੇ ਜਵਾਬ ਦਾ output:

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

ਫੰਕਸ਼ਨ ਚਲਾਓ, ਫਿਰ ਕਾਲ ਅਤੇ ਉਸਦੇ ਨਤੀਜੇ ਨੂੰ 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\"}"
  }
]

ਸਿਰਫ਼ function ਕਿਸਮ ਦੇ ਟੂਲ ਪੜ੍ਹੇ ਜਾਂਦੇ ਹਨ। shannon-1.6-*, shannon-2-* ਅਤੇ shannon-coder-1 ਉੱਤੇ parameters schema ਨੂੰ ਆਮ JSON Schema ਕੀਵਰਡਾਂ ਤੱਕ ਘਟਾ ਦਿੱਤਾ ਜਾਂਦਾ ਹੈ: oneOf ਨੂੰ anyOf ਵਜੋਂ ਪੜ੍ਹਿਆ ਜਾਂਦਾ ਹੈ, ਅਤੇ $ref, additionalProperties, const, default ਅਤੇ title ਵਰਗੇ ਕੀਵਰਡ ਮਾਡਲ ਨੂੰ ਨਹੀਂ ਭੇਜੇ ਜਾਂਦੇ।

tool_choice ਦੇ ਮੁੱਲ required ਅਤੇ ਨਾਮ ਦੇ ਕੇ ਚੁਣਿਆ ਫੰਕਸ਼ਨ ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਲਾਗੂ ਕਰਦੇ ਹਨ।

ਟੂਲ ਲੂਪ ਦਾ ਪੂਰਾ ਵੇਰਵਾ ਉਸਦੇ ਆਪਣੇ ਪੰਨੇ ਉੱਤੇ ਹੈ। ਫੰਕਸ਼ਨ ਕਾਲਿੰਗ

ਸੰਗਠਿਤ ਆਉਟਪੁੱਟ

ਇਹ ਫਾਰਮੈਟ structured output ਨੂੰ text.format ਵਜੋਂ ਲਿਖਦਾ ਹੈ। schema ਸਿੱਧੀ format ਵਿੱਚ, name ਅਤੇ strict ਦੇ ਕੋਲ ਹੁੰਦੀ ਹੈ, json_schema ਮੈਂਬਰ ਹੇਠ ਨਹੀਂ ਜਿਵੇਂ Chat Completions ਵਿੱਚ ਹੁੰਦੀ ਹੈ।

  • {"type": "json_object"} ਕਿਸੇ ਵੀ JSON object ਦੀ ਮੰਗ ਕਰਦਾ ਹੈ।
  • {"type": "json_schema", "name", "schema", "strict"} ਤੁਹਾਡੀ schema ਦੀ ਪਾਲਣਾ ਕਰਨ ਵਾਲੇ JSON ਦੀ ਮੰਗ ਕਰਦਾ ਹੈ। ਜੇ ਤੁਸੀਂ strict ਛੱਡ ਦਿਓ ਤਾਂ ਇਹ true ਹੁੰਦਾ ਹੈ।
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 ਸੰਦੇਸ਼ ਦੇ output_text ਹਿੱਸੇ ਵਿੱਚ ਟੈਕਸਟ ਵਜੋਂ ਆਉਂਦਾ ਹੈ; ਇਸਨੂੰ ਆਪ parse ਕਰੋ। structured output ਤੋਂ ਬਿਨਾਂ ਹੋਸਟ ਕੀਤਾ open-weight ਮਾਡਲ 400 ਵਾਪਸ ਕਰਦਾ ਹੈ।

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

ਕਿਹੜਾ ਮਾਡਲ ਕਿਹੜਾ ਰੂਪ ਲੈਂਦਾ ਹੈ, ਇਹ ਉਸਦੇ ਆਪਣੇ ਪੰਨੇ ਉੱਤੇ ਦਿੱਤਾ ਹੈ। ਸਟ੍ਰਕਚਰਡ ਆਉਟਪੁੱਟਸ

ਰੀਜ਼ਨਿੰਗ

ਰੀਜ਼ਨਿੰਗ ਕਰਨ ਵਾਲਾ ਮਾਡਲ ਆਪਣੀ ਰੀਜ਼ਨਿੰਗ reasoning ਕਿਸਮ ਦੀ ਆਉਟਪੁੱਟ ਆਈਟਮ ਵਜੋਂ, ਸੰਦੇਸ਼ ਤੋਂ ਪਹਿਲਾਂ, ਵਾਪਸ ਕਰਦਾ ਹੈ। ਸਟ੍ਰੀਮ ਵਿੱਚ ਇਹ response.reasoning_summary_text.delta ਇਵੈਂਟਾਂ ਵਜੋਂ ਆਉਂਦੀ ਹੈ।

ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ reasoning.effort ਲਾਗੂ ਕਰਦੇ ਹਨ: off, low, medium ਜਾਂ high; ਕੁਝ ਨਾ ਭੇਜਣ ਉੱਤੇ high ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ। off ਕੋਈ reasoning ਆਈਟਮ ਵਾਪਸ ਨਹੀਂ ਕਰਦਾ। ਇਸਨੂੰ object ਵਜੋਂ ਭੇਜੋ; ਇਸ endpoint ਉੱਤੇ ਸਿਰਫ਼ string ਪੜ੍ਹੀ ਨਹੀਂ ਜਾਂਦੀ।

effort ਦੇ ਪੱਧਰਾਂ ਦਾ ਵੇਰਵਾ ਉਨ੍ਹਾਂ ਦੇ ਆਪਣੇ ਪੰਨੇ ਉੱਤੇ ਹੈ। ਰੀਜ਼ਨਿੰਗ effort

ਆਉਟਪੁੱਟ ਦੀ ਸੀਮਾ

ਜਦੋਂ ਤੁਸੀਂ max_output_tokens ਨਾ ਭੇਜੋ ਤਾਂ ਇਹ 4,096 ਹੁੰਦਾ ਹੈ। ਇਹ ਉਹ tokens ਦੀ ਗਿਣਤੀ ਹੈ ਜੋ ਰਿਕੁਐਸਟ ਸ਼ੁਰੂ ਹੋਣ ਸਮੇਂ ਤੁਹਾਡੇ ਬੈਲੇਂਸ ਵਿੱਚੋਂ ਵੱਖ ਰੱਖੇ ਜਾਂਦੇ ਹਨ; ਜਵਾਬ ਪੂਰਾ ਹੋਣ ਉੱਤੇ ਉਹ ਰਕਮ ਉਸ ਨਾਲ ਬਦਲ ਦਿੱਤੀ ਜਾਂਦੀ ਹੈ ਜੋ ਰਿਕੁਐਸਟ ਨੇ ਵਰਤਿਆ। ਜੋ ਮੁੱਲ ਤੁਹਾਡੇ ਬਾਕੀ ਬੈਲੇਂਸ ਵਿੱਚ ਨਹੀਂ ਸਮਾਉਂਦਾ ਉਹ 429 Quota exceeded ਵਾਪਸ ਕਰਦਾ ਹੈ।

ਇਹ shannon-1.6-*, shannon-2-* ਅਤੇ shannon-coder-1 ਉੱਤੇ ਜਵਾਬ ਦੀ ਲੰਬਾਈ ਨੂੰ, ਅਤੇ ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲਾਂ ਉੱਤੇ ਜਵਾਬ ਦੇ ਟੈਕਸਟ ਦੀ ਲੰਬਾਈ ਨੂੰ ਸੀਮਤ ਕਰਦਾ ਹੈ।

ਇਸ endpoint ਉੱਤੇ shannon-coder-1 ਦਾ ਚਾਰਜ ਹਰ ਹੋਰ ਮਾਡਲ ਵਾਂਗ ਤੁਹਾਡੇ ਬੈਲੇਂਸ ਦੇ tokens ਵਿੱਚ ਲੱਗਦਾ ਹੈ।

ਰਿਕੁਐਸਟ body 32 MiB ਤੱਕ ਹੋ ਸਕਦੀ ਹੈ। ਸੀਮਾਵਾਂ ਅਤੇ ਬੈਲੇਂਸ

ਗਲਤੀਆਂ

ਗਲਤੀਆਂ OpenAI ਦੀ ਗਲਤੀ body ਵਰਤਦੀਆਂ ਹਨ: type ਅਤੇ message ਵਾਲਾ error object; ਕੁਝ ਵਿੱਚ ਮੁੱਲ null ਨਾਲ code ਅਤੇ param ਵੀ ਹੁੰਦੇ ਹਨ। ਟੇਬਲ ਉਹ ਸੂਚੀਬੱਧ ਕਰਦਾ ਹੈ ਜੋ ਇਹ endpoint ਸਭ ਤੋਂ ਵੱਧ ਵਾਰ ਵਾਪਸ ਕਰਦਾ ਹੈ। ਪੂਰੀ ਸੂਚੀ, ਇਸ ਸਮੇਤ ਕਿ ਕੀ ਦੁਬਾਰਾ ਅਜ਼ਮਾਉਣਾ ਹੈ, ਦਾ ਆਪਣਾ ਪੰਨਾ ਹੈ। ਗਲਤੀਆਂ

ਸਟੇਟਸ ਕਿਸਮ ਸੁਨੇਹਾ ਕਦੋਂ
401 authentication_error Missing authentication
Invalid API key
ਕੋਈ API key ਨਹੀਂ ਭੇਜੀ ਗਈ, ਜਾਂ key ਅਣਜਾਣ ਹੈ ਜਾਂ ਰੱਦ ਕੀਤੀ ਗਈ ਹੈ।
400 invalid_request_error unknown model: <id> model ਗੈਰਹਾਜ਼ਰ ਹੈ ਜਾਂ ਪ੍ਰਕਾਸ਼ਿਤ id ਨਹੀਂ ਹੈ।
400 invalid_request_error No user message provided. Shannon ਟੀਅਰ: input ਵਿੱਚ user ਟੈਕਸਟ ਨਹੀਂ ਹੈ।
400 invalid_request_error <id> does not accept image input ਇਮੇਜ ਇਨਪੁਟ ਤੋਂ ਬਿਨਾਂ ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਨੂੰ ਇੱਕ ਇਮੇਜ ਭੇਜੀ ਗਈ।
400 invalid_request_error <id> does not accept response_format ਸੰਗਠਿਤ ਆਉਟਪੁੱਟ ਤੋਂ ਬਿਨਾਂ ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਨੂੰ text.format ਭੇਜਿਆ ਗਿਆ।
400 invalid_request_error unknown reasoning effort '<value>'; expected off, low, medium or high reasoning.effort ਵਿੱਚ ਸੂਚੀ ਤੋਂ ਬਾਹਰ ਦਾ ਮੁੱਲ ਹੈ।
422 invalid_request_error Failed to deserialize the JSON body into the target type: … body ਜਾਇਜ਼ JSON ਹੈ ਪਰ ਕਿਸੇ ਫੀਲਡ ਦੀ ਕਿਸਮ ਗਲਤ ਹੈ।
429 rate_limit_error Quota exceeded. Upgrade your plan at shannon-ai.com/plan max_output_tokens ਤੁਹਾਡੇ ਬੈਲੇਂਸ ਵਿੱਚ ਬਚੀ ਰਕਮ ਤੋਂ ਵੱਡਾ ਹੈ।
429 rate_limit_error Too many requests. Retry in <n>s. ਫਲੱਡ ਪ੍ਰੋਟੈਕਸ਼ਨ: ਤੁਹਾਡੇ ਖਾਤੇ ਉੱਤੇ ਇੱਕ ਮਿੰਟ ਵਿੱਚ 120 ਤੋਂ ਵੱਧ ਰਿਕੁਐਸਟਾਂ।
500 api_error The model backend failed to answer. Please retry. ਮਾਡਲ ਨੇ ਜਵਾਬ ਨਹੀਂ ਬਣਾਇਆ। ਰਿਕੁਐਸਟ ਦੁਬਾਰਾ ਭੇਜੋ।
502 api_error The model backend failed to answer. Please retry. ਉਹੀ, ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲਾਂ ਉੱਤੇ।
504 api_error upstream timed out ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਨੇ stream ਨਾ ਕੀਤੇ ਜਵਾਬ ਦੀ ਸਮਾਂ ਸੀਮਾ ਤੋਂ ਵੱਧ ਸਮਾਂ ਲਿਆ। ਇਸ ਨੂੰ stream ਨੂੰ true ਕਰ ਕੇ ਭੇਜੋ।