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 (background only) — see Webhooks |
prompt_cache_key | Routes 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_s | 5–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:
| Status | type | code | param | When |
|---|---|---|---|---|
| 400 | invalid_request_error | sync_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 |
| 400 | invalid_request_error | context_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.code | Meaning | Extra fields |
|---|---|---|
| The worker's own code | Generation failed; message is the engine's text | — |
timeout | No result arrived before the stream's time budget | — |
max_queue_wait_exceeded | A queue-wait rejection after the stream started | type (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.
| 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 |
| priority | service_tier: "priority" (priority-enabled orgs) | 1.3 × list |
| flex | service_tier: "flex" | 0.7 × list |
| batch | background: 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.
OpenAI Chat API
POST /v1/chat/completions on sference: the OpenAI Chat Completions shape, with priority and 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.