Official TypeScript library providing comprehensive client access to Mux's video infrastructure API including asset management, live streaming, analytics, and webhook handling
The System module provides system-level utilities including JWT signing key management and account information retrieval.
import Mux from '@mux/mux-node';
const client = new Mux({
tokenId: 'YOUR_TOKEN_ID',
tokenSecret: 'YOUR_TOKEN_SECRET',
});
// Access system resources
const signingKeys = client.system.signingKeys;
const utilities = client.system.utilities;Manage JWT signing keys for secure playback. Signing keys are used to create JWT tokens for signed playback IDs and DRM licenses.
interface SigningKeys {
/**
* Create a new signing key
*/
create(options?: RequestOptions): Promise<SigningKey>;
/**
* Retrieve signing key details
*/
retrieve(signingKeyId: string, options?: RequestOptions): Promise<SigningKey>;
/**
* List all signing keys
*/
list(query?: SigningKeyListParams, options?: RequestOptions): PagePromise<SigningKeysBasePage, SigningKey>;
/**
* Delete a signing key
*/
delete(signingKeyId: string, options?: RequestOptions): Promise<void>;
}
interface SigningKey {
/** Unique identifier */
id: string;
/** Creation timestamp */
created_at: string;
/** RSA private key in PEM format (only returned on creation) */
private_key?: string;
/** RSA public key in PEM format */
public_key: string;
}
interface SigningKeyListParams {
/** Items per page */
limit?: number;
/** Page number */
page?: number;
}Usage Example:
// Create a new signing key
const signingKey = await client.system.signingKeys.create();
// IMPORTANT: Save the private_key immediately - it's only returned once
console.log('Private Key:', signingKey.private_key);
console.log('Key ID:', signingKey.id);
// List all signing keys
const keys = await client.system.signingKeys.list();
// Delete a signing key
await client.system.signingKeys.delete(signingKey.id);Important Notes:
private_key is only returned when creating a new signing key. Store it securely.System utility endpoints for account information.
interface Utilities {
/**
* Get information about the authenticated account
*/
whoami(options?: RequestOptions): Promise<WhoamiResponse>;
}
interface WhoamiResponse {
/** Environment ID */
id: string;
/** Environment name */
name: string;
/** Creation timestamp */
created_at: string;
}Usage Example:
// Get current environment information
const account = await client.system.utilities.whoami();
console.log('Environment ID:', account.id);
console.log('Environment Name:', account.name);
console.log('Created At:', account.created_at);Here's a complete workflow for creating and using signing keys:
// Step 1: Create a signing key
const signingKey = await client.system.signingKeys.create();
// Step 2: Save the private key securely (it won't be retrievable later)
// In production, store in a secure secret manager
process.env.MUX_PRIVATE_KEY = signingKey.private_key;
process.env.MUX_SIGNING_KEY = signingKey.id;
// Step 3: Create a new client with the signing key
const clientWithSigning = new Mux({
tokenId: 'YOUR_TOKEN_ID',
tokenSecret: 'YOUR_TOKEN_SECRET',
jwtSigningKey: signingKey.id,
jwtPrivateKey: signingKey.private_key,
});
// Step 4: Use the signing key to create signed playback tokens
const token = await clientWithSigning.jwt.signPlaybackId('PLAYBACK_ID', {
type: 'video',
expiration: '1h',
});
// Step 5: Use the token in playback URLs
const playbackUrl = `https://stream.mux.com/PLAYBACK_ID?token=${token}`;To rotate signing keys without downtime:
// 1. Create a new signing key
const newKey = await client.system.signingKeys.create();
// 2. Update your application to use the new key for new tokens
// Keep the old key active for existing tokens
// 3. Wait for all old tokens to expire (based on expiration time)
// 4. Delete the old signing key
await client.system.signingKeys.delete(oldKeyId);Install with Tessl CLI
npx tessl i tessl/npm-mux--mux-nodedocs