# Paykit > Billing and entitlements for your product, declared in TypeScript and deployed with your stack. ## Docs - [Paykit](https://paykit.32stack.com/): Billing and entitlements for your product, declared in TypeScript and deployed with your stack. - [What is Paykit?](https://paykit.32stack.com/what-is-paykit): How plans, balances, checks and payments fit together, and what your customer sees. - [Getting started](https://paykit.32stack.com/getting-started): Install Paykit, declare two plans, deploy them, subscribe an account, and record usage. - [Build a billing page](https://paykit.32stack.com/billing-page): Show the plans, the current plan, usage and the price of a change, then collect it. ## Concepts - [Pricing models](https://paykit.32stack.com/concepts/pricing-models): What you can sell, and the declaration that states it. - [Features](https://paykit.32stack.com/concepts/features): What a plan meters or grants, and how a feature states its kind and its credit rate. - [Plans and prices](https://paykit.32stack.com/concepts/plans): A purchasable bundle, the price it sells at, the allowance it grants, and the terms a move replaces. - [Subscriptions](https://paykit.32stack.com/concepts/subscriptions): The plans an account holds, the period they run for, and the states between a trial and a cancellation. - [Balances](https://paykit.32stack.com/concepts/balances): What an account has of one feature, where it came from, and the controls a customer sets over it. - [Credits](https://paykit.32stack.com/concepts/credits): One pool per account, priced per dimension, and what spends it. ## Runtime - [Check](https://paykit.32stack.com/runtime/check): The read that answers whether an account may do the work, from local state in one call. - [Track usage](https://paykit.32stack.com/runtime/track-usage): Record what the work consumed, make a retry the same fact, and read the refusal when there is no room. - [Holds](https://paykit.32stack.com/runtime/holds): Reserve capacity before the work runs, then settle what it used or release the rest. - [Commands](https://paykit.32stack.com/runtime/commands): Every write is a named command with an id, and the log records it once. ## Providers - [Providers](https://paykit.32stack.com/providers): The Payments port, the capabilities a provider declares, and what the deploy validates. - [Manual](https://paykit.32stack.com/providers/manual): A provider that sells by invoice, so a deploy needs no key. - [Stripe](https://paykit.32stack.com/providers/stripe): Sell the catalog through Stripe Checkout, with prices and meters the deploy creates. - [Polar](https://paykit.32stack.com/providers/polar): Sell the catalog through Polar as merchant of record, with products and meters the deploy creates. ## Hosting - [Database](https://paykit.32stack.com/hosting/database): One port for billing storage, and a schema the deploy converges. - [Auth](https://paykit.32stack.com/hosting/auth): Gate the Api with any session, without teaching the model who answered. ## Reference - [Reference](https://paykit.32stack.com/reference): Every tagged public module in the four packages, generated from the JSDoc beside its source. - [Packages](https://paykit.32stack.com/reference/packages): What ships together, and what each package owns. ### Paykit - [Paykit](https://paykit.32stack.com/reference/paykit): Billing and entitlement for Alchemy. - [actionsFor](https://paykit.32stack.com/reference/paykit/actions-for): The actions that make sense for a standing, in a stable display order. - [BillingMcp](https://paykit.32stack.com/reference/paykit/billing-mcp): The surfaces an Api projects onto, without a second declaration. - [BillingStack](https://paykit.32stack.com/reference/paykit/billing-stack): The deploy-time billing stack, in one call. - [BillingStack.resource](https://paykit.32stack.com/reference/paykit/billing-stack-resource): The deploy-time billing stack: it records the validated catalog, the provider descriptors and the store kind, retains on removal, and versions that state shape with BILLING_STACK_VERSION. - [CatalogGuard](https://paykit.32stack.com/reference/paykit/catalog-guard): Exports `CatalogGuard`, `CatalogGuardLive`. - [CatalogRpc](https://paykit.32stack.com/reference/paykit/catalog-rpc): Exports `PaykitCatalogRpcs`, `PaykitCatalogClient`. - [doctor](https://paykit.32stack.com/reference/paykit/doctor): Rebuild every read model from billing_event and diff it. - [Handler](https://paykit.32stack.com/reference/paykit/handler): Exports `moneyRoutes`, `handler`. - [httpStatus](https://paykit.32stack.com/reference/paykit/http-status): The HTTP status a paykit refusal deserves. - [make](https://paykit.32stack.com/reference/paykit/make): Billing as Effect atoms: the tenant bindings, shaped for a client. - [Outbound](https://paykit.32stack.com/reference/paykit/outbound): The outbound edge as a port: the endpoints to notify and the transport that sends a signed request. - [Paykit](https://paykit.32stack.com/reference/paykit/paykit): The four export groups as one namespace, so the docs' Paykit.feature(...) and the flat named exports are the same functions. - [Payments](https://paykit.32stack.com/reference/paykit/payments): Exports `providerSet`, `resolveProvider`. - [planVersionOf](https://paykit.32stack.com/reference/paykit/plan-version-of): The generation of a plan's terms the catalog currently sells, or null when the catalog has no such plan. - [providers](https://paykit.32stack.com/reference/paykit/providers): Every Alchemy provider this package owns, as one Layer, so a stack declares Paykit.providers() beside Cloudflare.providers(). - [resolvePolarProductId](https://paykit.32stack.com/reference/paykit/resolve-polar-product-id): Resolve a tier's product handle to the id Polar's API expects. - [TierCommand](https://paykit.32stack.com/reference/paykit/tier-command): Exports `TierGrantInput`, `withGrants`, `subscribeInputOf`, `scheduleTierChangeInputOf`, `purchaseCreditsInputOf`, `planChangeTier`. - [timelineOf](https://paykit.32stack.com/reference/paykit/timeline-of): Fold a log into a timeline. - [Verify](https://paykit.32stack.com/reference/paykit/verify): Check one account's standing against the catalog and the configured provider. - [Webhooks](https://paykit.32stack.com/reference/paykit/webhooks): Exports `WEBHOOK_TRANSITIONS`, `webhookActionOf`. - [world](https://paykit.32stack.com/reference/paykit/world): One deployment graph, built from the parts a host chooses. #### Admin - [ChangeTier](https://paykit.32stack.com/reference/paykit/admin/change-tier): Exports `AdminChangeTier`, `AdminChangeTierClient`. - [Reads](https://paykit.32stack.com/reference/paykit/admin/reads): Exports `AdminReads`, `makeAdminReads`, `AdminReadsClient`. - [Refund](https://paykit.32stack.com/reference/paykit/admin/refund): Exports `AdminRefund`, `AdminRefundClient`. #### Auth - [Actor](https://paykit.32stack.com/reference/paykit/auth/actor): The caller of a request, provided by the Session or Admin middleware and carried with the command. - [FromHeaders](https://paykit.32stack.com/reference/paykit/auth/from-headers): Exports `accountFromHeaders`, `InsecureSessionFromHeaders`, `InsecureAdminFromHeaders`, `InsecureDevGuards`. - [FromResolver](https://paykit.32stack.com/reference/paykit/auth/from-resolver): Exports `ActorResolver`, `SessionFrom`, `authenticate`, `AdminFrom`, `GuardsFrom`. - [Guards](https://paykit.32stack.com/reference/paykit/auth/guards): Exports `Session`, `Admin`. #### Billing - [AddAddOn](https://paykit.32stack.com/reference/paykit/billing/add-add-on): Attach an add-on plan beside whatever the account already runs. - [Admin](https://paykit.32stack.com/reference/paykit/billing/admin): Exports `GrantCredits`, `ExtendTrial`, `EnterGrace`, `Recover`, `Expire`, `RecordPayment`, `RecordPaymentFailure`, `Refund`. - [Attach](https://paykit.32stack.com/reference/paykit/billing/attach): Exports `Attach`, `Update`, `PreviewAttach`, `PreviewUpdate`. - [Balances](https://paykit.32stack.com/reference/paykit/billing/balances): A customer's balances: the read side of the entitlement plane, one shape for check, track and this. - [Balances.layer](https://paykit.32stack.com/reference/paykit/billing/balances-layer): Exports `BalancesRead`, `BalancesLive`. - [BillingAdminApiLayer](https://paykit.32stack.com/reference/paykit/billing/billing-admin-api-layer): Every operator binding, implemented over BillingAdminApi — the Api whose commands declare Admin, so a tenant session cannot reach one. - [BillingAdminInProcess](https://paykit.32stack.com/reference/paykit/billing/billing-admin-in-process): Every operator binding, implemented in the process that hosts the model. - [BillingApiLayer](https://paykit.32stack.com/reference/paykit/billing/billing-api-layer): Every paykit tenant binding, implemented over BillingApi — the Api's own Session middleware decides whether this caller may act for this account, and its reply decoding turns a rejection back into the class a caller matches. - [BillingInProcess](https://paykit.32stack.com/reference/paykit/billing/billing-in-process): Every paykit binding, implemented in the process that hosts the model. - [Bindings](https://paykit.32stack.com/reference/paykit/billing/bindings): Exports `BindingFailed`, `BindingCall`. - [Cancel](https://paykit.32stack.com/reference/paykit/billing/cancel): Exports `ScheduleCancellation`, `Resume`. - [ChangeTier](https://paykit.32stack.com/reference/paykit/billing/change-tier): Change the tier a standing is on. - [ChargeQuantityProration](https://paykit.32stack.com/reference/paykit/billing/charge-quantity-proration): Collect the money a quantity change moved. - [Check](https://paykit.32stack.com/reference/paykit/billing/check): The entitlement plane: one local read, no provider round trip, and the balance the customer has of one feature. - [CheckOverTransport](https://paykit.32stack.com/reference/paykit/billing/check-over-transport): Check over a transport: delegate the question to whatever serves the entitlement elsewhere — an HTTP call, a Durable Object, another Worker's binding. - [CheckReadModel](https://paykit.32stack.com/reference/paykit/billing/check-read-model): Check over the edge read model: one row from billing_rm_, no event fold and no view to resolve. - [Commands](https://paykit.32stack.com/reference/paykit/billing/commands): Exports `BillingCommands`, `BillingCommandsLive`, `BillingCommandsClient`. - [ConsumeCredits](https://paykit.32stack.com/reference/paykit/billing/consume-credits): Spend credits from the account's pool: one pool per account, whatever feature the work belonged to. - [CreateCustomer](https://paykit.32stack.com/reference/paykit/billing/create-customer): Record the identity a billing page shows for this account: its name and its email address. - [Customers](https://paykit.32stack.com/reference/paykit/billing/customers): A customer's record: the identity it recorded, the plans it holds and the controls it states over them. - [Customers.layer](https://paykit.32stack.com/reference/paykit/billing/customers-layer): Exports `CustomersRead`, `CustomersLive`. - [Entities](https://paykit.32stack.com/reference/paykit/billing/entities): A customer's child scopes: a team, a project, a workspace. - [Entities.layer](https://paykit.32stack.com/reference/paykit/billing/entities-layer): Exports `EntitiesRead`, `EntityWrites`, `EntitiesLive`. - [GrantBalance](https://paykit.32stack.com/reference/paykit/billing/grant-balance): Create a standalone grant of a counted feature: the API behind Paykit.Balances(account).create. - [Hold](https://paykit.32stack.com/reference/paykit/billing/hold): Hold capacity for work that has not finished: an agent turn, a long job, a request whose cost is known up front. - [List](https://paykit.32stack.com/reference/paykit/billing/list): One page of accounts, in a stable cursor order. - [MultiPlan](https://paykit.32stack.com/reference/paykit/billing/multi-plan): Exports `MultiAttach`, `MultiUpdate`. - [Portal](https://paykit.32stack.com/reference/paykit/billing/portal): Exports `Portal`, `ChargeProration`. - [Preview](https://paykit.32stack.com/reference/paykit/billing/preview): Run the model's pure decide and report what a command would produce: the events, the state after them, and the proration it would charge. - [ReleaseHold](https://paykit.32stack.com/reference/paykit/billing/release-hold): Return a hold without billing it: the work failed, was cancelled, or never ran. - [ScheduleTierChange](https://paykit.32stack.com/reference/paykit/billing/schedule-tier-change): Exports `ScheduleTierChange`, `WithdrawTierChange`. - [SetBillingControls](https://paykit.32stack.com/reference/paykit/billing/set-billing-controls): Replace a customer's billing controls: its auto top-up line, its spend ceilings and its usage alerts (ADR 0038). - [SetQuantity](https://paykit.32stack.com/reference/paykit/billing/set-quantity): Set a non-consumable feature's quantity. - [SettleHold](https://paykit.32stack.com/reference/paykit/billing/settle-hold): Turn a hold into usage: bill what ran and return the rest, in the same command. - [SetupPayment](https://paykit.32stack.com/reference/paykit/billing/setup-payment): Add a payment method without a purchase. - [SetUsage](https://paykit.32stack.com/reference/paykit/billing/set-usage): Set how much of a non-consumable feature is in use. - [StartTrial](https://paykit.32stack.com/reference/paykit/billing/start-trial): Open a trial on a tier. - [Subscribe](https://paykit.32stack.com/reference/paykit/billing/subscribe): The one door to a purchase. - [TrackUsage](https://paykit.32stack.com/reference/paykit/billing/track-usage): Record usage in the same transaction that checks the allowance. - [TransferBalance](https://paykit.32stack.com/reference/paykit/billing/transfer-balance): Move balance units between the customer's own scope and one of its entities, or between two entities. - [TransferBalance.layer](https://paykit.32stack.com/reference/paykit/billing/transfer-balance-layer): Exports `TransferBalanceWrite`, `TransferBalanceLive`. - [Webhook](https://paykit.32stack.com/reference/paykit/billing/webhook): The webhook edge as a binding: the model's services resolved once, an event applied per delivery. #### Database - [D1](https://paykit.32stack.com/reference/paykit/database/d1): A Cloudflare D1 billing database. - [Database](https://paykit.32stack.com/reference/paykit/database/database): Exports `DatabaseService`, `Database`. - [Drizzle](https://paykit.32stack.com/reference/paykit/database/drizzle): The billing model on a Postgres database a Drizzle instance already opened. - [MySQL](https://paykit.32stack.com/reference/paykit/database/my-sql): A MySQL billing database, from any connection source. - [Postgres](https://paykit.32stack.com/reference/paykit/database/postgres): A Postgres billing database, from any connection source: a Hyperdrive connection string, Neon, PlanetScale Postgres, RDS, or a literal URL. - [registerMigrations](https://paykit.32stack.com/reference/paykit/database/register-migrations): Register the deploy-time migration Action for a Database, mirroring Alchemy's own BetterAuth.Migrate. - [Sqlite](https://paykit.32stack.com/reference/paykit/database/sqlite): A bun:sqlite billing database — development, tests, and a single-process host. #### Migrations - [converge](https://paykit.32stack.com/reference/paykit/migrations/converge): Converge the shipped description against the target, additively. - [Migrations](https://paykit.32stack.com/reference/paykit/migrations/migrations): Exports `migrationFiles`, `schemaFingerprint`, `migrationFingerprint`, `migrateDryRun`, `migrate`, `sync`. #### Store - [d1Executor](https://paykit.32stack.com/reference/paykit/store/d1-executor): A SqlExecutor over Cloudflare's D1, implementing the asynchronous half of the port that Alchemy's D1 executor implements (@alchemy.run/cloudflare/D1/ApplyMigrations, makeD1MigrationExecutor): query/get for reads, write/batch for writes, and atomic for a unit. - [mysqlExecutor](https://paykit.32stack.com/reference/paykit/store/mysql-executor): A SqlExecutor over an @effect/sql-mysql2 client — the client @alchemy.run/sql/MySQL builds from a connection URL. - [PostgresDriver](https://paykit.32stack.com/reference/paykit/store/postgres-driver): Exports `toPostgresPlaceholders`, `postgresExecutor`, `pgPoolExecutor`. - [SqlAggregateStore](https://paykit.32stack.com/reference/paykit/store/sql-aggregate-store): A Domain.AggregateStore over SqlEventLog. - [SqlBillingReadStore](https://paykit.32stack.com/reference/paykit/store/sql-billing-read-store): The projection's port, backed by the same database as the event log: one schema holds the truth and its read models, so a dashboard, the edge read path and doctor all see the same rows without a second store to drift. - [SqlConsumers](https://paykit.32stack.com/reference/paykit/store/sql-consumers): Exports `SqlViewStore`, `SqlPolicyStore`, `SqlStreamStore`. - [SqlEventLog](https://paykit.32stack.com/reference/paykit/store/sql-event-log): The durable half of the store: events are the truth, receipts dedupe by command id, the outbox carries deliveries, and the read model is rebuildable. - [SqlPlatform](https://paykit.32stack.com/reference/paykit/store/sql-platform): Exports `SqlPlatform`, `layerSqlPlatform`. #### Subscription - [ArchiveEntity](https://paykit.32stack.com/reference/paykit/subscription/archive-entity): Archive an entity and sweep its unspent own sources to the customer in the same command. - [AttachEntity](https://paykit.32stack.com/reference/paykit/subscription/attach-entity): Create an entity under a customer. - [autoTopUp](https://paykit.32stack.com/reference/paykit/subscription/auto-top-up): The auto top-up policy's configuration. - [CreateCustomer](https://paykit.32stack.com/reference/paykit/subscription/create-customer): Record the customer's identity: the name and email a billing page shows. - [dunning](https://paykit.32stack.com/reference/paykit/subscription/dunning): Turn on a dunning retry ladder. - [HoldPhase](https://paykit.32stack.com/reference/paykit/subscription/hold-phase): Exports `HOLD_STATUS_TRANSITIONS`, `nextHoldStatus`. - [StandingPhase](https://paykit.32stack.com/reference/paykit/subscription/standing-phase): Exports `standingPhaseOf`, `standingPhaseOfView`, `standingPhaseTagOfStatus`, `standingConditionsOf`, `STANDING_PHASE_TRANSITIONS`, `nextStandingPhase`, `standingTransitionOf`, `STANDING_PHASE_EDGES`. - [TransferBalance](https://paykit.32stack.com/reference/paykit/subscription/transfer-balance): Move units between two scopes of one customer: the customer's own scope and one of its entities, or two entities. - [UpdateEntity](https://paykit.32stack.com/reference/paykit/subscription/update-entity): Rename an entity, or clear its name. ### Paykit Polar - [Paykit Polar](https://paykit.32stack.com/reference/paykit-polar): Polar for paykit: a merchant of record in one call. - [fromAuthProvider](https://paykit.32stack.com/reference/paykit-polar/from-auth-provider): Build a Polar Credentials layer that resolves credentials via the Alchemy AuthProvider using the configured profile (defaults to default, overridable with the ALCHEMY_PROFILE env/config value). - [Meter](https://paykit.32stack.com/reference/paykit-polar/meter): A Polar meter that sums one feature's billable units. - [Polar](https://paykit.32stack.com/reference/paykit-polar/polar): Polar as a merchant of record, ready for Paykit.BillingStack. - [PolarAuth](https://paykit.32stack.com/reference/paykit-polar/polar-auth): Layer that registers the Polar {@link AuthProvider} into the {@link AuthProviders} registry. - [PolarBilling](https://paykit.32stack.com/reference/paykit-polar/polar-billing): Polar provisioning and the Polar provider in one call. - [PolarPrices](https://paykit.32stack.com/reference/paykit-polar/polar-prices): The Polar products a tier is sold through, reconciled from the catalog. - [polarProviders](https://paykit.32stack.com/reference/paykit-polar/polar-providers): Register the Polar provider a stack needs to reconcile PolarPrices. - [polarWebhook](https://paykit.32stack.com/reference/paykit-polar/polar-webhook): Verify and translate one Polar webhook into paykit's provider-neutral event. - [Product](https://paykit.32stack.com/reference/paykit-polar/product): A Polar product that sells one tier at the price the catalog states. - [RetiredProducts](https://paykit.32stack.com/reference/paykit-polar/retired-products): Archive the Polar products a stage still sells that its catalog no longer declares. - [WebhookEndpoint](https://paykit.32stack.com/reference/paykit-polar/webhook-endpoint): Exports `WebhookEndpoint`, `polarWebhookEndpoint`. ### Paykit Stripe - [Paykit Stripe](https://paykit.32stack.com/reference/paykit-stripe): Stripe for paykit: a processor in one call. - [MeteredPrice](https://paykit.32stack.com/reference/paykit-stripe/metered-price): A Stripe metered price that states more than one unit amount: a package transform or a graduated/volume ladder. - [RetiredPrices](https://paykit.32stack.com/reference/paykit-stripe/retired-prices): Turn off the Stripe prices a stage still has active that its catalog no longer declares. - [Stripe](https://paykit.32stack.com/reference/paykit-stripe/stripe): Stripe as a processor, ready for Paykit.BillingStack. - [StripeBilling](https://paykit.32stack.com/reference/paykit-stripe/stripe-billing): Stripe provisioning and the Stripe provider in one call. - [StripePrices](https://paykit.32stack.com/reference/paykit-stripe/stripe-prices): The price resources a tier is sold through, reconciled from the catalog. - [stripeWebhook](https://paykit.32stack.com/reference/paykit-stripe/stripe-webhook): Verify and translate one Stripe webhook into paykit's provider-neutral event. - [stripeWebhookEndpoint](https://paykit.32stack.com/reference/paykit-stripe/stripe-webhook-endpoint): The webhook endpoint a deployment serves Stripe's deliveries on. ### Paykit Admin - [Paykit Admin](https://paykit.32stack.com/reference/paykit-admin): A Foldkit ops console for paykit. - [decodeSnapshotFlags](https://paykit.32stack.com/reference/paykit-admin/decode-snapshot-flags): Decode what the host seeded. - [Route](https://paykit.32stack.com/reference/paykit-admin/route): Exports `ConsoleRoute`, `reflectRoute`. ## Agent skills - [paykit](https://paykit.32stack.com/.well-known/agent-skills/paykit/SKILL.md): Read the Paykit docs instead of answering from memory. Billing and entitlements for your product, declared in TypeScript and deployed with your stack. Use when a task involves Paykit: how it works, how to set it up or configure it, or its API. ## Agent resources - [llms-full.txt](https://paykit.32stack.com/llms-full.txt): The full Markdown of every page in one file. - [Page Markdown](https://paykit.32stack.com/index.md): Append `.md` to any page URL to fetch that page as raw Markdown. - [JSON API](https://paykit.32stack.com/api/docs/pages.json): Page index of the JSON docs API; each entry links the page's JSON and Markdown forms. Described by the OpenAPI document at https://paykit.32stack.com/openapi.json. - [Agent skills](https://paykit.32stack.com/.well-known/agent-skills/index.json): Agent Skills discovery index of the skills this site publishes. - [API catalog](https://paykit.32stack.com/.well-known/api-catalog): RFC 9727 linkset of the APIs documented here. - [AI catalog](https://paykit.32stack.com/.well-known/ai-catalog.json): ARD manifest of the agent-facing resources on this site (MCP server, skills, APIs). - [agent-readability.json](https://paykit.32stack.com/agent-readability.json): Manifest of every agent-facing artifact on this site. - [Sitemap](https://paykit.32stack.com/sitemap.xml): Every indexable page URL with its last-modified date.