# Elevation, and why grade matters more than distance

`POST /elevation` samples terrain height for up to 500 coordinates, and `POST /elevation/along` returns a profile down a route with the percent grade of every segment plus whole-route ascent and descent. Where our terrain tiles have no coverage, `elevation_m`, `source` and `resolution_m` come back null together, never an interpolated guess. Both are switched on for anyone calling `api.mapmap.ai`. In the self-host distro they answer 501 until the operator stages terrain tiles and sets `SN_ELEVATION_ENABLED`, because they are useless without them and we would rather say so than serve zeroes.

## Why does grade matter more than distance?

Because for a loaded vehicle, a bicycle or a battery, the work is in the climb and the risk is in the descent, and neither is visible in a distance figure. A 3 km leg is a 3 km leg whether it is flat or averages 9%, but the second one changes the fuel burn, the brake temperature at the bottom, the range estimate and, for a cyclist, whether the route is usable at all.

Three cases we hear about repeatedly:

- **Cycling.** A router can prefer flat ways, but a rider planning a day wants the profile before they commit. Our routing engine exposes a `use_hills` weight from 0 to 1 on bicycle and pedestrian costing, which biases the choice of route using grade stored in the routing graph; we have proven that grade is there across Europe. In Bath on 25 November 2026, a 3.19 km bicycle route with `use_hills: 0` came back as a different, 3.35 km route with `use_hills: 1`. The profile endpoint is the other half: it tells you what you actually got.
- **Trucks.** Gradient governs achievable speed on the climb and brake strategy on the descent, and a long steep descent is a different operational risk from a long flat run. This sits alongside the dimensional and ADR limits already enforced in [truck costing](/news/truck-routing-dimensions).
- **Electric range.** Net ascent is a first-order term in consumption, and it is asymmetric because regeneration recovers only part of the descent. Total ascent over a route is a better range input than route length, which is why our [EV charge-stop planner](/news/ev-charge-stop-planner) models consumption over the route's own gradient and says, in `gradient_data`, when elevation was missing and it fell back to the flat.

## What do the two endpoints return?

Point elevation returns one result per input point, in order, each carrying its own provenance:

```sh
curl -fsS -X POST "https://api.mapmap.ai/elevation" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"points": [{"lat": 56.796889, "lon": -5.003599},
                  {"lat": 45.832622, "lon": 6.865175}]}'
```

```json
{"attribution": "Terrain data Mapzen, AWS Open Data. Built from open elevation sources that require credit, and modified; the credits are at attribution_url",
 "attribution_url": "https://mapmap.ai/legal/terrain-credits",
 "results": [
  {"lat": 56.796889, "lon": -5.003599,
   "elevation_m": 1332.99, "source": "mapzen-terrain-tiles", "resolution_m": 30.0},
  {"lat": 45.832622, "lon": 6.865175,
   "elevation_m": 4791.57, "source": "mapzen-terrain-tiles", "resolution_m": 30.0}
]}
```

Those are Ben Nevis and Mont Blanc, captured on 25 November 2026, and both read about a dozen metres under their surveyed summit heights (1,345 m and about 4,806 m), which is what a 30 m sampling grid does to a peak. That is the point of returning `resolution_m` next to the value rather than the value alone.

The profile endpoint takes a route, either as `geometry_polyline6` or as `route`, the whole `{"trip": …}` object that `POST /route` gives back, and at most one of `interval_m` (default 100 m) or `sample_count`:

```sh
curl -fsS -X POST "https://api.mapmap.ai/route" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"locations": [{"lat": 51.3811, "lon": -2.3590}, {"lat": 51.3700, "lon": -2.3300}],
       "costing": "bicycle"}' > route.json

curl -fsS -X POST "https://api.mapmap.ai/elevation/along" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"route\": $(cat route.json), \"interval_m\": 200}"
```

It returns `samples[]` of `{distance_m, lat, lon, elevation_m, source, resolution_m, grade_percent}`, plus `total_distance_m`, `total_ascent_m`, `total_descent_m`, `coverage_fraction`, `sample_count` and the same attribution fields. For that ride out of central Bath it came back with 17 samples over 3,187.5 m, 154.0 m of ascent, 10.9 m of descent and a `coverage_fraction` of 1.0. Three details in that shape are deliberate:

- `grade_percent` on sample `i` is the grade of the segment **ending** at `i`, computed as rise over run times 100 and rounded to one decimal place. Sample 0 is always null, because it has no preceding segment.
- Any sample whose segment has an endpoint without elevation gets a null grade rather than a grade computed across a hole.
- `total_ascent_m` and `total_descent_m` are null, not zero, when no consecutive pair of samples both have height. Zero would be a claim that the route is flat. Null is the truth, which is that we do not know.

`coverage_fraction` tells you how much of the profile is real, so a caller can decide whether to trust a range estimate built on it.

## Where does the terrain data come from?

The AWS Open Data terrain tiles, staged on our own disk in Valhalla's native skadi layout. They are the Mapzen and tilezen composite, drawing per cell on SRTM, EU-DEM and others, at roughly 30 m ground resolution over our coverage, which is why the deployment declares `SN_ELEVATION_RESOLUTION_M=30` and echoes it on every sample. The hosted API now carries the whole set: worldwide land from 71°N to 56°S, 32,960 one-degree cells. Cells are sampled lazily per request, so extending coverage on a self-hosted deployment needs no graph rebuild and no restart. Ocean-only cells do not exist upstream, are skipped, and read back null.

We serve looked-up heights, never the tiles themselves, so there is no redistribution of the source data. Attribution follows the upstream per-source terms rather than a single blanket licence, and that is recorded in our data lineage rather than paraphrased here. The web SDK's 3D terrain and hillshading default to that same Mapzen set, served through `https://mapmap.ai/terrain/{z}/{x}/{y}.png`, a sanitising proxy that replaces the set's rare corrupt tiles with a clean 0 m tile. A rendered map and an elevation query therefore agree with each other instead of disagreeing by a dataset.

The `source` field is operator-declared, not inferred. If a deployment stages tiles but sets no `SN_ELEVATION_DATASET`, samples that got a real height are labelled `self-hosted-dem`: true, self-hosted, and not overclaiming a provider we cannot verify from inside the engine. If `SN_ELEVATION_RESOLUTION_M` is unset, `resolution_m` stays null even where the height is present, because the engine does not report per-tile provenance and a guess would be worse than a gap.

## What does it cost?

Standard class, which is 0.05p per call at the entry band, falling to 0.03p beyond 1M calls a month and 0.02p beyond 10M, exactly as on the [pricing page](/pricing). Neither elevation path is ever classified premium.

The unit rules match `/matrix`'s pattern of billing by size rather than by request:

| Request | Billable units |
|---|---|
| `POST /elevation` | one call per started block of 25 points, maximum 500 points |
| `POST /elevation/along` | a flat 5 calls |

The profile bills flat because the sample count depends on route length and interval, neither of which is knowable from the request body the way a bare `points` array is. Five calls of Standard is well under `/matrix`'s worst case, and the engine's own shape limit of 2,000 samples bounds the work regardless. `sample_count` must be between 2 and 2,000, and an `interval_m` that would exceed that is clamped rather than rejected, so a very long route degrades to coarser sampling instead of failing.

## What it does not do

- **These endpoints do not feed costing.** They read the terrain tiles directly and lazily, with no graph rebuild involved, so measuring a climb with them does not make the next route avoid it. Hill avoidance is a different mechanism: `use_hills` acts on grade written into the routing graph when it was built, and we have proven that grade across Europe only (latitude 34 to 71, longitude -25 to 44). Outside Europe we have not verified it, so treat `use_hills` there as unproven until we say otherwise. Wheelchair routes on `POST /route` carry a `grade` block sampled from the same terrain, which reports a route's climb rather than choosing it.
- **Coverage is whatever has been staged.** On `api.mapmap.ai` that is worldwide land, 71°N to 56°S. On a self-hosted deployment it is whatever cells the operator staged, and outside them every sample reads null, honestly, with `coverage_fraction` reporting how much of a profile was real. Antarctica is absent from the upstream tile set altogether, so nothing below 56°S resolves at all rather than pretending it might. Open water has no tiles either, so a null mid-ocean is the format working rather than a gap. Check `coverage_fraction` on a route you care about before you build a range estimate on top of it.
- **Off by default when you self-host.** A self-hosted gateway answers 501 with `elevation-not-enabled` until the operator stages tiles and sets `SN_ELEVATION_ENABLED=true`. That is deliberate: an endpoint that silently returns nothing useful is worse than one that refuses. The hosted API has both done already.
- **A 30 m grid is a 30 m grid.** Summits read low, narrow cuttings and embankments are smoothed, and a bridge deck reads as the terrain beneath it. For engineering work, use surveyed data.

## Try it

Route first, then profile the result: `POST /route`, hand the whole response straight to `POST /elevation/along` as `route`, and read `total_ascent_m` next to `duration_s`. The [API reference](/docs/api-reference) has both request shapes in full, and the [matrix write-up](/news/matrix-api) explains the size-metered billing pattern that elevation follows. If you are self-hosting, stage the terrain tiles for your region before you enable the endpoints, and check `coverage_fraction` on a route you know.

Routing derives from OpenStreetMap. Credit "© OpenStreetMap contributors" when you render or republish it.
