Repository navigation
[Proposal]: Monetization support for API Platform #3651
nisan-abeywickrama
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Background
The API Platform lets API providers publish APIs and control access to them through subscription plans, but it provides no way to charge for that access. API providers who want to sell their APIs need pricing on plans, a checkout for subscribers, usage-based billing and invoicing
Scope
Initial scope
Future work
Architecture
Platform API (control plane): Holds subscription plans with their pricing (price per request, currency, billing period) and the plans enabled for each API. Publishes plans and pricing to the API Portals, receives subscription and payment status through the existing subscription webhook, and sends billing metadata to the gateways. It holds no billing credentials and never calls a billing provider.
API Portal: Introduce a new monetization module with four parts:
The module communicates with billing providers through a billing provider interface.
Proposed Flow
Monetization Setup, API publishing and subscription
sequenceDiagram actor Admin as Platform Administrator actor PortalAdmin as API Portal Administrator actor Publisher as API Publisher actor Subscriber participant PAPI as Platform API participant Portal as API Portal participant GW as Gateway participant Moesif participant Stripe Admin->>PAPI: Define the pricing of a subscription plan PortalAdmin->>Portal: Connect Moesif and Stripe (test or live) Publisher->>PAPI: Enable the paid plan for an API version and publish PAPI->>Portal: Publish the API version, plans and pricing Portal->>Moesif: Create plan, price and billing meter Moesif->>Stripe: Create product and price Subscriber->>Portal: Subscribe to the paid plan Portal->>Stripe: Create a checkout session Subscriber->>Stripe: Pay Stripe-->>Portal: Payment event Stripe-->>Moesif: Subscription synchronized Portal->>PAPI: Subscription and payment status PAPI->>GW: Subscription with billing metadataUsage, invoicing and payment failure
sequenceDiagram actor Subscriber participant GW as Gateway participant Moesif participant Stripe participant Portal as API Portal participant PAPI as Platform API Subscriber->>GW: API request GW->>GW: Check subscription and payment status GW-->>Subscriber: Response GW->>Moesif: Request usage with billing customer ID Moesif->>Stripe: Usage totals from the billing meter Stripe->>Subscriber: Invoice and charge alt Payment fails or subscription is cancelled Stripe-->>Portal: Payment failed or subscription cancelled Portal->>PAPI: Updated subscription and payment status PAPI->>GW: Block access for the subscription Subscriber->>GW: API request GW-->>Subscriber: Rejected, payment required endAPI Platform to Moesif Model Mapping
Test and Live Billing Mode
Discussion Points
Billing credentials live only in the API Portal. The control plane defines what is sold, but never communicates with a billing provider.
Usage goes from the gateways directly to the billing provider, never through the control plane. The analytics collector must stay enabled while monetization is enabled. Calls that the gateway blocks are not counted.
Only requests are metered in the initial scope. Custom counting rules, such as counting only successful responses or weighting requests, are not covered.
Customizable meters (possible extension). Let API providers define their own meters. A meter counts the usage events that match a filter on request details, such as the response status code or the API operation, and a plan sets a price for each meter, with an optional recurring fee.
Example:
Prepaid credits (possible extension). Subscribers pay in advance, and their usage is deducted from that balance.
Example for one subscriber:
Moesif supports prepaid credits: it keeps a balance for each subscription, deducts usage in near real time using the billing meters, and applies the balance as credits on the Stripe invoice. This works only with Stripe, and only for per-unit and package pricing
All reactions