Skip to main content

Overview

The WebSocket API provides real-time bidirectional communication with Modrinth Hosting servers. It enables:
  • Real-time console log streaming
  • Server statistics monitoring (CPU, RAM, network)
  • Power state change notifications
  • Backup progress tracking
  • Mod installation status updates
  • Sending console commands
WebSocket connections are automatically authenticated using JWT tokens and support auto-reconnection with exponential backoff.

Connection Flow

The WebSocket client handles the complete authentication flow automatically:

Connecting to a Server

Safe Connect Options

Event Types

Log Events

Real-time console output from the server.
string
Always "log"
string
Output stream: stdout or stderr
string
Log message content

Stats Events

Server resource usage statistics, sent periodically.
string
Always "stats"
number
CPU usage percentage (0-100)
number
Current RAM usage in bytes
number
Total RAM available in bytes
number
Current storage usage in bytes
number
Total storage available in bytes
number
Network bytes transmitted
number
Network bytes received

Power State Events

Notifications when server power state changes.
string
Always "power-state"
string
Power state: running, stopped, starting, stopping, or crashed
boolean
Present when state is crashed - indicates if killed due to out of memory
number
Present when state is crashed - process exit code

Uptime Events

Server uptime information.
string
Always "uptime"
number
Server uptime in seconds

Backup Progress Events

Track backup creation, restoration, or file operations.
string
Always "backup-progress"
string
Backup ID (UUID)
string
Task type: file, create, or restore
string
Task state: ongoing, done, failed, cancelled, or unchanged
number
Progress value from 0.0 to 1.0

Installation Result Events

Mod installation success or failure notifications.
string
Always "installation-result"
string
Installation result: ok or err
string
Error message (only present when result is err)

New Mod Events

Notification when a new mod is detected on the server.
string
Always "new-mod"
string
Modrinth project ID
string
Modrinth version ID

Filesystem Operation Events

Track long-running filesystem operations (e.g., archive extraction).
string
Always "filesystem-ops"
array
Array of filesystem operations
string
Operation type (currently only unarchive)
string
Operation ID (UUID)
number
Progress from 0.0 to 1.0
number
Number of bytes processed
number
Number of files processed
string
State: queued, ongoing, done, cancelled, failure-corrupted, or failure-invalid-path
string
MIME type of the archive
string
Currently processing file
string
Invalid path that caused failure
string
Source file path
string
ISO 8601 timestamp when operation started

Authentication Events

WebSocket authentication status notifications.
string
auth-ok, auth-expiring, or auth-incorrect
The client automatically handles auth-expiring events by fetching a new token and re-authenticating.

Sending Commands

Send console commands to the server.
string
required
The server ID to send the command to
string
required
Always "command"
string
required
The console command to execute (include leading / for game commands)

Auto-Reconnection

The WebSocket client automatically reconnects on unexpected disconnections using exponential backoff:
  • Base delay: 1 second
  • Max delay: 30 seconds
  • Max attempts: 10
  • Backoff strategy: Exponential with jitter

Manual Reconnection

Complete Example: Server Console

Here’s a complete example building a server console interface:

Example: Real-time Server Dashboard

Platform Support

WebSocket functionality is only available in the GenericModrinthClient, which uses the browser’s native WebSocket API. It is not available in:
  • NuxtModrinthClient (SSR context)
  • TauriModrinthClient (use Tauri’s WebSocket plugin instead)