Subscriptions - cred.diy API documentation
Subscriptions
Charge customers monthly and add credits after every paid invoice. A checkout becomes recurring only when the request explicitly sends billing: "recurring".
https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/hosted-checkoutStart a monthly subscription. The pricing tier must support recurring billing. Omitting billing always creates a one-time checkout.
Body parameters
user_idstringrequiredYour unique identifier for the customerpricing_tier_idstringrequiredA pricing tier with recurring or both billing enabledbillingstringrequiredSet to "recurring"user_emailstringCustomer emailsuccess_urlstringHTTPS redirect after checkoutcancel_urlstringHTTPS redirect when checkout is canceled
Example request
curl -X POST "https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/hosted-checkout" \
-H "x-api-key: sk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user_123",
"user_email": "user@example.com",
"pricing_tier_id": "tier_monthly",
"billing": "recurring"
}'Response
{
"url": "https://checkout.stripe.com/...",
"session_id": "cs_...",
"purchase_id": "purchase_..."
}/subscriptionsList subscriptions by customer or status. status=active includes active, trialing, and past_due subscriptions.
Query parameters
user_idstringFilter by external user IDemailstringFilter by customer emailstatusstringactive or an exact Stripe subscription status
Example request
curl -X GET "https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/subscriptions?email=user@example.com&status=active" \
-H "x-api-key: sk_live_your_api_key"Response
{
"subscriptions": [{
"id": "subscription_...",
"stripe_subscription_id": "sub_...",
"user_id": "user_123",
"user_email": "user@example.com",
"credits_per_period": 1000,
"price": "10.00",
"currency": "USD",
"interval": "month",
"status": "active",
"current_period_end": "2026-11-02T19:00:00Z",
"cancel_at_period_end": false
}]
}/subscriptions/cancelCancel one subscription by ID, or every live subscription for a customer by user ID or email. Cancellation defaults to the end of the paid period and is idempotent.
Body parameters
subscription_idstringCred subscription ID or Stripe sub_ IDuser_idstringCancel all live subscriptions for this useremailstringCancel all live subscriptions for this emailat_period_endbooleanDefault true; false stops immediately without a refund
Example request
curl -X POST "https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/subscriptions/cancel" \
-H "x-api-key: sk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{ "subscription_id": "sub_123", "at_period_end": true }'Response
{
"success": true,
"at_period_end": true,
"subscriptions": [{ "id": "subscription_...", "status": "active", "cancel_at_period_end": true }]
}/subscriptions/portalCreate a short-lived Stripe-hosted link for updating a payment method or viewing invoices. Create it when the customer clicks; do not store it. Plan changes and cancellation are disabled.
Body parameters
subscription_idstringCred subscription ID or Stripe sub_ IDuser_idstringUse this customer's most recent subscriptionemailstringUse this customer's most recent subscriptionreturn_urlstringHTTPS page to return toflowstring"payment_method_update" (default) or "overview"
Example request
curl -X POST "https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/subscriptions/portal" \
-H "x-api-key: sk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{ "email": "user@example.com", "flow": "payment_method_update" }'Response
{
"url": "https://billing.stripe.com/p/session/...",
"subscription": { "id": "subscription_...", "status": "past_due" }
}Renewals and lifecycle events
Credits are issued once per paid invoice, including the first invoice and every renewal. Own-keys renewals and cancellations can take up to about ten minutes to appear; Stripe Connect events arrive immediately.
subscription.created— first checkout completedsubscription.renewed— invoice paid and credits addedsubscription.cancel_scheduled— cancellation set for period endsubscription.canceled— subscription endedsubscription.payment_failed— payment failed; create a portal link when the customer chooses to fix it
Your first credit is one request away.
Create a project, copy an API key, and issue a credit from your server.
