WebSockets

Connect to the ModelBeam WebSocket server for real-time job status updates. Uses the Pusher protocol, compatible with any Pusher client library.

Connection Details

SettingValue
Hostsoketi.modelbeam.ai
Port443
ProtocolWSS (encrypted)
App Keymodelbeam-prod-key
Auth EndpointPOST https://api.modelbeam.ai/broadcasting/auth
Channelprivate-client.{client_id}
Eventrequest.status.updated

Event Payload

{
  "request_id": "uuid",
  "status": "processing",
  "preview": "base64_or_null",
  "result_url": "https://storage.modelbeam.ai/...",
  "progress": 45.0
}

Status Flow

pending → processing → in_progress → done
Error events are not sent via WebSocket. Use webhooks to catch job failures.

JavaScript Example (Pusher.js)

import Pusher from "pusher-js";

const pusher = new Pusher("modelbeam-prod-key", {
  wsHost: "soketi.modelbeam.ai",
  wsPort: 443,
  wssPort: 443,
  forceTLS: true,
  enabledTransports: ["ws", "wss"],
  authEndpoint: "https://api.modelbeam.ai/broadcasting/auth",
  auth: {
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      Accept: "application/json",
    },
  },
});

// Subscribe to your private channel
const channel = pusher.subscribe(`private-client.${clientId}`);

channel.bind("request.status.updated", (data) => {
  console.log("Status update:", data);

  if (data.status === "done") {
    console.log("Result URL:", data.result_url);
  }

  if (data.preview) {
    // Display base64 preview image
    document.getElementById("preview").src = `data:image/jpeg;base64,${data.preview}`;
  }
});

// Handle connection events
pusher.connection.bind("connected", () => {
  console.log("Connected to ModelBeam WebSocket");
});

pusher.connection.bind("error", (err) => {
  console.error("WebSocket error:", err);
});

Connection Requirements

  • Send a ping every 30 seconds to keep the connection alive
  • Implement reconnection with exponential backoff for dropped connections
  • Each client subscribes to their own private channel based on their client_id