Streaming for live feedback
A stream delivers progress while the agent works. Forward appropriate events through your application server to the user interface. Treat text deltas, tool activity, and terminal outcomes as different UI states. Keep the OpenAI application key on the server.
Webhooks for asynchronous work
Webhooks notify your backend about session state changes without holding a client connection open. A handler can retrieve results or dispatch work to a tool handler. Verify signatures according to the official webhook guide and deduplicate deliveries before side effects.
Disconnection is not cancellation
A browser refresh or interrupted stream does not prove that the turn failed. Save session identifiers, retrieve durable history, and reconnect. Show a reconnecting state rather than marking incomplete transport as completed work.
Use actual outcome events
Check turn.completed, turn.failed, turn.cancelled, and session failure events. An idle session is not itself a successful result. Tool failures can also appear inside a completed turn, so inspect the reported outcome and required artifacts.
Read the official reference
Check the source for current API fields, account requirements, and service limits.
OpenAI: architecture