Settings & Usage

Rate Limits

Requests and tokens per minute as refilling buckets, with a retry-after countdown and queued calls when throttled.

3 variantsMIT

Preview

Installation

Copies the component into components/ui and installs its dependencies and theme tokens.

pnpm dlx shadcn@latest add https://uilab.tmih06.com/r/rate-limits.json

Usage

Pass your own data and wire the callbacks to your agent runtime.

import { RateLimits } from "@/components/ui/rate-limits";

// Fill it from the rate-limit headers on each API response.
export function Limits({ headers, queue, retryAfter }: Props) {
  return (
    <RateLimits
      data={{
        model: "opus-5.5 · Tier 3",
        limits: [
          {
            id: "req",
            label: "Requests",
            limit: Number(headers["requests-limit"]),
            remaining: Number(headers["requests-remaining"]),
            resetsInMs: msUntil(headers["requests-reset"]),
          },
          // …input and output tokens the same way
        ],
        queued: queue, // calls your client is holding back
        retryAfterMs: retryAfter * 1000, // from a 429's retry-after header
      }}
      onRetry={() => client.flushQueue()}
    />
  );
}

// Pass null while the first response is in flight; keep stale data and set
// loading when refetching.
export function LimitsState({ query }: { query: LimitsQuery }) {
  return (
    <RateLimits
      data={query.data ?? null}
      loading={query.isRefetching}
      skeleton={{ count: 3 }}
    />
  );
}

Props

PropTypeDefaultDescription
data*{ model?: string; limits: RateLimit[]; queued?: QueuedCall[]; retryAfterMs?: number } | null—One gauge per limit. retryAfterMs (or a bucket at zero) switches to the throttled state; both timers count down locally. Pass null while the limits load.
loadingbooleanfalseForce the layout-preserving skeleton while refetching, even when stale data is available. Neutral placeholders only — never the warning tint, so it can't be read as real throttling.
skeleton{ count?: number }—Shape hints for the loading state; count is the number of bucket row placeholders.
onRetry() => void—Called by Retry now, which unlocks when the retry-after countdown ends.
localestring"en-US"BCP 47 locale for counts.
labelsPartial<RateLimitsLabels>—Your own UI strings (loading, status, countdowns, queue, screen-reader text), for translating. Right-to-left works under `dir="rtl"`; the bars fill from the right.
classNamestring—Extra classes for the root element.
type RateLimit = {
  id: string;
  label: string; // shown as "<label> / min"
  limit: number;
  remaining: number;
  resetsInMs: number;
};

type QueuedCall = { id: string; label: string; tokens?: number };