Manage billing, checkout, plan changes, cancellations, and usage tracking. Powered by Polar for seamless payment processing.
/subscriptionRetrieve the current user's subscription details. Returns the subscription object or null if no subscription exists.
subscriptionobject | nullSubscription object with plan, status, apiKey, cancelAtPeriodEnd, period dates, createdAt, updatedAt. Null if no subscription.// GET /subscription
// 200 OK — active subscription
{
"subscription": {
"plan": "starter",
"status": "active",
"apiKey": "abc123...",
"cancelAtPeriodEnd": false,
"currentPeriodStart": "2026-03-12T...",
"currentPeriodEnd": "2026-04-12T...",
"createdAt": "2026-03-12T...",
"updatedAt": "2026-03-12T..."
}
}/subscription/usageRetrieve API usage statistics for the current billing period.
planstringCurrent plan name.quotanumberTotal API calls allowed.usednumberAPI calls used this period.remainingnumberRemaining API calls.percentUsednumberUsage percentage.throttleobjectRate limit and burst limit.// GET /subscription/usage
// 200 OK
{
"plan": "professional",
"quota": 100000,
"used": 15420,
"remaining": 84580,
"percentUsed": 15.42,
"periodStart": "2026-01-01",
"periodEnd": "2026-02-01",
"throttle": {
"rateLimit": 50,
"burstLimit": 100
}
}/subscription/checkoutCreate a checkout session for subscribing to a plan. Returns a URL to redirect the user to the payment page.
planstring*Plan to subscribe to (starter, professional).successUrlstringURL to redirect after successful payment.// POST /subscription/checkout
{
"plan": "professional",
"successUrl": "https://knowledgedb.dev/console/checkout/success?checkout_id={CHECKOUT_ID}"
}/subscription/confirmConfirm a checkout session after the user completes payment on Polar. Call this on your success page to activate the subscription and receive the new API key.
checkoutIdstring*The checkout ID from the Polar redirect URL query parameter.// POST /subscription/confirm
{
"checkoutId": "466de8b3-d631-451d-ac6d-e6f1d595301b"
}/subscription/cancelCancel the current subscription. Access continues until the end of the current billing period.
// POST /subscription/cancel // No body required
/subscription/reactivateReactivate a subscription that has a pending cancellation. Undoes cancelAtPeriodEnd so the subscription renews normally. No request body needed.
// POST /subscription/reactivate
// 200 OK
{
"message": "Subscription reactivated. Cancellation has been undone.",
"subscription": {
"plan": "professional",
"status": "active",
"cancelAtPeriodEnd": false,
"currentPeriodEnd": "2026-04-12T..."
}
}/subscription/portalGet a URL to the customer billing portal where users can manage payment methods and view invoices.
// POST /subscription/portal
// 200 OK
{
"portalUrl": "https://polar.sh/portal/..."
}/subscription/webhookPolar webhook endpoint for subscription events. This is called by Polar, not by your application directly.
// POST /subscription/webhook
// Called by Polar
{
"type": "subscription.updated",
"data": {
"id": "sub_xxx",
"status": "active",
...
}
}