# Matrix API

Last updated:

<!-- -->

November 23, 2026

<!-- -->

\| 5 minutes read

<br />

<br />

[v](/docs/cloud-rest-api/guides/routing-navigation/CHANGELOG/#matrix-api)

<!-- -->

[1.0.0 Release notes →](/docs/cloud-rest-api/guides/routing-navigation/CHANGELOG/#matrix-api)

<br />

<br />

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](/docs/cloud-rest-api/api/matrix-api.html) for detailed request/response schemas, examples, and interactive documentation. :::

***

**Endpoint:** `POST /matrix`

### Key Features[​](#key-features "Direct link to 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[​](#required-parameters "Direct link to 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[​](#optional-parameters "Direct link to 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[​](#example-request---car-matrix "Direct link to Example Request - Car Matrix")

```bash
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:

```json
{
  "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[​](#example-request---mountain-bike-matrix "Direct link to Example Request - Mountain Bike Matrix")

```bash
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[​](#unreachable-pairs "Direct link to 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:

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

```

### Response Structure[​](#response-structure "Direct link to Response Structure")

| Field             | Type                        | Description                                                                                                                    |
| ----------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `info.copyrights` | array of strings            | data copyrights                                                                                                                |
| `distances`       | array of arrays of integers | distance in meters; `distances[i][j]` from waypoint `i` to waypoint `j`; `null` when no route connects them; 0 on the diagonal |
| `durations`       | array of arrays of integers | duration in seconds, the same layout as `distances`                                                                            |
| `error`           | object                      | returned instead of the matrices when the request cannot be answered                                                           |

### Errors[​](#errors "Direct link to Errors")

| HTTP | `error.code`  | When                                                                                                                                                       | `error.details`                                                                                           |
| ---- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| 400  | -15           | invalid request: an unknown parameter, a bad value, fewer than 2 or more than 5000 waypoints, a profile other than the four bike profiles                  | the parameter, for example `Unknown key ( json key path /avoid )` or `Waypoints limit exceeded, max 5000` |
| 422  | -19           | a 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 nearby | `Waypoint at index 1 could not be matched to the road network`                                            |
| 429  | -38           | too many requests                                                                                                                                          |                                                                                                           |
| 503  | -22, -25, -36 | a service or data the calculation needs is not available                                                                                                   |                                                                                                           |
| 500  | -21, -1       | internal 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.

## Related Documentation[​](#related-documentation "Direct link to Related Documentation")

For the full route between waypoints, with geometry and instructions, see [Routing API](/docs/cloud-rest-api/guides/routing-navigation/routing-api.md).

For the transport modes and vehicle profiles, see [Common Parameters](/docs/cloud-rest-api/guides/routing-navigation/common-parameters.md).
