Skip to main content
Auto-recharge charges your saved card a fixed amount whenever the organization’s balance drops below a threshold you choose. Turn it on if your runs must not stop at 402 insufficient_credits while nobody is watching the balance. This page covers the one route that configures it, the rules it validates, when a charge actually happens, and how to confirm it worked. You can set the same two numbers on the Billing page in the console, in the fields When below, ∗∗and∗∗Buy,** and **Buy, .

Before you start

  • You need billing_write. Owners, admins and billing users hold it; members and viewers do not. See Credits and billing.
  • You need a saved card. GET /v1/billing reports it as has_payment_method. Paying through checkout saves the card, or you can add one in the billing portal (POST /v1/billing/portal) without buying anything. Without a card, auto-recharge can be enabled but never charges.

Turn it on

PUT /v1/billing/auto-recharge sets auto-recharge and returns the updated billing state, the same body as GET /v1/billing. The body refuses any other field. Every amount is micro-USD: 1,000,000 micros is 1 US dollar.

Turn it off

Send enabled: false. The threshold and amount are optional then.

When a charge happens

Saving the setting does not charge anything. The check runs in the background at two moments:
  • after each run is admitted by POST /v1/runs, and
  • after each run is refused with 402 insufficient_credits.
At that moment a charge is made only if all of these hold: The charge is amount_micros on the saved card. The credit lands when the payment succeeds, as a purchase transaction with the description Auto-recharge. What follows from those rules:
  • Nothing happens without traffic. If no run is sent, no check runs, even when the balance is below the threshold. Buy credit through checkout if you need the balance up now.
  • The run that triggers a charge is not held for it. A run admitted while the balance is low goes ahead on the current balance. A run refused with 402 stays refused: the charge it queued helps the next attempt, once the payment has landed.
  • One charge per hour is the ceiling. If one hour’s spend is larger than amount_micros, the balance can still run out before the next hour. Size amount_micros above your busiest hour, or buy extra credit through checkout.
  • Changing the setting takes effect at the next check. The next admitted or refused run sees the new values.

Pick the numbers

  • Threshold: at least your spend over the time a charge takes to land, plus 20,000 micros so the next run can still start. Every run needs 20,000 micros of available credit to be admitted.
  • Amount: at least one busy hour of spend, because one charge per hour is the most you get. Read your spend per day from GET /v1/usage/daily to size it.
For example, a pipeline that settles about 2anhouratitspeakiscoveredbya2 an hour at its peak is covered by a 5 threshold and a $20 amount.

Confirm it works

  1. Read GET /v1/billing and check auto_recharge.enabled is true, both numbers are what you sent, and has_payment_method is true.
  2. After the balance has dropped below the threshold and a run has been sent, look for a new purchase row described Auto-recharge in transactions.
  3. If none appears, check the saved card in the billing portal, and check that a charge was not already made in the same clock hour.

Errors

Malformed JSON, an unknown field, a wrong type or a missing Content-Type gets a plain-text 400, 415 or 422 with no JSON envelope. Check the body against the field table above.