Docs
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.
TikTok supports two runtime types for your mini game: HTML and Native. As the Mini Games SDK is already preloaded into the TikTok app, you only need to initialize the SDK if your mini game uses HTML runtime.
- HTML: Web-based build that runs in a webview using HTML/CSS/JavaScript, fast to ship but limited performance. Requires you to initialize Mini Games SDK in your HTML before calling JavaScript APIs.
- 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 | |
Device and Network |
| 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 | |
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 | |
unzip | 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 | |
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 | |
| 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 | |
SubpackageLoading |
| 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 |
| (HTML mini games only) Get the layout position information of the menu button (capsule button in the upper right corner) |
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. |