Documentation menu
POST/v1/cluster
Access and price
| Auth | An API key, as Authorization: Bearer snk_… or ?api_key=snk_…. Metered. Needs a full key; a browser (maps) key is refused. |
|---|---|
| Price | 1 call per started block of 100 locations, at most 5000 locations. Class: standard, or premium for truck and ADR work. Published as unit_rules.cluster in /pricing.json. |
| Premium | When the body asks for truck routing: "costing": "truck", a top-level adr object or "hazmat": true |
What it does
Capacity-constrained clustering.
An API key, as Authorization: Bearer snk_… or ?api_key=snk_…. Metered. Price: 1 call per started block of 100 locations, at most 5000 locations.
Call it
curl -fsS -X POST "https://api.mapmap.ai/v1/cluster" \
-H "Authorization: Bearer $MAPMAP_KEY" \
-H "Content-Type: application/json" \
-d '{"locations":[{"id":"d-1001","lat":51.28,"load":3,"lon":1.08},{"id":"d-1002","lat":51.29,"load":5,"lon":1.11},{"id":"d-1003","lat":51.51,"load":2,"lon":-0.09}],"max_cluster_size":{"locations":150}}'Request body
application/json
locations ([{id, lat, lon, load?}], ids unique, at most 5,000), plus EXACTLY ONE of clusters (how many groups to produce, balanced by stop count) or max_cluster_size ({"locations": n} or {"load": x}, a per-cluster ceiling from which the count is derived). Optional territories ([{id, polygon}], GeoJSON [lon, lat] rings, same shape as on POST /optimise) keeps clusters from straddling a round: each territory is clustered on its own, and so are the stops inside none of them. Optional seed (default 42) drives the k-means++ seeding; the same request with the same seed always returns the same clusters
Example: From website/public/docs/optimisation.md:837
{
"locations": [
{
"id": "d-1001",
"lat": 51.28,
"load": 3,
"lon": 1.08
},
{
"id": "d-1002",
"lat": 51.29,
"load": 5,
"lon": 1.11
},
{
"id": "d-1003",
"lat": 51.51,
"load": 2,
"lon": -0.09
}
],
"max_cluster_size": {
"locations": 150
}
}Responses
clusters[] with id, member locations (your ids), count, summed load, centroid and the territory each belongs to; parameters echoing the seed, the cluster count, the iterations run and whether it converged; balance naming the constraint applied and whether it had to be relaxed; and a basis stating that this is straight-line clustering, with the pointer to POST /optimise for road-network order| Field | Type | Required | Description |
|---|---|---|---|
| balance | object | no | How the clusters were balanced, the largest cluster's size and load, and whether a limit was relaxed. |
| basis | string | no | What the distances are: straight lines on a local projection, not road distances. |
| clusters | object[] | no | One entry per cluster: id, centroid, count, load and the
member locations. |
| parameters | object | no | The solve: clusters, locations, iterations, converged,
seed and territory counts. |
Example: Recorded from the hosted gateway on 2026-11-05 with a test key: POST /v1/cluster, two Brighton drops and one London drop; lists trimmed to their first items
{
"balance": {
"basis": "locations",
"largest_cluster_load": 10,
"largest_cluster_locations": 3,
"max_load_per_cluster": null,
"max_locations_per_cluster": 150,
"note": "every cluster is inside the ceiling.",
"relaxed": false
},
"basis": "Straight-line clustering. Distances are measured between coordinates on a local planar projection, NOT along the road network: no road, river, motorway junction or one-way system is consulted, and two stops either side of an estuary look adjacent. Use this to decide which stops belong together, then POST /optimise per cluster to decide the order, because that is where the routing engine's own matrix, your costing and any truck or ADR constraints actually apply. Clustering here commissions no engine work and makes no claim about drive time.",
"clusters": [
{
"centroid": {
"lat": 51.05493333333334,
"lon": -0.12546666666666667
},
"count": 3,
"id": 0,
"load": 10,
"locations": [
"d-1001",
"d-1002",
"d-1003"
],
"territory": null
}
],
"parameters": {
"clusters": 1,
"converged": true,
"iterations": 2,
"locations": 3,
"locations_outside_all_territories": 0,
"seed": 42,
"territories": 0
}
}application/problem+json · Problem
unauthorized); the body carries signup, docs and a one-call hint for a free keyapplication/problem+json · Problem
X-PAYMENT). Not problem+jsonapplication/json · X402PaymentRequired
scope-insufficient), a request from an origin the key does not allow (origin-not-allowed), or an account restriction (forbidden)application/problem+json · Problem
text/plain
locations x clusters assignment larger than 500,000application/problem+json · Problem
rate-limited, with Retry-After), or monthly quota exhausted with no payment path (quota-exceeded)application/problem+json · Problem
request-timeout)application/problem+json · Problem
Error bodies follow the shared problem model documented on API conventions.
Also under Optimisation and jobs
Generated from https://api.mapmap.ai/openapi.json on 2026-11-12 · operationId post_cluster