billing

Charge the saved card for credits, or start Stripe Checkout

Charge the saved card, or start Checkout when that is not possible.

Teams with a default payment method are charged in place and credits are granted here. Teams without a usable card, or whose bank requires a 3DS challenge, still go through hosted Checkout; the checkout.session.completed webhook applies those credits.

Args: request: Raw request, required by the rate limiter. team_id: Team the credits are bought for. body: Purchase amount, attempt id, and the Checkout return URLs. auth: Caller identity; payment enforcement is off because this route is how a team with no funds acquires them.

Returns: checkout_url set when the buyer must finish on Stripe; None when the saved card was charged and credits are already on the balance.

Raises: HTTPException: 403 without MANAGE_BILLING; 400 when a Stripe customer cannot be resolved; 402 when the saved card is declined; 500 when payment succeeded but the grant failed; 502 or 503 when Stripe cannot start a session.

post/billing/team/{team_id}/purchase-credits

Path parameters

team_idstring required

Request body

amount_usdnumber required

Amount in USD to purchase (max $500 per transaction)

success_urlstring required

URL Stripe redirects to after a successful payment

cancel_urlstring required

URL Stripe redirects to if the purchase is cancelled

attempt_idstring nullable

Caller-generated id for this purchase attempt, stable across retries of it (e.g. a UUID). Guarantees the card is charged once per attempt; omit and same-minute retries are collapsed instead.

Response

Successful Response

successboolean required
checkout_urlstring nullable

Stripe-hosted Checkout URL to redirect the user to

messagestring

Human-readable status detail

Changes