Skip to content
Documentation menu
docs / api / post-matrix
Matrix

POST/matrix

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.
Price1 call per started block of 25 elements (sources × targets), at most 10000 elements per request. Class: standard, or premium for truck and ADR work. Published as unit_rules.matrix in /pricing.json.
PremiumWhen the body asks for truck routing: "costing": "truck", a top-level adr object or "hazmat": true

What it does

Many-to-many travel times and distances between sources and targets.

An API key, as Authorization: Bearer snk_… or ?api_key=snk_…. Metered. Price: 1 call per started block of 25 elements (sources × targets), at most 10000 elements per request.

Call it

bash
curl -fsS -X POST "https://api.mapmap.ai/matrix" \
  -H "Authorization: Bearer $MAPMAP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"costing":"truck","costing_options":{"truck":{"height":4,"weight":40}},"sources":[{"lat":51.5074,"lon":-0.1278}],"targets":[{"lat":52.4862,"lon":-1.8904},{"lat":53.4808,"lon":-2.2426}]}'

Request body

application/json

Valhalla matrix request JSON: sources, targets, costing, optional units and costing_options. Scenario analysis: optional exclude_polygons; areas whose intersecting roads are avoided, as a JSON array of rings of [lon, lat] pairs (note the lon-first order), e.g. [[[-0.1,51.5],[-0.11,51.5],[-0.11,51.52]]], and exclude_locations, {lat, lon} objects each mapped to its nearest road(s), which are then excluded, so "close this bridge and recompute the matrix" is one request. Valhalla engine only: a GraphHopper-backed deployment ignores both fields. When the first search leaves cells null, the gateway searches once more with a wider snap (radius 1000 m, minimum_reachability 500) at every source and target that did not set its own, keeping every value the caller did set, and takes the second search's value for the null cells only. The retry is never sent when the request carries exclude_locations or exclude_polygons: a wider snap would route round the exclusion, so those cells stay null. Optional top-level snap_retry: false turns the retry off

Example: From website/public/docs/analysis.md:255

json
{
  "costing": "truck",
  "costing_options": {
    "truck": {
      "height": 4,
      "weight": 40
    }
  },
  "sources": [
    {
      "lat": 51.5074,
      "lon": -0.1278
    }
  ],
  "targets": [
    {
      "lat": 52.4862,
      "lon": -1.8904
    },
    {
      "lat": 53.4808,
      "lon": -2.2426
    }
  ]
}

Responses

200{durations, distances}: row-major seconds and metres, null when unreachable. Car (auto) durations on local roads in Great Britain include typical junction and congestion delay, as on POST /route; then an eta_calibration block names the method, the period, the cell counts and the engine's own engine_durations. When the widened-snap retry filled any cell, a snap_retry block lists those cells ([source, target] pairs), the widened_sources and widened_targets, and moved[]: each widened location's role, index, requested point, the snapped point the filled cells really start or end at, and the distance_m between them
FieldTypeRequiredDescription
distancesnumber[][]noMetres, distances[source][target]; null where no route was found.
durationsnumber[][]noSeconds, durations[source][target]; null where no route was found.
enginestringnoThe routing engine that answered.
eta_calibrationobjectnoThe typical-delay calibration applied to the durations, with the engine's own durations kept in engine_durations.
snap_retryobjectnoPresent when the widened-snap retry produced the matrix.

Example: Recorded from the hosted gateway on 2026-11-05 with a test key: POST /matrix, Trafalgar Square to St Paul's and Westminster by car; lists trimmed to their first items

json
{
  "distances": [
    [
      2477,
      1594
    ]
  ],
  "durations": [
    [
      413.753,
      302.648
    ]
  ],
  "engine": "valhalla",
  "eta_calibration": {
    "applied": true,
    "cells_calibrated": 2,
    "cells_not_walked": 0,
    "cells_unchanged": 0,
    "engine_durations": [
      [
        297,
        231
      ]
    ],
    "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. engine_durations holds the engine's own times.",
    "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"
    ]
  }
}
400Invalid request

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 10,000 source×target elements, or a source/target pair further apart than the deployment's configured max_matrix_distance (SN_ENGINE_MAX_MATRIX_DISTANCE_M; 400 km by default, 1,500 km on the hosted gateway; not chunkable around). The span refusal names the offending pair as furthest_pair: {source_index, target_index} and carries max_span_km, span_km, limit_env, engine_setting and self_host_docs

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

502Upstream routing engine failed

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 Matrix

Generated from https://api.mapmap.ai/openapi.json on 2026-11-12 · operationId post_matrix