Stream chat responses with the EpochLLM API
For supported text models, set stream: true on a chat completion request to receive server-sent events rather than wait for a complete JSON response.
Send a streaming request
Use an available model ID and an API key stored in EPOCH_API_KEY. The -N flag disables curl output buffering.
curl -N "https://epochllm.com/v1/chat/completions" \
-H "Authorization: Bearer $EPOCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"YOUR_MODEL_ID","stream":true,
"stream_options":{"include_usage":true},
"messages":[{"role":"user","content":"Say hello."}]}'Handle usage and interruptions
With stream_options.include_usage enabled, Chat Completions and legacy Completions send one final usage chunk before [DONE]. Read usage.buyer_cost_micro for the settled charge in integer micro-USD when available.
A stream that starts with HTTP 200 can still end with an SSE error. A dropped connection or partial output does not prove a live text request was unbilled. Save the request ID and check the original request before retrying. Final settlement fields may be sent as HTTP trailers when your connection exposes them.
See the streaming reference and error handling guide for details.