API / Optimized Route
POST /v1/routing/optimized

Optimized Route API.

Pass up to 25 waypoints and get back the optimal visit order - minimising total travel time across the real road network, not straight-line distance.

Solves the travelling salesman problem with real-world road constraints: one-way streets, turn restrictions, vehicle profiles, and time windows. Returns the reordered waypoint sequence, full route geometry, and leg-by-leg durations and distances - ready to pass to your fleet or driver app.

25

Max waypoints

<800ms

P95 latency

$1.00

Per 1k requests

API OPERATIONAL · View status
# Optimise a 5-stop delivery run
curl -X POST "https://api.farun.io/v1/routing/optimized" \
  -H "X-RapidAPI-Key: YOUR_KEY" \
  -H "X-RapidAPI-Host: farun-maps.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{
    "origin":[77.2090, 28.6139],
    "destination":[77.2090, 28.6139],
    "waypoints": [[77.1025, 28.7041],[77.2311, 28.5355],[77.0688, 28.6692],
      [77.3910, 28.5245],
      [77.1734, 28.6867]
    ],
    "profile": "driving",
    "return_geometry": true
  }'

Returns

Ordered waypoints + geometry

Profiles

driving · truck · bicycle

Max stops

25 waypoints

The problem it solves

Manual stop ordering wastes time and fuel.

With 10 stops there are 3.6 million possible orderings. A driver choosing manually or a system using straight-line distance will rarely find the shortest-time route. The Optimized Route API solves it against real road data in under a second.

Without optimisation

Manual Ordering on Straight-Line Distance

Drivers sequence stops by gut feel or nearest-neighbour on a map. One-way streets, turn restrictions, and traffic patterns mean the obvious order is rarely the fastest. Extra kilometres compound across every vehicle in a fleet, every day.

What the API does

Solves TSP on the Real Road Network

Farun's optimisation engine runs a constrained vehicle routing algorithm against the full road graph including one-way streets, turn restrictions, and vehicle-specific road access to find the minimum total-time visit order.

What you get back

Reordered Stops, Geometry, and Leg Timings

The response includes the optimised waypoint sequence, each leg's duration and distance, the full GeoJSON route geometry, and the total trip time. Pass it directly to a navigation device or driver app with no further processing.

Who uses it

Any workflow with multiple stops and a time constraint.

Route optimisation pays back immediately in reduced fuel cost, fewer driver hours, and higher delivery density. The API is priced per-request so it makes sense to optimise on every dispatch event not just for bulk planning runs.

Last-Mile Delivery

Daily Route Planning at Dispatch

Optimise each driver's stop sequence at the start of every shift. Pass the depot as origin and destination, the day's delivery addresses as waypoints, and the profile as 'driving' or 'truck'. The response sequences stops to minimise total drive time.

Field Service

Engineer and Technician Scheduling

Sequence site visits for maintenance crews, meter readers, and field engineers to minimise drive time between jobs. Combine with time_window constraints to respect appointment slots while still finding the best overall ordering.

Agriculture & Land

Multi-Site Farm Visit Ordering

Coordinate inspection runs, equipment deliveries, and harvest logistics across multiple landholdings. The truck profile respects weight and height restrictions on rural roads that car-profile routing would ignore.

Healthcare & Emergency

Multi-Patient Home Visit Runs

Sequence home visits for district nurses, care workers, and sample collection crews. Time-window constraints ensure patients with fixed appointment windows are visited in the right slot while the overall run is minimised.

Waste & Utilities

Collection Route Sequencing

Sequence refuse, recycling, and utility meter collection runs across dense urban areas. The truck profile handles road access rules for large vehicles. Combine with return_to_origin: true for circular depot runs.

SaaS & Platforms

Embedded Route Optimisation

Add a 'Optimise route' button to any logistics SaaS product. Send the user's stop list to this endpoint and render the reordered sequence and the full GeoJSON geometry back onto a Farun vector tile map in the same flow.

Response shape

Optimised sequence, legs, and full geometry.

The response gives you everything needed to hand off to a driver app or navigation device, the reordered stop list, the full route as a GeoJSON LineString, and per-leg breakdowns for ETA calculation and progress tracking.

  • waypoints_ordered The input waypoints resequenced into the optimal visit order
  • legs Array of leg objects - each with duration (s), distance (m), and GeoJSON geometry
  • total_duration Total trip time in seconds across all legs
  • total_distance Total distance in metres
  • geometry Full GeoJSON LineString for the complete optimised route
  • savings Time saved (seconds) vs the input waypoint order - useful for showing optimisation value in a UI
Example response - 5 stops optimised 200 OK
{
  "waypoints_ordered": [
    { "index": 0, "coordinates": [77.1025, 28.7041] },
    { "index": 3, "coordinates": [77.0688, 28.6692] },
    // ... reordered stops
  ],
  "total_duration": 5820,  // seconds
  "total_distance": 68400,  // metres
  "savings": 1140,  // 19 min saved vs input order
  "legs": [
    {
      "duration": 840,
      "distance": 9200,
      "geometry": { "type": "LineString", "coordinates": [...] }
    }
    // one leg per stop transition
  ],
  "geometry": {
    "type": "LineString",
    "coordinates": [...]  // full route
  }
}

Endpoint reference

POST https://api.farun.io/v1/routing/optimized

Request body - JSON

origin req
[lon, lat]
Start coordinate. The route departs from here.
waypoints req
array
Array of [lon, lat] pairs to visit. Min 2, max 25.
destination
[lon, lat]
End coordinate. Defaults to origin if omitted (circular run).
profile
string
driving (default) · truck · bicycle. Truck applies weight/height restrictions.
return_geometry
boolean
Include full GeoJSON geometry per leg and for the complete route. Default: true.
time_windows
array
Per-waypoint [open, close] time constraints in seconds from departure. Enforces appointment-based ordering.
approach
string
curb (default) - snap to driveable side of road. unrestricted for pedestrian use.
overview
string
full (default) · simplified · false. Controls geometry detail level.

Response codes

200 application/json Optimised route with ordered waypoints, legs, and geometry.
400 Bad request Missing required fields, fewer than 2 waypoints, or invalid coordinates.
401 Unauthorized Missing or invalid RapidAPI key.
422 Unroutable No feasible route found between the given waypoints - check that all coordinates are on a routable road.
429 Rate limited Request rate exceeds your plan. Upgrade on RapidAPI.

Integration example

Node.js - optimise and render to map TypeScript
async function optimiseRun(
  depot: [number, number],
  stops: [number, number][]
) {
  const res = await fetch(
    'https://api.farun.io/v1/routing/optimized',
    {
      method: 'POST',
      headers: {
        'Content-Type':     'application/json',
        'X-RapidAPI-Key':  process.env.RAPIDAPI_KEY,
      },
      body: JSON.stringify(
        origin:          depot,
        destination:     depot,  // return to depot
        waypoints:       stops,
        profile:         'driving',
        return_geometry: true,
      ),
    }
  );

  const data = await res.json();

  return {
    orderedStops: data.waypoints_ordered,
    routeLine:    data.geometry,   // → Static Images overlay
    savedMins:   Math.round(data.savings / 60),
  };
}

Method

POST - JSON body

Max waypoints

25 per request

Profiles

driving · truck · bicycle

Time windows

Per-waypoint [open, close]

Geometry format

GeoJSON LineString per leg

P95 latency

< 800 ms for 25 stops

Navigation API family

Often used together

Start building

25 stops, optimal order,
in under a second.

Subscribe on RapidAPI for instant key access. The free tier covers 50 optimisation requests per month, enough to build and test a complete dispatch flow end to end.