# Estimate cost before a run

An estimate tells you what a job would cost and whether the router would accept it now, without
running the job.

## Ask for an estimate

With eigenkit, building a circuit asks the router for an estimate and shows one `CostWarning` with
the price of a job: the vendor's cost plus the EigenOrbit fee. `circuit.dry_run_info()` returns the
same estimate without sending anything.

Over HTTP, `POST /v1/jobs/estimate` takes the same body as a submit and runs the same checks. It
takes no `Idempotency-Key`, because it changes nothing.

<CodeTabs syncKey="client">

```python title="eigenkit"
from eigenkit import Circuit
from eigenkit.core.blocks import (
    AngleEncoding, BasicVariational, assemble,
)
from eigenkit.core.observables import all_z
from eigenorbit_router_client import RouterConfig

spec = assemble([
    AngleEncoding(in_features=2),
    BasicVariational(depth=1),
])

# The API key is read from EIGENORBIT_ROUTER_API_KEY.
# Building the circuit asks the router for an estimate.
provider = RouterConfig(device="braket/sv1", shots=1000)
circuit = Circuit(spec, all_z(2), provider=provider)

# The same estimate, without sending a job.
print(circuit.dry_run_info())
```

```bash title="HTTP"
curl https://router.eigenorbit.com/v1/jobs/estimate \
  --request POST \
  --header 'Content-Type: application/json' \
  --header 'EO-Protocol-Version: 1' \
  --header "Authorization: Bearer $EIGENORBIT_ROUTER_API_KEY" \
  --data '{
    "device": "braket/sv1",
    "method": "run",
    "shots": 0,
    "circuit_spec": {
      "n_qubits": 1,
      "n_weights": 1,
      "n_inputs": 0,
      "gates": [{"n": "RY", "q": [0], "p": [{"t": "WeightRef", "i": 0}]}]
    },
    "observables": [{"terms": [{"coeff": 1.0, "paulis": [["Z", 0]]}]}],
    "weights": [0.5],
    "inputs": []
  }'
```

</CodeTabs>

Each row of a 2-D batch and each parameter-shift gradient evaluation is a separate paid job.

## What an estimate returns

```json
{
  "device": "braket/sv1",
  "method": "run",
  "shots": 0,
  "estimate_usd_micro": 90000,
  "vendor_cost_usd_micro": 75000,
  "fee_usd_micro": 15000,
  "price_version": "braket/sv1@1",
  "available_usd_micro": 910000,
  "would_reject_reason": null
}
```

| Field | Meaning |
|---|---|
| `device`, `method`, `shots` | Echoed from the request. |
| `estimate_usd_micro` | The amount a submit would hold on your balance. |
| `vendor_cost_usd_micro` | The vendor's cost inside the estimate. |
| `fee_usd_micro` | The EigenOrbit fee inside the estimate. With the vendor cost it always sums to `estimate_usd_micro`. |
| `price_version` | The price version the job would be priced with, for example `braket/sv1@1`. |
| `available_usd_micro` | Your balance minus the funds held for your jobs, at the time of the call. |
| `would_reject_reason` | Null when a submit would be accepted now, else the error code it would be refused with. |

`dry_run_info()` carries the same values under the same names: `estimate_usd_micro`,
`vendor_cost_usd_micro`, `fee_usd_micro`, `price_version`, `available_usd_micro` and
`would_reject_reason`, next to keys that describe the circuit.

Amounts are integers in micro-USD: 1000000 is $1. The estimate above is 90000 micro-USD, or $0.09:
75000 ($0.075) for the vendor and 15000 ($0.015) for EigenOrbit. The available balance in this
example is 910000, or $0.91.

## How the amount is priced

The estimate depends on the device's pricing model (see [Devices and prices](/docs/devices)):

- Simulators (`duration_per_minute`): the price per minute times the larger of `min_billable_ms`
  and `hold_seconds`, plus the markup, rounded up once to a whole micro-USD. Shots do not change
  it. On `braket/sv1@1` it is 90000.
- QPUs (`task_plus_shot`): the task fee plus `shots` times the price per shot, plus the markup,
  rounded up once. On `braket/iqm_garnet@1` at 10 shots it is (300000 + 10 × 1450) × 1.2 = 377400:
  314500 vendor cost and 62900 fee. A completed task that ran every requested shot is charged
  exactly this amount.

## No job, no hold

An estimate creates no job, holds no funds and changes no balance, so you can ask for as many as
you like, at the same time. It is a snapshot: a submit right after it can still be refused if your
balance or your jobs in flight change in between.

## `would_reject_reason`

The estimate answers `200` even when a submit would be refused. `would_reject_reason` is then the
first of these codes that applies, in this order:

1. `device_unavailable`: the device is offline or retired, or its status is too old to trust.
2. `method_not_supported`: the device does not run this method.
3. `shots_invalid`: the shots are inside the device's range but outside this method's range.
4. `terms_not_accepted`: you have not accepted the current router terms.
5. `concurrency_limit_exceeded`: you already have the most jobs in flight the router allows.
6. `key_budget_exceeded`: the key's budget does not cover the job (see
   [API keys and budgets](/docs/api-keys)).
7. `negative_balance`: your balance is below zero.
8. `insufficient_balance`: your available balance is below the estimate.

For an IBM Quantum device the list is `device_unavailable`, `method_not_supported`,
`shots_invalid`, `terms_not_accepted`, `ibm_connection_invalid`, `ibm_account_not_connected`, then
`concurrency_limit_exceeded`. The budget and balance codes never apply to IBM jobs.

For a device in limited preview the list is `device_unavailable`, `method_not_supported`, `shots_invalid`, `terms_not_accepted`, `device_access_restricted`, then `concurrency_limit_exceeded`. The budget and balance codes never apply to its jobs, and its estimate is 0, 0 and 0, with `available_usd_micro` 0. The router does not read your balance for it, so the 0 is not your balance.

`would_reject_reason` never reports `user_blocked`. The estimate answers it as an error,
`403 user_blocked`, and a block that the router learns of only when it holds funds shows only at
submit.

## Errors an estimate still answers

Some problems are errors, not reasons: `401 unauthenticated`, `403 user_blocked`,
`422 validation_error`, `422 unknown_device`, `422 shots_invalid` (outside the device's range),
`422 batch_not_supported`, `422 circuit_invalid`, `426 protocol_unsupported`, `451 region_blocked`
and `503 ledger_unavailable`. See [Errors, retries and idempotency](/docs/errors).

## IBM Quantum devices

The router charges nothing for an IBM job, so its estimate is 0, 0 and 0, with `price_version`
`ibm/<backend>@1` and `available_usd_micro` 0. The router does not ask for your balance for it, so
an IBM estimate never answers `503 ledger_unavailable`. IBM bills your instance for quantum time,
which the router cannot estimate; a job's IBM quantum time is `ibm_usage_seconds` on the job once
IBM reports it.

## Reference

- [Estimate a job](/docs/api/jobs#estimate-a-job)
- [Submit a job](/docs/api/jobs#submit-a-job)
- [List devices](/docs/api/devices#list-devices)
