Optimization Streaming
Get real-time updates on optimization progress using WebSocket streaming. Build responsive UIs and monitor long-running optimization jobs as they execute.Subscribe to Updates
Connect to a job’s event stream to receive updates as they happen:Event Types
| Event | Description | Key Fields |
|---|---|---|
job_started | Optimization job has begun | jobId, timestamp |
iteration_start | New iteration beginning | iteration, timestamp |
mutation_generated | Prompt variant created | preview, mutationType |
evaluation_start | Variant evaluation beginning | iteration |
evaluation_complete | Variant evaluation finished | score, metrics |
new_best | New best-performing prompt found | score, improvement, prompt |
iteration_complete | Iteration finished | iteration, bestScore |
job_paused | Job was paused | iteration, reason |
job_resumed | Job was resumed | iteration |
job_complete | Optimization finished successfully | results |
job_failed | Optimization failed | error |
job_cancelled | Optimization was cancelled | reason |
Event Payloads
job_started
iteration_start
mutation_generated
evaluation_complete
new_best
job_complete
UI Integration
Build a real-time progress UI using streaming events:React Example
Vue Example
Connection Management
Automatic Reconnection
The SDK handles reconnection automatically:Manual Reconnection
Error Handling
Handle various error scenarios:Best Practices
Clean up subscriptions
Clean up subscriptions
Always call the unsubscribe function when the component unmounts or the job completes to prevent memory leaks.
Handle reconnection gracefully
Handle reconnection gracefully
Show appropriate UI feedback during reconnection attempts so users know the connection is being restored.
Batch UI updates
Batch UI updates
If receiving many events quickly, consider batching state updates to avoid excessive re-renders.
Persist critical state
Persist critical state
For long-running optimizations, consider persisting the best result locally in case of browser refresh.