Streaming and cancellation
Stream tokens as they are generated
Chat completions support true upstream streaming. Bytes arrive as OpenAI-compatible server-sent events with bounded buffering and cancellation that propagates upstream.
Enable streaming
Set stream: true on a chat completions request. The response is text/event-stream with OpenAI-style chunks, terminated by a data: [DONE] sentinel.
curl -N https://api.hardcarrx.com/v1/chat/completions \
-H "Authorization: Bearer $HARDCARRX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"provider": "openai",
"model": "gpt-4.1-mini",
"stream": true,
"messages": [{"role": "user", "content": "Count to five slowly"}]
}'Each data event carries a chat.completion.chunk payload:
data: {"id":"chatcmpl_...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"1"},"finish_reason":null}]}
data: {"id":"chatcmpl_...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"2"},"finish_reason":null}]}
data: [DONE]Cancellation
Closing the connection cancels the exchange. Cancellation propagates upstream: the provider poll is stopped and no further tokens are billed into memory writeback. A slow client pauses upstream polling instead of accumulating unbounded memory.
Bounded resources
- A single SSE line or event larger than the platform's bounded limits aborts the stream rather than buffering unboundedly.
- Invalid upstream events are handled explicitly; raw upstream data payloads are forwarded verbatim.
Responses endpoint
The /v1/responses compatibility layer is non-streaming in its first phase. Sending stream: true is rejected explicitly with 422 — it never silently degrades to a non-streaming call.
curl https://api.hardcarrx.com/v1/responses \
-H "Authorization: Bearer $HARDCARRX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4.1-mini",
"stream": true,
"input": "Hello"
}'
# 422 — streaming is not yet supported by the /v1/responses compatibility layer