Streaming text and detecting failure

Consume Chat Completions SSE and recognize partial or failed output.

Also available as Markdown · all agent guides in one file

Key points

  • HTTP 200 only means the stream started. Check every JSON event for error before accepting text.
  • [DONE] alone does not prove success. A disconnect before the protocol finishes is incomplete output.
  • Execute streamed tool calls only after the complete call has arrived and the turn has finished successfully.

For a chat model that supports streaming, set stream: true on POST /v1/chat/completions. The response uses text/event-stream. This example requires curl and jq, plus AETHER_API_KEY and an exact AETHER_MODEL chosen from the catalogue.

jq -n --arg model "$AETHER_MODEL" \
  '{model: $model, messages: [{role: "user", content: "Say hello briefly."}], stream: true}' \
  | curl --no-buffer --fail-with-body --silent --show-error \
      https://api.aetherapi.dev/v1/chat/completions \
      -H "Authorization: Bearer $AETHER_API_KEY" \
      -H 'Content-Type: application/json' --data-binary @-

Client parsing rules

Detect failure

Other protocols and testing

For deterministic parser checks, use the enabled sandbox's success and stream_error scenarios. stream_error emits partial text or tool-call arguments, then sandbox_simulated_stream_error without a successful completion (no [DONE] on chat). See the sandbox document before testing; no production enablement is assumed.