Skip to content
Documentation menu
docs / api / post-optimise
Optimisation and jobs

POST/optimise

Also served at /optimize: the same operation and price.

Access and price

AuthAn API key, as Authorization: Bearer snk_… or ?api_key=snk_…. Metered. Needs a full key; a browser (maps) key is refused.
Price10 calls per started block of the engine's matrix-pair limit over the problem's unique locations (10 up to 50 locations). Class: standard, or premium for truck and ADR work. Published as unit_rules.optimise in /pricing.json.
PremiumWhen the body asks for truck routing: "costing": "truck", a top-level adr object or "hazmat": true

What it does

Route-optimisation endpoint. /optimize is an alias.

An API key, as Authorization: Bearer snk_… or ?api_key=snk_…. Metered. Price: 10 calls per started block of the engine's matrix-pair limit over the problem's unique locations (10 up to 50 locations).

Also served at /optimize (the American spelling): the same handler, body, answer and price.

Call it

bash
curl -fsS -X POST "https://api.mapmap.ai/optimise" \
  -H "Authorization: Bearer $MAPMAP_KEY" \
  -H "Content-Type: application/json" \
  -d @request.json

Request body

application/json

Optimisation problem: vehicles (id, start/end, capacity, skills, time_window, plus breaks, max_travel_time, max_tasks and a costs model), jobs (id, location, service_s, delivery, pickup, skills, time_windows), optional shipments (pickup+delivery pairs), costing (auto|truck|bicycle|pedestrian|motor_scooter), optional Valhalla-style costing_options and an optional top-level adr vehicle profile (as on /route). Set eu_drivers_hours (true or {driving_before_break_s, break_duration_s}) to auto-generate EC 561/2006 rest breaks for windowed vehicles without explicit breaks (single-shift approximation). An optional emissions object (vehicle_category, fuel, euro_standard, as on /route) reports which of the problem's own locations sit in a UK clean-air zone and what this vehicle pays there; avoid_zones: true additionally keeps the internal travel-time matrix out of those zones. Optional territories ([{id, polygon}], GeoJSON [lon, lat] rings) plus per-vehicle territory_ids confine a vehicle to named rounds: it may serve a task only if the task sits inside at least one of its territories, a vehicle with no territory_ids serves anywhere, and a task inside no territory at all is servable by unrestricted vehicles only. Per-vehicle reloads ({max_trips, reload_time_s, depot}) lets a vehicle return to its depot, reload and go out again; the waste-collection tipping round: the vehicle is split into one virtual vehicle per trip and its time_window (which becomes required) is partitioned into consecutive trip windows separated by reload_time_s, so capacity, max_tasks, max_travel_time and costs apply PER TRIP. Optional relax_if_unassigned ({time_windows_by_s, allow_overtime_s}) re-solves ONCE with those caps applied when the first solve leaves work unassigned, keeps the relaxed plan only if it assigns more, and bills two solves when it runs. /optimize is accepted as an alias. Fair use: at most 200 unique locations per request, and no wider than the routing engine's matrix span (1,500 km on the hosted gateway, 400 km stock on a self-host)

Example: From website/public/docs/optimisation.md:241

json
{
  "adr": {
    "dimensions": {
      "gross_weight_t": 40,
      "height_m": 4,
      "length_m": 16.5,
      "width_m": 2.55
    },
    "hazmat": true,
    "tunnel_code": "C"
  },
  "costing": "truck",
  "jobs": [
    {
      "delivery": [
        2
      ],
      "id": 10,
      "location": {
        "lat": 52.4862,
        "lon": -1.8904
      },
      "service_s": 300
    },
    {
      "delivery": [
        3
      ],
      "id": 11,
      "location": {
        "lat": 53.4808,
        "lon": -2.2426
      },
      "service_s": 300
    }
  ],
  "vehicles": [
    {
      "capacity": [
        10
      ],
      "end": {
        "lat": 51.5074,
        "lon": -0.1278
      },
      "id": 1,
      "start": {
        "lat": 51.5074,
        "lon": -0.1278
      },
      "time_window": [
        28800,
        64800
      ]
    }
  ]
}

Responses

200Optimised plan: summary, unassigned and routes[] with ordered steps[] (durations in seconds, distances in metres, locations echoed as {lat, lon}), plus the matrix profile used and, when any location sits in a UK clean-air zone or avoid_zones was set, a zones block naming those zones and the avoidance applied to the matrix. When territories was given, a territories block reports per-territory job counts (inside, assigned, unassigned), the jobs outside every territory, anything no vehicle was allowed to serve, and the semantics in force. When any vehicle declared reloads, each route carries its trip (1-based) beside the caller's own vehicle id, summary.routes counts TRIPS, and a reloads block reports trips used vs allowed, the depot, the trip windows and the sequencing approximation. When relax_if_unassigned was given, a relaxation block states whether a second solve ran, whether its plan is the one returned, what was widened and what is still unassigned
FieldTypeRequiredDescription
codeintegerno0 when solved.
eta_calibrationobjectnoThe typical-delay calibration applied to the plan's times.
profilestringnoThe costing the plan was solved for.
relaxationobjectnoConstraints relaxed to find a plan, and whether a second solve ran.
reloadsnot statednoDepot reload stops, when vehicles reload.
routesobject[]noOne route per used vehicle: vehicle, cost, distance, duration, service, waiting_time and steps (start, job, pickup, delivery, break, end) with arrival times and location.
solverstringnoThe solver used. Off by default.
summaryobjectnoTotals: cost, distance (metres), duration, service and waiting_time (seconds), routes and unassigned counts.
territoriesnot statednoPer territory polygon the caller sent: the jobs inside it and the jobs the plan assigned. Present when territories were sent.
unassignedobject[]noJobs no vehicle could take.
zonesobjectnoClean-air zone charges at the plan's stops (at_locations), with basis and caveats.

Example: Recorded from the hosted gateway on 2026-11-05 with a test key: POST /optimise, one car from Trafalgar Square with two London jobs; lists trimmed to their first items

json
{
  "code": 0,
  "eta_calibration": {
    "applied": true,
    "cells_calibrated": 6,
    "cells_not_walked": 0,
    "cells_unchanged": 3,
    "method": "gb_typical_delay_v1",
    "note": "Local roads in Great Britain carry no live traffic data, so the time on them includes the junction and congestion delay a typical car meets at this time of day, from Department for Transport statistics, on top of the routing engine's free-flowing time: the same delay POST /route adds, applied to the path each cell was costed on. It is a typical figure, not live traffic. Motorways, roads covered by National Highways traffic data and roads outside Great Britain keep the engine's own time.",
    "period": "all_day",
    "sources": [
      "Department for Transport, tables CGN0503 and CGN0504: average speed and delay on local 'A' roads in England, urban and rural, by time of day, rolling year to June 2026"
    ]
  },
  "profile": "auto",
  "routes": [
    {
      "cost": 1376,
      "distance": 7749,
      "duration": 1376,
      "service": 600,
      "steps": [
        {
          "arrival": 0,
          "duration": 0,
          "location": {
            "lat": 51.508,
            "lon": -0.1281
          },
          "service": 0,
          "type": "start",
          "waiting_time": 0
        },
        {
          "arrival": 414,
          "duration": 414,
          "id": 10,
          "location": {
            "lat": 51.5138,
            "lon": -0.0984
          },
          "service": 300,
          "type": "job",
          "waiting_time": 0
        }
      ],
      "vehicle": 1,
      "waiting_time": 0
    }
  ],
  "summary": {
    "cost": 1376,
    "distance": 7749,
    "duration": 1376,
    "routes": 1,
    "service": 600,
    "unassigned": 0,
    "waiting_time": 0
  },
  "unassigned": [],
  "zones": {
    "at_locations": [
      {
        "assessment": "unknown",
        "currency": "GBP",
        "daily_charge": null,
        "enforcement": "charge",
        "id": "gb-london-lez",
        "locations_inside": 3,
        "name": "London Low Emission Zone",
        "operator": "Transport for London",
        "source": {
          "checked": "2026-09-03",
          "licence": "TfL website content; reuse of tfl.gov.uk page content is restricted by TfL's website terms. These figures are transcribed by hand for citation, not extracted as a dataset.",
          "publisher": "Transport for London",
          "url": "https://tfl.gov.uk/modes/driving/low-emission-zone/make-a-payment"
        },
        "type": "lez"
      },
      {
        "assessment": "unknown",
        "currency": "GBP",
        "daily_charge": null,
        "enforcement": "charge",
        "id": "gb-london-ulez",
        "locations_inside": 3,
        "name": "London Ultra Low Emission Zone",
        "operator": "Transport for London",
        "source": {
          "checked": "2026-09-03",
          "licence": "TfL website content; reuse of tfl.gov.uk page content is restricted by TfL's website terms. These figures are transcribed by hand for citation, not extracted as a dataset.",
          "publisher": "Transport for London",
          "url": "https://tfl.gov.uk/modes/driving/ultra-low-emission-zone/cars"
        },
        "type": "ulez"
      }
    ],
    "basis": "the optimiser is fed a travel-time matrix, not road geometry, so this block reports the zones this problem's own locations sit in and the avoidance applied to the matrix. It does NOT enumerate the zones the driven roads pass through. Route each vehicle's ordered stops through POST /route with the same `emissions` object for that.",
    "caveats": "Zone boundaries are simplified from the published geometry to the tolerance stated on each zone, so a route running within that distance of a boundary may be classified either way. Charges are the published daily amounts as at each zone's `checked` date, quoted per zone per day and never summed into any routing cost; a vehicle crossing the same zone twice in a day pays once, and this estimate does not model residency, disability, historic-vehicle or trade exemptions, discounts, or accounts you may already hold. Verify against the cited source before relying on a figure.",
    "note": "charge depends on vehicle emissions, supply `emissions` (vehicle_category, fuel, euro_standard) to resolve"
  }
}
400Invalid request, geometry requested, an invalid or unknown territory, a caller skill inside the reserved territory range, a vehicle id inside the reserved virtual-vehicle range, an impossible reload split (max_trips outside 2..=5, no time_window, a start/end that is not the depot, a shift too short for its trips, or a break that fits no trip window), a relaxation cap that is missing, non-positive or above seven days, or the solver rejected the problem

application/problem+json · Problem

401Missing or invalid API key. Also: No key, or a missing, malformed, unknown, revoked or expired one (unauthorized); the body carries signup, docs and a one-call hint for a free key

application/problem+json · Problem

402Beyond the included volume with no way to pay this call: an x402 body naming how to pay (provisional key past its allowance, prepaid balance below the price, or a rejected X-PAYMENT). Not problem+json

application/json · X402PaymentRequired

403The key may not call this: a browser key outside its scope (scope-insufficient), a request from an origin the key does not allow (origin-not-allowed), or an account restriction (forbidden)

application/problem+json · Problem

413The request declares a body larger than 1048576 bytes (plain text, not problem+json)

text/plain

422More than 200 unique locations (fair-use cap), or a problem spread wider than the routing engine's max_matrix_distance (1,500 km on the hosted gateway, 400 km stock on a self-host: the internal matrix is chunked to fit the engine's pair ceiling, but its span cannot be chunked around), or a problem too large for the solver's cost arithmetic (optimisation-beyond-solver, not billed)

application/problem+json · Problem

429Quota or rate limit exceeded. Also: Per-key rate limit (rate-limited, with Retry-After), or monthly quota exhausted with no payment path (quota-exceeded)

application/problem+json · Problem

502The VROOM solver is unreachable or failed

application/problem+json · Problem

503Optimisation is not enabled on this deployment (SN_VROOM_URL unset)

application/problem+json · Problem

504The request did not finish within the gateway's request deadline (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_optimise