Sell plans
Your users pay a monthly plan, and each plan buys a budget of AI. This guide covers selling plans on the web through Polar, showing a user their plan in your app, and offering a free plan. To sell inside Android and iOS apps, see Sell in app stores.
Connect Polar
Polar is the merchant of record: your customers pay your Polar organization.
- In the panel, open your app's Settings → Payments (or the Payments step of its launch) and connect Polar in sandbox.
- Test a whole purchase with Polar's test cards.
- Connect again, live, to take real payments.
PlanGate creates a private monthly product in Polar for each plan, with its checkout and its webhook.
Put a plan on sale
- In the Plans tab, under New plan, give the plan a name and a monthly price.
- PlanGate fills in the largest budgets the price can pay, per rolling 5 hours and per rolling 7 days. Lower them if you like; they can't go above that limit.
- Choose Put on sale.
Why there is a limit: the margin guarantee.
Show a user their plan
Ask for the user's plan and the plans on sale:
GET https://api.plangate.dev/apps/<app>/me
Authorization: Bearer <access token>
quotaisnulluntil the user has a plan. Then it holds their two budgets and what is spent:budget_5h_usd,used_5h_usd,budget_week_usd,used_week_usd.planslists what they can buy. To subscribe, open a plan'scheckout_urlin the browser. Add&return=<url>(URL-encoded: your app's URL scheme, a loopback address, or an address under your Return link) to bring the user back to the app once paid.plans_urlis a plan page PlanGate hosts under your brand: the user's plan, the others, switching, managing the subscription. Open it in the browser rather than building these screens. For an app with its own sign-in, the link signs the user in there, is theirs alone and lasts a day: read it from/meright before opening it.
The whole answer is in the API reference.
Your server can hear about each payment, plan change and cancellation as it happens, without asking /me: add a webhook.
Handle a spent budget
When a call to the model answers:
402 subscription_required: the user has no plan. Showplans, or openplans_url.429 rate_limit_5hor429 rate_limit_week: the budget of that window is spent. Say when it comes back, or offer a larger plan.
Your server gets a quota.exhausted webhook event too, once per window and user.
Let a user change plans
Open plans_url, or call POST /apps/<app>/plans/<plan>/switch from your own screen. A dearer plan applies at once; a cheaper one waits for the renewal, and /me says what is scheduled (quota.pending_plan_name, pending_at).
Offer a free plan
A free plan lets users try your app before paying, for a cost you fix in advance. An app can have one.
- In the Plans tab, under New plan, tick Free plan.
- Enter the monthly budget, the most the free plan may cost you in a month, and the minimum per user per day, the least each user it serves gets.
- Choose Offer it.
Every user without a paid plan is then served from it, and /me answers a quota with free: true. Two more answers can come back from the model:
402 free_tier_full: every free place of the day is taken. Openerror.checkout_url(your paid plans), or say to come back aterror.resets_at.429 free_daily_limit: the user spent their share of the day. It starts again aterror.resets_at, midnight UTC.
/me tells both ahead: quota.free_full is true once the day is full. The panel warns you when the free plan reaches 80% and 100% of its month.
How the daily share is decided: The free plan.
