Async & validate

Submit a job, track it to completion, and pull the result back, plus the dry-run and the safety rails (idempotency, cancel).

When to use this

  • You're integrating the core submit→poll→fetch loop and want to handle every lifecycle state correctly.
  • You want to validate a request and catch bad input before it costs you a job.
  • You need safe retries (Idempotency-Key) or a clean way to cancel a job that's in flight.

The job lifecycle

Solving is asynchronous. Every job moves through:

queued → running → succeeded | failed | cancelled

The last three are terminal: once a job reaches one it never changes again.

Job lifecycle state machine

the job state machine: queued/running are transient; succeeded/failed/cancelled are terminal.

Walkthrough

Which call to make, and what its response leaves you holding:

Flowchart of the calls a client makes: optionally POST /v2/jobs/validate first, which creates no job and answers 400 validation_failed when the body is invalid, so you fix it and validate again; then POST /v2/jobs, then a loop polling GET /v2/jobs/{id} while the status is queued or running, with failed and cancelled as dead ends and succeeded continuing to GET /v2/jobs/{id}/result; from there two optional branches, POST /v2/jobs/{id}/share which returns a link right away, and POST /v2/jobs/{id}/instructions which starts a second job with its own id that you poll the same way before downloading one PDF per carrier

the branch worth reading twice is the lower one. POST /v2/jobs/{id}/instructions answers with a job, not a document, so it needs a poll loop of its own on the new id before any PDF exists. Steps 1 to 3 below are the single path down the middle; the optional validate call above it is Validate first.

1. Submit the job

POST /v2/jobs returns 202 Accepted with a jobId and status: queued. A Location header points at the new job.

curl -i -X POST https://api.loadoptimizer.ai/v2/jobs \
  -H "X-Api-Key: ck_live_..." \
  -H "Content-Type: application/json" \
  -d @job.json
{ "jobId": "01975cba-67b9-7b7c-a2f1-3d29e4a01c44", "status": "queued" }

2. Poll for status

GET /v2/jobs/{id} returns a JobStatus. While the job runs you get percentage: a packing job reports only 0, 50 or 100, an instructions job reports finer progress. errorCategory and error are set only once the job has failed; see Reading a failed job below.

curl https://api.loadoptimizer.ai/v2/jobs/01975cba-67b9-7b7c-a2f1-3d29e4a01c44 \
  -H "X-Api-Key: ck_live_..."
{
  "jobId": "01975cba-67b9-7b7c-a2f1-3d29e4a01c44",
  "status": "running",
  "percentage": 50,
  "queuePosition": null,
  "errorCategory": null,
  "error": null,
  "name": null,
  "createdAt": "2026-08-19T08:12:33.412+00:00",
  "createdBy": { "type": "apiKey", "id": "0192f3a4-7e8f-7a9b-8c0d-1e2f3a4b5c6d", "via": null },
  "expiresAt": "2026-11-17T08:12:33.412+00:00",
  "problemType": "LoadPlanning",
  "saved": false
}

Poll every few seconds until status is terminal (no need to poll faster). Don't assume the job is still queued right after submitting: once the job leaves the queue and starts calculating, the status moves straight to running.

3. Fetch the result

Once status is succeeded, GET /v2/jobs/{id}/result returns the packing result. This is a different endpoint from the status one in step 2: keep your wait loop on the status endpoint (GET /v2/jobs/{id}), and call GET /v2/jobs/{id}/result once, after it reports succeeded.

Don't loop on the result endpoint itself waiting for it to "turn ready." While the job is still queued or running there is no result yet, so it returns 404 (code result_not_ready), and a 404 here is ambiguous (it also means an unknown or foreign job id), so it's not a reliable "not done yet" signal. The status endpoint is the one built to tell you when to fetch.

curl https://api.loadoptimizer.ai/v2/jobs/01975cba-67b9-7b7c-a2f1-3d29e4a01c44/result \
  -H "X-Api-Key: ck_live_..."

Reading back the request

GET /v2/jobs/{id}/input returns the request of an order with every library reference resolved to the values the solver used: the JobRequest shape under request, with any name trimmed and members the API does not know left out. Every line comes back inline. A carrier or cargo line that referenced a library entry carries the entry's definition as frozen into the job when you submitted it: the sizes and weights the solver used, overrides included, in the job's units, and on a cargo line the effective constraints. Stacking rules come back inline under constraints.stackingRules, as applied: a saved rule set resolved, its overrides applied, and only the rules about classes in the job kept; stackingRuleSet names the set (ruleSetId and name), its revision and the overrides the job sent, as sent (null for inline rules or none). A cargo line that referenced a SKU carries the SKU's classes. Rules you sent of which none applied read back as two empty lists (directOn and towerLimits), which differs from a job sent without constraints, where constraints is absent. The request is written inline, so sending a read-back request again whose lines carry classes (a SKU's class too, which the read-back writes on the line) needs the cargo_classes.read permission. A class on a line need not still be saved: a deleted one is used as a key for that job only, and a rule or override about a class that no line carries must still be a class you have saved. Lines that referenced the same SKU come back as separate inline lines, and an inline line is a SKU of its own, so sending the read-back request again no longer keeps their boxes together under sameSkuStacking; sources shows which lines came from one entry. A carrier with no label on the line or the entry comes back with the entry's id as its externalId, because an inline carrier needs one; /result shows null for it. sources lists each entry with the revision used and the lines of request it resolved, as JSON Pointers such as /cargo/0. Enum values come back in their published spelling (see Conventions), and a direction on CenterLoadMass is left out. A cargo line whose stored category the closed set does not know (a job from before that set was closed) reads back as box. Use it for what the result does not repeat, such as the size and rules of a cargo line that was not placed, or the carriers you asked for. A later rename changes the job's name, not this request, and a later change to a library entry changes neither this request nor its sources. resolvedAt is the order's createdAt. Orders only, in any status.

Validate first (dry-run)

POST /v2/jobs/validate takes the identical body as POST /v2/jobs, runs the same validation, but creates no job and triggers no solve:

curl -X POST https://api.loadoptimizer.ai/v2/jobs/validate \
  -H "X-Api-Key: ck_live_..." \
  -H "Content-Type: application/json" \
  -d @job.json

On success you get a ValidateResult:

{
  "valid": true,
  "warnings": [
    {
      "code": "stacking_disabled",
      "pointer": "/cargo",
      "message": "No cargo line allows anything on top of it, so nothing will be stacked."
    }
  ]
}

warnings lists non-blocking findings (see Validate-only warnings); they never stop a submit. Validating does not run the problem-type, plan-limit or quota checks that a real submit does, so it spends no quota. A body that validates fine can still be turned down by POST /v2/jobs with a 403 (the problem type is not on your plan), a 422 (plan limits) or a 429 (active jobs or monthly quota). It does apply the one access check a submit applies to company-library references: a carrier or a cargo line whose libraryId is a UUID gets 403 libraries_not_entitled here too when that library type is not available on the plan. A type is available when the plan includes company libraries and its own size limit is not 0; see Plans and limits. A malformed body returns the same 400 problem+json shape you'd get from POST /v2/jobs. See Errors & troubleshooting.

One warning is about what validate had to ignore: unknown_member means that a member the contract does not define was found in constraints, in constraints.stackingRules, or in an item of its directOn, towerLimits or overrides, and the API ignores it. It covers only those places: an unknown member elsewhere in the body (at the root, in carriers[] or cargo[]) is ignored without a warning, and so is a rule about a class the job does not carry. These warnings come after the others, outside in: constraints, then stackingRules, then the items of directOn, towerLimits and overrides, each in list order. It is almost always a typo, such as directsOn for directOn, which would otherwise run the job without those rules. pointer is the member, as an RFC 6901 JSON Pointer: a path in the contract's spelling, then the member as you sent it, with ~ written ~0 and / written ~1:

{
  "valid": true,
  "warnings": [
    {
      "code": "unknown_member",
      "pointer": "/constraints/stackingRules/directsOn",
      "message": "'directsOn' is not a member of stackingRules and was ignored."
    }
  ]
}

Only validate warns. POST /v2/jobs accepts the same body, ignores the member and answers as usual. The other codes are in Validate-only warnings.

Safe retries with Idempotency-Key

Send an Idempotency-Key header on POST /v2/jobs so a network retry doesn't create a duplicate job:

curl -X POST https://api.loadoptimizer.ai/v2/jobs \
  -H "X-Api-Key: ck_live_..." \
  -H "Idempotency-Key: order-4821-submit" \
  -H "Content-Type: application/json" \
  -d @job.json
  • Same key + same body → returns the original job (no new job created), for at least 24 hours after it was submitted, and for as long as it is queued or running (see Retention). Bodies are compared canonically: key order and whitespace in the JSON you sent are ignored. Values are compared as sent: a body that differs only in the case of an enum value (Pallet against pallet) is a different body and, in that window, gets the 409.
  • Same key + a different body → 409 with an empty body, in that same window. Reusing a key for genuinely different work is rejected, never silently re-run; once the window has passed, the same key can start a new job.
  • Scope is per-account, so keys you choose only collide with your own account's requests.

The whole request body is the fingerprint, units included. Retrying the same key with the order re-expressed in different units (say mm the first time and m on the retry) is a different body, and within the window above gets the 409, not a replay of the original job. There is no unit block exempted from the comparison. If you rely on idempotency, keep the whole body (units included) identical across retries of the same key.

Cancelling a job

POST /v2/jobs/{id}/cancel requests a cooperative cancel:

curl -X POST https://api.loadoptimizer.ai/v2/jobs/01975cba-67b9-7b7c-a2f1-3d29e4a01c44/cancel \
  -H "X-Api-Key: ck_live_..."
  • 202: accepted; a queued job is finalized to cancelled immediately, a running job gets a cooperative cancel flag and winds down at its next checkpoint.
  • 409 (code job_already_terminal): the job already reached a terminal state; there's nothing to cancel.
  • 404 (code job_not_found): unknown job id, a job that belongs to another account, or a job deleted after its expiresAt.

Cancel is a request, not an instant kill: a 202 on a running job doesn't mean it has stopped yet. Keep polling status until it actually reaches cancelled.

Reading a failed job

A failed job is still a 200 from GET /v2/jobs/{id}: the failure lives in the body, not the HTTP status. When status is failed, the JobStatus carries errorCategory (a category string; diagnostic only, not a closed set) and an error object with a stable code and a safe, human-readable message that never contains exception detail.

{
  "jobId": "01975cbd-3a52-7e8f-8c14-6d0b9f3e7a52",
  "status": "failed",
  "percentage": 50,
  "queuePosition": null,
  "errorCategory": "solver_error",
  "error": { "code": "solver_error", "message": "The solve did not complete. Please retry." },
  "name": null,
  "createdAt": "2026-08-18T15:47:02.861+00:00",
  "createdBy": { "type": "apiKey", "id": "0192f3a4-7e8f-7a9b-8c0d-1e2f3a4b5c6d", "via": null },
  "expiresAt": "2026-11-16T15:47:02.861+00:00",
  "problemType": "LoadPlanning",
  "saved": false
}

error.code is a closed set, so switch on it, not on errorCategory:

error.code Meaning
invalid_input The job couldn't be solved as submitted; have the user adjust the input.
solver_error The solve didn't complete; retry.
render_error Document rendering failed; retry.
internal_error Everything else: retry, or contact support.

Cargo that couldn't be placed in a succeeded job is not a failure: it comes back in unplacedItems on the result, each entry with a reason. See Errors & troubleshooting and Why cargo was left unplaced.

Listing your jobs

GET /v2/jobs lists the orders your account submitted, newest first, up to 50 per page. Each item is exactly the JobStatus that GET /v2/jobs/{id} returns. A loading-instructions job is not listed: reach it through the id POST /v2/jobs/{id}/instructions returned.

curl "https://api.loadoptimizer.ai/v2/jobs?status=succeeded&q=rotterdam&limit=20" \
  -H "X-Api-Key: ck_live_..."
{
  "items": [
    {
      "jobId": "01975cbc-1f40-7d21-9b3e-5a7c2e8f0d19",
      "status": "succeeded",
      "percentage": 100,
      "queuePosition": null,
      "errorCategory": null,
      "error": null,
      "name": "Rotterdam week 40",
      "createdAt": "2026-09-28T08:12:33.412+00:00",
      "createdBy": { "type": "user", "id": "0192f3a4-5b6c-7d8e-9f01-23456789abcd", "via": null },
      "expiresAt": null,
      "problemType": "LoadPlanning",
      "saved": true
    }
  ],
  "nextCursor": "djE6WyJjcmVhdGVkQXQiLCJkZXNjIixudWxsLCIyMDI2LTA5LTI4VDA4OjEyOjMzLjQxMiswMDowMCIsIjAxOTc1Y2JjLTFmNDAtN2QyMS05YjNlLTVhN2MyZThmMGQxOSJd"
}

When nextCursor is a string, pass it back unchanged as cursor for the next page, with the same filters, sort and direction; when it is null, this is the last page. The cursor is opaque: don't build or parse it. There is no total count.

  • Filters. status and problemType take several values by repeating the parameter (?status=succeeded&status=cancelled), and different filters combine. q matches names containing the text, ignoring case; % and _ are ordinary characters. createdFrom is inclusive and createdTo exclusive, both RFC 3339 with an offset; in a URL, send a + offset as %2B. saved=true or saved=false keeps only the orders that are, or are not, kept as a saved load; it takes one value and answers 400 for anything else.
  • Who created it. createdBy takes the id of a user or of an API key, the one createdBy shows on an order. Repeat it to add another user or a key, and an order matches any of them: GET /v2/jobs?createdBy=0192f3a4-5b6c-7d8e-9f01-23456789abcd&createdBy=0192f3a4-7e8f-7a9b-8c0d-1e2f3a4b5c6d lists the orders of that user and of that key. A user's orders include those they created through an AI agent. An id that created nothing keeps nothing; at most 50 ids, and a malformed id is a 400 on createdBy. It combines with the other filters like they do with each other.
  • Sorting. sort=createdAt (the default, newest first), name or problemType (A to Z by default), with direction=asc or desc. Within equal names or problem types the newest order comes first, and orders created at the same moment follow their id, in the direction you ask for under sort=createdAt. Orders without a name come last. An order renamed while you page through a name-sorted list can move, so it may appear twice or not at all.
  • Errors. Every invalid parameter is reported at once, in one 400 with code: "validation_failed" and one errors[] entry per parameter; its pointer is the parameter's name. A parameter the API does not know is ignored, so check the spelling of a filter that seems to have no effect.

Saving a load

A run you want to keep can be saved under a name and found again later; see Saved loads.

Key fields

Field Where Notes
status JobStatus queued/running/succeeded/failed/cancelled.
percentage JobStatus Progress: a packing job reports only 0, 50 or 100; an instructions job reports finer progress.
queuePosition JobStatus Always null.
errorCategory JobStatus Set only when status=failed; null otherwise. Raw and diagnostic-only; switch on error.code, not this.
error.code / error.message JobStatus Failure detail: a closed-set code (invalid_input, solver_error, render_error, internal_error) plus a safe message.
name JobStatus The caller's optional label, set at submit or with PUT /jobs/{id}/name; null when the job has none. See Naming a job.
createdAt JobStatus When the job was submitted (UTC), always present.
createdBy JobStatus Who submitted the job, as an actor: a user (with via: agent through an AI agent) or an API key; for a loading-instructions job, who asked for it. Always present. See Users, API keys and who did what.
expiresAt JobStatus When the job is deleted, with its input, result, edited result, loading instructions and share link: 90 days after createdAt (for a job that is already older, not before 16 November 2026), or later after a saved load of it is released. Always present; null while the order is kept as a saved load. A loading-instructions job shows its order's value. After it, the job answers 404 job_not_found. See Retention.
saved JobStatus Whether the order is kept as a saved load; always present, and always false for a loading-instructions job. See Saved loads.
Idempotency-Key header Canonical-body compare (the whole body, units included), per-account; conflict → empty 409.
valid / warnings ValidateResult Dry-run output from POST /v2/jobs/validate. warnings: non-blocking findings, validate only; an empty list does not mean nothing was ignored.

Notes & caveats

  • Poll status, not the result. GET /v2/jobs/{id}/result is 404 (result_not_ready) until the job succeeds; that 404 is expected while the job is queued or running.
  • Validate doesn't reserve anything. A body that validates fine can still be refused by POST /v2/jobs; see Validate first for the checks validate skips.
  • Idempotency compares the whole body you sent (including units) and replays the original job even if the original failed, for at least 24 hours after it was submitted, and for as long as it is queued or running. Change any part of the body, units included, and in that window the same key gets a 409 instead of a replay.
  • Cancelling a running job is cooperative. A 202 means the request was accepted, not that the job has stopped; poll status to confirm it reached cancelled.