OpenAI Responses API

POST /v1/responses on sference: the OpenAI Responses shape with background execution, streams, the 24h window, and the events API.

OpenAI Responses API

POST https://api.sference.com/v1/responses is the OpenAI Responses shape, and it is the surface with the most sference-specific capability: background execution, the 24h completion window, and the events API.

Inference is modeled as a response resource: you create it, observe status, and read structured output (text, optional reasoning, errors). A response is either realtime (blocking, returns when inference finishes) or background (background: true, polled or streamed to completion).

curl https://api.sference.com/v1/responses \
  -H "Authorization: Bearer $SFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "zai-org/GLM-5.3",
    "input": "Summarize the case for prefix caching."
  }'

Where to read schemas

Open API Reference in the sidebar → Inference for POST/GET /v1/responses and /v1/responses/events. Everything is generated from the same OpenAPI document as production.

Mental model

  1. POST /v1/responses — create the work (model, input, optional sampling knobs, metadata).
  2. GET /v1/responses/{id} — poll status, output, and error until terminal.
  3. GET /v1/responses/events — cursor through completion events instead of re-reading the full document.
  4. Streams — group related responses under one stream_id with a cost rollup and a resumable cursor. See Streams.

Request fields

FieldNotes
modelCatalog id
inputA string (shorthand for one user message) or a list of input items
instructionsDeveloper/system instructions
max_output_tokensOutput cap. On reasoning models this covers hidden reasoning too
temperature, top_pSampling
tools, tool_choiceOpenAI tool shape
text.formatStructured output — see Structured outputs
reasoning, include_reasoning, enable_thinkingReasoning controls
includeAccepted; server-side tools (web search, file search, computer use) are not available
streamSSE stream
backgroundRun on the 24h window and return immediately
metadata.completion_window"24h" — the only supported value; requires background: true
metadata.stream_idAttach the response to a stream
metadata.completion_webhook, metadata.webhook_tokenCallback delivery (background only) — see Webhooks
prompt_cache_keyRoutes the request to a warm worker for prefix-cache hits. No retention or TTL — see Prompt caching
service_tier"flex" for 0.7 × list; "priority" for 1.3 × list (queue jump, priority-enabled orgs)
max_queue_wait_s5–300s admission bound

Send an Idempotency-Key header to make a retry return the original response instead of creating a second one — see Idempotency keys.

Background execution

Set background: true and the call returns a response id immediately instead of blocking. Collect it later by polling or by webhook.

response = client.responses.create(
    model="zai-org/GLM-5.3",
    input="Summarize this 200-page filing.",
    background=True,
    metadata={"completion_window": "24h"},
)
print(response.id)   # collect later
# Later
r = client.responses.retrieve(response.id)
if r.status == "completed":
    print(r.output_text)

Background responses bill at 0.5 × list. This is the surface to use for long-horizon agent steps, overnight jobs, and anything nobody is waiting on.

Collect on the finish reason, not on status alone

On a reasoning model, max_output_tokens covers hidden reasoning as well as the answer. A response can settle incomplete with a perfectly good answer attached. Check the incomplete detail and use the output if it is there rather than discarding it.

Streaming

with client.responses.stream(
    model="zai-org/GLM-5.3",
    input="Write a haiku about GPUs.",
) as stream:
    for event in stream:
        if event.type == "response.output_text.delta":
            print(event.delta, end="", flush=True)

Errors

HTTP errors on every /v1/responses route use the OpenAI envelope, {"error": {"message", "type", "param", "code"}}, with the same statuses and codes as Chat Completions. Two codes behave differently here:

StatustypecodeparamWhen
400invalid_request_errorsync_output_budget_exceeded"max_output_tokens"Returned on a non-streaming request when you set max_output_tokens above the default and generation ran past half of the sync window (the 1200s timeout on Chat Completions). Stream, use background: true, or lower the cap. Otherwise the timeout is a 504
400invalid_request_errorcontext_length_exceeded"input"A prompt longer than the context window

On this surface the top-level param for a prompt-related error is "input" rather than "messages". When the error also carries error.extra, as a context-length rejection at intake does, extra.param still says "messages":

{
  "error": {
    "message": "...",
    "type": "invalid_request_error",
    "param": "input",
    "code": "context_length_exceeded",
    "extra": { "code": "context_length_exceeded", "param": "messages" }
  }
}

A request that fails before its stream starts gets an ordinary HTTP error. If generation fails after the stream has started, the stream ends with a response.failed event, and the error is on response.error:

event: response.failed
data: {"type":"response.failed","response":{"id":"...","object":"response","created_at":1761836400,"model":"zai-org/GLM-5.3","status":"failed","service_tier":"default","output":[],"error":{"code":"timeout","message":"inference timed out"}},"sequence_number":7}
response.error.codeMeaningExtra fields
The worker's own codeGeneration failed; message is the engine's text—
timeoutNo result arrived before the stream's time budget—
max_queue_wait_exceededA queue-wait rejection after the stream startedtype (rate_limit_error for your bound, server_error for the platform ceiling), param, retry_after_s, source

Only an unexpected failure inside the API ends the stream with a Responses error event instead, which the OpenAI SDK yields like any other event:

event: error
data: {"type": "error", "code": "server_error", "message": "Internal server error", "param": null, "sequence_number": 2}

sequence_number continues the stream's own sequence.

The events API

GET /v1/responses/events returns completions in order with a cursor, so a consumer can resume where it stopped. Pass stream_id for one stream's feed, or omit it for the account-wide feed of every background response.

ParameterMeaning
stream_idOne stream's events; omit for the account-wide feed
limitPage size
starting_after / ending_beforeCursor by completion id
wait_msLong-poll: hold the request open for new events
from sference_sdk import SferenceClient

client = SferenceClient()
for event in client.iter_responses_events(consumer_name="worker-1"):
    process(event)

The SDK's checkpoint helpers persist the cursor per consumer, so a restarted worker resumes rather than replaying. See Streams.

Processing modes

ModeHowPrice
realtimeblocking POST /v1/responses (no background)list
priorityservice_tier: "priority" (priority-enabled orgs)1.3 × list
flexservice_tier: "flex"0.7 × list
batchbackground: true + metadata.completion_window: "24h"0.5 × list

All four share the same models and request shape; only scheduling priority and price differ. Responses echo the tier actually served in service_tier. For large static backfills prefer the Batch API — cheaper, simpler to retry, easier to reconcile.

Statelessness

Every request is answered from the content you send. previous_response_id and conversation are removed rather than rejected, so your request still runs — it just does not see the turn they name. Send the full conversation in input on every turn; every OpenAI-compatible SDK does this by default. See API compatibility.