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
POST /v1/responses— create the work (model,input, optional sampling knobs,metadata).GET /v1/responses/{id}— pollstatus,output, anderroruntil terminal.GET /v1/responses/events— cursor through completion events instead of re-reading the full document.- Streams — group related responses under one
stream_idwith a cost rollup and a resumable cursor. See Streams.
Request fields
| Field | Notes |
|---|---|
model | Catalog id |
input | A string (shorthand for one user message) or a list of input items |
instructions | Developer/system instructions |
max_output_tokens | Output cap. On reasoning models this covers hidden reasoning too |
temperature, top_p | Sampling |
tools, tool_choice | OpenAI tool shape |
text.format | Structured output — see Structured outputs |
reasoning, include_reasoning, enable_thinking | Reasoning controls |
include | Accepted; server-side tools (web search, file search, computer use) are not available |
stream | SSE stream |
background | Run on the 24h window and return immediately |
metadata.completion_window | "24h" — the only supported value; requires background: true |
metadata.stream_id | Attach the response to a stream |
metadata.completion_webhook, metadata.webhook_token | Callback delivery — see Webhooks |
prompt_cache_key | Pins the worker for prefix-cache hits — see Prompt caching |
service_tier | "flex" for 0.7 × list |
max_queue_wait_s | 5–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.
| Parameter | Meaning |
|---|---|
stream_id | One stream's events; omit for the account-wide feed |
limit | Page size |
starting_after / ending_before | Cursor by completion id |
wait_ms | Long-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
| Mode | How | Price |
|---|---|---|
| realtime | blocking POST /v1/responses (no background) | list |
| flex | service_tier: "flex" | 0.7 × list |
| batch | background: 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.
OpenAI Chat API
POST /v1/chat/completions on sference: the OpenAI Chat Completions shape, with flex processing, tools, structured output, vision, and streaming.
Anthropic Messages API
POST /v1/messages on sference: an Anthropic Messages-compatible endpoint for open models. Auth, streaming SSE, tool use, extended thinking, vision, usage, and the exact compatibility surface.