oslew docs
Console
Menu

RoutingroutingoperationId optimize

GET/v1/optimize

The fastest order to visit 2 to 500 points: a duration matrix, then nearest-neighbour, 2-opt and Or-opt (exact up to 8 points), with the legs routed.

Send Authorization: Bearer sk_live_…. The key's plan must include therouting product; which plans do.

Explained in Visit order and Delivery planning.

Example

The fastest round trip through four points.

curl
curl -G "https://api.oslew.com/v1/optimize" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  --data-urlencode 'points=19.4406,-99.2047;19.4326,-99.1332;19.4352,-99.1412;19.3500,-99.1620' \
  --data-urlencode 'geometry=false'
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

answer = client.optimize(
    "19.4406,-99.2047;19.4326,-99.1332;19.4352,-99.1412;19.3500,-99.1620",
    geometry=False,
)
TypeScript
import { Client } from "@oslew/client";

// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });

const answer = await client.optimize("19.4406,-99.2047;19.4326,-99.1332;19.4352,-99.1412;19.3500,-99.1620", { geometry: false });
Response
HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 294
ratelimit-reset: 1

{
  "order": [
    0,
    2,
    1,
    3,
    0
  ],
  "waypoints": [
    [
      19.4406,
      -99.2047
    ],
    [
      19.4352,
      -99.1412
    ],
    [
      19.4326,
      -99.1332
    ],
    [
      19.35,
      -99.162
    ],
    [
      19.4406,
      -99.2047
    ]
  ],
  "duration_s": 2173,
  "legs_s": [
    561,
    170,
    651,
    791
  ],
  "nearest_neighbour_s": 2173,
  "distance_m": 34016,
  "geometry": [],
  "engine": "base/hierarchy",
  "provenance": {
    "name": "overture-transportation",
    "release": "2026-08-19.0",
    "license": "ODbL-1.0"
  },
  "took_us": 5137
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.

Query

NameTypeDescription
points
queryrequired
string
lat,lon;lat,lon;…
roundtrip
query
boolean
default true
source
query
string
first | any
default first
destination
query
string
last | any
default any
profile
query
string
driving | walking | cycling | rail
default driving
The mode; each has its own network, speeds and access rules.
traffic
query
string
live
Use the traffic feed's weights when one is applied (driving only).
geometry
query
boolean
default true

Responses

200 — The order.

  • distance_mintegerrequired
  • duration_snumberrequired
  • enginestringrequired
  • geometrynumber[][]required
  • legs_snumber[]required
  • nearest_neighbour_snumberrequired
    The unimproved order's duration.
  • orderinteger[]required
  • provenanceSourcerequired
    • licensestringrequired
    • namestringrequired
    • releasestringrequired
  • took_usintegerrequired
  • waypointsnumber[][]required

With RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset(and their X-RateLimit-* aliases); see rate limits.

Refusals

Every refusal is a JSON object with an error string, except where noted.

400Bad request, or no order visits every point.
401No key, or one that is unknown, revoked or suspended.
403The key's plan does not include this route's product, or the request is larger than the plan allows. The body names the plan that does.
429This product's bucket is empty: the key is going faster than its plan's sustained rate. Wait Retry-After seconds; nothing is used up. Carries Retry-After.
503The pod cannot reach the control plane and its entitlements are too old to trust. Retry.

A malformed query string or JSON body is refused by the framework before this route runs, in plain text rather than JSON; see errors.

More examples

Start at the first point and end anywhere
curl
curl -G "https://api.oslew.com/v1/optimize" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  --data-urlencode 'points=19.4406,-99.2047;19.4326,-99.1332;19.4352,-99.1412;19.3500,-99.1620' \
  --data-urlencode 'roundtrip=false' \
  --data-urlencode 'geometry=false'
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

answer = client.optimize(
    "19.4406,-99.2047;19.4326,-99.1332;19.4352,-99.1412;19.3500,-99.1620",
    roundtrip=False,
    geometry=False,
)
TypeScript
import { Client } from "@oslew/client";

// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });

const answer = await client.optimize("19.4406,-99.2047;19.4326,-99.1332;19.4352,-99.1412;19.3500,-99.1620", { roundtrip: false, geometry: false });
Response
HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 293
ratelimit-reset: 1

{
  "order": [
    0,
    2,
    1,
    3
  ],
  "waypoints": [
    [
      19.4406,
      -99.2047
    ],
    [
      19.4352,
      -99.1412
    ],
    [
      19.4326,
      -99.1332
    ],
    [
      19.35,
      -99.162
    ]
  ],
  "duration_s": 1382,
  "legs_s": [
    561,
    170,
    651
  ],
  "nearest_neighbour_s": 1382,
  "distance_m": 20755,
  "geometry": [],
  "engine": "base/hierarchy",
  "provenance": {
    "name": "overture-transportation",
    "release": "2026-08-19.0",
    "license": "ODbL-1.0"
  },
  "took_us": 4153
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.

Rendered from the OpenAPI document at commit b8f4bde-dirty; the same document is served at/v1/openapi.json and generates both clients.