# API reference: billing

The plan, the prepaid balance, and what was used.

[API conventions](../api.md) explains auth, IDs, lists, errors and idempotency. The examples read the API key from `ARVM_API_KEY`.

## Operations

| Operation | Request |
|---|---|
| [Get the plan and the balance](#get-the-plan-and-the-balance) | `GET /v1/billing` |
| [Claim the free trial](#claim-the-free-trial) | `POST /v1/trial/claim` |
| [Start the subscription checkout](#start-the-subscription-checkout) | `POST /v1/billing/checkout` |
| [Start a top-up](#start-a-top-up) | `POST /v1/billing/top-ups` |
| [Show auto top-up](#show-auto-top-up) | `GET /v1/billing/auto-top-up` |
| [Turn auto top-up on, or change it](#turn-auto-top-up-on-or-change-it) | `PUT /v1/billing/auto-top-up` |
| [Turn auto top-up off](#turn-auto-top-up-off) | `DELETE /v1/billing/auto-top-up` |
| [Open the Stripe customer portal](#open-the-stripe-customer-portal) | `POST /v1/billing/portal` |
| [List ledger entries](#list-ledger-entries) | `GET /v1/billing/ledger` |
| [List usage by day](#list-usage-by-day) | `GET /v1/billing/usage` |

## Get the plan and the balance

`GET /v1/billing`

The org's plan, its subscription if it has one, its balance, and how long that balance runs
one machine of each size. The balance is the sum of the grants that have not expired; usage
draws from the grant that expires first.

- Operation ID: `getBilling`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The org's billing state. | `application/json`: [Billing](schemas.md#billing) |

Errors: `401`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/billing" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "plan": {
    "id": "standard",
    "name": "Pro",
    "price_micros": 20000000,
    "grant_micros": 20000000,
    "period_months": 1,
    "max_machines": 30,
    "max_running_vcpus": 40,
    "max_running_memory_bytes": 85899345920,
    "max_disk_bytes": 1642824990720,
    "max_snapshots": 20,
    "snapshot_rate_micros_per_gib_month": 100000,
    "topup_min_micros": 10000000,
    "topup_max_micros": 500000000,
    "topup_expires_months": null,
    "machine_inbound_default": "open",
    "allow_inbound_open": true,
    "allow_public_endpoints": true,
    "egress_profile": "standard",
    "max_idle_timeout_seconds": null,
    "nic_bytes_per_second": null,
    "connection_limit": null
  },
  "subscription": {
    "status": "active",
    "current_period_start": "2026-11-10T20:30:00Z",
    "current_period_end": "2026-12-10T20:30:00Z",
    "cancel_at_period_end": false,
    "period_granted": true
  },
  "subscription_ended_at": null,
  "balance_micros": 20000000,
  "runtime_remaining": [
    {
      "size": "small",
      "seconds": 8000000
    },
    {
      "size": "default",
      "seconds": 4000000
    },
    {
      "size": "large",
      "seconds": 2000000
    }
  ],
  "grants": [
    {
      "id": "grant_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "kind": "plan",
      "amount_micros": 20000000,
      "remaining_micros": 20000000,
      "starts_at": "2026-11-10T20:30:00Z",
      "expires_at": "2026-12-10T20:30:00Z"
    }
  ]
}
```

## Claim the free trial

`POST /v1/trial/claim`

Browser session only. Grants a one-time $5 starter credit (5,000,000 micros, 14-day expiry)
on the Free (`trial`) plan for eligible accounts. Depending on automated risk checks
and email domain infrastructure, the response either grants the trial immediately (`granted`)
or returns a $0 Stripe card verification URL (`card_verification_required`) that verifies
a non-prepaid card via Stripe Radar without charging it.

Consumer freemail, disposable domains, domains with no MX, duplicate identities, and
high-risk attempts are refused with `trial_ineligible` (403); they may still subscribe
directly via `startCheckout`. An org with a live subscription is refused with
`subscription_exists` (409).

- Operation ID: `claimTrial`
- Auth: the web app's session cookie only

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `Idempotency-Key` | header | string | no | A value the client chooses, such as a UUID. For 24 hours after a request succeeded, a request with the same key and the same body returns the first request's response instead of creating again. A request that failed leaves the key free, with one exception: a `createMachine` refused with `no_capacity` returns the same 503 until its `Retry-After` has passed, and is tried again after. The same key with a different body is `idempotency_key_reused` (409). Minimum length: `1`. Maximum length: `255`. |

**Request body**

`application/json`: [TrialClaimRequest](schemas.md#trialclaimrequest)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | Trial granted, or card verification started. | `application/json`: [TrialClaimResponse](schemas.md#trialclaimresponse) |

Errors: `400`, `401`, `403`, `409`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/trial/claim" \
    -b "session=$ARVM_SESSION" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{"return_to": "/start"}'
```

Response body, `application/json`:

```json
{
  "outcome": "granted",
  "billing": {
    "plan": {
      "id": "trial",
      "name": "Free",
      "price_micros": 0,
      "grant_micros": 5000000,
      "period_months": 1,
      "max_machines": 3,
      "max_running_vcpus": 8,
      "max_running_memory_bytes": 17179869184,
      "max_disk_bytes": 238370684928,
      "max_snapshots": 0,
      "snapshot_rate_micros_per_gib_month": 100000,
      "topup_min_micros": 10000000,
      "topup_max_micros": 500000000,
      "topup_expires_months": null,
      "machine_inbound_default": "closed",
      "allow_inbound_open": false,
      "allow_public_endpoints": false,
      "egress_profile": "trial",
      "max_idle_timeout_seconds": 1800,
      "nic_bytes_per_second": 3125000,
      "connection_limit": 256
    },
    "subscription_ended_at": null,
    "balance_micros": 5000000,
    "runtime_remaining": [
      {
        "size": "small",
        "seconds": 2000000
      },
      {
        "size": "default",
        "seconds": 1000000
      },
      {
        "size": "large",
        "seconds": 500000
      }
    ],
    "grants": [
      {
        "id": "grant_01jcz3k8x0e5v9w2r4t6y8a0bq",
        "kind": "trial",
        "amount_micros": 5000000,
        "remaining_micros": 5000000,
        "starts_at": "2026-11-10T20:30:00Z",
        "expires_at": "2026-11-24T20:30:00Z"
      }
    ],
    "trial": {
      "status": "granted",
      "expires_at": "2026-11-24T20:30:00Z",
      "deny_code": null
    }
  }
}
```

## Start the subscription checkout

`POST /v1/billing/checkout`

Returns a Stripe Checkout URL for a paid subscription (`standard`, `max`, or `ultra`; defaults to `standard`). The balance is granted when Stripe reports the payment. An org that already has a subscription is refused with `subscription_exists` (409). Returns 503 when the requested paid tier's Stripe price is not configured on the server.

- Operation ID: `startCheckout`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `Idempotency-Key` | header | string | no | A value the client chooses, such as a UUID. For 24 hours after a request succeeded, a request with the same key and the same body returns the first request's response instead of creating again. A request that failed leaves the key free, with one exception: a `createMachine` refused with `no_capacity` returns the same 503 until its `Retry-After` has passed, and is tried again after. The same key with a different body is `idempotency_key_reused` (409). Minimum length: `1`. Maximum length: `255`. |

**Request body**

`application/json`: [CheckoutStart](schemas.md#checkoutstart)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The checkout was created. Send the browser to `url`. | `application/json`: [HostedPage](schemas.md#hostedpage) |

Errors: `400`, `401`, `403`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/billing/checkout" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{"plan": "standard", "return_to": "/billing"}'
```

Response body, `application/json`:

```json
{
  "url": "https://checkout.stripe.com/c/pay/cs_test_a1B2c3D4"
}
```

## Start a top-up

`POST /v1/billing/top-ups`

Returns a Stripe Checkout URL for a one-off payment. Requires an active subscription; otherwise fails with `invalid_request` (400). When Stripe reports the payment, the amount is granted to the balance; a top-up's grant expires after the plan's `topup_expires_months`, and has no expiry (`expires_at` is `null`) when the plan has none, as the standard plan does. The amount must be within the plan's top-up limits.

- Operation ID: `startTopUp`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `Idempotency-Key` | header | string | no | A value the client chooses, such as a UUID. For 24 hours after a request succeeded, a request with the same key and the same body returns the first request's response instead of creating again. A request that failed leaves the key free, with one exception: a `createMachine` refused with `no_capacity` returns the same 503 until its `Retry-After` has passed, and is tried again after. The same key with a different body is `idempotency_key_reused` (409). Minimum length: `1`. Maximum length: `255`. |

**Request body**

`application/json`: [TopUpStart](schemas.md#topupstart)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The checkout was created. Send the browser to `url`. | `application/json`: [HostedPage](schemas.md#hostedpage) |

Errors: `400`, `401`, `403`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/billing/top-ups" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{"amount_micros": 10000000, "return_to": "/billing"}'
```

Response body, `application/json`:

```json
{
  "url": "https://checkout.stripe.com/c/pay/cs_test_e5F6g7H8"
}
```

## Show auto top-up

`GET /v1/billing/auto-top-up`

Auto top-up charges the card the subscription is paid with when the balance falls under a
threshold. It is off until `setAutoTopUp` turns it on. The answer says where it stands
(`state`), what it has charged in this UTC calendar month, and whether a card is saved for it.

- Operation ID: `getAutoTopUp`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | Where auto top-up stands. | `application/json`: [AutoTopUp](schemas.md#autotopup) |

Errors: `401`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/billing/auto-top-up" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "state": "on",
  "threshold_micros": 5000000,
  "amount_micros": 20000000,
  "monthly_max_micros": 100000000,
  "charged_this_month_micros": 20000000,
  "month_ends_at": "2026-12-01T00:00:00Z",
  "payment_method_saved": true
}
```

## Turn auto top-up on, or change it

`PUT /v1/billing/auto-top-up`

Browser session only: an API key cannot turn auto top-up on or raise its amounts, so a
key cannot spend money on a saved card. Turn it on or change it from the dashboard's
billing page.

When the balance falls under `threshold_micros`, the saved card is charged `amount_micros`,
which is added to the balance as a top-up when Stripe reports the payment. One charge is in
flight at a time. Each charge is a `grant` entry in the ledger, and its receipt is emailed, as
for a top-up paid by hand.

`monthly_max_micros` is the most auto top-up may charge in one UTC calendar month. A charge
that would go over it is not made: `state` becomes `at_monthly_max`, the org's owners are
emailed once, and charging resumes when the month ends or the maximum is raised.

A declined charge turns nothing off silently: `state` becomes `stopped` with the reason, the
owners are emailed, and nothing is charged until this operation is called again.

The org needs an active subscription and the card it is paid with (`payment_method_required`,
409, when no card is saved: add one in the billing portal). `amount_micros` must be within the
plan's top-up limits, and `monthly_max_micros` at least one `amount_micros`.

- Operation ID: `setAutoTopUp`
- Auth: the web app's session cookie only

**Request body**

`application/json`: [AutoTopUpSet](schemas.md#autotopupset)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | Auto top-up is on, with these values. | `application/json`: [AutoTopUp](schemas.md#autotopup) |

Errors: `400`, `401`, `403`, `409`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X PUT "https://api.arvm.dev/v1/billing/auto-top-up" \
    -b "session=$ARVM_SESSION" \
    -H "Content-Type: application/json" \
    -d '{"threshold_micros": 5000000, "amount_micros": 20000000, "monthly_max_micros": 100000000}'
```

Response body, `application/json`:

```json
{
  "state": "on",
  "threshold_micros": 5000000,
  "amount_micros": 20000000,
  "monthly_max_micros": 100000000,
  "charged_this_month_micros": 20000000,
  "month_ends_at": "2026-12-01T00:00:00Z",
  "payment_method_saved": true
}
```

## Turn auto top-up off

`DELETE /v1/billing/auto-top-up`

Nothing more is charged. A charge already sent to Stripe still adds to the balance if it is
paid. Turning off what is off is also 204: auto top-up is a setting of the org, not a thing
that can be missing.

- Operation ID: `turnOffAutoTopUp`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Responses**

| Status | Description | Body |
|---|---|---|
| 204 | Auto top-up is off. |  |

Errors: `401`, `403`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X DELETE "https://api.arvm.dev/v1/billing/auto-top-up" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

## Open the Stripe customer portal

`POST /v1/billing/portal`

Returns a short-lived URL where the customer changes the card, downloads invoices or cancels. An org that has never paid has no portal (`no_billing_account`, 409).

- Operation ID: `openBillingPortal`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Request body**

`application/json`: [PortalOpen](schemas.md#portalopen)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The portal session was created. Send the browser to `url`. | `application/json`: [HostedPage](schemas.md#hostedpage) |

Errors: `400`, `401`, `403`, `409`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/billing/portal" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"return_to": "/billing"}'
```

Response body, `application/json`:

```json
{
  "url": "https://billing.stripe.com/p/session/test_YWNjdF8x"
}
```

## List ledger entries

`GET /v1/billing/ledger`

Every movement of the balance, newest first. The ledger is append-only, so an entry never changes.

- Operation ID: `listLedgerEntries`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `limit` | query | integer (int32) | no | The most items to return. Default: `50`. Minimum: `1`. Maximum: `200`. |
| `cursor` | query | string | no | The `next_cursor` of the previous page. Opaque. Maximum length: `512`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | A page of ledger entries. | `application/json`: [LedgerEntryList](schemas.md#ledgerentrylist) |

Errors: `400`, `401`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/billing/ledger" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "data": [
    {
      "id": "le_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "kind": "usage",
      "amount_micros": -300,
      "grant_id": "grant_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "grant_kind": "plan",
      "created_at": "2026-11-10T20:33:00Z",
      "usage": {
        "machine_id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
        "machine_name": "calm-river-otter",
        "window_start": "2026-11-10T20:32:00Z",
        "window_end": "2026-11-10T20:33:00Z",
        "seconds": 60
      }
    },
    {
      "id": "le_01jcz3k8w0e5v9w2r4t6y8a0bq",
      "kind": "grant",
      "amount_micros": 20000000,
      "grant_id": "grant_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "grant_kind": "plan",
      "created_at": "2026-11-10T20:30:00Z"
    }
  ],
  "next_cursor": null
}
```

## List usage by day

`GET /v1/billing/usage`

One row per UTC day and per machine or snapshot that used anything that day, newest day first. The default range is the current calendar month.

- Operation ID: `listUsage`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `starts_at` | query | string (date-time) | no | The start of the time range, inclusive. |
| `ends_at` | query | string (date-time) | no | The end of the time range, exclusive. |
| `limit` | query | integer (int32) | no | The most items to return. Default: `50`. Minimum: `1`. Maximum: `200`. |
| `cursor` | query | string | no | The `next_cursor` of the previous page. Opaque. Maximum length: `512`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | A page of usage rows. | `application/json`: [UsageList](schemas.md#usagelist) |

Errors: `400`, `401`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/billing/usage" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "data": [
    {
      "date": "2026-11-10",
      "machine_id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "machine_name": "calm-river-otter",
      "seconds": 7200,
      "amount_micros": 36000
    },
    {
      "date": "2026-11-10",
      "snapshot_id": "snap_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "seconds": 86400,
      "amount_micros": 19726
    }
  ],
  "next_cursor": null
}
```
