Overview
WebSocket endpoint for observing batch processing progress in real-time. This is a read-only observer - processing runs independently in the background, and disconnecting the WebSocket does not cancel the job.Connection Details
Endpoint:ws://localhost:8000/api/batch/ws/{job_id}
Authentication: Pass token as query parameter
Authorization header:
Path Parameters
Unique identifier for the batch processing job. Generated when starting a job via POST /api/batch/start.
Connection Flow
1. Client Connects
Connect to the WebSocket endpoint with the job ID and authentication token.2. Server Sends Catchup Message
On connect, the server immediately sends all results so far:Message type:
"catchup"The job identifier
Current job state including status, progress, processed_count, failed_count, total
Array of all document results processed so far
3. Server Streams Progress Updates
As each document is processed, the server sends progress updates:Message type:
"progress"The job identifier
Zero-based row index in the batch
One-based row number for display (row_id + 1)
Document title
Processing status:
"pending", "processing", "success", or "failed"Overall job progress as a decimal (0.0 to 1.0)
Generated tags (present on success)
Error message (present on failure)
Error category:
"rate-limit", "model-error", "network", etc.Milliseconds to wait before retry (for rate limit errors)
Current attempt number
AI model being used for processing
Additional metadata (extraction_method, is_scanned, ocr_confidence, etc.)
4. Server Sends Completion Message
When all documents are processed or the job is stopped:Message type:
"completed", "cancelled", or "error"The job identifier
Number of successfully processed documents
Number of failed documents
Completion summary message
5. Keepalive Messages
Every 30 seconds (if no updates), the server sends a keepalive:Message Types Summary
| Type | When Sent | Description |
|---|---|---|
catchup | On connection | All results and state so far |
progress | Per document | Individual document processing update |
completed | Job finished | All documents processed |
cancelled | Job cancelled | Processing stopped by user |
error | Job failed | Critical error occurred |
keepalive | Every 30s | Connection health check |
Error Responses
If authentication fails:1008 (policy violation).
Usage Example
Important Notes
Disconnecting from the WebSocket does not cancel the job. Processing continues in the background. Use POST /api/batch/jobs//cancel to stop a job.
If the job is already completed when you connect, you’ll receive the catchup message followed immediately by a completion message.