Skip to content

UsageLimit

Source: src/Railway/Usage.ts

A Railway.UsageLimit is a soft/hard dollar cap on a workspace customer. One limit per customer. usageLimitRemove is idempotent.

usage is a catalog helper — not a resource. It returns aggregated rows for the current workspace (or a project).

const rows = yield* Railway.usage({
measurements: ["CPU_USAGE", "MEMORY_USAGE_GB"],
});

Omit workspace / project to cap the current token workspace. A number is the soft dollar cap.

Soft cap

const cap = yield* Railway.UsageLimit("SpendCap", {
limit: 50,
});

Soft and hard

const cap = yield* Railway.UsageLimit("SpendCap", {
project: site,
limit: { softLimitDollars: 50, hardLimitDollars: 100 },
});

Resource-valued props accept the resource or an Effect producing it.

src/billing.ts
import * as Railway from "alchemy/Railway";
export const Site = Railway.Project("Site");
export const SpendCap = Railway.UsageLimit("SpendCap", {
project: Site,
limit: 50,
});