# Turn auto top-up on or off and set its amounts

> PUT /v1/billing/auto-top-up. .

Source: https://legion.ambient.xyz/docs/api/billing/put-auto-top-up

`PUT https://api.legion.ambient.xyz/v1/billing/auto-top-up`

Authenticate with an API key: `Authorization: Bearer $LEGION_API_KEY`.

. Sets the threshold, the amount added each time ($25 to $10,000), the monthly limit (at least the
amount, at most $100,000) and whether auto top-up is on. `threshold` is $1 to $10,000. Turning it on
without a saved card is 409 `no_saved_card`: save one with `createAutoTopUpCard` first. Saving resumes a
paused auto top-up (the next check is within a minute). A test organization (`getMe`'s `org.test_org`)
cannot turn it on while Stripe runs with live keys (409 `test_org_live_payment`).

Requires an `Idempotency-Key`: a repeat with the same key and body returns the same answer, and the same
key with another body is 422 `idempotency_key_reused`. Requires `billing.topup` (owners). At most 30
changes an hour per organization (429 `rate_limited`). Every change is recorded in the organization's
activity. Payments failing or not answering within 3 seconds is 503 `payments_unavailable`; retry with the
same key.

## Headers

- `Idempotency-Key`, string, required: Client-chosen key, unique per request intent, at most 255 characters.

## Request body

- `enabled`, boolean, required
- `threshold`, Money, required: Charge when the balance falls below this, $1 to $10,000.
- `amount`, Money, required: What each auto top-up adds, $25 to $10,000.
- `monthly_limit`, Money, required: The most auto top-ups may add in a calendar month (UTC), at least `amount` and at most $100,000.

Example:

```json
{
  "enabled": false,
  "threshold": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "amount": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "monthly_limit": {
    "amount_minor": 250,
    "currency": "USD"
  }
}
```

## Responses

### 200

The saved settings and state.

- `enabled`, boolean, required
- `threshold`, Money, required
  - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
  - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
- `amount`, Money, required
  - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
  - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
- `monthly_limit`, Money, required
  - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
  - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
- `added_this_month`, Money, required
  - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
  - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
- `card`, AutoTopUpCard, required: The card on file, null when there is none.
- `status`, AutoTopUpStatus, required: . `active`: on and charging when needed. `paused`: on, but not charging (see `paused_reason`). `off`: turned off.
- `paused_reason`, AutoTopUpPausedReason, required: Why it is paused, null unless `status` is `paused`.
- `last_attempt`, AutoTopUpAttempt, required: The most recent charge, null before the first.

Example:

```json
{
  "enabled": false,
  "threshold": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "amount": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "monthly_limit": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "added_this_month": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "card": {
    "brand": "string",
    "last4": "string",
    "exp_month": 1,
    "exp_year": 0
  },
  "status": "active",
  "paused_reason": "card_declined",
  "last_attempt": {
    "at": "2026-10-15T12:00:00Z",
    "outcome": "succeeded",
    "amount": {
      "amount_minor": 250,
      "currency": "USD"
    }
  }
}
```

### 400

The request is malformed or fails validation. An image reference that
is not a container image reference answers `invalid_image_reference`.

### 401

Missing, unknown, expired or revoked credentials.

### 403

The caller lacks the permission this operation requires (`forbidden`),
or signed in without having joined an organization yet
(`no_organization`; `getOnboarding` and the invitation and
organization operations under it work), or could not sign in
(`email_unverified`, `account_conflict`, and `domain_not_allowed`). `not_invited` is no longer returned to
session tokens.

`access_not_approved`: a signed-in person who is not approved
for the beta yet. Every operation that takes a credential answers it to
them, except `getMe` and `joinMyWaitlist`; the problem carries
`access` (`waitlisted` or `not_requested`, and the email). Approved
means a member of an organization, holding a pending invitation, or Legion; an API key always belongs to a member.

`oauth_token_mcp_only`: the caller sent an OAuth access token (`lgo_`), which is accepted
only by `mcpMessage` and the tool calls it dispatches. Every other operation answers it, whatever
the token's scope. Use an API key or the Legion web app.

`org_suspended`: the caller's organization is suspended. Every operation that takes a
credential answers it, by session or API key, except `getMe` (which shows `org.suspended_at` and
`org.suspension_reason`) and the support operations under `/v1/support/`.

`terms_not_accepted`: an approved caller who has not accepted
the current version of the Terms of Use and the Acceptable Use Policy. Every operation that takes a credential answers it, except `getMe`,
`acceptLegalDocuments`, `joinMyWaitlist` and the wind-down operations
(`listRentals`, `stopRental`, `deleteRental`, `listHosts`,
`updateListing` with `listed` false, `removeHost`); the problem
carries `legal`. An API key acts for the person who created it, so it
is refused until that person accepts. Terminal
operations also return
`session_required` (called with an API key) and `step_up_required`
(neither a sign-in nor a step-up challenge within the step-up window).

### 409

The resource's current state does not allow the operation. `legal_versions_stale`: a legal document version sent is not the current one; the
problem's `legal` holds the current documents.

### 422

The Idempotency-Key was already used with a different request body.

### 429

Rate limited (`code` is `rate_limited`), or the organization asked the
pull-through mirror to copy in too many different tags or digests of one
repository today (`mirror_quota_exceeded`). Retry after the `Retry-After`
seconds.

### 500

An unexpected server error. Safe to retry.

### 503

The payments service failed or did not answer within 3 seconds
(`payments_unavailable`). Nothing changed; retry with backoff.

## Errors

- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)
- 409 [`no_saved_card`](https://legion.ambient.xyz/docs/errors#no_saved_card)
- 409 [`test_org_live_payment`](https://legion.ambient.xyz/docs/errors#test_org_live_payment)
- 422 [`idempotency_key_reused`](https://legion.ambient.xyz/docs/errors#idempotency_key_reused)
- 429 [`rate_limited`](https://legion.ambient.xyz/docs/errors#rate_limited)
- 503 [`payments_unavailable`](https://legion.ambient.xyz/docs/errors#payments_unavailable)

## Example request

```sh
curl -s -X PUT "https://api.legion.ambient.xyz/v1/billing/auto-top-up" \
  -H "Authorization: Bearer $LEGION_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "enabled": false,
  "threshold": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "amount": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "monthly_limit": {
    "amount_minor": 250,
    "currency": "USD"
  }
}'
```
