responses.create. Your agent receives the request, including model and every other field, and its reply comes back in the OpenAI format, streamed or not. There is nothing to write on the agent’s side.
Onecortex follows the Open Responses specification, so a client that works against it works here.
The endpoint
Set the SDK’s base URL to your agent’s OpenAI URL. The SDK adds/responses itself.
api_key as a bearer token, which is what Onecortex expects, so an Onecortex API key goes in the same place an OpenAI key would.
Call it
- Python
- TypeScript
- curl
openai_call.py
Output
Stream the reply
Setstream to true, or use the SDK’s streaming helper, and the reply arrives as server sent events, one named event per step, ending with data: [DONE]. While your agent is silent, a : ping comment arrives every 15 seconds, which SDKs ignore.
- Python
- TypeScript
openai_stream.py
Every event carries a
sequence_number that counts up from zero. Anything still open when the run ends, a message or a tool call, is closed before the last event, so an SDK that accumulates the stream stays consistent.
The request
Onecortex reads three things and passes everything else to your agent.A string, or a list of items. The text of the last
user message is your agent’s prompt, and every message in the list reaches your agent as messages, each as { "role": "...", "content": "..." } with text parts joined. Images and files are not text, so your agent does not receive them. A request with no user message and no resume is refused with 400 before your agent is called: Send an input with at least one user message, or a resume to answer a paused run.The id of an earlier response from this agent. Your agent continues the same session. See Conversations.
Your own conversation key, as a string or as
{ "id": "..." }. It is your agent’s session, as threadId is for AG-UI. Sending it with previous_response_id is refused with 400: Send either previous_response_id or conversation, not both.Reach your agent unchanged, as
params, exactly as sent. Onecortex never uses model, because the URL chooses the agent, but an agent written to switch model on it receives exactly what OpenAI’s API would have given it. An unfamiliar field is never an error, because SDKs send defaults. Each framework page says where params arrive in your code. The request body is at most 1 MB.store is accepted. Nothing is stored beyond what a conversation already needs, whatever its value.
The response
The response object carries every field the Responses format requires. What you sent, such asmodel, temperature, tools and metadata, is echoed back, and the rest take OpenAI’s defaults. Which of those settings your agent honours is up to your agent: Onecortex reports what was asked. usage is null, because Onecortex does not meter tokens.
output holds, in order, what your agent did:
Your agent runs its own tools. Each
function_call arrives already answered by its function_call_output, so a client that matches calls to outputs by call_id has nothing left to run.
Tool outputs longer than 64 KB are cut by Onecortex before they reach any surface. See Limits.
Conversations
Your agent keeps its own history, so a chain of responses has to reach one session. Every response has anid. Send it back as previous_response_id and your agent continues the conversation, receiving only the new input.
- Python
- TypeScript
openai_chain.py
400 and the code previous_response_not_found, instead of quietly starting a new conversation:
GET /responses/{id}, and the conversation lives where your agent keeps it: in the running instance, or in the memory you gave your agent. An instance stops after 15 minutes with no calls and after 1 hour however busy, as Sessions explains. A response id stays valid after that, but an agent that held its history in memory has lost it, and receives only the latest input. If that matters, keep history in your own store, or send the whole conversation in input each time: it reaches your agent as messages.
Pauses
A run your agent pauses for a person, as in Human in the loop, ends as an incomplete response. Its text is the question, andincomplete_details lists the interrupts:
previous_response_id, and put the answers in metadata.onecortex_resume:
- Python
- TypeScript
openai_resume.py
metadata holds strings of at most 512 characters, so the answers go in as a JSON string and a long payload will not fit. For a longer answer, use Human in the loop. A value that is not a list of answers is refused with 400:
400: This agent does not pause for input, so there is nothing to resume.
Errors
A refusal before the reply starts, such as a missing key, another organization’s agent or a rate limit, is an HTTP error with the status the invoke API uses, in the body OpenAI clients read:type is invalid_request, not_found, too_many_requests or server_error, code is the Onecortex code, and param names the field when one is at fault, such as previous_response_id.
A failure after the stream starts is a response.failed event, with the same code and message in response.error. A non streamed call whose agent fails answers with an error status and the same body, so an SDK raises rather than returning a failed response.
WebSocket mode
For a long conversation, hold one socket open and send each turn on it, instead of one request per turn. This is the Responses WebSocket mode the OpenAI SDKs already speak, so the SDK’s own socket client works against your agent.Authorization: Bearer on the upgrade request, as you would on any call. A browser cannot set that header on a WebSocket, so open the socket from a server, and use the HTTP endpoint from a page.
- Python
- TypeScript
openai_socket.py
response.create, with the fields of the request except stream and background, which a socket does not use. It answers with the same events as a streamed reply, as text messages, with no data: [DONE]. Chain turns with previous_response_id as you would over HTTP, and send only the new input: your agent keeps the history in its session.
A named lane, 1 to 256 characters of letters, digits, underscore, hyphen and period. Turns on one lane run in order. Turns on different lanes run at the same time, and every event of a turn carries its
stream_id, so a client can tell them apart. Left out, a turn runs on the default lane.false creates a response without calling your agent: it completes at once with an empty output, and can be continued with previous_response_id. Use it to prepare a conversation before the first message.error message, and the socket stays open:
response.failed, as it is over HTTP. A refusal on the upgrade itself, such as a missing key or another organization’s agent, is the HTTP status and body of Errors, which the SDKs report as a failed connection.
Chains and store
With store left out or true, a response id continues on any socket, and over HTTP, until the agent’s session ends. With store: false, a chain lives on the socket that made it: after you reconnect, a previous_response_id from the old socket is refused with previous_response_not_found, and you start again without it. A turn that fails evicts the previous_response_id it named, so a retry that names the same id is refused too.
Limits and lifetime
Closing the socket stops the turns it was running: the call to your agent is cancelled.
From a browser
A web page can call the OpenAI HTTP URL directly, with the SDK’sdangerouslyAllowBrowser option in TypeScript. Onecortex allows any origin for requests that carry an API key, and never sends credentials of its own. Anyone who can read the page can read its key, so use a key scoped to this one agent, or call through your own server.
What is not supported
- Chat Completions.
/chat/completionsis not served. Useresponses.create. - Retrieving, deleting or listing responses. There is no
GETorDELETEon/responses/{id}, and no list of input items. Nothing is stored to return. - Background responses.
backgroundis ignored: the call returns when your agent finishes. /responses/compact.- Images and files in
input. Your agent receives the text.