Configuration
RevstackServerConfig
Configuration object for server-side API calls.Your project’s secret key from the Revstack dashboard. Keep this secure - never expose it to the client.
Custom API base URL (defaults to
https://app.revstack.dev)Optional redirect URL when
requireEntitlement() denies accessFunctions
getEntitlement
Checks if the current user has access to a feature. Must be called from a Server Component or Server Action. Signaturekey(string) - The feature key to checkconfig(RevstackServerConfig) - Server configuration withsecretKey
Entitlementobject with{ key, hasAccess, value? }
- Extracts user identity from request headers (
Authorization,X-Revstack-Auth,X-Revstack-Guest-Id) - Authenticates to Revstack API using your
secretKey - Forwards user identity headers to resolve their entitlements
- Returns the entitlement for the specified
key
requireEntitlement
Enforces entitlement access - redirects or throws an error if the user lacks access. Signaturekey(string) - The required feature keyconfig(RevstackServerConfig) - Server configuration
Entitlementobject if access is granted
- Redirects to
config.redirectToif provided and access is denied - Otherwise throws an error with message
"Access denied: missing entitlement \"<key>\""
trackUsage
Reports metered usage (e.g., API calls, credits consumed) for the current user. Signaturekey(string) - The feature key to track usage againstusage(UsageData) - Usage data (see below)config(RevstackServerConfig) - Server configuration
For standard metered billing (e.g., 1 API call = 1 credit)
For AI-specific billing based on token usage
- Error if tracking fails (e.g., user has exhausted quota)
withMetering
Higher-order function that wraps a Route Handler with fixed-cost metering. Signaturekey(string) - The feature key to meteramount(number) - Fixed cost per requestconfig(RevstackServerConfig) - Server configurationhandler(RouteHandler) - Your route handler function
- Wrapped route handler that:
- Deducts
amountcredits before invokinghandler - Returns
402 Payment Requiredif user lacks credits - Invokes
handleronly if metering succeeds
- Deducts
Types
Entitlement
UsageData
Identity Resolution
All server functions automatically extract user identity from request headers:AuthorizationorX-Revstack-Auth- User’s JWT tokenX-Revstack-Guest-Id- Guest fingerprint for anonymous users