# Job lifecycle

This page follows a job from submit to result: its statuses, how to poll it, what its result looks
like, how cancel works and how long the result is kept.

## One job, one task

One router job is one vendor task with one hold on your balance and one charge. For a qubit circuit, eigenkit runs a 2-D
batch of weights or inputs as one router job per row and stacks the results. On Amazon Braket and IBM Quantum devices the router accepts only 1-D `weights` and `inputs`; a 2-D array answers `422 batch_not_supported`. A photonic job may carry 2-D `inputs`: see [Photonic jobs](#photonic-jobs).

## Submit a job

`circuit(weights, inputs)` sends a job and blocks until it finishes. To come back to a job later,
submit it and keep the handle. Over HTTP, `POST /v1/jobs` needs an `Idempotency-Key` header (see
[Errors, retries and idempotency](/docs/errors)) and answers `202` with the new job.

<CodeTabs syncKey="client">

```python title="eigenkit"
import numpy as np
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.
provider = RouterConfig(device="braket/sv1", shots=1000)
circuit = Circuit(spec, all_z(2), provider=provider)

weights = np.linspace(-0.9, 1.1, spec.n_weights)
inputs = np.array([0.2, 0.6])
handle = circuit.submit(weights, inputs)
print(handle.job_id(), handle.status())
```

```bash title="HTTP"
curl https://router.eigenorbit.com/v1/jobs \
  --request POST \
  --header 'Content-Type: application/json' \
  --header 'EO-Protocol-Version: 1' \
  --header "Idempotency-Key: $(uuidgen)" \
  --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>

The job ID is also on the Jobs page of the router web app.

The HTTP samples below read the job's ID from `$JOB_ID`. Set it to the `id` of the submit's
answer, for example `JOB_ID=01a0d3c5-6d70-7894-b00c-bf5998ca19fa`.

## Statuses

| Status | Meaning | Terminal |
|---|---|---|
| `queued` | Accepted; not yet running at the vendor. | no |
| `running` | The vendor is running the task. | no |
| `completed` | The vendor finished and the result is ready. | yes |
| `failed` | The vendor or the router could not produce a result. `error` says why. | yes |
| `cancelled` | The job was cancelled, before it reached the vendor or by the vendor. | yes |
| `rejected` | Refused when it was submitted, before any vendor task. `error` says why. | yes |

`billing` says what happened to the funds: `held`, `settled` or `released`, or null when nothing was
ever held. See [Balance, holds and charges](/docs/billing). `error` is `{code, message, category}` for a
`failed` or `rejected` job and null otherwise; see [Errors, retries and idempotency](/docs/errors).

## Poll a job

Poll the job until its status is terminal. There is no push channel. Back off between polls, for
example 1 second, then 5, then 30, and stay at that cap. With `handle` from the submit script:

<CodeTabs syncKey="client">

```python title="eigenkit"
print(handle.status())
```

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

</CodeTabs>

`handle.result()` waits for the job by itself. Over HTTP, a completed job looks like this:

```json
{
  "id": "01a0d3c5-6d70-7894-b00c-bf5998ca19fa",
  "status": "completed",
  "billing": "settled",
  "device": "braket/sv1",
  "method": "run",
  "shots": 0,
  "estimate_usd_micro": 90000,
  "price_version": "braket/sv1@1",
  "error": null,
  "actual_cost_usd_micro": 4500,
  "vendor_cost_usd_micro": 3750,
  "fee_usd_micro": 750,
  "created_at": "2026-09-24T14:12:03.512000Z",
  "updated_at": "2026-09-24T14:12:21.907000Z",
  "completed_at": "2026-09-24T14:12:21.907000Z",
  "result_expires_at": "2026-12-23T14:12:21.907000Z",
  "credential_source": null,
  "ibm_usage_seconds": null
}
```

## Read the result

The result is ready as soon as the status is `completed`, even while the job's funds are still
held. Asking for it earlier answers `409 job_not_completed` with `details = {status}`. With
`handle` from the submit script:

<CodeTabs syncKey="client">

```python title="eigenkit"
values = handle.result()
```

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

</CodeTabs>

eigenkit returns the same shape, dtype and bit order as the same code run with your own vendor
credentials. Over HTTP the answer carries the job ID, the method, the bit order and the result,
and also `execution`, described below. This example omits `execution`:

```json
{
  "job_id": "01a0d3c5-6d70-7894-b00c-bf5998ca19fa",
  "method": "run",
  "bit_order": "qubit0_msb",
  "result": {
    "kind": "array",
    "dtype": "float64",
    "shape": [1],
    "data": [0.8775825618903728]
  }
}
```

`result` has one of three kinds:

- `{"kind": "array", "dtype": "float64", "shape": [...], "data": ...}`: a float64 array. `data` is
  nested as deep as `shape` is long, and is a bare number when `shape` is `[]`. In numpy:
  `np.asarray(data, dtype=np.float64).reshape(shape)`.
- `{"kind": "counts", "n_qubits": ..., "data": {"<bitstring>": count}}`: measurement counts. Every
  key is a string of `n_qubits` zeros and ones.
- `{"kind": "fock_counts", "n_modes": ..., "data": [{"<fock state>": count}, ...]}`: the sampled Fock states of a photonic job, one object per input row. See [Photonic jobs](#photonic-jobs).

| Method | Result |
|---|---|
| `run` | array of shape `[n_observables]`: one expectation value per observable, in request order |
| `zero_state_probability` | array of shape `[]`: the probability of the all-zeros state |
| `probabilities` | array of shape `[2**n_qubits]`, indexed in `qubit0_msb` order |
| `sample` | counts |
| `photonic_sample` | Fock-state counts |

`bit_order` is always `qubit0_msb`: in every bitstring and every basis-state index, qubit 0 is the
leftmost bit, the same order eigenkit uses locally. A `sample` result on two qubits:

```json
{"kind": "counts", "n_qubits": 2, "data": {"00": 489, "01": 14, "10": 11, "11": 486}}
```

`bit_order` describes bitstring results: a `fock_counts` result has no bitstrings, and its keys list the modes from mode 0.

## What the router ran

`execution` says what the router ran on the vendor. eigenkit returns it from
`handle.execution()`, from the same request as `handle.result()`.

- `vendor_job_id` is the IBM job ID, the Amazon Braket task ID or the Quandela Cloud job ID.
- For an IBM job: the physical qubits (`initial_layout`, `final_layout`, `active_qubits`), the
  transpiled circuit as OpenQASM 3 (`transpiled_qasm3`), `seed_transpiler`, `optimization_level`
  and the Qiskit versions.
- For a Braket job: on IQM and AQT devices also the compiled OpenQASM 3 program
  (`transpiled_qasm3`), on Rigetti devices the compiled Quil program (`compiled_quil`), and on all
  three the qubits the program touches (`active_qubits`) and the physical qubit each classical bit
  was measured on (`final_layout`).
- For a photonic job every other field is null.

Every field except `vendor_job_id` may be null. `execution` itself is null for results stored
before the router recorded it.

## Photonic jobs

A job on a Quandela Cloud device uses the method `photonic_sample`. These devices are in limited
preview (see [Devices and prices](/docs/devices#photonic-devices)). With eigenkit, a photonic circuit
runs through the router with `RouterPhotonicBackend` from `eigenorbit-router-client` 0.4.0 or
later.

- `circuit_spec` carries a linear-optical circuit as eigenkit encodes it, and `observables` is `[]`.
  An angle expression in the circuit may nest at most 32 levels and may not exceed 1e15 in
  magnitude; otherwise the job answers `422 circuit_invalid`.
- `inputs` may be 2-D: one row per run, all in one router job and one vendor job. `weights` stays
  1-D. Each device takes a limited number of rows (500 on `quandela/sim_slos`, 16 on the others);
  more answer `422 batch_not_supported` with `details = {max_rows}`.
- `shots` is, for each run, both the number of samples asked for and the shot limit. A device that
  loses photons returns fewer samples than shots.
- The router charges nothing for the job: `billing` stays null, `estimate_usd_micro` is 0 and the
  cost fields stay null.
- A job that Quandela stops at its own time limit reads `failed`, not `cancelled`.

The result has the kind `fock_counts`:

```json
{"kind": "fock_counts", "n_modes": 4, "data": [{"1,0,1,0": 261, "0,1,0,1": 276}, {"1,0,1,0": 498}]}
```

`data` has one object per input row, in request order; a job with 1-D `inputs` has one. A key is
the photon count of every mode, mode 0 first, joined by commas. A value is the number of samples
that showed that state. A row can be `{}`: no shot passed the photon filter. eigenkit
normalizes the counts of each row to a distribution.

## Cancel a job

With `handle` from the submit script:

<CodeTabs syncKey="client">

```python title="eigenkit"
handle.cancel()
```

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

</CodeTabs>

A cancel answers `202` with the job as it is right after the request. `202` means the cancel was
requested, not that the job is or will be cancelled:

- A job that has not reached the vendor is cancelled at once. The answer already says
  `cancelled`, and the whole hold is returned. No vendor task is created.
- A job at the vendor keeps its status in the answer. The router asks the vendor to cancel the
  task, and the job ends as the vendor reports. If the vendor cancels it, the job ends `cancelled`
  and is charged what the vendor billed for it, often nothing. If the vendor finishes the task
  first, or does not stop a task that already runs, the job ends `completed` with its result and is
  charged like any completed job. The Amazon Braket simulators run a started task to the end.
- A job whose hold or vendor submission is still in progress is cancelled as soon as the router
  knows whether a vendor task exists, then handled as one of the two cases above.

There is no cancel fee. A second cancel answers `202` again. A `completed`, `failed` or `rejected`
job answers `409 job_not_cancellable` with `details = {status}`. Keep polling after a cancel: only
the terminal status says how the job ended.

## Retention

A job's result and the request it was submitted with are deleted a retention period after the job
reached a terminal status, together with the vendor output the router stored for it.
`result_expires_at` on the job says when: today that is `completed_at` plus 90 days. It is null
while the job is in flight and stays set after the deletion.

- The job itself stays: its status, timestamps, error and every cost field.
- After the deletion, the result answers `410 result_expired` with `details = {expired_at}`, the
  time of the deletion. Do not retry it. `404 job_not_found` and `409 job_not_completed` come first.
- The router deletes due results every hour, so `expired_at` can be up to about an hour after
  `result_expires_at`.
- The router's database backups keep deleted data for 14 days after each backup is taken. They are
  used only to restore the service, never to answer a request.

Download a result you need to keep before `result_expires_at`.

## Reference

- [Submit a job](/docs/api/jobs#submit-a-job)
- [Get a job](/docs/api/jobs#get-a-job)
- [Get a job result](/docs/api/jobs#get-a-job-result)
- [Cancel a job](/docs/api/jobs#cancel-a-job)
