Skip to content
AIRO

Optimizations

Create an optimization from JSON, follow it to completion, then read routes or download driver-ready files.

MethodPathPurpose
POST/v1/optimizations/quotePrice for each option (standard, traffic), from the same body. Nothing is created
POST/v1/optimizationsCreate (202). Idempotency-Key required
GET/v1/optimizationsList, newest first (page, page_size)
GET/v1/optimizations/{id}Status and progress
GET/v1/optimizations/{id}/resultRoutes, KPIs, unassigned (include_path=true for polylines)
POST/v1/optimizations/{id}/cancelCancel a queued or running optimization
POST/v1/optimizations/{id}/exportsExcel or CSV export with a signed link

Create: request body

FieldTypeNotes
depotobjectRequired. address, or latitude and longitude. Optional label.
ordersarrayRequired, 1 to 500. Unique id per order.
vehiclesarrayIndividual vehicles: id, capacity, optional driver, shift_start, shift_end, fixed_cost, max_weight, max_volume, skills, break_minutes, break_start, break_end. Use this or fleet.
fleetobjectN identical vehicles: count (1-100), capacity, shift_start, shift_end, fixed_cost, and the same optional fields as vehicles. Use this or vehicles.
namestringOptional label shown in the portal.
options.strategystringoptimized (default) or baseline: your file order, for comparison.
options.objectivestringdistance (default) or duration.
options.solver_secondsinteger1 to 60. More time can improve large problems.
options.balancestringoff (default), duration, stops or load: spread working time (driving + stops), stop count or load evenly across all vehicles. Usually adds some distance.
options.balance_strengthstringlow, medium (default) or high: how much extra distance balancing may cost.
options.vehicle_usagestringauto (default): as many vehicles as is cheapest; all: every vehicle gets at least one stop; fewest: as few vehicles as possible. fewest cannot be combined with balance.
options.traffic, options.plan_dateboolean, YYYY-MM-DDtraffic: true uses typical traffic for the earliest shift start on plan_date (default: the next working start, today or tomorrow). Requires Google routing; otherwise a warning says free-flow times were used.
options.open_routesbooleantrue: every route ends at its last stop, except vehicles with an end_address.
options.max_route_minutes, options.max_route_km, options.max_stops_per_routenumberStrict limits per route, depot to depot. An order that cannot fit is returned as unassigned with the reason.

Order fields

FieldNotes
idYour reference, returned in results. Required.
address, city, region, postal_code, countryGive an address, or coordinates. Postal code improves geocoding.
latitude, longitudeSkip geocoding when you already have coordinates.
demandLoad units, same unit as vehicle capacity. Default 1.
service_minutesTime spent at the stop. Default 5.
time_window_start, time_window_endHH:MM, 24-hour. Arrival must fall inside the window.
customer, phone, notesShown on driver exports. Not required.
weight, volumeOptional. Limited only when a vehicle has max_weight or max_volume (same unit).
required_skillsOptional list, e.g. ["liftgate", "fridge"]. Only vehicles with every skill can serve the order (case-insensitive).
priorityhigh, normal (default) or low. When not everything fits, low-priority orders are left out first and high-priority orders last.
vehicle_idOptional. Lock the order to that vehicle (its id); the engine still chooses the stop order. Unknown ids are rejected.
pickupOptional object: address (or latitude and longitude), time_window_start, time_window_end, service_minutes. Makes the order a shipment: the same vehicle collects it there first, then delivers it to the order's address. Without it, the order is loaded where the vehicle starts.

Vehicle fields

FieldNotes
id, capacityRequired. Capacity is in the same load unit as order demand.
driverShown on exports. Not required.
shift_start, shift_endHH:MM, 24-hour. Default 08:00 to 18:00.
fixed_costDaily cost of using the vehicle. Makes the engine prefer fewer vehicles.
max_weight, max_volumeOptional limits. Leave out for no limit.
skillsOptional list, e.g. ["fridge"]. Matched against order required_skills.
start_address, end_addressOptional. Where this vehicle leaves from and ends (default: the depot, and back to where it started). Vehicles with different start addresses make a multi-depot plan: the engine decides which base serves which stop.
open_routetrue: the route ends at its last stop (no return leg).
break_minutes, break_start, break_endOne break of break_minutes, started and finished between break_start and break_end (default: the shift). Never placed during a stop; routes that end before the window need no break.

Times are local to the depot and expressed as HH:MM. Unknown fields are rejected, so typos are caught instead of ignored.

Status values

  • unpaid: priced and waiting for its payment. Open links.payment (a Stripe page, valid 2 hours); it moves to queued as soon as the payment is confirmed. price.amount_cents is what it costs.
  • queued, running: still working. progress is 0 to 100 and stage names the step (geocoding, matrix, optimizing, storing).
  • completed: the result is ready.
  • failed: see error_code and error_message. Fix the cause and create a new optimization.
  • cancelled: you cancelled it, or its payment page expired (error_code payment_expired).

Result

GET /v1/optimizations/{id}/result (abridged)
{
  "id": "0d1f0c3e-…",
  "status": "completed",
  "strategy": "optimized",
  "kpis": {
    "orders_total": 3, "orders_assigned": 3, "orders_unassigned": 0,
    "vehicles_available": 2, "vehicles_used": 1,
    "distance_m": 14320, "drive_seconds": 1860, "route_seconds": 3540,
    "late_stops": 0, "avg_utilization": 0.65,
    "balance": { "work_seconds_max": 3540, "work_seconds_min": 0, "work_seconds_spread": 3540,
                 "stops_max": 3, "stops_min": 0, "stops_spread": 3 },
    "per_vehicle": [{ "vehicle_ref": "van-1", "stops": 3, "distance_m": 14320, "work_seconds": 3540, "load": 39, "capacity": 60 }]
  },
  "routes": [{
    "vehicle_ref": "van-1", "driver_name": "Sam",
    "depart_s": 28800, "return_s": 32340, "distance_m": 14320, "load": 39, "capacity": 60,
    "stops": [{
      "seq": 1, "order_ref": "SO-1001", "address": "255 Bremner Blvd, Toronto, ON",
      "latitude": 43.6416, "longitude": -79.3874,
      "arrival_s": 29400, "start_s": 32400, "depart_s": 33000, "wait_s": 3000, "late_s": 0,
      "leg_distance_m": 2100, "leg_travel_s": 600
    }]
  }],
  "unassigned": [],
  "warnings": []
}
  • All *_s fields are seconds since midnight (28800 = 08:00). Distances are metres.
  • stops are in driving order (seq). arrival_s is when the vehicle arrives; start_s is when service begins after any wait.
  • unassigned lists orders that could not be planned, each with a reason (for example geocode_failed, too_large, too_heavy, too_bulky, missing_skill, low_priority, pickup_geocode_failed, locked_vehicle_unfit, window_unreachable, beyond_route_limit, no_fit_limits) and a message you can show.
  • Each route has start and end points ({latitude, longitude, label}; end is null for an open route). Each stop has kind: pickup or delivery; a shipment appears twice on the same route, pickup first.
  • Each route has break_start_s and break_seconds when the driver's break falls during the route, and break_before_seq: the stop it comes before (one more than the last stop means on the way back).
  • kpis.balance compares the busiest and the lightest vehicle (idle vehicles count as zero): working time is driving plus time at stops, waiting excluded.

Re-plan the rest of the day

POST /v1/optimizations/{id}/replan with an Idempotency-Key creates a new optimization from a completed one. Stops planned before at (HH:MM) or listed in done_order_ids drop out; each vehicle starts where it is, at that time; deliveries already on board stay with their vehicle. Vehicles in unavailable_vehicle_ids leave the plan and what they carry becomes a pickup at their last position. New orders (same format as above) are loaded at the depot, so a vehicle on the road comes back for them; shipments with a pickup are collected where they are. It assumes vehicles kept to the plan: send done_order_ids (ahead) and pending_order_ids (running late) to correct it. A stop in progress is finished first. working_vehicle_ids limits the re-plan to some vehicles (in a plan where each vehicle is a day, today's). For service visits (work_type service, set on the optimization's options or in this request) nothing is carried: the visits of unavailable vehicles and new visits are spread over the others, the rest stay with their vehicle unless keep_assignments is false, and visits that no longer fit come back unassigned with reason carried_over.

POST /v1/optimizations/{id}/replan
{
  "at": "13:30",
  "done_order_ids": ["SO-1004"],
  "unavailable_vehicle_ids": ["van-2"],
  "orders": [{ "id": "SO-2001", "address": "88 Queen St E, Toronto, ON", "priority": "high" }]
}

Exports for drivers

curl -X POST https://ai-route-optimization.com/v1/optimizations/$ID/exports \
  -H "Authorization: Bearer $AIRO_API_KEY" -H "Content-Type: application/json" \
  -d '{"format": "xlsx", "include_driver_instructions": true}'

The response contains download_url and expires_at. Links are signed and short-lived: request a new export (same arguments return the same file) when one expires.

Idempotency

  • Send a unique Idempotency-Key (8 to 128 characters) per business operation, for example your dispatch run id.
  • Retrying with the same key and payload returns the same optimization. It does not run or bill again.
  • The same key with a different payload is rejected: use a new key for a new plan.