XP and Levels
Auto-award XP based on engagement events with configurable rules, daily caps, and cooldowns.
XP (experience points) automatically accrue when users track events. Define rules that map events to XP amounts, and Amba handles the rest.
How it works
- Admin creates XP rules that map event names to XP amounts
- When a user tracks a matching event, XP is awarded automatically
- XP accumulates in the user's XP balance with total, level, and period tracking
- Every XP award is logged for a full audit trail
SDK usage
Get current XP
Use xp_this_period to drive weekly/monthly leaderboards or "earn 500 XP this week" challenges — the window is defined by the project's XP rules and rolls over server-side, so the client just reads the current value.
Get XP history
Manual adjustments (support & promos)
Most XP flows through rules that fire automatically on events. For one-off corrections — a support credit, a promo top-up, reversing a mistaken award — adjust a user's XP directly with amba_xp_grant and amba_xp_deduct (REST: POST /admin/xp/grant, POST /admin/xp/deduct).
A manual adjustment is deliberately quieter than a rule-driven award: it updates the user's total and recomputes their level, but it does not emit level-up engagement events or re-evaluate achievement criteria — those belong to genuine user actions, not operator corrections. The ledger records each adjustment so it's distinguishable from rule-driven XP. deduct floors at zero — it returns INSUFFICIENT_XP rather than driving a balance negative. Amounts are positive integers.
To also award a badge use amba_achievements_grant; a manual XP grant never auto-unlocks achievements.
The level curve
A user's level is computed from their total_xp against the project's level curve. By default the curve is flat — xp_per_level of 1000, so level = floor(total_xp / 1000) + 1. You can make it non-flat by setting explicit level_thresholds: a strictly-increasing array of cumulative-XP boundaries.
Read and set the curve via the admin XP config endpoints:
level_thresholds: null clears the explicit curve and falls back to the flat xp_per_level. The PATCH response includes persisted — true once the curve is durably stored, false on a project that predates the feature (the effective default is returned but not saved).
Clients can read the effective curve so the app shows exact thresholds instead of reverse-engineering them:
Setting a new curve does not retroactively recompute existing rows — levels rebase naturally on each user's next XP write (so changing the curve never re-fires level-up events for past XP).
Admin API reference
| Method | Path | Description |
|---|---|---|
POST | /admin/xp | Create XP rule |
GET | /admin/xp | List XP rules |
GET | /admin/xp/config | Read the project's level curve |
PATCH | /admin/xp/config | Set xp_per_level and/or level_thresholds |
POST | /admin/xp/grant | Manually add XP to a user (support/promo) |
POST | /admin/xp/deduct | Manually subtract XP from a user |
Client API reference
| Method | Path | Description |
|---|---|---|
GET | /client/xp | Get user's XP, level, and period XP |
GET | /client/xp/config | Effective level curve (xp_per_level + thresholds) |
GET | /client/xp/history | Get XP ledger entries (paginated) |
GET | /client/xp/rules | Get active XP rules |
MCP tools
| Tool | Description |
|---|---|
amba_xp_rules_create | Create an XP rule with event trigger, amount, daily cap, and cooldown |
amba_xp_rules_list | List all XP rules for a project |
amba_xp_grant | Manually add XP to a user (support / promo correction) |
amba_xp_deduct | Manually subtract XP from a user (inverse of grant) |
amba_users_get_xp | Get a specific user's XP and level |
Example: Set up XP rules
Rule options
| Field | Type | Description |
|---|---|---|
name | string | Display name for the rule |
event_name | string | Event that triggers the XP award |
xp_amount | number | XP to award per trigger |
max_per_day | number | Max triggers per user per day (null = unlimited) |
cooldown_seconds | number | Min seconds between awards for same user (default 0) |