Show users where they stand
Your users want to know how much they have left before they run out: “60¢ of your $2 AI budget left this month”. Limitry knows the exact numbers for every limit that applies to a user, including the balances they share with their team. This guide uses the $2 AI budget from Limit AI spend per user and the team credits from Sell prepaid credits. It adds a route on your server that asks Limitry, and a React component that shows the result.
Limitry doesn’t host the screen. You copy the component, style it, and it stays yours.
1. Ask Limitry from your server
Section titled “1. Ask Limitry from your server”limitry.standing() returns every enabled limit on one subject, with
what’s used, what’s left and when it resets. Name shared subjects too,
such as the user’s team, and their limits come back in the same list:
import { createClient } from "@limitry/sdk";
// Uses the LIMITRY_API_KEY environment variable.const limitry = createClient();
// Express-style handler for the signed-in user.app.get("/api/usage", async (req, res) => { const user = req.user; const standing = await limitry.standing({ subject: { kind: "user", id: user.id }, shared: [{ kind: "team", id: user.teamId }], }); res.json(standing);});from flask import Flask, jsonifyfrom limitry import Limitry
app = Flask(__name__)# Uses the LIMITRY_API_KEY environment variable.limitry = Limitry()
# Flask handler for the signed-in user.@app.get("/api/usage")def usage(): user = current_user() standing = limitry.standing( subject={"kind": "user", "id": user.id}, shared=[{"kind": "team", "id": user.team_id}], ) return jsonify(standing.to_dict())Call it from your server with your API key, and only for the signed-in
user. The key can read every subject in the workspace, so it must never
reach a browser. The key needs Limits: View (limits:read), which
Check limits includes.
Asking isn’t a check. Limitry counts nothing, and it doesn’t use your plan’s checks.
The same question over HTTP:
import { createClient } from "@limitry/sdk";
// Uses the LIMITRY_API_KEY environment variable.const limitry = createClient();
const standing = await limitry.subjects.standing("user", "user_123", { shared: "team:team_42",});console.log(standing);from limitry import Limitry
# Uses the LIMITRY_API_KEY environment variable.limitry = Limitry()
standing = limitry.subjects.standing("user", "user_123", shared="team:team_42")print(standing)limitry subjects standing user user_123 --shared team:team_42curl "https://api.limitry.com/v1/subjects/user/user_123/standing?shared=team:team_42" \ -H "Authorization: Bearer $LIMITRY_API_KEY"The path names the user by kind and ID. shared takes up to 4 more
subjects as kind:id, separated by commas.
2. What comes back
Section titled “2. What comes back”{ "subject": { "kind": "user", "id": "user_123" }, "limits": [ { "limitId": "lmt_…", "limitName": "AI budget", "subject": { "kind": "user", "id": "user_123" }, "action": "ai-call", "unit": "cents", "window": "month", "rolling": false, "amount": 200, "used": 140, "remaining": 60, "credited": 0, "resetsAt": "2026-12-01T00:00:00.000Z" }, { "limitId": "lmt_…", "limitName": "Credits", "subject": { "kind": "team", "id": "team_42" }, "action": "*", "unit": "credits", "window": "total", "rolling": false, "amount": 100, "used": 125, "remaining": 4975, "credited": 0, "resetsAt": null } ]}Each item is one limit. The first is the user’s own AI budget: 140 of
200 cents used this month, and 60 left until it resets. The second is
the team’s balance: 100 free credits to start, 5,000 credits bought
since, and 125 spent. Its subject is the team, because the limit is
on the shared subject rather than on the user. A few cases to handle:
- No limits: a user with no limit in this environment gets an empty
limitslist. Show nothing. - Balances (window
total):resetsAtisnull, because a balance never resets. After you add credits,remainingcan be more thanamount, as above. Show “credits left” rather than a share ofamount. - Limits that reset (
day,monthand the rest): show “60 of 200 cents left” and when it resets. - Rolling limits:
resetsAtis when the oldest use in the window leaves it, which is when the next unit frees up. - Concurrent limits:
usedis how many are running now.
The numbers are exact at the moment you ask, the same counts a check sees. A test key reads test usage and a live key reads live usage.
3. The usage bar
Section titled “3. The usage bar”Copy this component into your app. It needs React and nothing else, and it reads the route from step 1:
import { useEffect, useState } from "react";
type Limit = { limitId: string; limitName: string; unit: string; window: string; amount: number; used: number; remaining: number; resetsAt: string | null;};
export function UsageBar() { const [limits, setLimits] = useState<Limit[] | null>(null);
useEffect(() => { fetch("/api/usage") .then((res) => (res.ok ? res.json() : { limits: [] })) .then((body) => setLimits(body.limits)) .catch(() => setLimits([])); }, []);
if (!limits || limits.length === 0) return null;
return ( <ul style={{ listStyle: "none", padding: 0 }}> {limits.map((l) => ( <li key={l.limitId} style={{ marginBottom: 16 }}> <UsageRow limit={l} /> </li> ))} </ul> );}
function UsageRow({ limit }: { limit: Limit }) { const balance = limit.window === "total"; const max = Math.max(limit.amount, limit.used + limit.remaining); const left = Math.max(limit.remaining, 0); const label = balance ? `${left} ${limit.unit} left` : `${left} of ${limit.amount} ${limit.unit} left`; const resets = limit.resetsAt ? `Resets ${new Date(limit.resetsAt).toLocaleString()}` : null;
return ( <div> <div style={{ display: "flex", justifyContent: "space-between", gap: 8 }}> <span>{limit.limitName}</span> <span>{label}</span> </div> <div role="meter" aria-label={limit.limitName} aria-valuemin={0} aria-valuemax={max} aria-valuenow={left} aria-valuetext={label} style={{ height: 8, borderRadius: 4, background: "#e5e7eb", overflow: "hidden", }} > <div style={{ width: `${max > 0 ? (left / max) * 100 : 0}%`, height: "100%", background: left === 0 ? "#b91c1c" : "#1d4ed8", }} /> </div> {resets && <small>{resets}</small>} </div> );}The bar shows what’s left, so it empties as the team spends. Screen readers announce the same words the user sees, such as “4975 credits left”. Swap the inline styles for your own classes.
Fetch it when the page opens, not on a timer. If your product shows the bar on every page, cache the route’s response for a few seconds on your server.
4. When they run out
Section titled “4. When they run out”A refused check throws LimitReachedError from limitry.guard()
and limitry.reserve(). Answer it where your product talks to the user, and
point them at the bar or a way to get more:
import { LimitReachedError } from "@limitry/sdk";
try { return await limitry.guard( { subject: { kind: "user", id: user.id }, shared: [{ kind: "team", id: user.teamId }], action: "report", cost: 25, }, () => buildReport(params), );} catch (err) { if (err instanceof LimitReachedError && err.reason === "limit_reached") { return res.status(402).json({ message: "Your team is out of credits. Buy more to keep going.", buyUrl: "/billing/credits", }); } throw err;}from flask import jsonifyfrom limitry import LimitReachedError
try: with limitry.guard( subject={"kind": "user", "id": user.id}, shared=[{"kind": "team", "id": user.team_id}], action="report", cost=25, ): return build_report(params)except LimitReachedError as err: if err.reason == "limit_reached": return jsonify( message="Your team is out of credits. Buy more to keep going.", buyUrl="/billing/credits", ), 402 raiseA balance’s retryAfterSeconds is null, because waiting won’t help.
Show a “Buy more credits” button when remaining reaches 0, and add
the credits from your payment webhook (see
Sell prepaid credits). For a limit that
resets, tell the user when, from err.retryAfterSeconds.
To tell users before they run out, see Warn your users before they hit a limit.