POST /v1/optimize

Route Optimization API for multi-stop days

Send a start point and a list of stops. Wayline returns the visiting order with the least total drive time, plus the road distance and time of every leg, so a rep, technician or rider knows exactly where to go next.

Request and response

Copy, paste and run with your test key. The response below is an illustrative example.
curl -X POST "https://api.wayline.cloud/v1/optimize" \
  -H "Authorization: Bearer $WAYLINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"stops":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852},{"lat":37.8716,"lng":-122.2727},{"lat":37.9358,"lng":-122.3478},{"lat":37.8044,"lng":-122.2712}],"end":"start","units":"imperial"}'
Response (example)
{
  "order": [
    0,
    2,
    3,
    1,
    4
  ],
  "legs": [
    {
      "from_index": 0,
      "to_index": 2,
      "distance_meters": 4210,
      "duration_seconds": 540,
      "distance_text": "2.6 mi",
      "duration_text": "9 mins"
    },
    {
      "from_index": 2,
      "to_index": 3,
      "distance_meters": 3010,
      "duration_seconds": 420,
      "distance_text": "1.9 mi",
      "duration_text": "7 mins"
    },
    {
      "from_index": 3,
      "to_index": 1,
      "distance_meters": 6120,
      "duration_seconds": 840,
      "distance_text": "3.8 mi",
      "duration_text": "14 mins"
    },
    {
      "from_index": 1,
      "to_index": 4,
      "distance_meters": 9870,
      "duration_seconds": 1140,
      "distance_text": "6.1 mi",
      "duration_text": "19 mins"
    },
    {
      "from_index": 4,
      "to_index": 0,
      "distance_meters": 19870,
      "duration_seconds": 1260,
      "distance_text": "12.3 mi",
      "duration_text": "21 mins"
    }
  ],
  "returns_to_start": true,
  "total_distance_meters": 43080,
  "total_duration_seconds": 4200,
  "region": "us",
  "map_version": "20261121-2330",
  "profile": "car",
  "units_charged": 5,
  "warnings": []
}

What the Route Optimization API gives you

  • Real road drive times

    The order is optimized on a full drive-time matrix from the road network, not straight-line distance, so one-way streets and river crossings are accounted for.

  • Flexible start and end

    Start at the depot or home (default) or anywhere; finish at the best stop, the last stop you give, or back at the start.

  • Car and motorcycle

    Use profile=motorcycle in regions that support it, such as Bangladesh, where riders take roads cars cannot.

  • Legs and totals included

    Get distance_text and duration_text per leg plus total distance and time, ready to show in your app without extra calls.

How route optimization works

Wayline builds a drive-time matrix between all stops in your region and solves the visiting order (a traveling salesman problem) for the lowest total time. Results include each stop's snapped road position and a warning when a stop is far from any mapped road.

When to use it

Daily plans for sales reps and merchandisers, technician rounds, courier batches and collection routes, typically 5 to 50 stops. For dispatch across many vehicles with time windows, use the Distance Matrix API as input to your own solver.

Frequently asked questions

How many stops can I optimize?

Up to 100 stops per request, all inside one coverage region.

How is route optimization billed?

One optimize unit per stop on a successful response. A 12-stop plan costs 12 units. Errors are never billed.

Does it support multiple vehicles or time windows?

Not yet. The endpoint orders one route. For fleets with time windows, compute a Distance Matrix and feed it to a solver such as VROOM or OR-Tools.

Does the drive time include traffic?

No. Drive times are free-flow estimates tuned per region. Add a buffer for peak hours when you promise arrival times.

Start building in minutes

Create an account, grab a test key and make your first request in under five minutes.