Docs/Installation & Setup

Installation & Setup

Install the Mistscale Web SDK and create your first client.

Setup is two steps: install the package, and create a client with your project's API key. There is no build step or config asset — the client is a single import.

1. Install the package

The SDK ships as @mistscale/web-sdk on the npm registry. It has no runtime dependencies beyond the browser's own fetch and WebSocket APIs.

Terminal
npm install @mistscale/web-sdk

Works the same with pnpm or yarn (pnpm add @mistscale/web-sdk / yarn add @mistscale/web-sdk). Ships as ESM and CJS with bundled TypeScript types, so it works unmodified with Vite, Next.js, webpack, or a plain script bundler.

2. Create the client

mistscale.ts
import { MistScale } from "@mistscale/web-sdk";

const mistscale = new MistScale({
  apiKey: "ms_your_key_here", // Project Settings → API Keys
});

That's the whole setup. No network call happens until you use the client — construction only validates that the key looks like a Mistscale key (starts with ms_), so a bad key fails immediately and locally rather than on your first request.

3. Get an API key

  1. 1

    Open your project in the Mistscale dashboard.

  2. 2

    Go to Project Settings → API Keys.

  3. 3

    Create a key. It's shown once — copy it immediately.

  4. 4

    Pass it as apiKey when constructing MistScale, as shown above.

Client configuration

apiKey
Required. Your project API key, starting with ms_.
controlPlaneUrl
REST API base URL. Defaults to the production Mistscale API; leave it unless support tells you otherwise.
npcServiceUrl
Realtime NPC endpoint your connections open against. Defaults to production; leave it unless support tells you otherwise.
playerId
Default player/sender id used for every connection you open. Auto-generated if you don't set one — see Your First NPC for when to set your own.
requestTimeoutMs
Timeout for REST calls (npcs.list(), npcs.verifyKey()). Defaults to 15000.
This key runs in the browser
Unlike a compiled game binary, anything shipped to a browser is visible to whoever opens developer tools — your API key included, whether it's in the page source or just observed on the network tab. A project API key can only list your NPCs and open chat connections against them, so the realistic risk of a leaked key is someone else burning your project's chat quota, not broader account access. If that's a concern for a public release, proxy requests through your own backend instead of constructing the client directly in the player's browser, so the key never reaches the client at all.