Core concepts
Cancel a job
Stop a job and what you are charged.
POST /v1/jobs/{id}/cancel asks to stop a job. Whether you are charged depends on how far the job got.
Refund rules
| When you cancel | Charge |
|---|---|
| The job is still waiting in your account's queue | Free. It is canceled at once and the full amount is returned. |
| The job was sent, but the provider hasn't confirmed it yet | Refunded in full, unless the job completes first. |
| The provider has accepted the job | Charged in full, even if no output arrives, unless the job fails. |
| The job already succeeded or failed | 409 job_not_cancelable. Nothing changes. |
The cancel response includes a message that says which case applied, for example "Job canceled before it started. The full amount was refunded." Show it to users if you like, but don't parse it.
Waiting for the outcome
A cancel answers 202. A job still in your account queue comes back already canceled. A job that was sent comes back as cancel_requested: keep polling until it reaches a final status. It may still finish as succeeded if the provider completes it first.
import { Astorie } from "@astorie/client";
const client = new Astorie();
const job = await client.cancel("job_3k7qz2m5x4rbd6wn2yhv7tcl4a");
console.log(job.status, job.message);
const final = await client.wait(job.id);
console.log(final.status);Canceling twice is safe. A job that is already canceled answers 200.