Kuma for developers Early access API reference Manage keys

Rewards from your app

Give coins when someone wins a match, XP when they come to an event, or take coins back for a purchase on your site.

Before you start

Give coins

JavaScript
const API = "https://api.kumabot.xyz/v1";
const SERVER_ID = process.env.KUMA_SERVER_ID;

/**
 * Give (or, with a negative amount, take) coins once per event.
 * eventId must be unique to what you're rewarding ("match-8812-winner"):
 * it's the Idempotency-Key, so sending it twice never pays twice.
 */
export async function giveCoins(userId, amount, eventId, reason) {
  for (let attempt = 1; attempt <= 4; attempt++) {
    let res;
    try {
      res = await fetch(`${API}/servers/${SERVER_ID}/members/${userId}/coins`, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${process.env.KUMA_KEY}`,
          "Content-Type": "application/json",
          "Idempotency-Key": eventId,
        },
        body: JSON.stringify({ amount, reason }),
      });
    } catch {
      // Network trouble: safe to retry with the same Idempotency-Key.
      await new Promise((r) => setTimeout(r, 2 ** attempt * 500));
      continue;
    }
    const body = await res.json();
    if (res.ok) return body; // { applied, balance, ... }

    const { code, message, retry_after } = body.error;
    if (code === "rate_limited" || res.status >= 500) {
      await new Promise((r) => setTimeout(r, (retry_after ?? 2 ** attempt) * 1000));
      continue;
    }
    // daily_limit_reached, feature_disabled, user_not_allowed, invalid_body…
    // won't fix themselves on a retry: report them.
    throw new Error(`${code}: ${message}`);
  }
  throw new Error("Kuma didn't answer after 4 tries");
}

await giveCoins("01HZX…", 250, "match-8812-winner", "Won match 8812");

What comes back

Response
{
  "id": "txn_9c1e2f3a4b5d6e7f",
  "user": { "id": "01HZX…", "username": "honeybear", "avatar_url": null },
  "amount": 250,
  "applied": 250,
  "balance": 1840,
  "reason": "Won match 8812",
  "created_at": "2026-11-22T14:02:51.000Z",
  "dry_run": false
}

A negative amount removes coins but never goes below 0, so applied can be smaller than you asked for. Up to 1,000,000 coins either way per request.

Idempotency: never pay twice

Every write needs an Idempotency-Key header. Kuma remembers it for 24 hours:

Use something that identifies the reward itself (a match id, a subscription id), not a random value made at the moment you send: then even your own code running twice can't pay twice.

Give XP

Request
curl -X POST https://api.kumabot.xyz/v1/servers/$SERVER_ID/members/$USER_ID/xp \
  -H "Authorization: Bearer $KUMA_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: event-2026-11-22-attended-$USER_ID" \
  -d '{"amount": 500, "reason": "Came to movie night"}'

XP works like chatting: members who linked their accounts share it, and a level-up gives the server's level roles and badges and is sent to webhooks as member.level_up. Chat's "levelled up!" message isn't posted for API grants. Up to 100,000 XP per request; XP can't be taken away.

Try it without changing anything

Add "dry_run": true to the body. Kuma runs every check (scope, limits, the member, the amount) and answers as if it happened, without changing anything or using your daily limit. A dry run doesn't need an Idempotency-Key.