APIs
Distance matrix API
A distance matrix API returns the travel time from every origin to every destination in a set, so you can rank, assign or optimise without routing each pair on its own. oslew answers a whole matrix — up to 100 × 100 on the Routing plan and 500 × 500 on Scale — as one request against the routing rate, where per-element pricing charges for every cell. Each cell is a free-flow travel time by car, on foot, by bicycle or on rail; road distances are not part of the answer.
Last reviewed
A matrix request is GET /v1/matrix?points=lat,lon;lat,lon;… with an optional profile. The answer’s durations_s is a square table: row i, column j is the time in seconds from point i to point j, in the order you sent them, with zeros on the diagonal. Alongside it, snapped says where each point joined the network, and provenance names the road data and its licence.
Charged per request, not per cell
Google and Mapbox price a matrix by the element — one charge for every origin–destination pair. Google’s published price, read from its own page:
Routes: Compute Route Matrix Essentials is billed at $5.00 per 1,000 elements from the end of the 10,000 free cap to 100,000 a month. (Google Maps Platform, read 24 Sep 2026)And Mapbox’s:
Matrix API elements are free up to 100,000 a month, then $2.00 per 1,000 elements to 500,000, $1.60 to 1,000,000 and $1.20 above. (Mapbox, read 24 Sep 2026)Under per-element pricing, the bill grows with the square of the number of points: doubling the stops you rank against each other quadruples the elements. On oslew the same matrix is one request against the routing rate, and a request inside that rate is already paid for. What the plan limits instead is the size of one matrix and how many you can ask for each second.
That trade has a losing side, and it is worth naming. A team that computes a small matrix a few times a day may fit inside a per-element provider’s free allowance and pay nothing, which no monthly plan beats. The capacity model pays off when matrices are large or frequent — a dispatcher refreshing assignments every minute, a planner ranking hundreds of candidates for every order.
The plan decides the side
| Plan | Price a month | Largest matrix | Routing rate |
|---|---|---|---|
| Routing | $299 | 100 × 100 | 5 requests a second sustained, burst 25 |
| Platform | $699 | 200 × 200 | 20 requests a second sustained, burst 100 |
| Scale | $999 | 500 × 500 | 100 requests a second sustained, burst 300 |
Whatever the plan, the server will not build a matrix with more than 500 points on a side. A request over the plan’s side is refused with HTTP 403 and a body stating the cap; the count is checked before anything else, so a larger request always meets that refusal first. The pricing page has the whole list.
The points travel in the query string, so a large matrix makes a long URL. Four decimal places of latitude and longitude are ample for a travel time, and more only lengthens the request line; check that your HTTP client and any proxy of your own accept one that long.
What a matrix is for
- Dispatch. Send the free vehicles first and the waiting jobs after them, then read the block where vehicle rows meet job columns. Assign greedily, smallest time first, or solve it as an assignment problem with the Hungarian algorithm, which most numerical libraries include. Replace nulls with a very large number before handing the block to a solver so that an unreachable pair is never picked.
- Ranking by time, not by crow-flies distance. Put the customer first and the candidates after. Row zero answers “which store can I drive to soonest”; column zero answers “which store can reach me soonest”. On a one-way street grid those are different questions, and a store locator usually wants the second.
- Territories and assignment. Allocating customers to depots, technicians to regions or schools to catchments is the same pattern at larger scale: a block of the matrix, and a rule for choosing within it.
- Input to a vehicle routing solver. A fleet problem with time windows, capacities and several vehicles is a vehicle routing problem, and every solver for one starts from a travel-time matrix. oslew does not solve VRPs itself; TSP vs VRP explains the difference, and the last-mile delivery workflow shows where the matrix fits.
For a single vehicle’s stop order, you do not need your own solver: route optimisation builds the matrix and orders the stops in one request.
Snapped to junctions, not to the kerb
To answer every pair from one search per point, the matrix moves each point to its nearest road junction, where a route moves each end to the nearest point along a road. The two can therefore differ by a few seconds for the same pair. Use one or the other for a given decision rather than mixing them. snapped[i].distance_m says how far each point was from its junction; a large value means the point is not really on the network, and its row deserves suspicion before it drives a decision.
Bigger than the plan allows
A problem with more points than the plan’s side can still be answered, in blocks. Split the points into blocks of half the side. Any two blocks together fit in one request, and that request answers all four quarters — each block to itself and each to the other — so every pair of blocks needs one request and no more. The number of requests grows with the square of the number of blocks, so pace the loop to your routing rate rather than letting it run into HTTP 429 refusals, and wait out Retry-After when one arrives. Because each point snaps to the same junction in every request, a pair answered twice is answered identically.
Limits, stated plainly
- Cells hold travel times only; there is no distance table.
- Times are free-flow — posted limit or class speed, nothing for congestion. A driving matrix can use current speeds only where an Enterprise operator has applied a traffic feed, and it is much slower to build in the moments after a new feed arrives.
- One profile per request and no departure time.
- The plan’s side caps a single request, and the server’s cap is the same on every plan above it.
- Matrices derive from road data licensed ODbL-1.0; a database of stored times that you share with others is share-alike. See the licensing page.
Bottom line
Choose this endpoint whenever the question is which of many is closest in time, or when a solver of your own needs the travel times between everything. Ask for the largest matrix your plan allows rather than many small ones, treat nulls as unreachable, keep both directions, and route the few pairs whose distance you need.
Questions
How is a travel-time matrix charged on oslew?
As one request from the routing bucket, whatever its size: the largest matrix a plan allows costs the same as a single route. The plan sets the largest side — 100 × 100 on Routing, 200 × 200 on Platform, 500 × 500 on Scale — and the routing rate sets how many matrices a second you may ask for.
Does the matrix include road distances as well as times?
No. Every cell is a travel time in seconds, to a tenth. When you need the road distance for a particular pair — the mileage of an assignment you have already chosen, say — route that pair with the routing API, which returns the distance along the road as well as the time.
What happens if I send more points than my plan allows?
The request is refused with HTTP 403, and the body names your plan’s largest side. For a bigger problem, split the points into blocks of half that side: any two blocks fit in one request, so every pair of blocks costs one request, and the pieces agree because each point snaps to the same junction wherever it appears.
Why is the time from A to B different from B to A?
Because they are two different routes. One-way streets and divided roads make the way there and the way back differ, and the matrix keeps both. Averaging the two or copying one half of the matrix over the other throws away exactly what a dispatcher needs to know.
What does a null in the matrix mean?
That there is no time to give. A whole row and column are null when a point had no road near it in the profile’s network; a single cell is null when both points are on the network but nothing joins them in that direction. Treat null as unreachable and never as zero, or the nearest candidate becomes the one you cannot reach.