OpenAI-compatible server
superfluid serve exposes an OpenAI-compatible HTTP API at http://127.0.0.1:8453 by default, on the same listener as the Anthropic and Ollama APIs. Every request runs as a fresh durable session, so a later request that repeats a conversation prefix is served warm from the prefix cache with no client-side session handling.
superfluid serve basecompute/Qwen3.8-27B
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8453/v1", api_key="unused")
reply = client.chat.completions.create(
model="basecompute/Qwen3.8-27B",
messages=[{"role": "user", "content": "Say hello."}],
max_tokens=32,
)
print(reply.choices[0].message.content)
The model field names an id from GET /v1/models. Unknown fields are ignored. The request body limit is 100 MiB (413 above it; the multipart routes answer with code payload_too_large, the JSON routes with a plain-text body).
Endpoints
| method | path | purpose |
|---|---|---|
POST | /v1/chat/completions | chat completion, streaming or not |
POST | /v1/completions | raw-text completion; with suffix, fill-in-the-middle |
POST, GET, DELETE | /v1/responses, /v1/responses/{id}, /v1/responses/{id}/input_items, /v1/responses/{id}/cancel | Responses API, with previous_response_id |
POST | /v1/embeddings | text embeddings (embedding models only) |
POST | /v1/rerank | cosine rerank of documents against a query |
POST | /v1/audio/transcriptions, /v1/audio/translations | speech to text (Whisper models only) |
POST | /v1/messages | Anthropic Messages API |
GET | /v1/models, /v1/models/{model} | known models, loaded or not, with capabilities |
POST | /v1/models/load, /v1/models/unload | load / unload a model (admin) |
DELETE | /v1/models/{model} | unload a model (admin) |
POST | /v1/tokenize | token ids of a text, no chat scaffold |
POST, GET, DELETE | /v1/files, /v1/files/{id}, /v1/files/{id}/content | upload, list, read, delete files |
POST, GET | /v1/batches, /v1/batches/{id}, /v1/batches/{id}/cancel | batch jobs |
POST, GET | /v1/lora/load, /v1/lora/unload, /v1/lora | activate (admin), clear (admin) or show a LoRA adapter; basert bundles only |
GET, DELETE | /v1/fleet/nodes, /v1/fleet/nodes/{name} | a fleet head's nodes; remove one (admin) (Distributed serving) |
GET | /health | liveness; never authenticated |
GET | /props | the served model and its effective generation defaults |
GET | /slots | lane and KV-pool snapshot (llama.cpp shape) |
GET | /metrics, /v1/metrics | Prometheus text; see Observability |
* | /api/*, / | Ollama API |
Chat completions
curl http://127.0.0.1:8453/v1/chat/completions -H 'content-type: application/json' -d '{
"model": "basecompute/Qwen3.8-27B",
"messages": [{"role": "user", "content": "Three facts about Oslo."}],
"stream": true,
"chat_template_kwargs": {"enable_thinking": false}
}'
Supported parameters
| field | default | notes |
|---|---|---|
model | required | 400 if absent, 404 if unknown |
messages | required | system, user, assistant, tool; content as a string or parts (text, image_url, input_audio) |
max_completion_tokens, max_tokens | fill the context, or --max-tokens | max_completion_tokens wins |
stream | false | SSE, ending in data: [DONE] |
stream_options | include_usage is always on | |
n | 1 | 1-128; streaming uses 1 |
temperature, top_p | model default | see Sampling |
seed | fresh per request | |
presence_penalty, frequency_penalty | 0 | -2 to 2; outside is a 400. --presence-penalty sets the first's default on basert |
stop | none | string or array; excluded from output |
logprobs, top_logprobs | off | top_logprobs 0-20 |
logit_bias | none | {"<token id>": bias} |
tools, tool_choice | [], auto | see Tool calling |
response_format | none | json_object or json_schema; see Structured outputs |
reasoning_effort | model default | see Chat templates |
Extra parameters
| field | notes |
|---|---|
top_k, min_p | truncation |
repeat_penalty (alias repetition_penalty) | 1.0 disables |
ignore_eos | decode to max_tokens |
chat_template_kwargs | template variables such as enable_thinking, reasoning_effort; a key the template refuses is a 400 |
enable_thinking | top-level shorthand; chat_template_kwargs wins |
stream_options.continuous_usage_stats | cumulative completion_tokens on every content chunk |
Response
{
"id": "chatcmpl-superfluid-17", "object": "chat.completion", "model": "Qwen3-4B",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "...", "reasoning_content": "...", "tool_calls": [...]},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 120, "completion_tokens": 40, "total_tokens": 160,
"prompt_tokens_details": {"cached_tokens": 96}},
"superfluid": {"spec": {"proposed": 60, "accepted": 38, "acceptance_rate": 0.633}}
}
reasoning_contentappears when the model produced reasoning;tool_callswhen calls were parsed.finish_reasonisstop,lengthortool_calls. A reply cut by the token cap islengtheven if it holds a tool call; do not run it.cached_tokensis the prompt prefix served from the prefix cache (also in thex-superfluid-warmheader).superfluid.specappears only when speculative decoding ran.
Streaming
- The first chunk's delta is
{"role":"assistant"}; content andreasoning_contentdeltas follow at token cadence. - Tool calls stream as OpenAI partial deltas: an opening entry with
idandfunction.name, thenargumentsfragments on the sameindex, at the same token cadence as content. - The terminal chunk carries
finish_reason,usageandsuperfluid.warm(cached prefix tokens). - Lines starting with
:are keep-alives. - A client that disconnects cancels the generation at the next tick.
- An error after the stream began arrives as a
{"error": {...}}data frame, thendata: [DONE].
Completions and fill-in-the-middle
POST /v1/completions tokenizes prompt directly (a string; arrays and token ids are not accepted). It reads prompt, suffix, fim_mode, stream, echo, max_tokens, logprobs (0-20), stop (a string or an array, as chat takes it: the text ends where the first stop string starts, with finish_reason stop) and the sampling fields; it does not read n, logit_bias, response_format or tools.
A request with suffix is fill-in-the-middle: prompt is the prefix, suffix the text after the cursor, the reply the middle.
curl http://127.0.0.1:8453/v1/completions -H 'content-type: application/json' \
-d '{"model":"Qwen2.5-Coder-1.5B","prompt":"def add(a, b):\n ","suffix":"\n\nprint(add(1, 2))","max_tokens":32}'
| FIM rule | value |
|---|---|
| scheduling class | completion, with --completion-deadline-ms |
| per-client token bucket | --completion-burst 20, refilled at --completion-rate 10/s; over it is 429 completion_rate_limited with Retry-After |
max_tokens default | --max-tokens, else 128 |
fim_mode | psm (default) or spm (extension) |
| refused | echo, logprobs (400 unsupported_parameter); a model with no FIM support and no --fim-model (400 fim_unsupported) |
The reply's superfluid object carries cached, expired and served_by.
Embeddings, rerank, audio
| endpoint | request | notes |
|---|---|---|
/v1/embeddings | model, input (string or array), encoding_format (float or base64) | vectors as the engine pools them (not normalized) |
/v1/rerank | model, query, documents, top_n, return_documents | cosine similarity of embeddings, sorted descending |
/v1/audio/transcriptions, /v1/audio/translations | multipart: file, model, language, prompt, response_format, stream | see Vision and audio |
These need a model whose capability record allows it (workload.embedding, modalities.whisper_*); the llamacpp and mlx runtimes serve neither. Otherwise: 400 unsupported_model.
Models
curl http://127.0.0.1:8453/v1/models
Each entry adds loaded, meta.n_ctx (the context window), architecture.input_modalities, runtime and capabilities (the runtime's capability record plus a dialect object: enable_thinking, reasoning_effort, reasoning_effort_levels, fim, fim_model). Loading and unloading are in Serving multiple models.
/props and /slots
GET /props returns the served model, default_generation_settings (what a request that names nothing runs with), max_context, chat_template, kv_cache and capabilities. ?model=<id> describes another model; ?autoload=1 loads a known model first. A sampling default is omitted, not guessed, while unknown.
GET /slots returns one aggregate entry in llama.cpp's slot shape (lanes, KV pool, tick plan, decode and prefill rates). POST /slots/{id}/save and /restore are retired: 501 route_retired.
Files and batches
| route | notes |
|---|---|
POST /v1/files | multipart file and purpose; stored under <sessions>/files/; ids file-<hex>. --files-max-bytes caps the store (413 files_quota_exceeded), --files-expiry ages files out |
POST /v1/batches | {"input_file_id", "endpoint"?, "completion_window"?}; JSONL lines {"custom_id", "method", "url", "body"} for /v1/chat/completions or /v1/embeddings |
POST /v1/batches/{id}/cancel | stops between lines |
A batch runs line by line against the default model. Up to 4 batches run at once; later ones wait in validating, in order, and a full queue (256 waiting) refuses a new batch with 429 batch_queue_full. Lines without max_tokens are capped at 2048 and use the model's defaults, not the operator's sampling flags. Status moves validating, in_progress, completed (or failed, cancelled). Under --key-policy, files and batches are visible only to the key that created them.
Headers
| header | direction | meaning |
|---|---|---|
Authorization: Bearer <key> or X-Api-Key | request | with --api-key or --key-policy |
x-superfluid-qos | request | interactive, completion, agent or background; see Scheduling |
x-superfluid-batch-invariant | request | a lane that ticks alone; needs --http-allow-batch-invariant |
x-superfluid-warm | response | prompt tokens served from the prefix cache |
x-superfluid-keepalive: whitespace | response | --nonstream-keepalive is padding the body with spaces |
Idempotency-Key | request | a POST sent again with its key gets the first one's answer; see below |
Idempotent-Replayed: true | response | this answer was recorded for an earlier request with the same key |
With --nonstream-keepalive <sec>, a non-streaming generation commits 200 OK at admission and writes one space every interval until the JSON body, so an idle-timing proxy does not drop a long prefill. Leading whitespace is valid JSON.
Retrying with Idempotency-Key
Send Idempotency-Key: <any string up to 255 characters> with a POST, on any route and in any API format, and send the same request with the same key to retry it. The answer the first one got is replayed whole, from its start, with Idempotent-Replayed: true:
- A connection that dropped mid-stream does not stop the generation. A retry reads the stream from its first event, then follows it to its end, so a client that keeps nothing from the dropped attempt reads one complete stream.
- A finished answer is kept for 24 hours under
<sessions>/idempotencyand replayed after a restart. - A request a restart cut short runs again under its key.
- A key belongs to the credential it came with: another API key with the same string is another request.
- The same key with another request body, or on another route, is refused with
422(code: idempotency_key).
Use a new key for each new request: a retry loop that sends the same request with the same key is safe, and it runs at most once.
Errors
{"error": {"message": "...", "type": "invalid_request_error", "param": null, "code": null}}
| status | code | when |
|---|---|---|
| 400 | context_length_exceeded | the prompt is longer than the window |
| 400 | unsupported_input | an image or audio part the model cannot take |
| 400 | unsupported_model | embeddings, rerank or audio on a model that does not serve them |
| 400 | unsupported_runtime | /v1/models/load on a runtime that is missing or does not read the model |
| 400 | unsupported_parameter, invalid_value | fim_mode without suffix, or not psm/spm |
| 400 | idempotency_key | an Idempotency-Key that is empty or over 255 characters |
| 400 | malformed body; constraint unsatisfiable: ... (a grammar that cannot compile); a penalty outside -2 to 2 | |
| 401 | invalid_api_key | missing or wrong key |
| 403 | admin_required | a non-admin key on an admin route |
| 403 | origin_refused | an Origin or Host from off this machine; see Security |
| 403 | a QoS header above the key's ceiling, or a batch-invariant lane not allowed | |
| 404 | unknown model | |
| 404 | model_not_found | /props?model= names an unknown model |
| 413 | payload_too_large, files_quota_exceeded | multipart body over 100 MiB; file store full |
| 413 | JSON body over 100 MiB (plain-text body) | |
| 422 | idempotency_key | an Idempotency-Key reused with another body or route |
| 429 | rate_limit_exceeded, concurrency_limit_exceeded, completion_rate_limited | per-IP, per-key, FIM limits |
| 500 | engine or worker failure | |
| 501 | route_retired | /slots/{id}/save, /restore |
| 503 | the model failed to load | |
| 503 | no_node_up | a fleet head with no node up for the model |
Browser transport (--web)
--web 127.0.0.1:<port> starts a separate loopback-only listener carrying the session API (not the OpenAI API) for browser front-ends: POST /web/rpc, POST /web/stream, GET /web/ws, GET /web/health. Authentication is described in Security.