Travel-time matrices
GET /v1/matrix answers the travel time from every point to every other, for up to 500 points, in one request. It is what to reach for whenever the question is "which of these is closest" in time rather than in straight-line distance — the nearest store, the nearest free vehicle — and it is the raw material for any routing solver of your own.
curl -G "https://api.oslew.com/v1/matrix" \
-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'from oslew import Client
# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")
answer = client.matrix(
"19.4406,-99.2047;19.4326,-99.1332;19.4352,-99.1412;19.3500,-99.1620",
)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.matrix("19.4406,-99.2047;19.4326,-99.1332;19.4352,-99.1412;19.3500,-99.1620");HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 296
ratelimit-reset: 1
{
"points": [
[
19.4406,
-99.2047
],
[
19.4326,
-99.1332
],
[
19.4352,
-99.1412
],
[
19.35,
-99.162
]
],
"snapped": [
{
"node": 394836,
"lat": 19.44024148258054,
"lon": -99.20469439858863,
"distance_m": 39.86969964600963
},
{
"node": 355496,
"lat": 19.432020221186303,
"lon": -99.13343108985583,
"distance_m": 68.87232944392214
},
{
"node": 289914,
"lat": 19.435305832231098,
"lon": -99.14069479599135,
"distance_m": 54.266522306414174
},
{
"node": 368462,
"lat": 19.35000467473249,
"lon": -99.16174576953559,
"distance_m": 26.677376568826062
}
],
"durations_s": [
[
0,
693.5,
561,
814.5
],
[
691.5,
0,
212.1,
651.1
],
[
546.3,
170.5,
0,
745.7
],
[
791.1,
656.5,
732.8,
0
]
],
"engine": "base/hierarchy",
"provenance": {
"name": "overture-transportation",
"release": "2026-08-19.0",
"license": "ODbL-1.0"
},
"took_us": 2093
}A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.
Four points — Museo Soumaya, the Zócalo, a point just under a kilometre west of it, and one about ten kilometres south — and sixteen times, one for every ordered pair. Every point snapped within 70 m of a junction, so no entry is null.
Parameters
| Parameter | Default | Is |
|---|---|---|
points | required | lat,lon pairs joined with semicolons: 19.4406,-99.2047;19.4326,-99.1332;…. From 1 to 500, and no more than the plan's side (below). |
profile | driving | driving, walking, cycling, rail or live. Each is its own network; see routes and profiles. |
traffic | none | live for the traffic feed's weights, driving only. See live traffic. |
A long list of points makes a long URL: five hundred points at four decimal places is around ten kilobytes once encoded. Four decimal places — about 11 m — is plenty for a travel time, and more only lengthens the URL. Check that your HTTP client, and any proxy of your own in front of it, accepts a request line that long.
Reading durations_s
durations_s[i][j] is the time in seconds, to a tenth, from point ito point j, in the order you sent them. Rows are origins, columns are destinations, and the diagonal is 0.
It is not symmetric, and should not be made so. In the example, point 1 (the Zócalo) to point 2 takes 212.1 s and the way back takes 170.5 s: the historic centre is a grid of one-way streets, and the two directions are two different routes. Averaging the two or copying one triangle into the other throws away exactly what the matrix knows.
Nulls
null in the matrix means there is no time to give, for one of two reasons:
- A point did not snap. Nothing in the profile's network is within about 9 km of it, so
snapped[i]isnulland so is its whole row and column. The rest of the matrix is still answered. - A pair is not connected. Both points are on the network but no route joins them in that direction — an island, an area the profile may not enter, a one-way trap. Only that entry is
null.
Treat null as unreachable, never as 0 — a 0 sorts first, and "nearest" becomes "the one we could not reach".
snapped: each point's junction
Each point is moved to its nearest road junction — {node, lat, lon, distance_m} — not to the nearest point along an edge as /v1/route does. That is what lets one search serve every pair, and it means a matrix entry can differ slightly from a route between the same two points: Museo Soumaya to the Zócalo is 693.5 s here and 695.2 s from /v1/route. Use one or the other for a given decision, not a mixture. distance_m says how far each point was from its junction; a large one means the point is not really on the network.
Size, the plan, and what it costs
A plan caps the number of points on a side — at most 500 on any plan, fewer on the smaller ones; thepricing page lists each plan's. A matrix larger than the key's plan allows is refused with 403, and the body says what the cap is:
HTTP/1.1 403 Forbidden
content-type: application/json
ratelimit-limit: 5
ratelimit-remaining: 24
ratelimit-reset: 1
{
"error": "this plan allows at most 3 points on a side; 4 were asked for. A larger matrix is what the next tier is for."
}A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.
That refusal came from a key held to three points a side, which four points exceeded. It is made after the request is admitted, so unlike the other 403s it carries the rate-limit headers. The number of points is counted before anything is parsed, so the cap is what a larger request will always meet first.
Whatever its size, a matrix is one request and one token from the key's routing bucket. A 500 by 500 matrix — 250,000 times — costs the same token as a single route. The service records a heavier weight against matrices for its own capacity planning, but nothing is charged by it; see rate limits. So ask for the largest matrix your plan allows rather than many small ones.
It is fast: a 500 by 500 driving matrix takes about 150 ms of server time, and the four-point example above took under 7 ms. On live traffic weights applied moments ago, before their hierarchy is built, a matrix runs one search per point and is much slower; see live traffic.
Patterns
The nearest by time
Put the customer first and the candidates after it. Row 0 is the time from the customer to each candidate — "which store can I drive to soonest". Column 0 is the time from each candidate to the customer — "which store can deliver to me soonest". They are different questions with different answers, for the same reason the matrix is not symmetric.
from oslew import Client
client = Client(base_url="https://api.oslew.com")
def nearest_by_time(customer, stores):
"""The store that can reach the customer soonest, and how long it takes."""
points = ";".join(f"{lat},{lon}" for lat, lon in [customer, *stores])
d = client.matrix(points)["durations_s"]
# Column 0, from each store to the customer. None is unreachable, not zero.
times = [(d[i + 1][0], i) for i in range(len(stores)) if d[i + 1][0] is not None]
return min(times, default=None)import { Client } from "@oslew/client";
const client = new Client({ baseUrl: "https://api.oslew.com" });
/** The store that can reach the customer soonest, and how long it takes. */
async function nearestByTime(customer: [number, number], stores: [number, number][]) {
const points = [customer, ...stores].map(([lat, lon]) => `${lat},${lon}`).join(";");
const d = (await client.matrix(points)).durations_s;
let best: { store: number; seconds: number } | null = null;
for (let i = 0; i < stores.length; i++) {
const s = d[i + 1][0]; // from store i to the customer; null is unreachable, not zero
if (s !== null && (best === null || s < best.seconds)) best = { store: i, seconds: s };
}
return best;
}With a plan's side of n, one request ranks n − 1 candidates. For more, pre-filter by straight-line distance and send the closest few hundred — or see a store locator for the whole pattern.
Dispatch
Send the free vehicles followed by the waiting jobs, and read the block of rows for vehicles and columns for jobs: how long each vehicle takes to reach each job. Assign greedily — the smallest time first — or, for the assignment that minimises the total, with the Hungarian algorithm, which most numerical libraries have (SciPy'slinear_sum_assignment, for one). Replace null with a very large number before handing it over, so an unreachable pair is never chosen.
Your own solver
/v1/optimize answers the order in which one vehicle should visit a set of points. For anything it does not model — several vehicles, time windows, capacities, service times — take a matrix and give it to a solver that does. Delivery planning works one through.
Larger than the plan allows: blocks
A problem with more points than the plan's side can be answered in pieces. Split the points into blocks of half the side. Any two blocks together fit in one request, and that one request answers all four of their quarters — each block to itself, and each to the other — so every pair of blocks needs only one request. For k blocks that is k(k + 1)/2 requests: 1,000 points on a side of 100 is 20 blocks and 210 requests, which at five requests a second is 42 seconds.
from oslew import Client, retry_on_rate_limit
client = Client(base_url="https://api.oslew.com")
def big_matrix(points, side):
"""durations[i][j] for every pair of `points` ([(lat, lon), …]), asking at most `side` points at a time."""
half = side // 2
blocks = [list(range(k, min(k + half, len(points)))) for k in range(0, len(points), half)]
out = [[None] * len(points) for _ in points]
for a in range(len(blocks)):
for b in range(a, len(blocks)):
idx = blocks[a] if a == b else blocks[a] + blocks[b]
query = ";".join(f"{points[i][0]},{points[i][1]}" for i in idx)
d = retry_on_rate_limit(client.matrix, query, attempts=5)["durations_s"]
for r, gi in enumerate(idx):
for c, gj in enumerate(idx):
out[gi][gj] = d[r][c]
return outThe blocks agree with one another: each point snaps to the same junction whichever request it is in, so a pair answered twice is answered the same way. Pace the loop to your plan's rate rather than letting it run into429s — retry_on_rate_limit waits out Retry-After when it does.