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 — see Webhooks
prompt_cache_keyPins the worker for prefix-cache hits — see Prompt caching
service_tier"flex" for 0.7 × list
max_queue_wait_s5–300s admission bound

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)

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
flexservice_tier: "flex"0.7 × list
batchbackground: true + metadata.completion_window: "24h"0.5 × list

All three 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.