---
title: "Matrix API"
description: "Travel durations and distances between every pair of points, in one request."
canonical_url: "http://0.0.0.0:6006/matrix"
markdown_url: "http://0.0.0.0:6006/matrix.md"
last_updated: "2026-11-17"
x_farming_labs_generated_preamble: true
---

# Matrix API
URL: /matrix
LLM index: /llms.txt
Description: Travel durations and distances between every pair of points, in one request.

# Matrix API

The Matrix API takes a list of coordinates and returns the travel duration and distance between every pair of them. Send ten points and you get all 100 trips back, so you can rank, sort or plan without making a directions call for each pair.

## When to use it

<Cards>
  <Card icon={<TargetIcon />} title="Nearest location">
    Find which store, driver or hospital is closest by road, not by straight line.
  </Card>
  <Card icon={<ListBulletIcon />} title="Delivery order">
    Feed the matrix into your own routing logic to pick the order of stops. For a ready-made optimal
    order, use the [Route Optimization API](/route-optimization).
  </Card>
  <Card icon={<SewingPinFilledIcon />} title="Trip planning">
    Compare legs of a multi-stop trip before committing to a route.
  </Card>
  <Card icon={<BarChartIcon />} title="Cost estimates">
    Turn distances into fuel or fare estimates for every origin and destination.
  </Card>
  <Card icon={<ActivityLogIcon />} title="Traffic analysis">
    Collect durations between fixed points over time to study how travel times change.
  </Card>
</Cards>

## Request

```bash
GET https://mapapi.gebeta.app/api/route/matrix?json=[{lat,lng},{lat,lng}]&apiKey={your-api-key}
```

| Parameter | Type     | Required | Description                                                                                                 |
| --------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------- |
| `json`    | `string` | Yes      | The points, as `[{lat,lng},{lat,lng},…]`. Every point is both an origin and a destination. Up to 10 points. |
| `apiKey`  | `string` | Yes      | Your Gebeta Maps API key.                                                                                   |

## Example

<Tabs items={["cURL", "JavaScript", "Python", "Go", "PHP", "Ruby", "Rust", "Dart"]}>
<Tab value="cURL">

```bash
curl "https://mapapi.gebeta.app/api/route/matrix?json=[{8.989022,38.79036},{9.03045,38.76530}]&apiKey={your-api-key}"
```

</Tab>
<Tab value="JavaScript">

```javascript
const points = "{8.989022,38.79036},{9.03045,38.76530}";
const url = `https://mapapi.gebeta.app/api/route/matrix?json=[${points}]&apiKey=${apiKey}`;

const response = await fetch(url);
const matrix = await response.json();
console.log(matrix.origin_to_destination);
```

</Tab>
<Tab value="Python">

```python
import requests

points = "{8.989022,38.79036},{9.03045,38.76530}"
url = f"https://mapapi.gebeta.app/api/route/matrix?json=[{points}]&apiKey={api_key}"

matrix = requests.get(url).json()
print(matrix["origin_to_destination"])
```

</Tab>
<Tab value="Go">

```go
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

func main() {
	apiKey := "{your-api-key}"
	points := "{8.989022,38.79036},{9.03045,38.76530}"
	url := fmt.Sprintf("https://mapapi.gebeta.app/api/route/matrix?json=[%s]&apiKey=%s", points, apiKey)

	resp, err := http.Get(url)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	var matrix map[string]any
	json.NewDecoder(resp.Body).Decode(&matrix)
	fmt.Println(matrix["origin_to_destination"])
}
```

</Tab>
<Tab value="PHP">

```php
<?php
$apiKey = "{your-api-key}";
$points = "{8.989022,38.79036},{9.03045,38.76530}";
$url = "https://mapapi.gebeta.app/api/route/matrix?json=[$points]&apiKey=$apiKey";

$matrix = json_decode(file_get_contents($url), true);
print_r($matrix["origin_to_destination"]);
```

</Tab>
<Tab value="Ruby">

```ruby
require "net/http"
require "json"

api_key = "{your-api-key}"
points = "{8.989022,38.79036},{9.03045,38.76530}"
url = URI("https://mapapi.gebeta.app/api/route/matrix?json=[#{points}]&apiKey=#{api_key}")

matrix = JSON.parse(Net::HTTP.get(url))
puts matrix["origin_to_destination"]
```

</Tab>
<Tab value="Rust">

```rust
use serde_json::Value;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = "{your-api-key}";
    let points = "{8.989022,38.79036},{9.03045,38.76530}";
    let url = format!("https://mapapi.gebeta.app/api/route/matrix?json=[{points}]&apiKey={api_key}");

    let matrix: Value = reqwest::blocking::get(url)?.json()?;
    println!("{}", matrix["origin_to_destination"]);
    Ok(())
}
```

</Tab>
<Tab value="Dart">

```dart
import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  const apiKey = '{your-api-key}';
  const points = '{8.989022,38.79036},{9.03045,38.76530}';
  final url = Uri.parse('https://mapapi.gebeta.app/api/route/matrix?json=[$points]&apiKey=$apiKey');

  final response = await http.get(url);
  final matrix = jsonDecode(response.body);
  print(matrix['origin_to_destination']);
}
```

</Tab>
</Tabs>

## Response

`origin_to_destination` has one entry for every pair of points, including each point to itself. `from` and `to` are positions in the list you sent.

```json
{
  "origins": [
    { "lat": 9.055978, "lon": 38.704943, "radius": null },
    { "lat": 9.030787, "lon": 38.730911, "radius": null },
    { "lat": 9.047874, "lon": 38.756519, "radius": null }
  ],
  "destinations": [
    { "lat": 9.055978, "lon": 38.704943, "radius": null },
    { "lat": 9.030787, "lon": 38.730911, "radius": null },
    { "lat": 9.047874, "lon": 38.756519, "radius": null }
  ],
  "origin_to_destination": [
    { "from": 0, "to": 0, "distance": 0, "time": 0 },
    { "from": 0, "to": 1, "distance": 6.067, "time": 878 },
    { "from": 0, "to": 2, "distance": 9.547, "time": 1264 },
    { "from": 1, "to": 0, "distance": 6.795, "time": 971 },
    { "from": 1, "to": 1, "distance": 0, "time": 0 },
    { "from": 1, "to": 2, "distance": 4.393, "time": 641 },
    { "from": 2, "to": 0, "distance": 8.699, "time": 1144 },
    { "from": 2, "to": 1, "distance": 4.307, "time": 614 },
    { "from": 2, "to": 2, "distance": 0, "time": 0 }
  ]
}
```

| Field                              | Description                                                                  |
| ---------------------------------- | ---------------------------------------------------------------------------- |
| `origins`                          | The points used as origins, snapped to the nearest road, as `lat` and `lon`. |
| `destinations`                     | The points used as destinations, snapped the same way.                       |
| `origin_to_destination[].from`     | Position of the starting point in the list you sent.                         |
| `origin_to_destination[].to`       | Position of the end point in the list you sent.                              |
| `origin_to_destination[].distance` | Road distance in kilometers.                                                 |
| `origin_to_destination[].time`     | Travel time in seconds.                                                      |

A trip and its return can differ, because of one-way streets and turns. In the example, point 0 to point 1 is 6.1 km but the way back is 6.8 km.

<Callout title="Points are snapped to roads">
  The coordinates in `origins` and `destinations` can differ slightly from the ones you sent. The
  API moves each point to the nearest routable road before measuring.
</Callout>

## Errors

| Status | Message                          | What to do                                                           |
| ------ | -------------------------------- | -------------------------------------------------------------------- |
| `401`  | `Not Authorized - No Token`      | Add your API key as the `apiKey` parameter.                          |
| `401`  | `Not Authorized - Invalid Token` | The key is wrong or expired. Copy a current key from your dashboard. |
| `404`  | `NoRoute`                        | At least one pair of points has no road between them.                |
| `422`  | `InvalidInput`                   | Check the `json` format and that every point is a valid lat/lng.     |

Errors come back in this shape:

```json
{
  "error": {
    "additional": null,
    "code": "A_ERR00004",
    "message": "Invalid access token!",
    "status": 401
  }
}
```

## Limits

- **Points:** Up to 10 per request.
- **Rate:** 50 requests per second per API key. Requests above that are rejected, so throttle or batch them.
- **Countries:** All points must be in the same country. Requests that cross a border are rejected.

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
