Video generation API SSE: stream progress and recover after disconnects
Video generation API SSE is useful when someone is watching a render. Genace exposes a progress stream for an existing job at GET /api/v1/jobs/{id}/stream. The stream describes the job; it does not contain the encoded video bytes. Successful completion still requires reading the output URL and downloading the resulting file.
Keep the job identifier in durable application state before opening the stream. A connection is temporary, while the identifier is what lets you recover the work after a browser refresh, laptop sleep, or proxy disconnect.
Inspect the real event protocol
Use curl against a job you already own. The no-buffer option makes events visible as they arrive. This command performs a status stream request, not a generation submission.
curl --no-buffer --fail-with-body \
"https://genace.ai/api/v1/jobs/$GENACE_JOB_ID/stream" \
-H "Authorization: Bearer $GENACE_API_KEY"
The implementation immediately emits a progress event for the current snapshot. It then refreshes the job and emits further events while collection continues. Each event contains JSON fields for state, progress, outputs, and error, with unavailable values represented as null.
| Event name | Application meaning | Required handling |
|---|---|---|
| progress | Current job snapshot | Update visible state; allow null progress |
| done | Successful terminal job | Validate the outputs array and collect files |
| error | Failed or canceled terminal job | Inspect payload state and preserve error details |
A progress event can already carry a terminal state immediately before the corresponding terminal event. Make your state update handler tolerant of repeated terminal information. Saving the output manifest twice should not cause two downstream publications.
Plan authentication before choosing a client
The endpoint requires a Bearer API key. Browser-native EventSource does not provide a general custom Authorization-header option. For a web interface, a backend relay can authenticate the user session and keep the Genace key on the server. Another option is a fetch-based SSE client in a trusted server environment.
Do not put a production key into a public page just to make a demo connect. Also avoid treating arbitrary network chunks as complete events. An SSE parser must buffer text across chunk boundaries and process blank-line-delimited event records. A newline can arrive in a different chunk from the data it terminates.
Recover the state, not the connection history
The route declares a sixty-second maximum duration. Your actual connection may end earlier because of another network component. The implementation does not expose event IDs or a replay cursor, so reconnecting should recover current state rather than promise replay of every intermediate update.
After an unexpected close, GET the same job identifier. If it remains active, reconnect with backoff or continue using polling. If it is terminal, finalize your local record. Do not resubmit the prompt when the stream closes.
Verification checklist
Disconnect a read stream, reload the UI, and confirm it reconnects to the saved job. Test null progress, terminal error events, repeated terminal snapshots, and a successful event with an empty outputs array. Verify that server credentials never appear in browser source or logs.
Related guides cover polling, resuming jobs, and observability.
Continue with production operations
Where these facts come from
- codebase: src/app/api/v1/jobs/[id]/stream/route.ts
- codebase: src/ai/jobs/http.ts
- Editorial keyword hypothesis; search volume not measured