Catalog and pricing
Define what usage to track and how many credits it costs.
Define your catalog in orbyte.config.ts:
import {
count,
credits,
defineConfig,
distinct,
feature,
plan,
sum,
usd,
} from "orbytelabs";
export default defineConfig({
features: {
requests: feature("API requests", credits("0.01"), count()),
tokens: feature("Tokens", credits.per("0.04", 1000), sum("tokens")),
seats: feature(
"Monthly seats",
credits(1),
distinct("userId").within("1 month"),
),
},
grantPolicies: {
welcome: {
on: "customer.created",
credits: credits(5),
expiresAfterDays: 30,
},
},
plans: {
pro: plan("Pro", {
costUsdInNanos: usd(20),
creditGrant: credits(20),
}),
},
});Deploy from the config directory with orbytelabs deploy. Feature, plan, and grant
policy map keys are stable identifiers. defineConfig checks plan and policy
feature keys at compile time and validates inputs at runtime.
Plan and policy grants cover any deployed feature by default, including features
added after issuance. Add featureKeys: ["requests", "tokens"] to a plan or
policy to limit access to those features. A plan accepts [] for no feature
access. A policy requires at least one key when you set a restriction.
Track usage
| Aggregation | Tracking payload |
|---|---|
count() | One unit for every event. |
sum() | A scalar whole-number quantity; omitted fixed-price usage defaults to one. |
sum("tokens") | An object such as { tokens: 1200 }. Nested paths work too. |
distinct("userId") | An object such as { userId: "alice" }; charges once per window within a customer. |
Price tracked usage
| Cost | Rule |
|---|---|
credits("0.01") | Fixed credits per unit. |
credits.per("0.04", 1000) | Proportional price per quantity. |
credits.percent("1%") | A percentage of the measured ledger amount. |
credits.markup("25%") | The measured ledger amount plus markup. |
Percentage and markup payloads must use integer ledger units, for example
credits(10). No client-side callbacks are deployed as pricing rules.
credits() and usd() both accept up to nine decimal places and return bigint.
Subscription prices must be exact cents for Stripe.
The signed 64-bit ledger supports up to 9,223,372,036.854775807 displayed credits.
Both accept decimal strings to avoid floating-point ambiguity.
Distinct windows
distinct() counts the customer; distinct("userId") counts the selected payload
value within that customer. Use a nonempty string or integer identity.
.within("18 hours") starts its window on the first counted use. Days, weeks, and
months use UTC calendar boundaries; weeks start Monday. Without .within(), the
window follows the matching subscription period, falling back to a UTC calendar
month for prepaid customers or conflicting periods.
Later events in the same window record zero units and still require a positive matching grant. Use a separate idempotency key for every visit.
