Amba

Leaderboards

Rank users by XP, streak length, or custom metrics 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, or custom event count) and period
  2. Entries are updated automatically as users earn XP, maintain streaks, or track events
  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

Periods

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

Admin API reference

MethodPathDescription
POST/admin/leaderboardsCreate leaderboard
GET/admin/leaderboardsList leaderboards
GET/admin/leaderboards/:id/entriesGet ranked entries

Client API reference

MethodPathDescription
GET/client/leaderboardsList active leaderboards
GET/client/leaderboards/:idGet entries (paginated, ranked)
GET/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

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