---
title: Traveling Salesman Problem Solver API
slug: travelling-salesman-problem
url: https://apyhub.com/modernsoftware-pro/service/travelling-salesman-problem
provider: ModernSoftware.pro
tags: [route-optimization, tour-planning, path-optimization, geospatial, algorithms, travelling-salesman]
auth: api_key
version: 1.0
service_type: sync
endpoints: 4
atoms: 100-200
mcp: true
---

# Traveling Salesman Problem Solver API

Finds a short tour that visits all points exactly once, minmizing the total travel cost. Point given as grid X-Y coordinates, geocoordinates or distance matrix.

## Endpoints

| Method | URL | Description | Atoms |
| --- | --- | --- | --- |
| POST | `https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/geo-coordinates` | What it does Builds a recommended travel tour from a set of geo-coordinates, starting from the poin… | 200 |
| POST | `https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/grid` | What it does Computes a travelling-salesman tour from a set of named grid points and returns the re… | 100 |
| POST | `https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-asymmetric` | What it does Calculates a recommended tour order for an asymmetric distance matrix, starting from t… | 100 |
| POST | `https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-symmetric` | What it does Builds a symmetric distance matrix input from the request body, then returns a recomme… | 100 |

## Endpoint reference

### travelling-salesman-geo-coordinates

`POST https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/geo-coordinates` · 200 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `geo-coordinates` | body | object | yes | Map of point id to its coordinates. Each key is a point id, 1-40 characters long and containing only letters, digits, underscores, colons, and hyphens (`^[a-zA-Z0-9_:-]{1,40}$`). At most 1000 points… |
| `start` | query | string | yes | Start point ID. Example: `home`. |
| `iterations` | query | integer | no | Number of additional probabilistic optimization iterations, range: 0-5000 Default: `0`. |

#### Quickstart

Find a tour order starting from a chosen point, using a small set of coordinates.

```bash
curl -X POST "https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/geo-coordinates?start=home" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "geo-coordinates": {
      "home": { "lat": 40.7128, "lon": -74.0060 },
      "office": { "lat": 40.7580, "lon": -73.9855 }
    }
  }'
```

#### What you'll get back

Returns a JSON object with `start` as the starting point ID, `tour` as the recommended visit order, and `cost` as the total tour cost in kilometers.

```json
{
  "start": "home",
  "tour": ["home", "office"],
  "cost": 5.2
}
```

### travelling-salesman-grid

`POST https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/grid` · 100 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `grid` | body | object | yes | Map of point id to its grid coordinates. Each key is a point id, 1-40 characters long and containing only letters, digits, underscores, colons, and hyphens (`^[a-zA-Z0-9_:-]{1,40}$`). At most 1000 po… |
| `start` | query | string | yes | Start point ID. Example: `A`. |
| `iterations` | query | integer | no | Number of additional probabilistic optimization iterations, range: 0-5000 Default: `0`. |

#### Quickstart

Send your grid and the starting point to get a recommended tour order.

```bash
curl -X POST "https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/grid?start=A" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "grid": {
      "A": { "x": 0, "y": 0 },
      "B": { "x": 3, "y": 4 },
      "C": { "x": 6, "y": 1 }
    }
  }'
```

#### What you'll get back

Returns a JSON object with three top-level fields: `start` is the starting point ID, `tour` is an array of point IDs in the recommended visit order, and `cost` is the total tour cost as a number.

```json
{
  "start": "A",
  "tour": ["A", "B", "C"],
  "cost": 10.2
}
```

### travelling-salesman-distance-matrix-asymmetric

`POST https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-asymmetric` · 100 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `distance-matrix-asymmetric` | body | object | yes | Map of point id to its row of distances to every point, in the same order the points are listed. Each key is a point id, 1-40 characters long and containing only letters, digits, underscores, colons,… |
| `start` | query | string | yes | Start point ID. Example: `A`. |
| `iterations` | query | integer | no | Number of additional probabilistic optimization iterations, range: 0-5000 Default: `0`. |

#### Quickstart

Find a recommended tour starting from a given point by posting an asymmetric distance matrix and the `start` query parameter.

```bash
curl -X POST "https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-asymmetric?start=A" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"distance-matrix-asymmetric":{"A":[0,10,15],"B":[7,0,9],"C":[6,13,0]}}'
```

#### What you'll get back

Returns a JSON object with `start` as a string, `tour` as an array of point IDs in visit order, and `cost` as an integer total tour cost.

```json
{
  "start": "A",
  "tour": ["A", "B", "C"],
  "cost": 25
}
```

### travelling-salesman-distance-matrix-symmetric

`POST https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-symmetric` · 100 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `distance-matrix-symmetric` | body | object | yes | Map of point id to its row of distances to only the points listed before it (the array grows by one entry per subsequent point, and the first point's array is empty). Each key is a point id, 1-40 cha… |
| `start` | query | string | yes | Start point ID. Example: `home`. |
| `iterations` | query | integer | no | Number of additional probabilistic optimization iterations, range: 0-5000 Default: `0`. |

#### Quickstart

Find a tour starting from a chosen point for the symmetric distance matrix you provide.

```bash
curl -X POST "https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-symmetric?start=home" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "distance-matrix-symmetric": {
      "home": [],
      "a": [10],
      "b": [10, 12]
    }
  }'
```

#### What you'll get back

Returns a JSON object with three required fields: `start` is the start point ID, `tour` is an array of point IDs in the recommended visit order, and `cost` is the total tour cost as an integer.

```json
{
  "start": "home",
  "tour": ["home", "a", "b"],
  "cost": 22
}
```

## About

## What it does
Traveling Salesman Solver computes a visit order for a set of points and returns the start point, the recommended tour, and the total tour cost.

Send point data as geo-coordinates, grid coordinates, or distance matrices. For geo-coordinates, provide a map of point IDs to `lat` and `lon`. For grid mode, provide a map of point IDs to integer `x` and `y`. For distance-matrix-asymmetric, provide a full row of integer distances for each point. For distance-matrix-symmetric, provide each point’s distances to the points listed before it, with the first point’s array empty. In every mode, you also pass a `start` point ID and may include `iterations` to request additional probabilistic optimization passes.

The response always includes `start`, `tour`, and `cost`. Use it when you need a route order for delivery stops, field visits, warehouse picks, inspection routes, or any workflow where minimizing travel distance matters.

This is a route-optimization endpoint, not a map service. It accepts up to 1000 points per request, and it returns the point IDs in the recommended order rather than turning them into coordinates or directions.

## Usage

Base URL: `https://api.eu.apyhub.com` (default region — see
`GET https://apyhub.com/api/public/regions` for the rest).

Authenticate with an ApyHub API key in the `apy-token` header.
Full docs and a live playground: https://apyhub.com/modernsoftware-pro/service/travelling-salesman-problem
