Amba

Leaderboards

Rank users by XP, streak length, custom event counts, or submitted game scores, with all-time, daily, weekly, and monthly periods.

Leaderboards rank users by a metric over a time period. Great for adding competitive elements to your app.

How it works

  1. Admin defines a leaderboard with a metric (XP, streak, custom event count, or a submitted score) and period
  2. Entries are updated automatically as users earn XP, maintain streaks, or track events. Score leaderboards take each score from your server (see Score leaderboards)
  3. The client SDK fetches ranked entries and the current user's position

SDK usage

Leaderboards are addressed by their key (the slug you set when creating one), not an opaque id.

Get a leaderboard

const board = await Amba.leaderboards.get('weekly_xp');
// { key, name, metric, period, max_entries, ... }

Get leaderboard entries

// Returns up to 100 ranked entries by default. Pass `limit` to cap.
const entries = await Amba.leaderboards.getEntries('weekly_xp');
const top10 = await Amba.leaderboards.getEntries('weekly_xp', 10);
// Returns ranked entries with user display names and avatars.

getEntries(key, limit?) takes the leaderboard key and an optional numeric limit. There is no offset/pagination — entries are always returned from rank 1.

Get my rank

const myRank = await Amba.leaderboards.getMyRank('weekly_xp');
// { rank: 12, score: 1500, app_user_id: "..." }

Metrics

MetricDescription
xpTotal XP earned (within period)
streakLongest streak (within period)
customCount of a specific event
high_scoreBest score your server submitted (see Score leaderboards)

Periods

PeriodDescription
all_timeCumulative, never resets
dailyResets every day at midnight UTC
weeklyResets every Sunday at midnight UTC
monthlyResets on the 1st of each month

Score leaderboards

A score leaderboard (metric: "high_score") ranks the best score each player has submitted. Your server submits a score after it checks the run; the board keeps one entry per player, their best, for each window. Reads rank the stored scores directly, so a new score shows on the next read.

  • One definition, many boards. Create the board with keyed: true and pass a key (for example the game id) on every submit and read. Each key is its own board under the same definition.
  • Windows in UTC. period is daily, weekly, monthly or all_time. Each window keeps its own best scores, and past windows stay readable, so yesterday's champion is one query away.
  • Ranking order. sort: "desc" (the default) ranks the highest score first. sort: "asc" ranks the lowest first, for times and move counts.
  • Ties. On an equal score, whoever reached it first ranks higher. Submitting the same score again keeps the earlier time.
  • Server-only submit. Scores go in through the admin API with a server key, from an Amba function or your backend. The client SDK reads.

Arcade example

An arcade with a dozen games wants a daily champion per game. One definition covers all of them:

amba_leaderboards_create({
  project_id: "proj_xxx",
  name: "arcade-daily",
  metric: "high_score",
  period: "daily",
  keyed: true
})

When a run ends, the game server (here an Amba function holding the server key) submits the score:

curl -X POST "https://api.amba.dev/v1/admin/projects/${PROJECT_ID}/leaderboards/arcade-daily/scores" \
  -H "Authorization: Bearer ${AMBA_SERVER_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{"app_user_id":"7b0c…","score":48210,"key":"pacman","idempotency_key":"run_9f2e"}'
{
  "data": {
    "leaderboard": "arcade-daily",
    "key": "pacman",
    "period": "daily",
    "period_start": "2026-11-06",
    "app_user_id": "7b0c…",
    "score": 48210,
    "best_score": 48210,
    "achieved_at": "2026-11-06T18:04:11.532Z",
    "new_personal_best": true,
    "rank": 3,
    "replayed": false
  }
}

new_personal_best is true when this score beat the player's stored best for today. A worse score leaves the stored best and its time unchanged and still returns the current rank. A retry with the same idempotency_key replays the first result (replayed: true).

The app reads today's board for a game, with the signed-in player's own entry alongside:

GET /v1/client/leaderboards/arcade-daily/entries?key=pacman&limit=10
{
  "data": [
    {
      "rank": 1,
      "user_id": "…",
      "app_user_id": "…",
      "display_name": "Ana",
      "avatar_url": null,
      "score": 91200,
      "achieved_at": "2026-11-06T09:12:40Z"
    }
  ],
  "total": 214,
  "offset": 0,
  "limit": 10,
  "key": "pacman",
  "period": "daily",
  "period_start": "2026-11-06",
  "me": { "rank": 3, "user_id": "7b0c…", "score": 48210, "achieved_at": "2026-11-06T18:04:11.532Z" }
}

Yesterday's champion is the same call with period_start set to any date in that window:

GET /v1/client/leaderboards/arcade-daily/entries?key=pacman&period_start=2026-11-05&limit=1

From the SDK (web 4.3.0, Node 4.3.0, React Native 4.4.0, Swift 4.4.0, Android 4.4.0), pass the board key and window after the limit:

const today = await Amba.leaderboards.getEntries('arcade-daily', 10, 'pacman');
const yesterday = await Amba.leaderboards.getEntries('arcade-daily', 1, 'pacman', '2026-11-05');
const mine = await Amba.leaderboards.getMyRank('arcade-daily', 'pacman');

GET /v1/client/leaderboards/:key/me takes the same key and period_start parameters. A time-trial game uses a second definition with sort: "asc", so the fastest time ranks first.

Admin API reference

MethodPathDescription
POST/v1/admin/projects/:projectId/leaderboardsCreate leaderboard
GET/v1/admin/projects/:projectId/leaderboardsList leaderboards
GET/v1/admin/projects/:projectId/leaderboards/:id/entriesGet ranked entries (key, period_start on score boards)
POST/v1/admin/projects/:projectId/leaderboards/:id/scoresSubmit a score to a high_score board (server only)

Client API reference

MethodPathDescription
GET/v1/client/leaderboardsList active leaderboards
GET/v1/client/leaderboards/:idGet a leaderboard's definition (id or name)
GET/v1/client/leaderboards/:id/entriesGet entries (paginated with limit and offset)
GET/v1/client/leaderboards/:id/meGet current user's rank

MCP tools

ToolDescription
amba_leaderboards_createCreate a leaderboard with metric, period, and max entries
amba_leaderboards_getGet leaderboard entries with user details
amba_leaderboards_submit_scoreSubmit a player's score to a high_score board

Example

Agent: "Create weekly and all-time XP leaderboards"

amba_leaderboards_create({
  project_id: "proj_xxx",
  name: "Weekly Top Earners",
  metric: "xp",
  period: "weekly",
  max_entries: 100
})

amba_leaderboards_create({
  project_id: "proj_xxx",
  name: "All-Time XP Leaders",
  metric: "xp",
  period: "all_time",
  max_entries: 100
})

On this page