Content पर जाएं

Session बनाएँ

POST/v1/agents/sessions

किसी saved Agent version के लिए, या request में परिभाषित inline Agent के लिए Session बनाएँ। Agent configuration, Skill versions और MCP connections Session के पूरे जीवनकाल के लिए frozen रहते हैं। Sessions हमेशा SandBase के hosted cloud में चलते हैं, इसलिए कोई execution environment चुनना नहीं पड़ता। stream=true और initial input के साथ, response JSON Session के बजाय पहले turn का 201 Server-Sent Events stream होता है। Execution admission (balance और organization status) यहीं जाँचा जाता है। OpenAI SDK को environment argument चाहिए; OpenAI compatibility (/agents/openai-compatibility) देखें।

Headers

वैकल्पिक<string>Idempotency-Key

वैकल्पिक। न भेजने पर सर्विस खुद एक key बनाती है, इसलिए दोबारा भेजा गया request डुप्लिकेट बना सकता है। retry के लिए अपनी स्थिर key भेजें।

Request body

Strict JSON object।

वैकल्पिक<string>agent_id

Saved Agent ID (agt_ prefix)। Agent active होना चाहिए और उसका projection_status ready होना चाहिए। agent_id, agent, या दोनों भेजें।

वैकल्पिक<object>agent

Agent configuration। स्वीकार किए जाने वाले fields हैं model, instructions, runtime_profile (codex, claude, या mcode; default codex), service_tier, tools, text, reasoning और multi_agent, जिन्हें Create Agent की तरह validate किया जाता है। agent_id के बिना यह inline Agent परिभाषित करता है और model आवश्यक है; inline Agents में कोई Skills या MCP connections नहीं होते। agent_id के साथ, आपके भेजे गए हर field से saved version का वह field केवल इसी Session के लिए बदल जाता है। अज्ञात fields 400 लौटाते हैं।

वैकल्पिक<integer>version

Agent version। Default रूप से current version। inline Agent के साथ अनुमति नहीं है।

वैकल्पिक<string>title

Session title।

वैकल्पिक<string | array>input

वैकल्पिक पहला input: एक string, या ठीक एक message वाला array, जैसे [{"role":"user","content":[{"type":"input_text","text":"…"}]}]। अकेला object 400 लौटाता है।

वैकल्पिक<string>model

Model override। agent.model OpenAI SDK वाला रूप है; दोनों भेजने पर उनका मेल खाना ज़रूरी है।

वैकल्पिक<object>metadata

अधिकतम 16 string pairs।

वैकल्पिक<boolean>stream

true होने पर non-empty input आवश्यक है और text/event-stream body के साथ 201 लौटता है। Events, Stream events format (event: <type>, data: <json>) का उपयोग करते हैं; पहला event, agent.session.created, Session snapshot लाता है, जिसके बाद turn के item और output events आते हैं। Stream शुरू होने से पहले की validation, admission और अन्य errors सामान्य JSON error लौटाती हैं। Default false।

वैकल्पिक<object>environment

केवल OpenAI SDK compatibility के लिए। सीधे HTTP calls में इसे न भेजें; {"type":"openai_hosted"} स्वीकार किया जाता है और कोई अन्य type 400 लौटाता है।

वैकल्पिक<object>model_provider

Model credential। अपनी calling API key इस्तेमाल करने के लिए इसे न भेजें। {"type":"custom","base_url":"https://…","api_key":"…"} आपके अपने OpenAI-compatible endpoint को call करता है। Write-only।

वैकल्पिक<object>github_workspace

इस Session के लिए /workspace में clone की जाने वाली GitHub repository: {"repository_id":"1195090324","ref":"main","connection_id":"plc_…"}। केवल repository_id आवश्यक है; ref default रूप से default branch है। न भेजने या null होने पर Agent की workspace repository (यदि हो) इस्तेमाल होती है, अन्यथा कुछ भी clone नहीं होता। Repository Agent के GitHub connection scope में होनी चाहिए। GitHub repository workspace (/agents/github-workspace) देखें।

Session object

create, get, update, rename, archive और unarchive द्वारा लौटाया जाता है।

stringidज़रूरी

ses_ prefix वाला Session ID।

stringstatusज़रूरी

Execution status: idle, in_progress या failed। requires_action अभी समर्थित नहीं है और 502 executor_contract_error के रूप में सामने आता है।

stringlifecycle_statusज़रूरी

active या archived। Archived Sessions input अस्वीकार करते हैं।

object · nullfailureज़रूरी

code, message, action और वैकल्पिक retryable के साथ public failure।

string · integer · stringagent_id · agent_version · modelज़रूरी

Frozen Agent version और effective model।

object · object | nullagent · usageज़रूरी

effective Agent configuration का OpenAI-shaped snapshot, और token usage (जब तक कोई turn usage रिपोर्ट नहीं करता, तब तक null)।

वैकल्पिक<string · null>source · source_id

Session का स्रोत। POST /v1/agents/sessions से बने Sessions direct और null source_id रिपोर्ट करते हैं।

integerrow_versionज़रूरी

rename, archive और unarchive के लिए compare-and-set token।