Streaming
Set "stream": true and the response becomes text/event-stream,
passed through from the upstream as it is produced.
Request
curl -N https://api.firesafety.men/v1/chat/completions \
-H "Authorization: Bearer $FREEGATE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "oss-20b",
"messages": [{ "role": "user", "content": "Count to five." }],
"stream": true
}' Frames
Each frame is a JSON object on a data: line, terminated by a blank line. The
stream ends with data: [DONE].
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","model":"oss-20b",
"choices":[{"index":0,"delta":{"content":"One"},"finish_reason":null}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","model":"oss-20b",
"choices":[{"index":0,"delta":{"content":" two"},"finish_reason":null}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","model":"oss-20b",
"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","model":"oss-20b",
"choices":[],"usage":{"prompt_tokens":18,"completion_tokens":9,"total_tokens":27}}
data: [DONE] Usage
The gateway always requests usage from the upstream, so a final chunk carries
usage with empty choices. If an upstream omits it, the gateway
estimates from the streamed text so quota accounting still settles.
Errors after the first byte
A rate limit or upstream failure that happens mid-stream cannot change the HTTP status ·
it has already been sent as 200. It arrives as a frame with
finish_reason: "error" and an error object. Treat it as a failed
completion, not a successful empty one.
Aborts
If the client disconnects, the upstream request is aborted and the reservation is settled against whatever was generated. You are not charged for tokens the upstream never produced.