AI
Response Handling
- Streamed Responses: This method streams data in real-time, providing immediate feedback as the response is generated. Set the
stream
parameter totrue
in your request, the API delivers responses via Server-Sent Events (SSE). - Non-Streamed Responses: When the
stream
parameter is set tofalse
, the API returns the complete response in a single JSON payload after processing is complete.
For stream:true
, you'll need to handle the following event types:
init
: Initializes the stream and provides session informationpresence
: Provides backend status updates about worker processingdelta
: Contains chunks of the response message textaction
: Contains blockchain transaction or action dataimage
: Contains image datacontext
: Contains context dataerror
: Contains error information if something goes wrong
Example SSE Stream:
We recommend using the fetch-event-stream
package to handle the event stream in TypeScript. This gives you an easy way to handle each event type.