Skip to main content

Matrix API

Last updated: November 23, 2026 | 5 minutes read

v1.0.0 Release notes

The Matrix API returns the road distance and the travel time between every pair of locations in a set, in one request. Give it N waypoints and it returns two N x N matrices: the distances in meters and the durations in seconds of the fastest route from each waypoint to each other waypoint.

Matrices are the input of route optimization, dispatching and nearest-vehicle searches: they replace straight-line distances with the real road network, one-way streets and turn restrictions included.

:::info Complete API Reference View the complete Matrix API Reference for detailed request/response schemas, examples, and interactive documentation. :::


Endpoint: POST /matrix

Key Features​

  • Up to 5000 waypoints: one request returns up to 5000 x 5000 values
  • Distances and durations: both matrices in every response
  • Transport modes: car, truck, pedestrian and bike, with the road, cross, city and mountain bike profiles
  • Directed values: the value from A to B can differ from the value from B to A ( one-way streets, turn restrictions )
  • Unreachable pairs: a pair with no route between its waypoints is null; the rest of the matrix is still returned

Required Parameters​

  • waypoints: the locations, each as [ lon, lat ] ( longitude first ), at least 2 and at most 5000. The same location may appear more than once

Optional Parameters​

  • transport: car ( default ), truck, pedestrian or bike
  • profile: the bike profile, for transport: "bike" only: road, cross, city ( default ) or mountain. It can also be sent as vehicle.profile
  • debug: true to pretty-print the response

The Matrix API accepts no other parameter: avoidances, vehicle dimensions or a departure time are rejected as invalid input. Every value is the fastest route for the transport mode.

Example Request - Car Matrix​

curl -X POST https://api.magiclane.net/api/v1/matrix \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"transport": "car",
"waypoints": [[4.3517, 50.8503], [4.4025, 51.2194], [5.5797, 50.6326]]
}'

This example requests the distances and durations between Brussels, Antwerp and Liège.

Response:

{
"info": { "copyrights": [ "MagicLane" ] },
"distances": [
[ 0, 55393, 97517 ],
[ 44793, 0, 133347 ],
[ 97709, 132066, 0 ]
],
"durations": [
[ 0, 2690, 3927 ],
[ 2605, 0, 5126 ],
[ 4013, 5051, 0 ]
]
}

Row i holds the values from waypoint i, column j the values to waypoint j: from Brussels ( row 0 ) to Antwerp ( column 1 ) is 55.4 km and 2690 s, from Antwerp to Brussels 44.8 km and 2605 s.

Example Request - Mountain Bike Matrix​

curl -X POST https://api.magiclane.net/api/v1/matrix \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"transport": "bike",
"profile": "mountain",
"waypoints": [[4.3517, 50.8503], [4.3700, 50.8400], [4.3900, 50.8450]]
}'

This example requests a matrix between three points in Brussels with the mountain bike profile.

Unreachable Pairs​

When no route connects two waypoints, for example an island without a road or ferry link, both values of the pair are null and the other values are still returned:

{
"info": { "copyrights": [ "MagicLane" ] },
"distances": [ [ 0, null ], [ null, 0 ] ],
"durations": [ [ 0, null ], [ null, 0 ] ]
}

Response Structure​

FieldTypeDescription
info.copyrightsarray of stringsdata copyrights
distancesarray of arrays of integersdistance in meters; distances[i][j] from waypoint i to waypoint j; null when no route connects them; 0 on the diagonal
durationsarray of arrays of integersduration in seconds, the same layout as distances
errorobjectreturned instead of the matrices when the request cannot be answered

Errors​

HTTPerror.codeWhenerror.details
400-15invalid request: an unknown parameter, a bad value, fewer than 2 or more than 5000 waypoints, a profile other than the four bike profilesthe parameter, for example Unknown key ( json key path /avoid ) or Waypoints limit exceeded, max 5000
422-19a waypoint cannot be matched to the road network of the transport mode, for example a point in the sea, or a car waypoint with no road open to cars nearbyWaypoint at index 1 could not be matched to the road network
429-38too many requests
503-22, -25, -36a service or data the calculation needs is not available
500-21, -1internal error

A waypoint that cannot be matched fails the whole request: remove it, or move it closer to a road, and send the request again.

For the full route between waypoints, with geometry and instructions, see Routing API.

For the transport modes and vehicle profiles, see Common Parameters.