Streaming & Async Patterns
Streaming & Async Patterns
Real-time responses and background processing
Streaming & Async Patterns
Real-time responses and background processing
Some API calls return immediately (creating a project takes milliseconds). Others — like asking the AI a complex question — can take several seconds. Streaming lets you show results as they’re generated instead of waiting for the complete response.
The Chat endpoint (POST /api/v2/chat) supports Server-Sent Events (SSE) for real-time streaming. Set stream: true in your request:
The response arrives as a stream of events:
Each event contains a small piece of the response. Your UI can display each piece as it arrives — creating a typing effect.
Some operations run in the background because they take too long for a synchronous response:
For background operations, poll the status endpoint until the job completes:
Don’t poll more frequently than every 2 seconds. Excessive polling wastes your rate limit quota without meaningfully improving responsiveness.