Media Tokens
Sign short-lived beam-media-token/v1 tokens in your backend: keys, claims, roles, rotation and revocation.
Every connection to a media session carries a media token that your backend signs with its own Ed25519 key. Beam's Workers check the token offline against the public keys you registered, so a token works without a call to your backend or to Beam, and a Worker can never create one.
Mint tokens only on a server you control. The signing key, like your API key, must never reach a browser or a mobile app.
Signing keys
Register one or more public keys on a project. Each has a key id (kid) that
tokens name.
beam media key generate --out media-key.json # a test key, mode 0600
beam media key add mprj_... --key-file media-key.json # registers its public keyOr with the API (public_key is the raw 32-byte Ed25519 public key in unpadded
base64url):
curl -X POST "$BEAM_CORE_URL/v1/media/projects/mprj_.../keys" \
-H "Authorization: Bearer $BEAM_API_KEY" -H "Content-Type: application/json" \
-d '{"public_key": "HjUcRj_JDsWsYTbaJhXzsUTzHqVtMiOYC0HF_HiCI0E", "kid": "k-2026-11", "label": "backend"}'- Key ids are 1 to 64 characters of
A-Z a-z 0-9 . _ -. Ids startingbeam-svc-ormk-are reserved (kid_reserved). - A key that is not a canonical Ed25519 public key is refused (
invalid_public_key). - Rotation: register the new key, sign with it, then revoke the old one with
DELETE /v1/media/projects/{project_id}/keys/{kid}. Tokens signed by a revoked key stop working at the session's next topology revision. - Managed key: every project also has one key that Beam holds (
mk-…). If you do not want to sign tokens yourself, ask Beam to mint them withPOST /v1/media/projects/{project_id}/tokens(reference). Recording playback tokens use it too.
Claims
A token carries these claims:
| Claim | Required | Meaning |
|---|---|---|
aud | yes | The project's token audience, beam-media unless you changed it. |
kid | yes | The signing key's id. |
project | yes | The project id (mprj_…). |
session | yes | The session id (msn_…), or a recording id (mrec_…) to play a recording. |
role | yes | subscribe, publish or admin (see below). |
identity | yes | Your user's id, 1 to 128 printable ASCII characters. One identity is one participant in a session. |
name | no | Display name shown to other participants, up to 64 characters. |
tracks | no | The sources a publisher may send: any of microphone, camera, screen, screen_audio, custom. Absent means all. Not allowed on a subscribe token. |
region | no | A region hint for the directory: wnam, enam, sam, weur, eeur, apac, oc, afr or me. |
meta | no | Your own data (up to 512 bytes), echoed in participant events. |
iat | yes | Issued at, in unix seconds. |
nbf | no | Not before, in unix seconds (defaults to iat). |
exp | yes | Expiry, in unix seconds, at most 24 hours after iat. |
nonce | yes | A unique random value per token (16 random bytes in base64url), used to revoke it. |
Any other claim makes the token invalid. Identities starting node:, audit:
or member: are reserved for Beam: node: for the Workers' own links,
audit: for Beam's auditors (never admitted to a members-only session), and
member: for Room members, as member:<member_id>, or
member:<member_id>/<client> when a member joins from several clients at once
(see Room Media Channels).
Roles nest: admin includes publish, which includes subscribe.
| Role | May |
|---|---|
subscribe | Watch and listen; on a stage, be a listener. |
publish | Also publish camera, microphone and screen (limited by tracks). |
admin | Also mute other participants and remove them from the session. |
Format
A token is three dot-separated parts:
bmt1.<base64url(payload JSON)>.<base64url(Ed25519 signature)>The signature covers the ASCII text bmt1.<base64url(payload)>. The payload is
compact JSON with the claims in this order, absent optional claims left out:
aud, kid, project, session, role, identity, name, tracks,
region, meta, iat, nbf, exp, nonce. A token is at most 4,096 bytes,
its payload at most 2,048.
The Beam server SDKs mint tokens for you. In Node
(@beam-network/web-sdk-server/media), with the key file beam media key generate
writes:
import { MediaTokenSigner } from "@beam-network/web-sdk-server/media";
const signer = await MediaTokenSigner.create({ projectId: file.project_id, keyId: file.kid, privateKey: file.private_key });
const { token, expiresAt } = await signer.mint({ session: "msn_...", role: "publish", identity: "user-42", name: "Ada", ttlSeconds: 600 });Python has MediaTokenSigner and mint_token in beam_network_sdk.media; Go
mints in its media package. Without an SDK, minting takes a few lines in any
language with Ed25519. In Node (the key file's private_key and public_key
are the JWK d and x):
import { createPrivateKey, randomBytes, sign } from "node:crypto";
import { readFileSync } from "node:fs";
const file = JSON.parse(readFileSync("media-key.json", "utf8"));
const signingKey = createPrivateKey({
key: { kty: "OKP", crv: "Ed25519", d: file.private_key, x: file.public_key },
format: "jwk",
});
export function mintMediaToken({ session, role, identity, name, ttlSeconds = 3600 }) {
const now = Math.floor(Date.now() / 1000);
// Claims in the canonical order; optional ones only when set.
const claims = { aud: "beam-media", kid: file.kid, project: file.project_id, session, role, identity };
if (name) claims.name = name;
Object.assign(claims, { iat: now, exp: now + ttlSeconds, nonce: randomBytes(16).toString("base64url") });
const input = "bmt1." + Buffer.from(JSON.stringify(claims)).toString("base64url");
return input + "." + sign(null, Buffer.from(input), signingKey).toString("base64url");
}Check a token from a terminal: beam media token inspect <token> --session msn_…
verifies it exactly as a Worker would.
Where tokens are checked
A token is checked when a connection starts: on the directory join, on each WebRTC (WHIP or WHEP) connection, on the HLS multivariant playlist, and on quality beacons and content-key requests. An established connection is not dropped when the token expires, so tokens can be short (minutes): the SDK only needs a valid token to reconnect.
Clocks may differ by 60 seconds. Errors are 401 (or 403 for a role or track
that is not allowed) with a code:
| Code | Meaning |
|---|---|
token_malformed, token_unsupported_version | Not a valid bmt1 token. |
token_key_unknown | Its kid is not an active key of the project. |
token_signature_invalid | Bad signature. |
token_claims_invalid | A claim breaks the rules above. |
token_audience_mismatch, token_project_mismatch, token_session_mismatch | Wrong audience, project or session. |
token_not_yet_valid, token_expired | Outside nbf..exp. |
token_revoked | Its nonce or identity is denied. |
token_role_forbidden, token_track_forbidden | The role or source is not allowed for this action. |
Revocation
Revoke a single token by its nonce, or every token of an identity until a time:
curl -X POST "$BEAM_CORE_URL/v1/media/sessions/msn_.../deny" \
-H "Authorization: Bearer $BEAM_API_KEY" -H "Content-Type: application/json" \
-d '{"identity": "user-17", "until": 1798765200}'Within about a second Beam pushes the deny list to every Worker of the session,
which closes the matching connections. POST /v1/media/sessions/{id}/kick does
the same for a participant and denies its identity until its token expires. A
session's deny list holds at most 2,000 nonces and 500 identities
(409 deny_list_full): keep tokens short so entries expire.
Promotion on a stage: to let a listener speak, mint a publish token for the
same identity. The SDK keeps the listener's connection and starts publishing;
the participant stays the same.