---
title: "Optimal waypoint ordering."
method: POST
path: "/optimized-route/v1"
tags: ["Routing"]
---

# Optimal waypoint ordering.

`POST /optimized-route/v1`

## Request

- Base URL: `https://api.rijwind.com`
- URL: `https://api.rijwind.com/optimized-route/v1`
- Auth: HTTP bearer

Find the optimal visiting order over a set of waypoints (a travelling-salesman solve) and return a route that visits them in that order. The first and last locations stay fixed.

**Quota cost:** `N` units per call, where `N` is the number of locations. Capped at 20 locations; requests beyond that return 400 without charging quota.

## Request body

- OptimizedRouteRequest: Find the optimal visiting order over a set of waypoints and return a route that visits them in that order. The first and last locations stay fixed; the stops in between are reordered.
  - `costing` 'auto' | 'bicycle' | 'pedestrian', required: Routing profile. `auto` (car), `bicycle`, or `pedestrian` (foot).
  - `locations` LngLat[], required: Two or more waypoints. The first is the start and the last is the end; the intermediate stops are reordered for the shortest total trip. Capped at 20 locations.
    - `lat` number, double, required
    - `lon` number, double, required
  - `units` 'kilometers' | 'miles'

## Response `200`

Optimized route.

- RouteResponse: Route response. The interesting fields are `trip.summary` (totals) and `trip.legs[i].shape` (an encoded polyline ready to render).
  - `trip` Trip, required
    - `language` string, required
    - `legs` RouteLeg[], required
      - `maneuvers` RouteManeuver[], required
        - `beginShapeIndex` integer, required
        - `endShapeIndex` integer, required
        - `instruction` string, required
        - `length` number, double, required
        - `time` number, double, required
      - `shape` string, required: Encoded polyline at 1e-6 precision (the standard Google polyline algorithm with 6 decimals instead of 5). Decoders are available for every major language — in JavaScript, `@mapbox/polyline` with the precision set to 6 returns `[lat, lon]` pairs.
      - `summary` RouteSummary, required
        - `length` number, double, required: Total length in the requested units.
        - `maxLat` number, double, nullable
        - `maxLon` number, double, nullable
        - `minLat` number, double, nullable
        - `minLon` number, double, nullable
        - `time` number, double, required: Total travel time in seconds.
    - `status` integer, required
    - `statusMessage` string, required
    - `summary` RouteSummary, required
      - `length` number, double, required: Total length in the requested units.
      - `maxLat` number, double, nullable
      - `maxLon` number, double, nullable
      - `minLat` number, double, nullable
      - `minLon` number, double, nullable
      - `time` number, double, required: Total travel time in seconds.
    - `units` string, required

## Other responses

- `400`: Body malformed, costing unsupported, fewer than 2 locations, or more than 20.
- `401`: Missing, malformed, or revoked API key.
- `429`: Monthly quota exhausted.

---

[API](https://skmtc.dev/rijwind/apis/rijwind-api.md) · [All operations](https://skmtc.dev/rijwind/apis/rijwind-api/llms.txt) · [OpenAPI document](https://skmtc.dev/rijwind/apis/rijwind-api/revisions/01d72fb6aa4d?raw)
