Limerino

Developers

Limerino Badge API

Limerino, a native Twitch chat app for iPhone and iPad, gives chat badges to some Twitch accounts. The badges are public, the way 7TV’s are, so any chat client can show them. One request, with no key, returns every badge and who shows which.

Base URL
https://api.limerino.com
Version
v1
Auth
None
Updated

Quick start

  1. Fetch the full list.

    Send GET https://api.limerino.com/v1/badges/all when your client starts and again every 10 minutes. Keep the etag header that comes back and send it in if-none-match next time. A 304 means nothing changed, so keep the copy you have.

  2. Look up each chatter.

    Find the chatter’s Twitch user ID, as a string, in users. It’s user-id in IRC and chatter_user_id in EventSub. The first badge ID in their list is the badge they wear beside their name, and the rest are the other badges they hold. No entry means no badge.

  3. Draw the badge.

    Find the badge in badges by its id, and pick a file from its data.host.files. For an 18-point slot, the size of Twitch’s own badges, take 1x on a 1x display, 2x on a 2x display, and 3x on a 3x display, in the first format you can decode. Every size comes as a PNG. An animated file names its still PNG in static_name, for a client that doesn’t play animations.

    The image URL is "https:" + data.host.url + "/" + file.name, for example https://api.limerino.com/v1/badges/art/founder/4/2x.webp. Use data.tooltip as its hover text.

The same steps in JavaScript, for a browser or Node 18 and later:

JavaScript

const LIST = "https://api.limerino.com/v1/badges/all";
let badges = new Map();  // badge ID -> badge object
let users = new Map();   // Twitch user ID -> badge IDs, the one they wear first
let etag = null;

async function refresh() {
  const headers = { "accept-encoding": "gzip" };  // Node sends the list uncompressed otherwise; browsers ignore this
  if (etag) headers["if-none-match"] = etag;
  const res = await fetch(LIST, { headers });
  if (res.status === 304) return;  // nothing changed: keep your copy
  if (!res.ok) throw new Error(`Limerino badges: HTTP ${res.status}`);
  const list = await res.json();
  const known = list.badges.filter((badge) => badge.kind === "BADGE");
  badges = new Map(known.map((badge) => [badge.id, badge]));
  users = new Map(Object.entries(list.users));
  etag = res.headers.get("etag");
}

// The badges of Twitch user `id`, a string, in the order to draw them. The first is the
// one they wear beside their name, and the only one the Limerino app draws.
function badgesFor(id) {
  return (users.get(id) ?? []).map((badgeId) => badges.get(badgeId)).filter(Boolean);
}

refresh().catch(console.warn);
setInterval(() => refresh().catch(console.warn), 10 * 60_000);

That is the whole integration. The Limerino app draws Limerino badges right after Twitch’s own badges and before other services’ badges; place them wherever suits your client.

The response

GET /v1/badges/all

Every badge and everyone who shows one, in one response. There are no parameters and no pagination.

Request

curl -i https://api.limerino.com/v1/badges/all

Response

HTTP/2 200
cache-control: public, no-cache
content-type: application/json; charset=utf-8
etag: "21c9e75cb287906d5a2c51a8a54f1653"

{
  "badges": [
    {
      "id": "founder",
      "kind": "BADGE",
      "data": {
        "id": "founder",
        "name": "Limerino Founder",
        "tooltip": "Limerino Founder",
        "about": "For the people who were here first.",
        "how_to_get": "Earned by being an early part of the Limerino community. If you hold it, link Discord on your Limerino profile to show it.",
        "needs": ["discord_link"],
        "host": {
          "url": "//api.limerino.com/v1/badges/art/founder/4",
          "files": [
            { "name": "1x.webp", "static_name": "1x.png", "width": 18, "height": 18,
              "frame_count": 29, "format": "WEBP", "size": 12638 },
            …
            { "name": "1x.png", "width": 18, "height": 18,
              "frame_count": 1, "format": "PNG", "size": 862 },
            …
          ]
        }
      }
    },
    …
  ],
  "users": { …, "54698159": ["founder"], … }
}

The examples on this page run as written. ETags and the users in them change as the data does, so take yours from a live response. Responses are trimmed to the headers that matter, and longer bodies are formatted, or shortened with …, for reading.

FieldMeaning
badgesarray of badge objectsEvery badge, highest priority first, which is catalog order. Each element is a badge object.
usersobjectEach key is a Twitch user ID, as a string, and its value is that user’s list of badge IDs (see Which badges a user shows). A user who shows no badge isn’t listed, so users can be empty.

Both halves are taken at the same moment, so every badge ID in users is in badges. FrankerFaceZ’s global badge list is keyed by badge, with the users under each; here, as in BetterTTV’s, users is keyed by Twitch user ID.

Badge object

The full list, the catalog, and the single-user lookup return badge objects. The holders list and the POST and GET lookups return badge IDs only. Every field in this table is always present.

FieldMeaning
idstringThe badge ID: 1 to 32 lowercase letters, digits, or hyphens, starting with a letter or digit. It never changes.
kindstring"BADGE", the only kind today. Skip an entry whose kind you don’t know.
data.idstringThe same as id.
data.namestringThe badge’s name, for a list or a detail view: 1 to 64 characters (Unicode code points), with no control characters.
data.tooltipstringHover text and screen-reader label, with the same limits as name. Use it, not name, for both.
data.aboutstringWhat the badge stands for: one plain-text paragraph of at most 200 characters, or "" when the badge has none.
data.how_to_getstringHow the badge is earned, in the same form, or "".
data.needsarray of strings["discord_link"] when earning the badge takes a linked Discord account, the only value today, and [] otherwise. Skip values you don’t know.
data.host.urlstringThe base URL of the badge’s current images, without a scheme, such as //api.limerino.com/v1/badges/art/founder/4.
data.host.filesarrayThe image files (see Image files).

about, how_to_get, and needs describe a badge for an info view. A client that only draws badges in chat can ignore them.

Image files

FieldMeaning
namestring1x, 2x, 3x, or 4x, then .webp, .gif, or .png. The file’s URL is "https:" + data.host.url + "/" + name.
formatstring"WEBP", "GIF", or "PNG".
width, heightnumber18, 36, 54, or 72 pixels, for 1x to 4x. Always square.
frame_countnumber1 for a still image, more for an animation.
static_namestring, optionalOnly on animated files: the name of the still PNG at the same size, such as "2x.png".
sizenumberThe file size in bytes.
  • Every badge has a still PNG and a WebP at all four sizes. The WebP may be a still or an animation.
  • GIF is optional, and comes at all four sizes or not at all.
  • Files are listed WebP first, then GIF, then PNG, each from 1x to 4x.
  • A still file is at most 128 KiB. An animated one is at most 256 KiB and 400 frames. A badge’s files total at most 1 MiB.
  • Animation is set per file, so check each file’s own frame_count.

Differences from 7TV

A badge object matches the object of a 7TV v3 cosmetic.create event, not the whole event. A 7TV badge decoder can read it once it handles these differences:

  • static_name is only on animated files; 7TV sends it on every file. When it’s missing, use name, and never build _static file names.
  • Every badge has WebP at all four sizes, as 7TV’s do, so a decoder that keeps only WebP files draws every badge.
  • An animated badge lists still PNGs beside its animated files; 7TV lists only the animated ones.
  • There’s no data.tag, and badge IDs are short names, not 7TV object IDs.
  • about, how_to_get, and needs are Limerino additions. A decoder that rejects unknown fields has to allow them.
  • There are no entitlement events and no subscriptions per channel. One live stream sends every change, and the full list, the holders list, or a lookup says who shows a badge now.

Which badges a user shows

A user’s list names every badge they hold: the one they picked in the Limerino app first, then the rest in catalog order. On Automatic, the default, or when their pick is a badge they no longer hold, the whole list is in catalog order. A user who chose None is left out entirely, exactly like someone who holds no badge. In chat, draw the first badge: it is the one they wear beside their name, and the only one the Limerino app draws. The rest of the list is their collection, for a profile or a tooltip, where you may show it in the order given.

Every response and the live stream apply these choices. Limerino makes every badge’s text and images, and users can’t change them.

Caching, limits and failures

The full list changes when a badge’s definition changes and when someone gains, loses, or picks a badge, so it’s sent with cache-control: public, no-cache: an HTTP cache, your client’s included, checks its copy by ETag before using it.

To revalidate, send the ETag back in if-none-match, unchanged. A compressed response carries a weak ETag, W/"…", and that form matches too. If nothing changed, you get a 304 with no body:

Request

curl -i https://api.limerino.com/v1/badges/all \
  -H 'if-none-match: "21c9e75cb287906d5a2c51a8a54f1653"'

Response

HTTP/2 304
cache-control: public, no-cache
etag: "21c9e75cb287906d5a2c51a8a54f1653"

A browser preflights a request that sets if-none-match (see CORS).

Outside a browser, send accept-encoding: gzip: the list is then about a fifth of the size. A request that lists br first, as Node’s fetch does by default, currently comes back uncompressed. Browsers ask for compression on their own.

Keeping your copy

  • Keep one copy for the whole app, across every channel, window, and tab, with its badges keyed by ID.
  • Check its age on a timer, and again when the app returns to the foreground or the network comes back. Refresh it when it’s 10 minutes old.
  • Don’t refresh less often. Without the live stream, a user’s change reaches you only at a refresh, so a badge a user hides keeps showing in your client until then.
  • You can store the list and its ETag between launches. Draw from the stored copy at startup and revalidate it.
  • Match IDs as strings. A Twitch user ID can run to 20 digits, which doesn’t fit exactly in a JavaScript number.
  • Skip a badge whose kind you don’t know.

Rate limits

Limits apply per IP address, counted in a fixed one-minute window that opens with the address’s first request. Every request counts, including errors and 304 responses. A HEAD request counts against its own limit, the same size as the endpoint’s GET.

EndpointRequests a minute
Full list5,000
Catalog600
Holders list5,000
Holder shards, shared by all 64640
Live stream, new streams30
POST and GET lookups, shared1,200
Single-user lookup600
Badge art3,000
Preflights (OPTIONS) of /v1/badges1,200
Preflights of every path under it, shared1,200

An address can also keep 50 live streams open at once. If the server cannot distinguish client addresses from proxy addresses, both stream limits per address are disabled; the server-wide limit of 2,000 open streams still applies.

Clients behind one address, such as an office network or a mobile carrier’s gateway, share its limits. A client that keeps the full list sends a request every 10 minutes, and one that keeps the catalog and the holders list sends two, so those limits fit thousands of clients behind one address. One that uses lookups sends at most 30 a minute, so the lookup limit fits about 40 of them.

HeaderMeaning
x-ratelimit-limitRequests allowed per window.
x-ratelimit-remainingRequests left in this window.
x-ratelimit-resetSeconds until the window resets. A count, not a timestamp.
retry-afterWith a 429: seconds left in the window.

Over the limit, you get a 429:

Response

HTTP/2 429
content-type: application/json; charset=utf-8
retry-after: 46
x-ratelimit-limit: 5000
x-ratelimit-remaining: 0
x-ratelimit-reset: 46

{"error":"rate_limited"}

Act on the 429 and retry-after (see Failures), not on x-ratelimit-remaining or the numbers on this page, which can change. If the limits get in your way, say so (see Help).

Failures

  • Give every request but the live stream a timeout. One that never completes would otherwise stall everything behind it.
  • On a 429, a 5xx, a timeout, or a network error, keep what you have: your copy of the list, and with lookups, your cached results and the IDs still waiting for a lookup. Never turn a failed lookup into a no-badge result.
  • Then wait retry-after seconds, or 60 when the response has none, and double that wait after each consecutive failure, to at most 10 minutes.
  • Add a few random seconds to each wait, so clients behind one address don’t all retry together.
  • A 400 means the request itself is wrong: fix it, and don’t resend it as it was. Treat each ID of a rejected lookup as looked up: keep drawing the result you had, or no badge, until its cache time passes.

Images

Pick a badge’s image from data.host.files (see Image files). The 18, 36, and 72 pixel sizes match Twitch’s own badges, so a Limerino badge fits the slot you already draw those in.

  • 1x · 18 px
  • 2x · 36 px
  • 3x · 54 px
  • 4x · 72 px
One badge at 18, 36, 54, and 72 CSS pixels.
  1. Multiply the slot size, in points or CSS pixels, by the display scale. An 18-point slot needs 18 pixels on a 1x display and 54 on a 3x display.
  2. Pick the smallest size that’s at least that big, or 4x if none is.
  3. Take the first file at that size in a format you can decode, and use the PNG if a WebP or GIF fails to decode.
  4. Build its URL (see Image files), taking the host and the revision from data.host.url every time; both can change.

The same steps in JavaScript:

JavaScript

// The image for `badge` in a slot `slot` CSS pixels wide. Pass animate = false
// if your client doesn't play animated images. Outside a browser, use your
// display's own scale in place of devicePixelRatio.
function badgeImage(badge, slot = 18, animate = true) {
  const { url, files } = badge.data.host;
  const need = slot * (globalThis.devicePixelRatio || 1);
  const size = [18, 36, 54, 72].find((px) => px >= need) ?? 72;
  // The formats your client decodes. `files` lists WEBP, then GIF, then PNG.
  const formats = ["WEBP", "GIF", "PNG"];
  const file = files.find((f) => f.width === size && formats.includes(f.format));
  const png = files.find((f) => f.width === size && f.format === "PNG");
  if (!file || !png) return null;
  const still = !animate ||
    globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
  const name = still && file.static_name ? file.static_name : file.name;
  return {
    src: `https:${url}/${name}`,
    // The PNG, to try once if `src` fails to decode; null when `src` is the PNG.
    fallback: name === png.name ? null : `https:${url}/${png.name}`,
    alt: badge.data.tooltip,
  };
}

Switch to fallback at most once. A PNG that fails too usually means the badge has left the catalog, so refresh the catalog instead of retrying.

Images are served from the host in data.host.url, today api.limerino.com. A loader that works from a host allowlist needs that host on it.

Animated badges

Play a file whose frame_count is above 1 as encoded, with its own frame timing and loop count.

Draw the still PNG its static_name names instead when your client doesn’t animate images or the viewer has turned animation off. On the web, that’s prefers-reduced-motion: reduce. The Limerino app draws the still when its own animation setting or Auto-Play Animated Images is off, or Dim Flashing Lights is on.

Badge art

GET /v1/badges/art/{badge}/{revision}/{file}

Returns one image. Build its URL from a badge object, as above, never from a badge ID and a revision of your own.

An image URL’s bytes never change: new art gets a new revision number, and so a new URL, which is why an image may be cached for a year. Older revisions keep working while the badge is in the catalog, so a client with an old catalog still draws its badges until it refreshes.

Request

curl -I https://api.limerino.com/v1/badges/art/founder/4/2x.webp

Response

HTTP/2 200
cache-control: public, max-age=31536000, immutable
content-type: image/webp
etag: "fec291956f15d4ffd20beb5d3978578a516483d714a5a4d2dd40f901a5f750e4"
StatusMeaning
200 OKThe image: image/webp, image/gif, or image/png.
304 Not ModifiedYour copy is current.
404 Not Foundnot_found: no such badge, revision, or file, or the badge has left the catalog. Refresh your catalog. This answer may be cached for 60 seconds.

Other endpoints

These keep working for integrations that already use them. A new integration needs only the full list and can skip this section.

Rate limits lists their limits, and each example shows its route’s cache-control. Every 200 except the POST lookup’s and the live stream’s carries an ETag, and a matching if-none-match gets a 304, meaning your copy is current. A 404 from the holders list or a holder shard may be cached for 60 seconds, and a 503 is never stored. Any endpoint can also return 429, 500, or 503 (see Errors).

The catalog

GET /v1/badges

The full list’s badges on their own: every badge object in catalog order, highest priority first, with no parameters and no pagination. The catalog changes only when a badge’s definition does, never when someone gains, loses, or picks a badge, so most refreshes end in a 304.

Request

curl -i https://api.limerino.com/v1/badges

Response

HTTP/2 200
cache-control: public, max-age=300, stale-while-revalidate=3600
content-type: application/json; charset=utf-8
etag: "55e184843e44850cf65c8dfb6bd96e60"

{"badges":[{"id":"founder","kind":"BADGE","data":{…}},…]}

The holders list

GET /v1/badges/holders

The full list’s users on their own, in the same form: everyone who shows a badge, in one response with no pagination, at about 25 bytes per user, plus about 17 for each further badge they hold, before compression. It can be empty: {"users":{}}.

Request

curl -i https://api.limerino.com/v1/badges/holders

Response

HTTP/2 200
cache-control: public, max-age=60, stale-while-revalidate=300
content-type: application/json; charset=utf-8
etag: "b09de8e30062898be02f9664a310f20a"

{"users":{…,"54698159":["founder"],…}}

The optional badge query parameter takes a badge ID from the catalog. The response then lists only the users whose list includes that badge, whether or not they wear it first, each with their whole list in the same shape, so the number of keys is how many users hold it and haven’t chosen None. To count who wears it beside their name, count the users whose first entry is that badge. Send the parameter once. Other query parameters are ignored.

Request

curl -i 'https://api.limerino.com/v1/badges/holders?badge=founder'
StatusMeaning
400 Bad Requestinvalid_badge_id: badge is empty or repeated, or isn’t a badge ID (see Badge object).
404 Not Foundnot_found: the catalog has no badge with that ID. Refresh your catalog.

Keeping the two lists

The catalog and the holders list are the full list’s two halves, each with its own ETag. Once the holders list is large, keeping them apart saves downloads: a holders event from the live stream carries the holders list’s new ETag, so the next refresh is a 304.

  • Fetch and refresh both as in Keeping your copy, revalidating each with its own ETag. Fetch the holders list bypassing your HTTP cache (cache: "no-store" with fetch): a cached copy may predate the patches you applied.
  • On sync, refresh both.
  • On holders, update the listed users as in Using the live stream, but instead of forgetting an ETag, keep the event’s etag as your holders ETag. Your catalog ETag stays as it is.
  • If the holders list names a badge your catalog doesn’t have, skip that badge. The two lists refresh together, so it appears at the next refresh.
  • For a copy too large to revalidate whole, use the holder shards.

Holder shards

GET /v1/badges/holders/shards/{shard}

The holders list in 64 shards, for a client that keeps a large copy and revalidates it often, such as a service that passes badges on to other apps. Each shard has its own ETag, so a change to one user costs you one shard instead of the whole list.

shard is the shard number, 0 to 63, with no leading zeros. Each user who shows a badge is in exactly one shard, the one numbered by their Twitch user ID mod 64. An ID can be too long for a JavaScript number, but 1,000,000 is a multiple of 64, so the last six digits give the same shard: Number(id.slice(-6)) % 64.

Request

curl -i https://api.limerino.com/v1/badges/holders/shards/47

Response

HTTP/2 200
cache-control: public, max-age=60, stale-while-revalidate=300
content-type: application/json; charset=utf-8
etag: "3b9e0d4c1f7a2e58c6d0b1a9e4f37c22"

{"shard":47,"shards":64,"users":{…,"54698159":["founder"],…}}

users has the holders list’s shape, with only this shard’s users, possibly none. shard is the shard’s number and shards is how many there are. To keep the holders list in shards:

  • Fetch all 64 shards, merge their users into one map, and keep each shard’s ETag.
  • To refresh, revalidate each shard with its own ETag. On a 200, remove every user in your map whose ID is in that shard, then add the ones it lists.
  • Apply holders events from the live stream to your map as usual, then forget the ETag of each shard that holds a listed user. Their etag is the whole holders list’s, so it fits no shard. The next refresh downloads those shards whole, bypassing your HTTP cache as above, and revalidates the rest.
  • On sync, refresh the catalog and revalidate every shard, following the rules in Using the live stream.
StatusMeaning
400 Bad Requestinvalid_shard: shard isn’t one or two digits, or has a leading zero, such as 07.
404 Not Foundnot_found: there’s no shard with that number. Shards run from 0 to 63.

The live stream

GET /v1/badges/events

Keeps the response open and sends each change to the holders list as a server-sent event, so a new badge reaches your client in seconds. Any server-sent events client reads it; in a browser, that’s EventSource. It adds to the timed refresh and never replaces it.

Request

curl -N https://api.limerino.com/v1/badges/events

Response

HTTP/2 200
cache-control: no-store, no-transform
content-type: text/event-stream; charset=utf-8

retry: 7312
event: sync
data: {"catalog":"\"55e184843e44850cf65c8dfb6bd96e60\"","holders":"\"b09de8e30062898be02f9664a310f20a\""}

: ping

event: holders
data: {"etag":"\"5d3f0c1b7a9e42f6b8c0d1e2f3a4b5c6\"","users":{"54698159":["founder"],"12826":[]}}
EventMeaning
syncRefresh what you keep. Sent when the stream opens, when the catalog changes, and when a change is too large to send as a patch: more than 1,000 users, or 64 KiB. catalog and holders are the current ETags of the catalog and the holders list; a client keeping those two can skip a list whose ETag matches its own, ignoring any leading W/.
holdersSome users now show different badges. users maps each of them to their new badge IDs, with an empty list for a user who now shows none. etag is the holders list’s ETag after the change.
  • retry is how many milliseconds to wait before you reconnect.
  • A line that starts with a colon is a comment. One arrives every 20 seconds to keep the connection open.
  • The stream doesn’t replay what you missed. The sync it opens with brings you up to date after any gap.
  • The server renews streams every 15 to 19 minutes, and a stream can end sooner, such as when the server restarts.

Using the live stream

  • Open one stream for the whole app.
  • On sync, refresh the list. Apply patches only after that refresh succeeds, and ignore them after a failed one.
  • On holders, set each listed user’s badges to the list given, and remove a user whose list is empty. Then forget your stored ETag: your copy has changed since you got it, so the next refresh downloads the list whole.
  • If an event arrives during a refresh, refresh once more when it succeeds. A queued patch may predate the downloaded snapshot, so replaying it can undo a newer change.
  • If a user’s badges include one your copy doesn’t have, skip that badge. It can happen only after a live update, and the badge arrives with the next refresh.
  • When the stream ends, reconnect after the wait it gave in retry. A browser’s EventSource does that for you.
  • If the stream is refused with a 429 or 503 (see Errors), carry on with the timed refresh and try again after retry-after seconds, or after 60 seconds when the answer has none.
  • A client that uses lookups can apply each holders event to the results it has cached.

Reference client

The full list, the live stream, and the failure rules in JavaScript, for a current browser or Node 18 and later:

JavaScript

const API = "https://api.limerino.com";
const REFRESH = 10 * 60_000;  // how often to refresh, and the longest backoff
const RETRY = 60_000;         // the first wait after a failure with no retry-after

let badges = new Map();   // badge ID -> badge object
let users = new Map();    // Twitch user ID -> badge IDs, the one they wear first
let etag = null;          // the ETag of the copy you keep; null downloads it whole
let failures = 0;
let refreshing = false;
let canPatch = false;     // a complete copy has loaded since the last sync
let again = false;        // an event arrived during a refresh: refresh once more
let nextAt = 0;           // when the next refresh is due
let timer;

async function load() {
  const headers = { "accept-encoding": "gzip" };  // Node sends the list uncompressed otherwise; browsers ignore this
  if (etag) headers["if-none-match"] = etag;
  const res = await fetch(API + "/v1/badges/all", {
    cache: "no-store",  // never take an older copy from the HTTP cache
    headers,
    signal: AbortSignal.timeout(10_000),
  });
  if (res.status === 304) return;  // unchanged: keep your copy
  if (!res.ok) {
    const error = new Error(`/v1/badges/all: HTTP ${res.status}`);
    error.retryAfter = Number(res.headers.get("retry-after")) * 1000;
    throw error;
  }
  const list = await res.json();
  const known = list.badges.filter((badge) => badge.kind === "BADGE");
  badges = new Map(known.map((badge) => [badge.id, badge]));
  users = new Map(Object.entries(list.users));
  etag = res.headers.get("etag");
}

async function refresh() {
  if (refreshing) {
    again = true;
    return;
  }
  refreshing = true;
  clearTimeout(timer);
  let wait = REFRESH;
  try {
    await load();
    canPatch = true;
    failures = 0;
  } catch (err) {
    canPatch = false;
    console.warn("Badge refresh failed; keeping the last copy.", err);
    // retry-after, or a minute; doubled per failure, to at most 10 minutes.
    wait = Math.min((err.retryAfter || RETRY) * 2 ** failures, REFRESH);
    failures += 1;
  }
  refreshing = false;
  // Redraw the messages on screen here, so new badges appear.
  const rerun = again && failures === 0;
  again = false;
  if (rerun) return refresh();
  nextAt = Date.now() + wait;
  // A few random seconds, so clients behind one address don't retry together.
  timer = setTimeout(refresh, wait + Math.random() * 5_000);
}

// One holders event: each listed user's new badges. An empty list removes them.
function patch(event) {
  if (refreshing) {
    again = true;
    return;
  }
  if (!canPatch) return;
  for (const [id, list] of Object.entries(event.users)) {
    if (list.length) users.set(id, list);
    else users.delete(id);
  }
  etag = null;  // your copy changed, so the next refresh downloads it whole
  // Redraw those users' messages here.
}

// Call for each message you draw, with its author's Twitch user ID as a string.
// Returns the author's badge objects, in the order to draw them.
function badgesFor(twitchId) {
  const ids = users.get(twitchId) ?? [];
  return ids.map((id) => badges.get(id)).filter(Boolean);
}

// The live stream. A browser reconnects a dropped stream by itself; a refused
// one (429 or 503) stays closed, so try again in a minute.
function listen() {
  const events = new EventSource(API + "/v1/badges/events");
  events.addEventListener("sync", () => {
    canPatch = false;
    refresh();
  });
  events.addEventListener("holders", (event) => patch(JSON.parse(event.data)));
  events.onerror = () => {
    if (events.readyState === EventSource.CLOSED) setTimeout(listen, RETRY);
  };
}

refresh();
// Without EventSource (Node, for one), the timed refresh alone keeps you current.
if (typeof EventSource !== "undefined") listen();

// A browser throttles timers in a hidden tab. Catch up when the tab is shown
// again or the network comes back. Outside a browser, call catchUp() from your
// app's own foreground and network events.
function catchUp() {
  if (Date.now() >= nextAt) refresh();
}
globalThis.addEventListener?.("online", catchUp);
globalThis.document?.addEventListener("visibilitychange", () => {
  if (!document.hidden) catchUp();
});

Look up users

POST /v1/badges/users

Takes 1 to 100 Twitch user IDs and returns the badges each user shows (see Which badges a user shows). The IDs travel in the body, which keeps them out of URLs (see Privacy).

The body is a JSON object with only one field, twitch_ids: 1 to 100 distinct Twitch user IDs (user-id in IRC, chatter_user_id in EventSub), each a string of 1 to 20 digits, sent exactly as Twitch gives it. A repeated ID counts once toward the 100. The API doesn’t normalize IDs. The body can be at most 4,096 bytes. Send content-type: application/json (a charset parameter is fine).

Request

curl -i https://api.limerino.com/v1/badges/users \
  -H 'content-type: application/json' \
  -d '{"twitch_ids":["54698159","12826"]}'

Response

HTTP/2 200
cache-control: no-store
content-type: application/json; charset=utf-8

{"users":{"54698159":["founder"]}}

users maps each ID that shows a badge to its list of badge IDs. IDs that show none, including IDs Twitch never issued, are left out, so users can be empty: {"users":{}}. Don’t rely on its key order.

StatusMeaning
400 Bad Requestinvalid_twitch_ids: the body isn’t a JSON object with only twitch_ids, breaks the ID rules above, or was sent as plain text (what fetch sends when you set no content-type).
413 Payload Too Largebody_too_large: the body is over 4,096 bytes. Even 100 IDs of 20 digits come to about 2,300.
415 Unsupported Media Typeunsupported_media_type: the body has no content type, or one other than JSON or plain text.

Look up users (GET)

GET /v1/badges/users?twitch_ids={ids}

Returns the same body as the POST lookup, with the IDs in the query string so that HTTP caches, such as a proxy or CDN you run, can store the response. In a chat client, prefer the POST lookup (see Privacy).

twitch_ids takes the same 1 to 100 distinct IDs, separated by commas (raw or encoded as %2C) with no spaces. Send the parameter once. Other query parameters are ignored.

Request

curl -i 'https://api.limerino.com/v1/badges/users?twitch_ids=54698159,12826'

Response

HTTP/2 200
cache-control: public, max-age=60
content-type: application/json; charset=utf-8
etag: "63869ed68482118e55d9a3d6f1e0b534"

{"users":{"54698159":["founder"]}}
StatusMeaning
400 Bad Requestinvalid_twitch_ids: the parameter is missing, empty, or repeated, has an entry that isn’t 1 to 20 digits (an empty one included), or names more than 100 distinct IDs.

Look up one user

GET /v1/badges/twitch/{id}

Takes one Twitch user ID, 1 to 20 digits, and returns full badge objects in two arrays, for a tool or a profile card about one person: badges, the user’s list in the order to draw it (see Which badges a user shows), and owned_badges, the same badges in catalog order, as their collection. Each badge object is about 1.2 KB, so the reply grows by about 2.5 KB for every badge held. For chat, keep the full list instead, or ask the users lookups for IDs alone: they answer one user in about 40 bytes, plus about 17 for each further badge.

Request

curl -i https://api.limerino.com/v1/badges/twitch/54698159

Response

HTTP/2 200
cache-control: public, max-age=60, stale-while-revalidate=300
content-type: application/json; charset=utf-8
etag: "…"

{
  "user_id": "54698159",
  "badges": [
    { "id": "founder", "kind": "BADGE", "data": { … } }
  ],
  "owned_badges": [
    { "id": "founder", "kind": "BADGE", "data": { … } }
  ]
}

Choosing None empties both public arrays; the signed-in owner can still read their full collection through the account API. A user who holds no published badges gets {"user_id":"12826","badges":[],"owned_badges":[]}.

StatusMeaning
400 Bad Requestinvalid_user_id: the ID isn’t 1 to 20 digits.

Using lookups

A lookup returns the same badges as the full list, for only the users you name. A tool that asks about one user can use the single-user lookup. Cache lookup results for the times below, not the HTTP lifetimes in the examples.

  • Fetch the catalog and refresh it as in Keeping your copy, and send no lookups until it has loaded.
  • Keep one queue for the whole app, across every channel and window. Send one request at a time, with 1 to 100 IDs, and at most one every 2 seconds.
  • Queue only IDs that are strings of 1 to 20 digits.
  • Cache each ID’s result for 10 minutes if the user shows a badge and 30 minutes if they show none. A user’s change reaches you when their result expires, so don’t cache it longer. Keep drawing an expired result until its replacement arrives.
  • Cap the cache and the queue. The Limerino app keeps 10,000 results and evicts the oldest first.
  • Don’t hold a message back for its lookup. Draw it, then add the badge when the result arrives.
  • Over IRC, also look up the signed-in user when they send a message: Twitch doesn’t echo a message to the IRC connection that sent it.
  • If a result names a badge your catalog doesn’t have, skip that badge and refresh the catalog, at most once a minute.
  • To learn about everyone, fetch the full list. Don’t walk ranges of IDs.

Errors

Every error the API sends has a JSON body with one field, error, that holds a code, such as {"error":"invalid_twitch_ids"}. Branch on the code (see Versioning).

An endpoint’s own 400, 404, 413, and 415 codes are explained with it: invalid_twitch_ids with the POST and GET lookups, body_too_large and unsupported_media_type with the POST lookup, invalid_user_id with the single-user lookup, invalid_badge_id with the holders list, invalid_shard with the holder shards, and not_found with those two and badge art. Any endpoint can return these:

StatusError
429 Too Many Requestsrate_limitedThe request is over a rate limit, or your address has too many live streams open. Back off (see Failures).
500 Internal Server Errorinternal_errorSomething failed on the server. Back off (see Failures).
503 Service Unavailablebadges_unavailableThe server can’t serve badges right now, or has no room for another live stream. It sends retry-after only for the stream, and only when the stream has no room; without one, wait 60 seconds. Back off the same way.

A request the API never sees gets another answer instead, with no CORS headers and a different body: the framework’s 404 when it matches no endpoint (a trailing slash, an extra segment, the wrong method), its 414 when a path segment is over 512 characters, and the hosting edge’s plain-text 502 when a path has broken percent-encoding (an escape that is valid but not UTF-8 gets the framework’s 400). Browser code sees each as a network error. If you get one, check the URL rather than retrying.

CORS

  • Every response from these endpoints carries access-control-allow-origin: *, including every error the API sends. Code in a web page can call the API directly.
  • Send no credentials. The default fetch settings are right. credentials: "include" fails against a wildcard origin.
  • A page can read etag, retry-after, and the three x-ratelimit headers: access-control-expose-headers lists them.
  • Every endpoint answers a preflight. OPTIONS returns 204 and allows GET and POST with the content-type and if-none-match headers.
  • A browser caches that preflight, so the POST lookup, or a GET that sets if-none-match, doesn’t always cost two requests. Chromium keeps it for up to 2 hours and Safari for up to 10 minutes.
  • Any other header that isn’t CORS-safelisted, such as authorization or an x- header, fails the preflight.
  • EventSource opens the live stream with no preflight.
  • Preflights count against limits of their own (see Rate limits).

Privacy

When your client calls the API:

  • Limerino sees each request’s IP address and, in a lookup, the IDs it asks about. There are no keys, tokens, or cookies. Fetching the full list or the holders list, or opening the live stream, says nothing about who is in your chat.
  • Limerino’s server doesn’t log individual lookups, but the hosting provider’s edge logs each request’s URL and IP address. The GET and single-user lookups put IDs in the URL, so those IDs appear there. IDs in a POST body don’t.

Badges are meant to be seen in chat, so who shows one is public:

  • The full list and the holders list name the Twitch user ID of every user who shows a badge, and anyone can read them. The live stream announces each change.
  • Users are named by Twitch user ID only. No response carries a username.
  • What a user’s list shows, and how choosing None hides it, is in Which badges a user shows. The single-user lookup also includes the full published collection in owned_badges.

The privacy policy says how badges are given and removed.

Versioning

Within v1, these don’t change:

  • Field names and types.
  • Error codes.
  • The format of badge IDs and Twitch user IDs.
  • What a user’s list means: the first badge is the one they wear beside their name, and the rest are the other badges they hold, in catalog order. Never re-sort a user’s list.
  • A user’s list names badges only: every ID in it is a badges entry of kind BADGE. Any other kind of cosmetic arrives in a top-level array of its own, with its own map of who shows it, never inside badges or a user’s list.

These can change without notice:

  • New fields can appear in any object, new endpoints under /v1, and new events on the live stream. Ignore the fields and events you don’t know.
  • The catalog can grow to hundreds of badges and a user’s list to any length. Key the catalog by ID, never by position. New image files, at new sizes or in new formats, are listed after the ones described here.
  • New values can appear for kind, needs, and format. Skip a catalog entry whose kind you don’t know, and skip needs values and image formats you don’t know; the PNGs stay.
  • The badges in the catalog, their order, and their images.
  • The host and revision in data.host.url.
  • The order of fields and keys.

A breaking change ships as /v2, next to /v1, and the changelog announces it.

Changelog

  • Changed: The documentation now teaches one integration, the full list GET /v1/badges/all; every other endpoint keeps working unchanged and moved under Other endpoints. Nothing in the API changed.
  • Changed: Wording brought in step with the live API: the single-user example, the holders list’s size per user, what ?badge= counts, the answers a request gets before it reaches the API, and a compression note for clients outside a browser. Nothing in the API changed.
  • Changed: In chat, draw a user’s first badge only; the rest of their list is their collection. Versioning now also promises that a user’s list names badges only, so a future kind of cosmetic can never displace the worn badge. Nothing in the API changed.
  • Added: Every badge has WebP at all four sizes beside its PNG, a still or an animation. The upload rules now require it, and both existing badges already had it, so a decoder that keeps only WebP files draws every badge.
  • Changed: Automatic lists every badge the user holds again, in catalog order, as it did before October 15. The holders list, its shards, the full list, the user lookups, badges on the single-user lookup and the live updates all carry those lists; the first badge is the one the Limerino app draws. None still hides the user, and owned_badges stays.
  • Changed: A picked badge is listed first, followed by the rest of the badges the user holds in catalog order, so the first entry is always the badge worn beside their name and the rest their collection. On the single-user lookup, badges therefore holds the same badges as owned_badges, in that order.
  • Added: owned_badges on the single-user lookup, for the full published collection. Choosing None hides this collection from public lookups too.
  • Changed: Automatic resolves to one displayed badge on the server. The user lists and live updates contain that badge alone; their JSON format is unchanged.
  • Added: The full list, GET /v1/badges/all: every badge and everyone showing one, in one response, so a client needs one request. The catalog and the holders list are unchanged.
  • Changed: The holders list allows 5,000 requests a minute, up from 60, the same as the full list.
  • Changed: about, how_to_get, and needs are on every badge object, as "" or [] when a badge has none. Every badge already had all three, so no response changed. If your client checked whether these fields were present, check for a non-empty about or how_to_get and for "discord_link" in needs instead.
  • Removed: availability from the badge object. This stays in v1 because v1 always said to treat any value but retired as available, and a missing value reads the same way. A decoder that requires the field should treat it as optional.
  • Added: Holder shards, GET /v1/badges/holders/shards/{shard}: the holders list in 64 parts, each with its own ETag, for clients that keep a large copy. The holders list itself is unchanged.
  • Added: The holders list, GET /v1/badges/holders, with everyone showing a badge in one response. Its badge parameter narrows it to the users showing one badge.
  • Added: The live stream, GET /v1/badges/events, which sends each change to the holders list as it happens.
  • Added: Every endpoint answers a CORS preflight that allows if-none-match, and a web page can read etag, retry-after, and the rate-limit headers.
  • Changed: 413, 415, and 429 responses have the one-field body every other error has, with the codes body_too_large, unsupported_media_type, and rate_limited. Their statusCode, message, and code fields are gone.
  • Changed: Lookups return the badges each user shows, not every badge they hold, since users can now pick one badge or none. Responses kept their shape, and users on Automatic still get every badge they hold.
  • Added: about, how_to_get, availability, and needs on the badge object.
  • Fixed: A weak ETag sent back in if-none-match now gets a 304.
· v1
  • Released: The catalog, the POST and GET lookups, the single-user lookup, and badge art in PNG, WebP, and GIF, with a still PNG for each animated file.

Help

Questions, or something here that doesn’t match what the API does? Email hello@meipath.com or ask in the Limerino Discord. The status page’s API row covers the server behind this API.