Cancel the authenticated user’s active subscription. Can cancel immediately or at the end of the current billing period.
Authentication
This endpoint requires end user authentication via HTTP Bearer Token with project scope.
Query Parameters
Use test mode credentials. Set to false for production.
Request Body
If true, cancels the subscription immediately and revokes access. If false, cancels at the end of the current billing period (user retains access until then).
Response
New subscription status: canceled or active (will cancel at period end)
When the subscription will be canceled (if scheduled)
When the cancellation was processed
Human-readable confirmation message
Example Request
Cancel at Period End (Recommended)
curl -X POST "https://api.devkit4ai.com/api/v1/payments/stripe/cancel-subscription?test_mode=true" \
-H "Authorization: Bearer {end_user_jwt}" \
-H "Content-Type: application/json" \
-d '{
"cancel_immediately": false
}'
curl -X POST "https://api.devkit4ai.com/api/v1/payments/stripe/cancel-subscription?test_mode=true" \
-H "Authorization: Bearer {end_user_jwt}" \
-H "Content-Type: application/json" \
-d '{
"cancel_immediately": true
}'
Example Response
Cancel at Period End
{
"subscription_id": "sub_1ABC123def456",
"status": "active",
"cancel_at": "2026-02-01T00:00:00Z",
"cancelled_at": "2026-01-24T15:30:00Z",
"message": "Subscription will be canceled at the end of the current billing period."
}
{
"subscription_id": "sub_1ABC123def456",
"status": "canceled",
"cancel_at": null,
"cancelled_at": "2026-01-24T15:30:00Z",
"message": "Subscription has been canceled immediately."
}
Cancellation Options
Best Practice: Default to cancel_immediately: false to give users time to reconsider or allow continued access until they’ve been billed for.
Integration Example
// Cancel subscription with confirmation
async function cancelSubscription(immediately: boolean = false) {
const confirmed = await showConfirmDialog(
immediately
? 'Cancel immediately? You will lose access now.'
: 'Cancel at period end? You will retain access until your next billing date.'
);
if (!confirmed) return;
const response = await fetch('/api/cancel-subscription', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ cancel_immediately: immediately })
});
const result = await response.json();
showToast(result.message);
refreshSubscriptionStatus();
}
Handling Scheduled Cancellations
When a subscription is scheduled to cancel, update your UI accordingly:
function SubscriptionStatus({ subscription }) {
if (subscription.cancel_at) {
return (
<div className="warning">
<p>Your subscription will end on {formatDate(subscription.cancel_at)}</p>
<button onClick={reactivateSubscription}>Keep Subscription</button>
</div>
);
}
return <p>Active until {formatDate(subscription.current_period_end)}</p>;
}
Reactivating Canceled Subscriptions
To reactivate a subscription scheduled for cancellation, users should use the Customer Portal or start a new checkout.
Error Responses
| Status | Description |
|---|
401 | Unauthorized - Invalid or missing authentication |
404 | No active subscription to cancel |
404 | Project not found or Stripe not configured |
Related Pages
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Request to cancel a subscription.
If true, cancels immediately. Otherwise cancels at period end.
Cancel subscription response.