Streaming

Streaming defaults to off.

View as MarkdownSuggest a change on GitHub

Set stream: true explicitly on /v1/chat/completions, /v1/completions or /v1/responses for progressive OpenAI-compatible server-sent events (SSE), with the response header x-openmayhem-stream-mode: live. The API forwards emitted deltas without buffering the entire output. Timing depends on the provider backend, which may buffer its own output rather than emit token by token.

You need an API key with the right scope and a model ID from Markets.

Request

curl -N https://api.openmayhem.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENMAYHEM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "hauhaucs/qwen3.6-35b-a3b-uncensored",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 2000,
    "stream": true,
    "stream_options": {"include_usage": true}
  }'

The usage chunk

For /v1/chat/completions and /v1/completions, with stream_options.include_usage set to true, one extra chunk arrives after the last delta and before [DONE], carrying token counts for the whole response:

event stream (abridged)
data: {"choices":[{"delta":{"content":"Hello!"}}], ...}

data: {"choices":[{"delta":{},"finish_reason":"stop"}], ...}

data: {"choices":[],"usage":{"prompt_tokens":10,"completion_tokens":42,
  "total_tokens":52,"completion_tokens_details":{"reasoning_tokens":30}}}

data: [DONE]

Without this option, Chat/Completions streams omit the usage chunk. /v1/responses uses the distinct OpenAI Responses event protocol, not Chat/Completions chunks or their [DONE] terminator. The error stream_recovery_unavailable means the gateway does not yet support stream recovery: the request fails before inference starts; use stream: false instead.

Disconnecting mid-stream

Native Core durable jobs preserve billing and reconciliation for streamed requests. Closing the connection does not guarantee cancellation or a refund. The charge is settled exactly from the signed receipt for work performed. Budget with max_tokens, not by hanging up.