Skip to navigation

Set a customer’s auto top-up

Buys credits for the customer when a pool’s available balance falls to the threshold, up to target_balance, charging the payment method the customer saved at checkout. It replaces any auto top-up the customer has. The customer’s plan must allow it (top_up.auto.allowed), the customer must have a saved payment method (otherwise invalid_state), and a monthly_limit above the plan’s maximum_monthly_limit is parameter_invalid. The limit caps automatic purchases only, and a spend limit caps consumption. Setting a customer’s auto top-up is a runtime write that takes auto_top_up:write. An agent key may turn it on within the plan’s bounds or lower the limit, but not raise the limit in live. Credits it buys expire after the plan’s top_up.credits_expire_in, or after one year when the plan sets none, the same as any other top-up. Creating the rule, changing it and turning it off (status disabled) each write an audit event with the actor: auto_top_up.created, auto_top_up.updated or auto_top_up.turned_off.

Authentication

AuthorizationBearer

A secret key (rl_sk_test_..., rl_sk_live_...) or a restricted key with limited scopes (rl_rk_test_..., rl_rk_live_...). A restricted key can carry agent: true and an expires_at, and is what a coding agent should hold. Keys end in a checksum so secret scanners can recognize them. People create, roll and revoke keys in the dashboard; GET /v1/api_keys lists them, masked.

Path parameters

customer_idstringRequired

The customer ID (cus_...).

Request

This endpoint expects an object.
thresholdstringRequired
Buy credits when the pool's available balance is at or below this, as a decimal string.
target_balancestringRequired

Buy enough to bring the available balance back to this. The purchase respects the plan’s top-up minimum and maximum.

poolstringOptional

The pool to keep topped up. Defaults to the plan’s top_up.pool.

enabledbooleanOptionalDefaults to true

false buys nothing and keeps the threshold, so balance.low still goes out when the balance falls to it.

monthly_limitobjectOptional
The most automatic purchases may cost in a calendar month. It limits purchases, not consumption. If it blocks a purchase, Runledger buys what fits under the limit, if that meets the minimum.

Response

The customer’s auto top-up.

idstring
object"auto_top_up"
customerstring
credit_typestring
poolstring
enabledboolean
thresholdstring
target_balancestring
statusenum

active tops up. disabled stopped after three failures in a row, or because you turned it off. Set it again to re-enable.

Allowed values:
consecutive_failuresinteger
livemodeboolean
created_atdatetime
monthly_limitobjectOptional
An amount of money in the currency's minor unit.
purchased_this_monthobjectOptional

What automatic purchases have cost since the start of the calendar month (UTC).

last_attemptobjectOptional
actorobjectOptional
Who last changed it.

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
404
Not Found Error
409
Conflict Error
429
Too Many Requests Error
500
Internal Server Error