Platform - Pricing

With the release of Liveblocks 1.0, we included new pricing plans that are based on Monthly Active Users (MAU). This guide will help you understand how to use the new pricing plans by providing guidance on the migration to Liveblocks 1.0 and how to include a userId when generating a token with the secret API key.

What is a Monthly Active User (MAU)?

In versions before 1.0 we used the number of connections to determine pricing segments. We counted each time a user connected to a Liveblocks room from a physical device as a connection. We introduced pricing based on Monthly Active Users (MAU) to reflect the value that Liveblocks offers to our customers. MAU makes pricing more predictable for our users by associating connections to users.

A monthly active user can be defined as:

  • A userId that connects to a Liveblocks room at least once a month (if using authorization with a secret API key)
  • An anonymous user who connects to a Liveblocks room, at least once a month who can be identified by a cookie (if using authorization with the public API key)

It doesn’t matter how many rooms a user connects to, or how frequently Liveblocks APIs are used—one user is one MAU.

How does authorization work with MAU?

When using @liveblocks/node’s authorize function

In @liveblocks/node, we made the field userId in the authorize option mandatory. This userId is used to track MAU associated with a Liveblocks account. Each userId will count as one MAU. To make sure you begin to track MAU as intended, first update @liveblocks/node.

$npm update @liveblocks/node@1.0

Then, update the authorize function to include the userId field.

import { authorize } from "@liveblocks/node";
// Replace this key with your secret key provided at// https://liveblocks.io/dashboard/projects/{projectId}/apikeysconst secret = "sk_prod_xxxxxxxxxxxxxxxxxxxxxxxx";
export default async function auth(req, res) { /** * Implement your own security here. * * It’s your responsibility to ensure that the caller of this endpoint * is a valid user by validating the cookies or authentication headers * and that it has access to the requested room. */ const room = req.body.room; const response = await authorize({ room, secret, // Corresponds to the UserMeta[id] type defined in liveblocks.config.ts userId: "123", groupIds: ["456"], // Optional userInfo: { // Optional, corresponds to the UserMeta[info] type defined in liveblocks.config.ts name: "Ada Lovelace", color: "red", }, }); return res.status(response.status).end(response.body);}

When calling the authorize API endpoint

When calling the authorize endpoint directly with a secret key, the userId is not required. However, should still include the userId in the request body to take advantage of MAU pricing logic. Set the Authorization: Bearer header to your secret key, then POST to the following endpoint:

POST https://api.liveblocks.io/v2/rooms/{roomId}/authorize

Set the following request body:

{  "userId": "user123",  "groupIds": [    "g1",    "g2"  ],  "userInfo": {    "name": "bob",    "colors": [      "blue",      "red"    ]  }}

To learn more about authorization and authentication in your Liveblocks application, check out our Authentication guide.

How is MAU calculated when using a public key?

To take advantage of Liveblocks 1.0 pricing with the public API key authorization, you must update your Liveblocks packages to 1.0. We will count each connection as one MAU if you do not update your packages to 1.0. Once the packages are updated, a cookie will be set on the client to track when a new user connects to a room. This cookie will track MAU associated with a Liveblocks account and expire after 30 days.

Inside the createClient function, you will use your public key instead of a private key.

import { createClient } from "@liveblocks/client";
const client = createClient({ publicApiKey: "pk_prod_xxxxxxxxxxxxxxxxxxxxxxxx",});

To illustrate how counting MAU works without a userId, consider the following:

If you have one user who connects to a Liveblocks room that does not enforce authorization, you will be billed for one MAU. That same person can reaccess a room the next day, and MAU would not increase. The cookie will expire at the end of the 30-day billing cycle, and the user will be counted as a new MAU. Liveblocks will count that anonymous user as two MAU if packages are not updated.

Development use

Users coming from localhost and .test domains are not counted towards your billing. However, you will still need to include a userId in the authorize option if you use it.

import { authorize } from "@liveblocks/node";
// Replace this key with your secret key provided at// https://liveblocks.io/dashboard/projects/{projectId}/apikeysconst secret = "sk_prod_xxxxxxxxxxxxxxxxxxxxxxxx";
export default async function auth(req, res) { /** * Implement your own security here. * * It’s your responsibility to ensure that the caller of this endpoint * is a valid user by validating the cookies or authentication headers * and that it has access to the requested room. */ const room = req.body.room; const response = await authorize({ room, secret, // Corresponds to the UserMeta[id] type defined in liveblocks.config.ts userId: "user123", // Check whether you are in the testing environment when passing the userId groupIds: ["456"], // Optional userInfo: { // Optional, corresponds to the UserMeta[info] type defined in liveblocks.config.ts name: "Ada Lovelace", color: "red", }, }); return res.status(response.status).end(response.body);}

Testing use

If you connect to rooms and call the Liveblocks API during any automated testing, you may want to provide a static userId to avoid hitting limits.

For example, you could do this by setting an environment variable and checking the process when you call authorize from @liveblocks/node.

TEST_USERID="machine"
export default async function auth(req, res) {  const room = req.body.room;  const response = await authorize({    room,    secret,    userId:      process.env.NODE_ENV === "test" ? process.env.TEST_USERID : "user123",  });  return res.status(response.status).end(response.body);}

How to migrate to Liveblocks 1.0

To update to Liveblocks 1.0, you will need to update your Liveblocks packages:

$npm update @liveblocks/node @liveblocks/client @liveblocks/react

You will then pick one of the two methods outlined above for tracking MAU: authorization or public key. After completing these steps to take advantage of the new pricing model, you should review the Liveblocks 1.0 upgrade guide for additional details on migrating to Liveblocks 1.0.