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
- Admin defines a leaderboard with a metric (XP, streak, custom event count, or a submitted score) and period
- Entries are updated automatically as users earn XP, maintain streaks, or track events. Score leaderboards take each score from your server (see Score leaderboards)
- 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
Get leaderboard entries
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
Metrics
| Metric | Description |
|---|---|
xp | Total XP earned (within period) |
streak | Longest streak (within period) |
custom | Count of a specific event |
high_score | Best score your server submitted (see Score leaderboards) |
Periods
| Period | Description |
|---|---|
all_time | Cumulative, never resets |
daily | Resets every day at midnight UTC |
weekly | Resets every Sunday at midnight UTC |
monthly | Resets 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: trueand pass akey(for example the game id) on every submit and read. Each key is its own board under the same definition. - Windows in UTC.
periodisdaily,weekly,monthlyorall_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:
When a run ends, the game server (here an Amba function holding the server key) submits the score:
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:
Yesterday's champion is the same call with period_start set to any date in that window:
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:
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
| Method | Path | Description |
|---|---|---|
POST | /v1/admin/projects/:projectId/leaderboards | Create leaderboard |
GET | /v1/admin/projects/:projectId/leaderboards | List leaderboards |
GET | /v1/admin/projects/:projectId/leaderboards/:id/entries | Get ranked entries (key, period_start on score boards) |
POST | /v1/admin/projects/:projectId/leaderboards/:id/scores | Submit a score to a high_score board (server only) |
Client API reference
| Method | Path | Description |
|---|---|---|
GET | /v1/client/leaderboards | List active leaderboards |
GET | /v1/client/leaderboards/:id | Get a leaderboard's definition (id or name) |
GET | /v1/client/leaderboards/:id/entries | Get entries (paginated with limit and offset) |
GET | /v1/client/leaderboards/:id/me | Get current user's rank |
MCP tools
| Tool | Description |
|---|---|
amba_leaderboards_create | Create a leaderboard with metric, period, and max entries |
amba_leaderboards_get | Get leaderboard entries with user details |
amba_leaderboards_submit_score | Submit a player's score to a high_score board |