GloopAPI integration guide

Streaming responses

Consume streaming events and end signals.

Streaming delivers output incrementally without changing model permissions or billing. Set stream: true and consume text/event-stream. Do not parse the entire response as one JSON document.

Responses uses typed events such as response.output_text.delta and response.completed; parse each event by its type.

Parse by protocol

For Chat Completions, SSE data contains JSON chunks. Text usually appears in choices[].delta, and tool calls may also be fragmented. data: [DONE] marks the protocol's end. Requesting stream_options.include_usage may produce a final usage chunk with empty choices; missing usage must not be interpreted as free usage.

Network boundaries

A network byte chunk is not an event. Buffer until the blank-line delimiter, combine multiline data, then parse JSON. Handle UTF-8 characters split across chunks, blank lines, comments, and error events. Examples on the right of endpoint pages show the protocol's event shapes.

On disconnect or a missing end event, mark output as incomplete and retain already displayed text and request diagnostics. Closing a connection does not guarantee that the request was not executed, or that a refund will occur. Unconfirmed synchronous text requests do not have persistent task recovery contracts and should not be automatically resent.

Usage and follow-up handling

Commit the complete result only after a normal ending. Final billing uses the platform's usage records and cannot be inferred from local chunk counts. If a stream reports an error after HTTP 200, handle it as a protocol error rather than relying only on the initial status. See Error handling and Billing for further decisions.