docs(credits): retire the auto-recharge contract

Merged
SW
3mo ago
+32-294

Contract half of recoupable/chat#1960. Row 1 of that issue's PR matrix.

Automatic off-session credit top-up is being removed from the api: it charged a saved card unless the customer had opted out of a Stripe metadata key they were never told about, collected $0 over 30 days, and minted 2,779 Checkout Sessions across 46 accounts (100% with no customer_email) as a side effect of credit-gated 402s. Per the decision recorded on the issue it is being deleted rather than flipped to opt-in.

This PR lands first because two of the three affected surfaces are published contracts, so the removal is described before it is made.

What changes

Endpoints removed (breaking)

  • GET /api/accounts/{id}/auto-recharge
  • PATCH /api/accounts/{id}/auto-recharge

Deleted: api-reference/accounts/auto-recharge-get.mdx, api-reference/accounts/auto-recharge-update.mdx, their two docs.json nav entries, the /api/accounts/{id}/auto-recharge path block in openapi/accounts.json, and the three now-orphaned schemas (AccountAutoRechargeResponse, AccountAutoRechargeUpdateRequest, AccountAutoRechargeErrorResponse).

402 envelope changed (breaking) in openapi/{research,social,releases}.json

FieldBeforeAfter
checkoutUrlLive Stripe Checkout Session URL, freshly minted on every 402Removed
billingUrl—Added. Static link to the Recoup app. A constant, so retrying the gate creates nothing
declineReasonPresent when Stripe declined the saved cardRemoved (unreachable once no off-session charge is attempted)

declineReason is deliberately kept on POST /api/credits/sessions, which is the consented top-up path where a real card decline still happens. open-agents' credits dialog parses that response, not the 402, so it keeps working.

Prose

  • credits.mdx: the ## Automatic top-up section (decision tree, "When auto top-up doesn't trigger", "Opting out", "Tuning") is replaced by ## Running out of credits, plus a migration <Note> for callers reading the removed fields. The ## 402 Payment Required table and "How to react" guidance are rewritten around billingUrl.
  • The POST /api/subscriptions/card-on-file description said saving a card meant an account "can be auto-recharged instead of dead-ending" — corrected to point at POST /api/credits/sessions and to state explicitly that saving a card does not authorize an automatic charge.

Verification

  • All four OpenAPI specs parse (json.load) after editing; edits were made as anchored text edits rather than a load/dump round-trip, because accounts.json, social.json and releases.json do not round-trip byte-for-byte through json.dumps(indent=2) (unicode escaping and compact security arrays). The diff is purely deletions plus the changed description strings.
  • grep -rn "auto-recharge\|checkoutUrl\|auto top-up" over all .mdx and docs.json returns only the intentional migration references in the new <Note> and the billingUrl field descriptions.
  • No page still links the two deleted reference pages, and #opting-out, the only in-page anchor into the removed section, has no remaining referrer.

Merge order

Merge before the api PRs that implement it. The api side is tracked as rows 3 and 4 of chat#1960.


Summary by cubic

Retires the automatic credit top-up contract and makes 402 insufficient-credits responses static. Previously, gates could charge a saved card and minted a Stripe Checkout Session on every 402; now they never charge automatically and return a constant billingUrl. Programmatic top-ups go through POST /api/credits/sessions.

  • Removes GET /api/accounts/{id}/auto-recharge and PATCH /api/accounts/{id}/auto-recharge, their reference pages, nav entries, and related schemas in openapi/accounts.json.
  • Changes the 402 envelope in openapi/research.json, openapi/social.json, and openapi/releases.json: replace checkoutUrl with billingUrl and drop declineReason. No Stripe objects are created on 402.
  • Keeps declineReason on POST /api/credits/sessions. Updates the card-on-file docs to point to POST /api/credits/sessions for charging.
  • Rewrites credits.mdx to “Running out of credits”, removes auto-top-up guidance and migration notes; docs.json removes links to deleted pages.

Migration

  • Stop calling the deleted auto-recharge endpoints.
  • Read billingUrl instead of checkoutUrl on 402; do not expect declineReason on 402.
  • Use POST /api/credits/sessions to buy credits. Parse declineReason there and open its url for Checkout when present.
  • Do not rely on off-session charging. A saved card is charged only when you request a top-up.
  • Merge before API implementations to keep published contracts in sync.

Summary by CodeRabbit

  • Documentation

    • Updated credit guidance to clarify that top-ups and administrative grants are handled explicitly.
    • Insufficient-credit requests now return an immediate error with a billing link for purchasing credits.
    • Clarified that failed requests do not create automatic charges or checkout sessions.
    • Updated billing navigation and removed auto-recharge documentation.
  • API Reference

    • Replaced checkout links and decline details with a static billing link in insufficient-credit responses.
    • Removed auto-recharge endpoints and related response definitions.
    • Clarified that saved payment methods support later credit top-ups.