Skip to content

Streaming

Streaming reduces time to first output and works well for chat and long-form generation.

Terminal window
curl -N https://cpa.momoyai.com/v1/chat/completions \
-H "Authorization: Bearer $MOMOYAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4-mini",
"stream": true,
"messages": [{"role": "user", "content": "List three API security practices."}]
}'
  1. Use an HTTP client that exposes the stream.
  2. Parse event boundaries instead of assuming one network read is one event.
  3. Support cancellation and forward its signal to the request.
  4. Distinguish normal completion, upstream errors, timeouts, and client disconnects.
  5. Retry only requests that have not started producing user-visible output.