Chat integrations
Rendering emotes in chat for millions of viewers needs a different shape than a dashboard: one small, edge-cached document per channel and a push stream for changes. That's what these REST endpoints are for. No key needed.
1. Load emotes
GET https://api.jiltv.app/v1/sets/global
GET https://api.jiltv.app/v1/channels/twitch/{twitchUserId}/bootstrapThe channel bootstrap holds the active set in a compact form; the global document holds the sets every channel can use. Channel emotes win over global ones with the same name.
{
"channel": { "id": "01J9…", "platform": "TWITCH", "platform_channel_id": "123456", "owner_id": "01J8…", "display_name": "Jilence" },
"set": {
"id": "01J9Z3K8…", "name": "Jilence's Emotes", "capacity": 1000,
"emotes": [
{ "id": "01M43XZ4…", "name": "catDance", "original_name": "catJAM", "v": 1, "w": 32, "h": 32, "f": 9 }
]
},
"cdn": "https://cdn.jiltv.app/emotes"
}| Field | Meaning |
|---|---|
name | What viewers type. original_name is present when the channel renamed the emote. |
v | File version. Files are immutable per version, so URLs are cacheable forever. |
w, h | Size at 1x in CSS pixels. |
f | Flags: 1 animated, 2 zero-width (overlays the previous emote), 4 NSFW, 8 AVIF stored. |
Responses carry an ETag; send If-None-Match to get a 304. Unknown channels answer 404.
During an outage the CDN keeps serving the last good version for a day (stale-if-error).
2. Build image URLs
// f bits: 1 animated, 2 zero-width, 4 NSFW, 8 AVIF stored
function sources(cdn, e, scale = 1) {
const base = `${cdn}/${e.id}/${e.v}/${scale}x`;
return {
avif: e.f & 8 ? `${base}.avif` : null,
webp: `${base}.webp`,
width: e.w * scale, // w/h are the 1x size: reserve the box, no layout shift
height: e.h * scale,
};
}Use a <picture> with the AVIF source (when stored) and WebP as the image. GIF and PNG are not stored, so never build
those URLs. Scales 1x–4x exist for every emote; pick by devicePixelRatio or use srcset.
Larger scales are never upscaled past the uploaded image, so always size the image from w/h.
3. Show what chatters wear
channel with the login of the channel you show, clear what you cached when the channel changes, and ask again when a live
event says ch: true. Otherwise chatters show the wrong look.Load the catalog once (every published paint, badge and decoration with its design), then look up the chatters you actually show, up to 100 logins per request. Batch new chatters over a short window instead of asking per message.
GET https://api.jiltv.app/v1/cosmetics/catalog
GET https://api.jiltv.app/v1/cosmetics/twitch?logins=alice,bob&channel=streamer
GET https://api.jiltv.app/v1/personal-emotes/twitch?logins=alice,bob&channel=streamer// /v1/cosmetics/twitch: IDs from the catalog; logins wearing nothing are left out
{ "users": { "alice": { "p": "01JA…", "b": "01JB…", "d": "01JC…", "bn": "01JD…" } } }
// /v1/personal-emotes/twitch: compact emotes as in the bootstrap
{ "users": { "alice": [{ "id": "01M4…", "name": "aliceWave", "v": 1, "w": 32, "h": 32, "f": 0 }] },
"cdn": "https://cdn.jiltv.app/emotes" }Answers are cached for a minute, so keep "wears nothing" as an answer too. For emotes, channel emotes win over personal ones and personal
over global ones with the same name. p, b and d are catalog IDs: the paint on the name, the badge,
the avatar frame. bn is the profile banner at {cdn}/banners/{id}/card.webp. How to draw a paint
on a name, with the Twitch color (or a contrast color) underneath and the right look for the time of day, is in Render paints.
Per channel, live
Follow the cosmetics topic (next section) to hear when someone changes their look or personal emotes. The event holds the
global look; for users with channel-specific looks it says ch: true without naming the channels, so ask again for yours. presence.joined already carries the look for the joined channel.
let channel = 'streamer'; // Twitch login of the channel you show
const looks = new Map(); // login -> { p, b, d, bn } in this channel, or null
const personal = new Map(); // login -> personal emotes in this channel
async function lookup(logins, bust = '') {
const q = `logins=${logins.join(',')}&channel=${channel}${bust && `&t=${bust}`}`;
const [c, e] = await Promise.all([
fetch(`https://api.jiltv.app/v1/cosmetics/twitch?${q}`).then((r) => r.json()),
fetch(`https://api.jiltv.app/v1/personal-emotes/twitch?${q}`).then((r) => r.json()),
]);
for (const l of logins) {
looks.set(l, c.users[l] ?? null); // cache "nothing" too
personal.set(l, e.users[l] ?? []);
}
}
// Every answer was for the old channel: start over.
function switchChannel(login) {
channel = login;
looks.clear();
personal.clear();
}
// On the cosmetics topic. Events carry the global look; ch: true means the
// user has channel-specific looks, so ask again for your channel. The event
// id as t skips the one-minute caches.
function handle(topic, type, d, eventId) {
if (type === 'user.cosmetics') {
if (d.ch) lookup([d.login], eventId);
else looks.set(d.login, { p: d.p, b: d.b, d: d.d, bn: d.bn });
}
if (type === 'user.personal_emotes') {
if (d.ch) lookup([d.login], eventId);
else personal.set(d.login, d.emotes);
}
}4. Receive live updates
One WebSocket carries every topic you follow: the channels you show, cosmetics (what chatters wear, everywhere) and me (your own notifications, signed in on jiltv.app only). Add and drop topics on the open socket, so switching channels
never reconnects. Every event has an id; keep the newest per topic and send it as since after a reconnect to
get exactly what you missed. If that is no longer possible you get resync: true: reload that topic's state.
const positions = new Map(); // topic -> newest event id, to resume
const ws = new WebSocket('wss://api.jiltv.app/v1/events/ws', 'jiltv.events.v1');
ws.onopen = () => ws.send(JSON.stringify({
op: 'subscribe',
topics: ['twitch:123456', 'cosmetics'].map((t) => ({ t, since: positions.get(t) })),
}));
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg.id) positions.set(msg.t, msg.id);
if (msg.op === 'subscribed' && msg.resync) reloadBootstrap(); // missed too much
if (msg.op === 'event') handle(msg.t, msg.type, msg.d);
if (msg.op === 'reconnect') ws.close(); // server restarts: reconnect now
};
// Switch channels on the same socket:
ws.send(JSON.stringify({ op: 'unsubscribe', topics: ['twitch:123456'] }));
ws.send(JSON.stringify({ op: 'subscribe', topics: [{ t: 'twitch:654321' }] }));| Server message | Meaning |
|---|---|
hello | Connected. heartbeat in ms, max_topics. |
subscribed | Following t from position id; resync when events were lost. |
event | t topic, id position, type, d data (tables below). |
hb | Heartbeat. Nothing for two intervals means the connection is dead: reconnect. |
reconnect | The server is restarting. Reconnect right away; every topic resumes. |
error | code, message and the topic t it concerns. |
Reconnect with exponential backoff and jitter. A client that can't keep up is disconnected (close code 1013) and simply
resumes. Big messages are compressed (permessage-deflate).
GraphQL subscriptions
The same topics and events, typed, over the standard graphql-transport-ws protocol. Each topic starts with a subscribed (or resync) event.
import { createClient } from 'graphql-ws';
const client = createClient({ url: 'wss://api.jiltv.app/v1/events/graphql' });
client.subscribe(
{
query: `subscription($t: [EventTopicInput!]!) {
events(topics: $t) { topic id type data }
}`,
variables: { t: [{ topic: 'twitch:123456' }, { topic: 'cosmetics' }] },
},
{ next: ({ data }) => handle(data.events), error: console.error, complete: () => {} },
);Server-Sent Events
Where WebSockets are blocked, follow one topic per stream with EventSource. It reconnects by itself and resumes through Last-Event-ID.
const es = new EventSource('https://api.jiltv.app/v1/events/channels/twitch/123456');
es.addEventListener('set.batch', (e) => {
const { set_id, added, removed, renamed } = JSON.parse(e.data);
if (set_id !== activeSetId) return;
for (const id of removed) index.deleteById(id); // removals first,
for (const r of renamed) index.rename(r.emote_id, r.name); // then renames,
for (const emote of added) index.add(emote); // then additions
});
es.addEventListener('emote.updated', (e) => { /* new version or emote disabled */ });
es.addEventListener('channel.set_switched', () => reloadBootstrap());| Event | Data |
|---|---|
set.batch | set_id, added (compact emotes), removed (IDs), renamed (emote_id, name) |
set.emote_added | set_id, emote |
set.emote_removed | set_id, emote_id |
set.emote_renamed | set_id, emote_id, name |
emote.updated | id, active, and when active the new v, w, h, f |
set.updated | Set renamed or resized. Refetch if you show set metadata. |
channel.set_switched | set_id of the new active set (or null). Refetch the bootstrap. |
presence.joined | A JilTV user arrived (updatePresence): user_id, login, cosmetics (p, b, d), personal_emotes and cdn, so their first message renders
without a lookup. |
user.cosmetics | On cosmetics: login and its global look (p, b, d, bn). ch: true: it wears outfits in some channels, look it up again for yours. |
user.personal_emotes | On cosmetics: login, its global personal emote list (emotes, compact) and cdn.
Replace what you cached; with ch: true look it up again for your channel. |
youtube.cosmetics, youtube.personal_emotes | The same for YouTube chat, with the chatter's YouTube channel ID in id instead of login. Look them up with /v1/cosmetics/youtube?ids= and /v1/personal-emotes/youtube?ids=. |
Ignore event types you don't know; new ones may be added without notice.
Resolve Twitch users
If you only know a channel's login (e.g. from the URL), resolve it once: GET /v1/resolve/twitch/{login} returns {"platform":"TWITCH","channel_id":"123456"}, or 404 when the channel isn't on JilTV.