multiplayerapi

Multiplayer API SDK

JavaScript client for the Multiplayer API — no dependencies, no mandatory build step.

JavaScript

Import directly from a module, no install required:

import { Multiplayer } from 'https://multiplayerapi.com/sdk/mp.esm.min.js';

const mp = new Multiplayer({
  key: 'mp_pk_...',
  // Prefer 'session' if the page may be exposed to XSS (tokens die with the tab).
  // store: 'session',
});

Session tokens default to localStorage. Pass store: 'session' or store: 'memory' to reduce XSS impact. Keep a strict Content-Security-Policy on your game origin.

Or via a script tag if your game doesn't use modules:

<script src="https://multiplayerapi.com/sdk/mp.min.js"></script>
<script>const mp = new MP.Multiplayer({ key: 'mp_pk_...' });</script>
FileFormatUsage
mp.esm.min.jsESM minifiedproduction
mp.esm.jsESM readabledebugging
mp.min.jsUMD minifiedscript tag
version.jsonJSONpublished version

Unity

Add the package from the Package Manager via Git URL, then install com.unity.webrtc to enable peer-to-peer. Without it, the SDK still works: everything goes through the relay.

using MultiplayerApi;

var mp = new Multiplayer("mp_pk_...") { DisplayName = "Alice" };
await mp.Login();
var room = await mp.Quickmatch(new JObject { ["mode"] = "ffa", ["max_players"] = 8 });

Without an SDK

The API is JSON over HTTP: three routes are enough to play (/v1/auth/guest, /v1/rooms/quickmatch, /v1/rt/sync). The OpenAPI 3.1 schema lets you generate a client in any language.