# Job statuses

Price a job, follow its status, and read the results when it ends.

## Check the price first

A submit returns the job's expected cost, but by then the job is already running. To see the price first, send the same job type, inputs, and params to `POST /v1/jobs/estimate`. For a single job, the estimate is available over HTTP only.

A job that finishes is charged the price it was quoted at submit. A job that fails or is cancelled costs nothing, and Phi returns the credits it was holding. Deleting a job that is still waiting or running returns them too, but deleting a job that has already finished does not.

[Estimate a job](https://dynophi.com/docs/api/jobs)

[How credits work](https://dynophi.com/docs/billing)

## Statuses

A submit returns right away with the job ID, its first status, and its expected cost. The job then runs in the background, so keep the ID to check on it.

| Status | What it means | Final |
| --- | --- | --- |
| `PENDING` | Accepted and waiting to start. | No |
| `RUNNING` | In progress. | No |
| `COMPLETED` | Finished. The results are ready. | Yes |
| `FAILED` | Stopped before it finished. Submitting again with the same idempotency key starts a new job. | Yes |
| `CANCELLED` | Cancelled before it finished. | Yes |
| `ERROR` | Stopped before it finished. Its idempotency key stays in use, so submit again without it. | Yes |

## When a job ends

`CANCELLED`, `COMPLETED`, `ERROR`, and `FAILED` are final. A job does not change after it reaches one. A job that stops early carries an `error_code` that says why.

[Errors and retries](https://dynophi.com/docs/reference/errors)

## Wait for a job

Let the client wait instead of polling in your own loop. It checks every 5 seconds, keeps going through brief rate limits and server errors, and returns the job when it reaches a final status.

The client returns a failed or cancelled job instead of raising an error, so check the status before you read results.

```bash
phi jobs submit ESMFOLD --input sequences=@peptide.fasta --wait --out out/
```

```python
job = phi.jobs.submit("ESMFOLD", inputs={"sequences": [sequence]})
print(phi.jobs.wait(job.job_id).status)
```

## Read the results

A finished job writes files, such as structures and score tables. Download them with `phi artifacts download`, or export the scores as one table with `phi export`. To download many runs at once, give `phi artifacts download` several run ids, `--ids-file`, or `--project`. Each run is written to its own folder under the output directory, and `summary.json` there records how each run went.

[Download artifacts](https://dynophi.com/docs/cli/artifacts)

[Export scores](https://dynophi.com/docs/cli/export)

---
Source: https://dynophi.com/docs/reference/jobs
