Skip to main content

Responses API

The Responses API is OpenAI's modern streaming surface. It uses a richer, strongly-typed event taxonomy and supports native resume — the killer feature for production UIs that need to recover from network drops without losing in-flight runs.

The Alien platform exposes two endpoints:

  • POST /agent/:id/responses — start a new response, optionally streaming.
  • GET /agent/:id/responses/:respId?starting_after=<seq> — resume an existing response from a sequence number.

Both are drop-in compatible with client.responses.create(...) from the official OpenAI SDKs (Python ≥ 1.50, Node ≥ 4.50, AI SDK 5+).

Quick start​

Python (openai SDK)​

from openai import OpenAI

client = OpenAI(
base_url="https://api.alien.club/agent/<agent_id>",
api_key="<your-access-token>",
)

with client.responses.stream(
model="agent",
input="What is the duration of the trial period for a SYNTEC executive?",
) as stream:
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)

TypeScript (openai SDK)​

import OpenAI from "openai"

const client = new OpenAI({
baseURL: "https://api.alien.club/agent/<agent_id>",
apiKey: "<your-access-token>",
})

const stream = await client.responses.create({
model: "agent",
input: "What is the duration of the trial period for a SYNTEC executive?",
stream: true,
})

for await (const event of stream) {
if (event.type === "response.output_text.delta") {
process.stdout.write(event.delta)
}
}

cURL — initial request​

curl -N \
-H "Authorization: Bearer <your-access-token>" \
-H "Content-Type: application/json" \
-d '{"model":"agent","input":"Hello","stream":true}' \
https://api.alien.club/agent/<agent_id>/responses

cURL — resume after a network drop​

# Read the last sequence_number you saw, then:
curl -N \
-H "Authorization: Bearer <your-access-token>" \
https://api.alien.club/agent/<agent_id>/responses/<resp_id>?starting_after=<last_seq>

Request body​

The request body matches OpenAI's Responses create request:

FieldRequiredNotes
modelyesFree-form string. The platform routes to the configured upstream model for this agent.
inputyesEither a free-form string (treated as a user message) or an array of input items per OpenAI's input taxonomy.
instructionsnoPer-turn system instructions, appended to the agent's own system prompt for this run. Main agent only. See Per-turn instructions.
streamno, defaults falseSet to true for streaming.
metadatanoFree-form key/value map (≤16 keys, 64-char keys, 512-char values). Forwarded to Response.metadata.
tools, tool_choicenoCurrently advisory.
temperature, top_p, max_output_tokens, parallel_tool_calls, previous_response_id, conversationnoAccepted, forwarded to the runtime where supported.
background: truerejectedBackground responses are out of scope for v1. Use stream: true and resume via GET instead.

Per-turn instructions​

An agent's system prompt is fixed when the agent is saved. instructions is the channel for whatever has to change from one turn to the next — the current date, a case reference, which step of a sequence the turn is working — without editing the agent or smuggling operator directives into the user's own message.

{
"model": "agent",
"input": "Résume la situation du dossier.",
"instructions": "Today is 8 September 2026. Cite only sources in force at that date."
}

It is appended, never a replacement. The prompt the model receives is assembled in this order:

  1. the agent's saved system prompt
  2. your instructions for this run
  3. the platform's own additions (available subagents, sandbox notes, and similar)

So the agent keeps its identity and its platform-side behaviour, and your text reads as an extra paragraph of the same prompt. This differs from OpenAI's Responses API, where instructions replaces the previous turn's instructions; here there is a stored agent to append to, and replacing it would discard both the agent's definition and the platform's additions.

It reaches the main agent only. Subagents keep the instructions they were configured with, so a per-turn directive cannot silently rewrite a specialist's brief. To change what a subagent does, edit the subagent.

It applies to one run. Nothing is stored. The next request needs its own instructions, including when that request carries a previous_response_id.

It is treated as literal text. Workflow template expressions such as {{ @node.field }} are not interpolated here — they reach the model exactly as written. Template syntax belongs to the prompt the agent's author writes, not to what a caller sends at runtime. Author-side templating is unaffected.

Send a non-blank string. Anything else — null, a number, an array, an empty or whitespace-only string — is ignored, and the turn runs on the agent's saved prompt alone.

tip

Put durable behaviour in the agent's system prompt and only per-turn facts in instructions. Anything you send on every single request is a sign it belongs in the agent instead, where it is versioned with the agent and cheaper to cache.

Event format​

Each event is a Server-Sent Events frame carrying both the SSE event: line (the event type discriminator) and a data: line (the JSON payload):

event: response.created
data: {"type":"response.created","sequence_number":0,"response":{...}}

event: response.output_item.added
data: {"type":"response.output_item.added","sequence_number":1,"output_index":0,"item":{...}}

event: response.output_text.delta
data: {"type":"response.output_text.delta","sequence_number":2,"item_id":"...","output_index":0,"content_index":0,"delta":"Hello","logprobs":[]}

event: response.completed
data: {"type":"response.completed","sequence_number":N,"response":{...}}

Every event validates against the OpenAI Python SDK's openai.types.responses.ResponseStreamEvent discriminated union.

There is no [DONE] terminator. The stream closes after exactly one terminal event:

  • response.completed — successful run.
  • response.failed — failure. Carries Response.error with code and message.
  • response.incomplete — truncated by max_output_tokens or content filter.

Event types​

The complete event subset emitted by this endpoint:

Event typeWhen
response.createdFirst event. Carries the Response object with status: "in_progress".
response.in_progressOptional progress signal during long runs.
response.output_item.addedA new top-level output item appears (message, function_call, or reasoning item).
response.content_part.addedWithin a message, a new content part starts (output_text, refusal, or reasoning_text).
response.output_text.deltaText token delta within an output_text part.
response.output_text.doneCloses an output_text part.
response.function_call_arguments.deltaStreaming JSON-string fragments of a function call's arguments.
response.function_call_arguments.doneCloses a function-call item.
response.reasoning_summary_part.addedA new reasoning summary part appears.
response.reasoning_summary_text.deltaText delta inside a reasoning summary.
response.reasoning_summary_text.doneCloses a reasoning summary part.
response.content_part.doneCloses a content part.
response.output_item.doneCloses a top-level output item.
response.completedTerminal success. Response.usage populated.
response.failedTerminal failure. Response.error populated.
response.incompleteTerminal partial result. Response.incomplete_details.reason populated.

The full schema for each event is documented at https://platform.openai.com/docs/api-reference/responses-streaming.

Sequence numbers and resume​

Every event carries a monotonically increasing sequence_number, starting at 0. This is the resume cursor.

When a streaming connection ends before its terminal event, reconnect by GETting the response id with starting_after set to the last sequence number you received:

GET /agent/:id/responses/<resp_id>?starting_after=<last_seq>

The server replays all events with sequence_number > <last_seq>. If the run is still in flight, the GET continues live as new events arrive. If the run has already terminated, the GET replays the tail and closes with the original terminal event. Any platform pod serves the resume. response.created is sent as soon as the stream opens, before the run starts on a worker, so a client always has the response id and a sequence_number to resume from. A connection lost before response.created arrived left no id behind: send the request again.

Interrupted streams​

A run outlives the connection that streams it. A stream ends before its terminal event when:

  • the platform pod serving it shuts down (a deploy, a scale-in, a node drain). The pod stops taking new requests and lets its open streams finish for up to 90 s first;
  • the platform's event store is briefly unreachable;
  • the ingress cuts the connection at its 600 s cap, which a long turn can reach;
  • the network drops.

The first two end the stream with one error event, then close the connection:

event: error
data: {"type":"error","sequence_number":41,"code":"stream_interrupted","message":"The event stream was interrupted, the response is still in progress. Resume with starting_after.","param":null}

Its sequence_number is the last event delivered, the exact starting_after to resume from, never below 0 since response.created is always delivered first. It is not a new event, and the response is not failed. The last two close the connection with no frame at all.

Treat any stream that ends without response.completed, response.failed or response.incomplete as interrupted, and resume it. A resilient client:

  1. Tracks the highest sequence_number received, and drops a frame whose (type, sequence_number) pair it already received. The pair is the key, not the number alone, since the platform's response.tool_call.output and response.cost_breakdown frames reuse the sequence_number of the event they follow.
  2. On stream_interrupted, or on a connection that ends without a terminal event, reconnects with starting_after set to that highest sequence_number.
  3. Backs off exponentially between attempts with some jitter, gives up after a bounded number of them, and resets the count whenever an attempt delivers a new event.

A complete TypeScript implementation, a fetch wrapper the Vercel AI SDK and the openai SDK can both use, is in Vercel AI SDK: Resume after an interruption.

Storage and TTL​

A response's metadata is cached for 72 hours after creation, backed by a durable record that outlives the cache. Its events live in a shorter-lived event stream. When neither the cache nor the durable record knows the response, or its events have been evicted:

  • GET /agent/:id/responses/<resp_id> returns HTTP 410 Gone.
  • The response cannot be resumed and must be re-issued via POST.

This covers any realistic recovery window. If you need durable replay beyond it, store the events client-side as you receive them.

Failure modes for resume​

StatusReason
200Normal — replay or live tail begins.
400starting_after is invalid (not a non-negative integer, or beyond the response's last sequence number).
404Response unknown to this agent — wrong id or wrong agent.
410Response unknown, past its retention, or its events evicted. Re-issue with POST.
503The event store is briefly unreachable. Retry after the Retry-After header.

Subagent context via metadata.x_alien_*​

Multi-agent runs (where the main agent dispatches subagents via tools) carry the agent registry in the Response.metadata field. The Responses API permits arbitrary metadata per response — this is a documented extension point, not a standards violation.

Example Response.metadata carrying subagent context:

{
"x_alien_root_agent_id": "MAIN",
"x_alien_agent_registry": "[{\"id\":\"MAIN\",\"kind\":\"main\",\"name\":\"main\",\"parent_id\":null},{\"id\":\"sub-legifrance\",\"kind\":\"subagent\",\"name\":\"Légifrance researcher\",\"parent_id\":\"MAIN\"}]"
}

Per-item agent identity is encoded in the item's id using a structured prefix: agent:<agent_id>::msg_<random> for messages, agent:<agent_id>::fc_<random> for function calls. Standard consumers treat the prefix as opaque (which is how the SDK treats every item id); extension-aware consumers parse the prefix to render per-subagent affordances.

The 512-character cap on a single metadata value means very large registries (≥50 agents) may be truncated. If truncation occurs, metadata.x_alien_registry_truncated is set to "true" and consumers should fall back to parsing per-item id prefixes.

Errors​

Pre-stream errors​

Failures before the first event return HTTP 4xx/5xx with a JSON body matching OpenAI's standard error envelope:

{ "error": { "message": "...", "type": "invalid_request_error", "code": "..." } }

Mid-stream errors​

An error event with code: "stream_interrupted" is not a failure, the run is still going, see Interrupted streams.

Failures after the first event are surfaced via the response.failed terminal event:

{
"type": "response.failed",
"sequence_number": <int>,
"response": {
"id": "resp_...",
"status": "failed",
"error": { "code": "server_error", "message": "..." },
"metadata": {
"x_alien_error_code": "upstream_timeout",
"x_alien_error_message": "upstream model timed out after 30s"
},
...
}
}

Response.error.code is constrained to OpenAI's documented Literal codes (server_error, rate_limit_exceeded, invalid_prompt, etc.) — Alien-specific codes are surfaced via metadata.x_alien_error_code.

Turns that never started​

Two x_alien_error_code values mean no worker ever ran the turn, so it produced nothing, cost nothing, and is safe to send again with POST:

x_alien_error_codeWhen
dispatch_failedThe platform could not queue the turn at all. The response.failed event arrives at once.
job_not_startedThe turn was queued, but no worker picked it up within 360 s.

Every other failure, worker_disconnected among them, may come after the turn did some work. Check what the stream already delivered before you retry it.

Heartbeat​

The server emits SSE comment lines (:keep-alive\n\n) every 15 seconds during quiet periods. Comments do not parse as events and do not advance sequence_number.

Compatibility checklist​

The streams produced by these endpoints are validated against:

  • The OpenAI Python SDK's openai.types.responses.ResponseStreamEvent discriminated union (ResponseCreatedEvent, ResponseOutputItemAddedEvent, ResponseTextDeltaEvent, etc.).
  • Reference fixtures derived from OpenAI's Responses streaming reference and the OpenAI Python SDK source.

If a standard OpenAI Responses consumer breaks against this endpoint, that's a bug — please report it.

See also​