# Balance, holds and charges

This page explains how a job is paid for: your balance, which you top up in advance, the hold
placed when you submit, and the charge or release when the job ends.

## Money is micro-USD

Every amount on the wire is an integer number of micro-USD: 1 is $0.000001, so 1000000 is $1.
Fields that carry money end in `_usd_micro`. There are no floats or cents. To show dollars, divide
by 1000000.

Amounts are computed in exact integer arithmetic and rounded up once, so a charge is never below the
vendor's cost. Every price is the vendor's cost plus the EigenOrbit fee: the vendor cost is the
exact cost rounded up, the total is the marked-up exact cost rounded up once, and the fee is the
difference. The fee is never negative.

## Your balance

Jobs on Amazon Braket devices are paid from your balance, which you top up in advance on the
Balance page of the router web app, https://router.eigenorbit.com/balance. A top-up adds whole US
dollars through a Stripe Checkout page; tax, if any, is charged on top and never credited to the
balance. You do not need to accept the router terms to top up.

The Balance page also shows the funds held for your jobs and the history of your balance. Over the
API, an estimate's `available_usd_micro` is your balance minus the funds held for your jobs (see
[Estimate cost before a run](/docs/estimates)).

## Hold at submit

Every paid job first holds its estimate on your balance. A job never reaches a vendor without a
successful hold.

- If your available balance (balance minus holds) is below the estimate, the submit answers
  `402 insufficient_balance`. The job is `rejected`, nothing is held and `billing` stays null.
- If your balance is below zero, the submit answers `402 negative_balance` until you top up.
- A retry with the same `Idempotency-Key` answers the same rejection. After topping up, submit
  with a new key.

## Settle or release

When the job ends, its hold is settled or released. `billing` on the job says which:

| `billing` | Meaning |
|---|---|
| `held` | Funds are reserved for the job. |
| `settled` | The actual cost was charged and the rest of the hold returned. |
| `released` | The whole hold was returned and nothing was charged. |
| null | No hold was ever placed, for example a job rejected for `insufficient_balance`, an IBM job or a photonic job. |

The charge comes from what the vendor reports for the task, not from the estimate:

- Simulators (`duration_per_minute`): the device time the vendor billed, raised to
  `min_billable_ms` when it is shorter, at the price per minute plus the markup. A long task can be
  charged more than its hold, and your balance can then go below zero.
- QPUs (`task_plus_shot`): the task fee plus the shots the vendor billed times the price per shot,
  plus the markup. It is never more than the hold. A task that ran every requested shot is charged
  exactly its estimate.
- A task the vendor reports no usage for is released in full, and so is a simulator task billed
  0 ms of device time: nothing is charged.
- A job rejected, failed or cancelled before it reached the vendor is released in full.
- A job that failed `internal_error` after its vendor task ran (the router could not read the
  vendor's result) is never charged: its hold is released in full.
- A job cancelled at the vendor is charged what the vendor billed for it plus the markup, often
  nothing. There is no cancel fee.

The result never waits for the charge: it is ready as soon as the status is `completed`, while
`billing` can still be `held` for some minutes.

## A job's charge, worked through

A `run` job on `braket/sv1@1` holds its estimate, 90000 micro-USD. It completes, the vendor bills
3000 ms of device time (the minimum, `min_billable_ms`), and the job settles at 4500 micro-USD.
The rest of the hold, 85500, goes back to your available balance.

In dollars: a hold of 90000 / 1000000 = $0.09 and a charge of 4500 / 1000000 = $0.0045, made of
3750 ($0.00375) vendor cost and 750 ($0.00075) EigenOrbit fee.

:::info

HTTP only. Read a job's money fields with `GET /v1/jobs/{job_id}`.

:::

`$JOB_ID` is the `id` of the job, from the answer to its submit:

```bash
curl https://router.eigenorbit.com/v1/jobs/$JOB_ID \
  --header 'EO-Protocol-Version: 1' \
  --header "Authorization: Bearer $EIGENORBIT_ROUTER_API_KEY"
```

The money fields of that job, once settled:

```json
{
  "status": "completed",
  "billing": "settled",
  "estimate_usd_micro": 90000,
  "actual_cost_usd_micro": 4500,
  "vendor_cost_usd_micro": 3750,
  "fee_usd_micro": 750,
  "price_version": "braket/sv1@1"
}
```

| Field | Meaning |
|---|---|
| `estimate_usd_micro` | The estimate the hold was placed for. |
| `actual_cost_usd_micro` | Null while `billing` is `held` or null; the charged amount once `settled`; 0 once `released`. |
| `vendor_cost_usd_micro` | The vendor's part of the charge; null until the job is settled or released. |
| `fee_usd_micro` | The EigenOrbit fee of the charge; null until the job is settled or released. With the vendor cost it sums to `actual_cost_usd_micro`. |
| `price_version` | The price version the job was submitted with. It is used for the charge, even if the price changed since. |

## Negative balance

A settlement may take your balance below zero when a simulator job costs more than its hold. A
negative balance refuses new jobs with `402 negative_balance` until you top up. Jobs already
holding funds go ahead.

## Key budgets

Each API key can have its own lifetime budget on top of your balance. See
[API keys and budgets](/docs/api-keys).

## IBM Quantum jobs carry no router charge

The router charges nothing for an IBM Quantum job. IBM bills your own instance for the quantum time
the job uses. Your balance needs no funds to run IBM jobs.

- `billing` is null for the job's whole life, and nothing is ever held.
- `estimate_usd_micro` is 0, and `actual_cost_usd_micro`, `vendor_cost_usd_micro` and
  `fee_usd_micro` are null.
- `price_version` is `ibm/<backend>@1`.
- `ibm_usage_seconds` is the IBM quantum time the job used, once IBM reports it.
- IBM jobs skip the key budget and the balance checks, and never appear in your balance history.

See [Connect your IBM Quantum account](/docs/ibm-quantum).

## Reference

- [Estimate a job](/docs/api/jobs#estimate-a-job)
- [Submit a job](/docs/api/jobs#submit-a-job)
- [Get a job](/docs/api/jobs#get-a-job)
