Building an overlay
An overlay is a web page, written by hand or built with React, Vue, Svelte or any other framework: Tokio only needs the finished folder. It serves the folder at http://tokio-app.local:37891/<overlay-id>/ and sends the page every LIVE event over a WebSocket.
Folder layout
Section titled “Folder layout”my-overlay/├── info.yaml # name and version├── config.yaml # settings shown in Tokio's gallery (optional)└── index.html # the overlay, or your framework's build outputAny other files in the folder (scripts, styles, images) are served next to index.html.
info.yaml
Section titled “info.yaml”name: Likes Counterversion: "1.0.0"config: true| Key | Description |
|---|---|
name |
Shown in the gallery. |
version |
Your overlay’s version, in quotes: YAML reads 1.0 as a number, which Tokio refuses. |
config |
Required: true when the overlay has a config.yaml with settings, else false. |
commands |
Optional: the chat commands your overlay answers that no setting holds, like ["!join"]. |
The setup block
Section titled “The setup block”index.html must contain a setup block, opened with exactly <script id="tokio-setup">. Write it yourself, before the scripts that read it:
<script id="tokio-setup"> window.__OVERLAY_ID__ = ""; window.__OVERLAY_CONFIG__ = { title: "Likes", main_color: "#ffffff" };</script>window.__OVERLAY_ID__is required. Pass it totokio.connect, never a hard-coded ID: Tokio’s previews only reach the overlay through its own ID.window.__OVERLAY_CONFIG__is only for overlays with settings (config: true). Give it the defaults fromconfig.yaml, see Settings.
Tokio refuses to import an overlay without the block. It replaces everything inside the block with the overlay’s ID, its saved settings and a script that sends the overlay’s WebSocket to the right computer, so put nothing else in it.
Listening to events
Section titled “Listening to events”@tokioapp/overlay (MIT) connects to Tokio and hands you the events. Overlays you import need it, since Tokio’s previews post their events to the overlay’s frame and the library receives them.
It has no dependencies, and ships an ES module, a CommonJS build and a browser build with TypeScript types.
tokio.on(event, callback)subscribes to an event and returns a function that unsubscribes.tokio.off(event, callback)removes a callback.tokio.connect(id, url?)connects to Tokio, atws://localhost:37891unless you pass another URL, and reconnects on its own if Tokio restarts. Call it once, when the overlay starts.tokio.disconnect()closes the connection.
See Events for every event and its data.
In a plain HTML page
Section titled “In a plain HTML page”Load the browser build from a CDN. It defines a global TokioOverlay:
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/@tokioapp/overlay@1"></script> <script id="tokio-setup"> window.__OVERLAY_CONFIG__ = { title: "Likes", main_color: "#ffffff" }; window.__OVERLAY_ID__ = ""; </script> </head> <body> <h1 id="title">Likes</h1> <p id="likes">0</p>
<script type="module"> const { tokio, TOKIO_EVENTS } = TokioOverlay; const title = document.getElementById("title"); const likes = document.getElementById("likes");
function apply(config) { title.textContent = config.title; title.style.color = config.main_color; }
apply(window.__OVERLAY_CONFIG__);
// Sent when the streamer saves the overlay's settings, and on each // change while they edit them in Tokio's preview. tokio.on(TOKIO_EVENTS.CONFIG, apply);
tokio.on(TOKIO_EVENTS.LIKE, (data) => { likes.textContent = data.totalLikes; });
tokio.connect(window.__OVERLAY_ID__); </script> </body></html>With a framework
Section titled “With a framework”Install the package and import it:
npm install @tokioapp/overlayimport { tokio, TOKIO_EVENTS } from "@tokioapp/overlay";
tokio.on(TOKIO_EVENTS.GIFT, (data) => { console.log(`${data.user.username} sent ${data.gift.name}`);});
tokio.connect(window.__OVERLAY_ID__);Because tokio.on returns its own unsubscribe function, it fits a component’s cleanup directly. In React, for example:
useEffect( () => tokio.on(TOKIO_EVENTS.LIKE, (data) => setLikes(data.totalLikes)), [],);When you build the overlay:
- Use relative asset paths. The overlay is served under
/<overlay>/, so absolute paths such as/assets/app.jsdon’t resolve. In Vite, setbase: "./". - Ship the YAML files with the build.
info.yamlandconfig.yamlmust sit next to the builtindex.html. In Vite, put them inpublic/and they’re copied into the output folder. - Keep the setup block in the HTML template. Put the
<script id="tokio-setup">block in yourindex.htmltemplate so it survives the build, and readwindow.__OVERLAY_ID__(andwindow.__OVERLAY_CONFIG__) at runtime.
Import the build output folder (for example dist/) into Tokio.
Settings
Section titled “Settings”When info.yaml has config: true, Tokio writes the overlay’s saved settings into window.__OVERLAY_CONFIG__, in the setup block. config.yaml describes the settings, which the streamer changes in the overlay’s Customize window. Fields are grouped in sections, and each field’s id becomes a key of __OVERLAY_CONFIG__:
sections: - name: General id: generalfields: - name: Title id: title type: input section: general attributes: mode: text placeholder: Overlay title... value: Likes default: Likes - name: Main color id: main_color type: color section: general attributes: value: ffffff default: ffffffEvery field has a name, a unique id, a section (the id of a section) and a type. Its attributes always include a value and a default of the same type. A table’s columns have only a default. A field can also show only for some values of another (Conditional fields), and every name can be translated (Translations).
| Type | Other attributes | Value in __OVERLAY_CONFIG__ |
|---|---|---|
input |
mode (text or number), placeholder |
The text or number |
dropdown |
options (value, label, optional img), multiple, searchable |
The selected value, or a list when multiple |
color |
none; values are hex codes without #, 6 or 8 characters, quoted when they’re all digits ("000000") |
The color with #, for example "#ffffff" |
check |
none | true or false |
toggle |
none | true or false |
slider |
min, max |
The number |
gifts |
multiple; values are TikTok gift IDs |
A gift { value, label, img, coins }, or a list when multiple |
font |
none; values are a font’s name, or "" for your overlay’s own font |
The font’s name, or "" (Fonts) |
table |
columns, optional max; values are lists of rows |
A list of rows, one object per row (Tables) |
mode, options, a table’s columns, and a slider’s min and max are required; multiple and searchable default to false. Each section’s id must be unique, and each field’s section must name one.
A gifts value is undefined, or [] with multiple, while Tokio has no gift list, and gift IDs it doesn’t know are left out.

A font setting lets the streamer pick one of the fonts installed on the Tokio computer. Its value is the font’s name, up to 60 characters, and "" means your overlay’s own font.
The streaming app draws the overlay, so the font has to be installed on the computer that runs it too. Without it, the browser uses the next font in the list.
The streamer’s side is in Fonts and sound.
Tokio gives the overlay the font’s name. Put it in quotes and add your own font after it:
const { font } = window.__OVERLAY_CONFIG__;document.body.style.fontFamily = font ? `${JSON.stringify(font)}, sans-serif` : "";Replace sans-serif with the font your stylesheet uses. An empty fontFamily leaves your stylesheet in charge.
Tables
Section titled “Tables”A table setting is a list of rows the streamer adds and removes, such as social links. Each column is a field without a section or a value, and its default fills that cell in a new row. The table’s value and default are lists of rows:
- name: Social links id: socials type: table section: general attributes: max: 4 columns: - name: Platform id: platform type: dropdown attributes: options: - { value: facebook, label: Facebook } - { value: instagram, label: Instagram } default: facebook - name: Username id: username type: input attributes: { mode: text, placeholder: "@username", default: "" } - name: Icon color id: icon_color type: color attributes: { default: ffffff } value: - { platform: facebook, username: "@tokio", icon_color: ffffff } default: - { platform: facebook, username: "", icon_color: ffffff }The overlay gets the rows as objects, each cell under its column’s id:
window.__OVERLAY_CONFIG__ = { socials: [ { platform: "facebook", username: "@tokio", icon_color: "#ffffff" }, ],};- A table has at least one column. A column can be any type except
tableandslider, and itsidis unique within the table. maxis the most rows the streamer can add, an integer of 1 or more. Without it, there’s no limit.- Every row has one value per column, keyed by the column’s
id, of a kind that column’sdefaultcould be. A row can’t have any other key.
Cells are read like fields: colors have their #, and a gifts cell is a gift object. Like a gifts field, that cell can be undefined, so check it before you use it.
Only official overlays get updates. When one updates, Tokio keeps the streamer’s rows, up to the new max.
A cell stays when its column keeps its id and type and the value still fits, like a dropdown option that’s still there. The others take their column’s default, so keep column ids stable across versions.
An imported overlay never updates: importing a new version makes a second overlay, with default settings.
Conditional fields
Section titled “Conditional fields”A field with when shows in Customize only while other fields have certain values, so a setting that matters for one choice stays out of the way until it’s picked:
- name: Seconds the message stays id: message_seconds type: slider section: message when: show_message: true attributes: { min: 2, max: 15, value: 5, default: 5 }when maps a field’s id to the values it needs:
- One value, such as
show_message: trueorlayout: one. - A list, for any of them:
visibility: [interval, command]. not, for none of them:next_count: { not: 0 }.
With more than one field, all of them must match. A field that holds a list, like a dropdown with multiple, matches when any of its items does. A field whose condition names a hidden field is hidden too, and so is a section with no field showing.
whencan only name fields listed before it infields, and not tables. Table columns can’t have one.- Each value must be one the named field can have: one of a dropdown’s options, a number within a slider’s range,
trueorfalsefor a toggle or a check.
Hiding a field only changes the Customize window. The field keeps its value, and your overlay still gets it in __OVERLAY_CONFIG__, so check the setting that controls it in your code too (if (config.show_message)).
Translations
Section titled “Translations”Tokio shows your settings in its language when you translate them. Add translations next to the text, with the text for each language under its code:
sections: - name: Songs id: songs translations: { es: Canciones }fields: - name: Text before the next songs id: next_label type: input section: songs translations: { es: Texto antes de las siguientes canciones } attributes: mode: text placeholder: Up next translations: { es: A continuación } value: Up next default: Up next - name: Layout id: layout type: dropdown section: songs translations: { es: Diseño } attributes: value: list default: list options: - value: list label: List translations: { es: Lista } - value: covers label: Covers only translations: { es: Solo portadas }- The
translationsof a section, a field or a table column translate itsname. An option’s translate itslabel, and the ones in aninput’sattributestranslate itsplaceholder. - Use the language’s code:
escovers Spanish. Tokio looks for its exact language first (es-419), then for the code before the-. A text without a translation shows as you wrote it. - Only the Customize window changes. Values, like
Up nextabove, stay as you wrote them until the streamer changes them, and your overlay doesn’t get Tokio’s language.
Tokio versions from before these keys show every field, in English.
Chat commands
Section titled “Chat commands”When your overlay answers a chat command, tell Tokio, so Chat translation leaves the messages that start with it as typed. For a command the streamer sets, add command: true to its input field’s attributes:
- name: Chat command id: command type: input section: main attributes: mode: text command: true value: "!socials" default: "!socials"A table’s input column takes it too. A command that never changes goes in info.yaml’s commands. Tokio versions from before these keys ignore them.
Testing without importing
Section titled “Testing without importing”While you build an overlay, test it from the Tools page instead of importing it after every change. It works with your framework’s dev server too:
- Turn on the overlay server in Settings → Overlay server.
- On Tools → Test overlays, enter a name and create an ID.
- Put that ID in your overlay’s
window.__OVERLAY_ID__, and open the overlay in your browser. - Click Test. Tokio sends your overlay every LIVE event and a sample of the fans and top gifters. The events carry on from your last test: the same viewers come back, likes and coins add up, and a gift streak grows over a few clicks before it ends.

Tests from Tools never send tokio:config, so the overlay keeps the settings in its own setup block.
If Tokio says “No overlay connected with this ID.”, check that the page is open and connected with the same ID.
Import it
Section titled “Import it”When it’s ready, import the folder with Overlays → Import overlay (the +). Tokio gives it an ID, writes its settings into the page and serves it. If Tokio refuses it, logs/overlays.log in the .tokio folder says why. See Overlays.
Without the library
Section titled “Without the library”Overlays you import into Tokio need the library, since Tokio’s previews post their events to the overlay’s iframe.
A page you don’t import can connect a WebSocket itself, to ws://localhost:37891/?id=<overlay ID>. Tokio doesn’t serve that page, so nothing rewrites its address.
Opened on another computer, it must connect to the Tokio PC instead of localhost: to tokio-app.local pointed at it, or to its network address (shown in Settings → Overlay server). Each message is JSON with the event name and its data:
{ "type": "tokio:event:like", "data": { "user": {}, "likeCount": 5, "totalLikes": 1200 }}