Optimizations
Create an optimization from JSON, follow it to completion, then read routes or download driver-ready files.
| Method | Path | Purpose |
|---|---|---|
| POST | /v1/optimizations/quote | Price for each option (standard, traffic), from the same body. Nothing is created |
| POST | /v1/optimizations | Create (202). Idempotency-Key required |
| GET | /v1/optimizations | List, newest first (page, page_size) |
| GET | /v1/optimizations/{id} | Status and progress |
| GET | /v1/optimizations/{id}/result | Routes, KPIs, unassigned (include_path=true for polylines) |
| POST | /v1/optimizations/{id}/cancel | Cancel a queued or running optimization |
| POST | /v1/optimizations/{id}/exports | Excel or CSV export with a signed link |
Create: request body
| Field | Type | Notes |
|---|---|---|
| depot | object | Required. address, or latitude and longitude. Optional label. |
| orders | array | Required, 1 to 500. Unique id per order. |
| vehicles | array | Individual 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. |
| fleet | object | N identical vehicles: count (1-100), capacity, shift_start, shift_end, fixed_cost, and the same optional fields as vehicles. Use this or vehicles. |
| name | string | Optional label shown in the portal. |
| options.strategy | string | optimized (default) or baseline: your file order, for comparison. |
| options.objective | string | distance (default) or duration. |
| options.solver_seconds | integer | 1 to 60. More time can improve large problems. |
| options.balance | string | off (default), duration, stops or load: spread working time (driving + stops), stop count or load evenly across all vehicles. Usually adds some distance. |
| options.balance_strength | string | low, medium (default) or high: how much extra distance balancing may cost. |
| options.vehicle_usage | string | auto (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_date | boolean, YYYY-MM-DD | traffic: 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_routes | boolean | true: 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_route | number | Strict limits per route, depot to depot. An order that cannot fit is returned as unassigned with the reason. |
Order fields
| Field | Notes |
|---|---|
| id | Your reference, returned in results. Required. |
| address, city, region, postal_code, country | Give an address, or coordinates. Postal code improves geocoding. |
| latitude, longitude | Skip geocoding when you already have coordinates. |
| demand | Load units, same unit as vehicle capacity. Default 1. |
| service_minutes | Time spent at the stop. Default 5. |
| time_window_start, time_window_end | HH:MM, 24-hour. Arrival must fall inside the window. |
| customer, phone, notes | Shown on driver exports. Not required. |
| weight, volume | Optional. Limited only when a vehicle has max_weight or max_volume (same unit). |
| required_skills | Optional list, e.g. ["liftgate", "fridge"]. Only vehicles with every skill can serve the order (case-insensitive). |
| priority | high, normal (default) or low. When not everything fits, low-priority orders are left out first and high-priority orders last. |
| vehicle_id | Optional. Lock the order to that vehicle (its id); the engine still chooses the stop order. Unknown ids are rejected. |
| pickup | Optional 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
| Field | Notes |
|---|---|
| id, capacity | Required. Capacity is in the same load unit as order demand. |
| driver | Shown on exports. Not required. |
| shift_start, shift_end | HH:MM, 24-hour. Default 08:00 to 18:00. |
| fixed_cost | Daily cost of using the vehicle. Makes the engine prefer fewer vehicles. |
| max_weight, max_volume | Optional limits. Leave out for no limit. |
| skills | Optional list, e.g. ["fridge"]. Matched against order required_skills. |
| start_address, end_address | Optional. 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_route | true: the route ends at its last stop (no return leg). |
| break_minutes, break_start, break_end | One 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
{
"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.
{
"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.