Significant-Gravitas/AutoGPT · error · HTTPException

Unable to cancel your subscription right now. Please try aga

Error message

Unable to cancel your subscription right now. Please try again or contact support.

What it means

HTTP 502 from POST /credits/subscription when cancelling (target tier NO_TIER) fails because cancel_stripe_subscription raised a stripe.StripeError. Payment must be enabled for the user; the cancel path calls Stripe to cancel the active subscription and a Stripe-side failure is mapped to 502 with the exception logged.

Source

Thrown at autogpt_platform/backend/backend/api/features/v1.py:1152

    target_price_id = await get_subscription_price_id(tier, request.billing_cycle)

    # Cancel: target NO_TIER. Schedule Stripe cancellation at period end;
    # cancel_at_period_end=True lets the webhook flip the DB tier. No active
    # sub (admin-granted or never-paid) or payment disabled → DB flip.
    # NO_TIER is never priceable, so this branch always fires for cancel
    # requests regardless of LD config.
    if tier == SubscriptionTier.NO_TIER:
        if payment_enabled:
            try:
                had_subscription = await cancel_stripe_subscription(user_id)
            except stripe.StripeError as e:
                logger.exception(
                    "Stripe error cancelling subscription for user %s: %s",
                    user_id,
                    e,
                )
                raise HTTPException(
                    status_code=502,
                    detail=(
                        "Unable to cancel your subscription right now. "
                        "Please try again or contact support."
                    ),
                )
            if not had_subscription:
                # No Stripe subscription drove this change (admin-granted or
                # never-paid).
                await set_subscription_tier(user_id, tier)
            return await get_subscription_status(user_id)
        await set_subscription_tier(user_id, tier)
        return await get_subscription_status(user_id)

    if not payment_enabled:
        raise HTTPException(
            status_code=422,
            detail=f"Subscription not available for tier {tier.value}",

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Retry after a short delay; check status.stripe.com if errors repeat
  2. Verify the Stripe API key has write access to subscriptions (not a read-only key)
  3. Inspect the backend log line 'Stripe error cancelling subscription' for the exact Stripe error code
  4. If the subscription was already cancelled in Stripe, sync the user's tier via set_subscription_tier / admin tooling
Defensive patterns

Strategy: retry

Try / catch

try { await api.cancelSubscription(); }
catch (e) { if (e.status === 502) { await backoffRetry(); } else throw e; }

Prevention

When it happens

Trigger: POST /credits/subscription with tier=BASIC (NO_TIER) while the user has an active paid Stripe subscription, and the Stripe cancel call errors.

Common situations: Stripe outage or timeout; subscription already cancelled in the Stripe dashboard causing a not-found error; wrong/stale Stripe API key; restricted-mode key missing the subscriptions:write permission.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/4b13fbc41a251075. Report an issue: GitHub.