POST /v1/optimize
Route Optimization API for multi-stop days
Request and response
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"}'const res = await fetch("https://api.wayline.cloud/v1/optimize", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WAYLINE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"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"
}),
});
if (!res.ok) throw new Error(`Wayline ${res.status}: ${await res.text()}`);
console.log(await res.json());import os, requests
res = requests.post(
"https://api.wayline.cloud/v1/optimize",
json={
"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"
},
headers={"Authorization": f"Bearer {os.environ['WAYLINE_API_KEY']}"},
timeout=10,
)
res.raise_for_status()
print(res.json())package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := `{"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"}`
req, _ := http.NewRequest("POST", "https://api.wayline.cloud/v1/optimize", strings.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("WAYLINE_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(res.Status, string(out))
}<?php
$ch = curl_init("https://api.wayline.cloud/v1/optimize");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("WAYLINE_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => '{"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"}',
CURLOPT_TIMEOUT => 10,
]);
print_r(json_decode(curl_exec($ch), true));require "net/http"
require "json"
uri = URI("https://api.wayline.cloud/v1/optimize")
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
req["Authorization"] = "Bearer #{ENV.fetch("WAYLINE_API_KEY")}"
req.body = {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"}.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(req) }
puts JSON.parse(res.body)import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
String body = """
{
"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"
}
""";
var req = HttpRequest.newBuilder(URI.create("https://api.wayline.cloud/v1/optimize"))
.header("Authorization", "Bearer " + System.getenv("WAYLINE_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body)).build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(res.statusCode() + " " + res.body());
}
}import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<void> main() async {
final res = await http.post(
Uri.parse('https://api.wayline.cloud/v1/optimize'),
headers: {
'Authorization': 'Bearer ${Platform.environment['WAYLINE_API_KEY']}',
'Content-Type': 'application/json',
},
body: jsonEncode({
"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"
}),
);
print(jsonDecode(res.body));
}{
"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.