Mini Games SDK Overview
Mini Games SDK is a client-side JavaScript SDK that runs inside the TikTok app. It provides in-app capabilities like login and authorization, payments, UI triggers, rewarded ads, lifecycle hooks, networking, and capability detection. JavaScript APIs contained within the Mini Games SDK contain the prefix TTMinis.game.
- Native: Compiled mini‑game that runs on TikTok’s native runtime, with optimized performance and smoother gameplay. No initialization required, you can call JavaScript APIs directly.
Here is a list of the JavaScript APIs contained within the Mini Games SDK:
Category | Function | Description |
Basic Utility |
| Checks if a JSAPI feature is available in the current client version |
| Provides the local file system path to the user's data directory | |
| Initiates an HTTPS network request | |
| Cancels an ongoing network request | |
Data Caching |
| Asynchronously saves a key-value pair to local cache |
| Synchronously saves a key-value pair to local cache | |
| Asynchronously retrieves a value from local cache | |
| Synchronously retrieves a value from local cache | |
| Asynchronously removes a key-value pair from local cache | |
| Synchronously removes a key-value pair from local cache | |
| Asynchronously clears all data from the mini-game's cache | |
| Synchronously clears all data from the mini-game's cache | |
| Asynchronously obtain relevant information about the current storage | |
| Synchronously obtain relevant information about the current storage | |
Device and Network |
| Shows the keyboard for text input with customizable types and buttons |
| Updates the content of the keyboard input box while it is active | |
| Manually hides the active keyboard | |
| Registers a listener for real-time keyboard input events | |
| Removes a listener for keyboard input events | |
| Registers a listener for changes in the keyboard's height | |
| Removes a listener for keyboard height change events | |
| Registers a listener for when the user clicks the "Confirm" button | |
| Removes a listener for the keyboard "Confirm" button event | |
| Registers a listener for the event of the keyboard being retracted | |
| Removes a listener for the keyboard retraction event | |
| Gets the user's current network type (such as 'wifi', '4g') | |
| Registers a listener for the start of a touch event | |
| Registers a listener for movement during a touch event | |
| Registers a listener for the end of a touch event | |
| Registers a listener for when a touch event is interrupted | |
| Removes a listener for the `onTouchStart` event | |
| Removes a listener for the `onTouchMove` event | |
| Removes a listener for the `onTouchEnd` event | |
| Removes a listener for the `onTouchCancel` event | |
| Make the phone vibrate for 15ms | |
| Make the phone vibrate for 400 ms | |
Event |
| Registers a callback for when the mini-game returns to the foreground |
| Unregisters a callback for the `onShow` event | |
| Registers a callback for when the mini-game is sent to the background | |
| Unregisters a callback for the `onHide` event | |
| Gets query parameters from the mini-game's initial cold start | |
| Gets query parameters from the most recent time the user opened the mini game | |
File |
| Returns the global manager for performing file system operations |
| Asynchronously reads the content of a local file | |
| Synchronously reads the content of a local file | |
| Asynchronously checks if a file or directory exists | |
| Synchronously checks if a file or directory exists | |
| Asynchronously writes data to a local file | |
| Synchronously writes data to a local file | |
| Asynchronously creates a new directory | |
| Synchronously creates a new directory | |
| Asynchronously copies a file to a new location | |
| Synchronously copies a file to a new location | |
| Unzips the file | |
In-App-Ads |
| Creates a rewarded video ad instance using an ad unit ID |
| Displays the loaded rewarded video ad | |
| Registers a listener for when the rewarded ad is closed | |
| Unregisters a listener for the rewarded ad close event | |
| Registers a listener for errors during ad playback | |
| Unregisters a listener for ad playback errors | |
| Creates an interstitial ad instance using an ad unit ID | |
| Displays the loaded interstitial ad | |
| Registers a listener for when the interstitial ad is closed | |
| Unregisters a listener for the interstitial ad close event | |
| Registers a listener for errors during ad playback | |
| Unregisters a listener for ad playback errors | |
In-App Purchases |
| Checks if the user's BEANS balance is sufficient for a specified amount |
| Initiates the client-side recharge flow for a given tier ID | |
| Triggers the client payment sheet using a `trade_order_id` | |
| Directs the user to their BEANS balance page within TikTok | |
Login and Authorization |
| Starts the silent login flow to get an authorization code |
| Prompts the user to grant permissions for specific scopes | |
Media |
| Creates an instance for straightforward audio playback |
| Creates an instance for advanced audio synthesis and processing | |
| Controls for starting, pausing, or stopping audio playback | |
| Jumps to a specific time position (in seconds) | |
| Destroys the audio instance and releases resources | |
| Manages listeners for the start/resume playback event | |
| Manages listeners for the audio pause event | |
| Manages listeners for the audio stop event | |
| Manages listeners for when playback completes naturally | |
| Manages listeners for when audio is buffered enough to play | |
| Manages listeners for playback progress updates | |
| Manages listeners for the start and end of seek operations | |
| Manages listeners for playback stalls due to buffering | |
| Manages listeners for errors (returns | |
| Asynchronously decodes an | |
| Resumes or pauses the entire audio context (returns Promise) | |
| Closes the context and immediately releases all resources | |
| Creates an empty | |
| Creates a node to play data from an | |
| Creates a node to control audio volume | |
| Creates a node to generate periodic waveforms | |
| Creates a node to delay the incoming audio signal | |
| Creates a node for frequency filtering (low-pass, high-pass, etc.) | |
| Creates a node for real-time time and frequency analysis | |
| Creates a node for spatializing audio in 3D space | |
| Creates a node for signal compression (threshold, knee, etc.) | |
| Creates a node for non-linear distortion effects | |
| Combines multiple input streams into a single output | |
| Separates an input stream into individual channel outputs | |
| Creates a node for custom JavaScript-based audio processing | |
Render and Canvas |
| Creates a canvas element for drawing (first call creates the on-screen canvas) |
| Creates an image object for loading and rendering image sources | |
| Retrieves the drawing context ('2d' or 'webgl') from a canvas object | |
| Exports the canvas content as a base64-encoded data URI string | |
| Modify the rendering frame rate | |
| Loads a custom font file for use in rendering | |
Revisit Incentives |
| Guides the user to add the mini-game to their TikTok Profile sidebar |
| Checks if the user is eligible for the reward for completing the profile entrance task | |
| Prompts the user to add a shortcut to their device's home screen | |
| Checks if the user can claim the reward for adding the shortcut | |
Sharing |
| Shares the Minis content directly to the user's TikTok Story |
| Triggers the contact selection interface to send a DM | |
| Listens for the "Copy Link" action to inject custom metadata | |
| Removes listeners for the "Copy Link" event | |
Subpackage Loading |
| Downloads a subpackage in the background without executing it |
| Downloads and immediately executes the code within a subpackage | |
| Listens for progress updates on a subpackage download task | |
| Registers a listener for subpackage download progress changes, receiving an object with progress percentage | |
System |
| Synchronously retrieves device and system information |
| Asynchronously retrieves device and system information | |
| Returns an object with current device and window metrics | |
UI |
| Get the layout position information of the menu button (capsule button in the upper right corner) |
Update Management |
| Obtains the globally unique version manager for checking and applying mini game updates |
| Listens for completion of the version check and returns whether a new version is available | |
| Listens for the event indicating the new version package is ready to be applied | |
| Listens for failure of the new version package preparation process | |
| Applies the prepared new version and restarts the mini game | |
Websocket |
| Creates a WebSocket connection to the specified WSS URL with optional headers, protocols, and timeout, returning a SocketTask |
| Closes the WebSocket connection, optionally providing a close code and reason, with success/fail/complete callbacks | |
| Registers a listener for when the WebSocket connection opens, receiving response headers and debugging profile info | |
| Registers a listener for incoming WebSocket messages, receiving the server’s data as a string or ArrayBuffer | |
| Registers a listener for the WebSocket close event, receiving the close status code and reason | |
| Registers a listener for WebSocket errors, receiving an error code and message | |
| Sends string or ArrayBuffer data over the WebSocket with optional success/fail/complete callbacks |