---
title: "Route Optimization API"
description: "The shortest order to visit a set of stops, as a round trip from the first one."
canonical_url: "http://0.0.0.0:6006/route-optimization"
markdown_url: "http://0.0.0.0:6006/route-optimization.md"
last_updated: "2026-11-17"
x_farming_labs_generated_preamble: true
---

# Route Optimization API
URL: /route-optimization
LLM index: /llms.txt
Description: The shortest order to visit a set of stops, as a round trip from the first one.

# Route Optimization API

Give the Route Optimization API a list of stops and it returns the order that visits them all in the least time, as a round trip that starts and ends at the first stop. You also get the total time and distance and the full route to draw on a map. This is the travelling salesman problem, solved over real roads.

## When to use it

<Cards>
  <Card icon={<CubeIcon />} title="Single-driver deliveries">
    Order a courier's drops so they drive as little as possible.
  </Card>
  <Card icon={<LoopIcon />} title="Service rounds">
    Plan a technician's or sales rep's visits for the day.
  </Card>
  <Card icon={<SewingPinFilledIcon />} title="Trips">
    Find the best order to see several places and get back to the start.
  </Card>
</Cards>

To split stops across several vehicles with capacities, use the [VRP API](/vrp). To keep the stops in your own order, use the [Direction API](/direction) with `waypoints`.

## Request

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

| Parameter | Type     | Required | Description                                                                                          |
| --------- | -------- | -------- | ---------------------------------------------------------------------------------------------------- |
| `json`    | `string` | Yes      | The stops, as `[{lat,lng},{lat,lng},…]`. The first stop is where the trip starts and ends. Up to 10. |
| `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/tss?json=[{9.0105,38.7613},{8.989022,38.79036},{9.03045,38.76530}]&apiKey={your-api-key}"
```

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

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

const response = await fetch(url);
const trip = await response.json();
console.log(trip.best_order);
```

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

```python
import requests

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

trip = requests.get(url).json()
print(trip["best_order"])
```

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

```go
package main

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

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

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

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

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

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

$trip = json_decode(file_get_contents($url), true);
print_r($trip["best_order"]);
```

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

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

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

trip = JSON.parse(Net::HTTP.get(url))
puts trip["best_order"].inspect
```

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

```rust
use serde_json::Value;

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

    let trip: Value = reqwest::blocking::get(url)?.json()?;
    println!("{}", trip["best_order"]);
    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 stops = '{9.0105,38.7613},{8.989022,38.79036},{9.03045,38.76530}';
  final url = Uri.parse('https://mapapi.gebeta.app/api/route/tss?json=[$stops]&apiKey=$apiKey');

  final trip = jsonDecode((await http.get(url)).body);
  print(trip['best_order']);
}
```

</Tab>
</Tabs>

## Response

```json
{
  "msg": "Ok",
  "best_order": [
    { "lat": 9.056218, "lon": 38.705173 },
    { "lat": 9.030789, "lon": 38.730922, "index": 1, "original_index": 1 },
    { "lat": 9.047741, "lon": 38.756671, "index": 2, "original_index": 2 },
    { "lat": 9.056218, "lon": 38.705173, "index": 3, "original_index": 3 }
  ],
  "original_order": [
    { "lat": 9.056218147277832, "lon": 38.70517349243164 },
    { "lat": 9.030789375305176, "lon": 38.73092269897461, "index": 1 },
    { "lat": 9.047741889953613, "lon": 38.75667190551758, "index": 2 },
    { "lat": 9.056218147277832, "lon": 38.70517349243164, "index": 3 }
  ],
  "total_distance": 19.698,
  "time_taken": 2774.798,
  "Direction": [[9.055978, 38.704943]]
}
```

| Field            | Description                                                                                                                                                              |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `msg`            | `Ok` when a trip was found.                                                                                                                                              |
| `best_order`     | The stops in the order to visit them, snapped to the nearest road. It starts and ends at your first stop. `original_index` is each stop's position in the list you sent. |
| `original_order` | The stops in the order you sent them, ending back at the first one.                                                                                                      |
| `total_distance` | Length of the whole round trip, in kilometers.                                                                                                                           |
| `time_taken`     | Travel time for the whole round trip, in seconds.                                                                                                                        |
| `Direction`      | The route as `[lat, lng]` points, in driving order. Note the capital `D`. A real response has hundreds of points; this example shows only the first.                     |

## 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 stop can't be reached by road from the others.          |
| `422`  | `InvalidInput`                   | Check that `json` is `[{lat,lng},…]`.                                |

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

## Limits

- **Stops:** Up to 10 per request, including the start.
- **Rate:** 50 requests per second per API key. Requests above that are rejected, so throttle or batch them.
- **Countries:** All stops must be in the same country.

## 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).
