# Cheapest fuel along a route, with the detour priced

A forecourt selling diesel a few cents a litre below the pump on your route is not cheaper if reaching it costs ten minutes. MapMap's `cheapest_fuel_along_route` tool, and the `POST /v1/fuel/along` endpoint behind it, rank fuel stations along a route cheapest first from live open-data price feeds, and attach to every station the real extra driving time the stop costs, computed by the routing engine rather than measured as a straight line. Each result also carries what it saves against the cheapest station already on the route, so the ranking can be argued with.

## How is the detour actually calculated?

The detour is three engine-computed legs, not a distance from the route line: `detour = (origin → station) + (station → destination) − (origin → destination)`. All three terms come from the same matrix pass with your costing, so they share one estimator and the subtraction is meaningful. That origin to destination term is published as `route.detour_baseline_s`, next to `route.duration_s`, the path search's own answer for the same journey, because the two engine computations can differ by a few seconds and only one of them is the route you would get. The straight-line offset is still reported as `off_route_m` because it is useful context, but nothing is ranked, filtered or sold on it.

The gap between the two numbers is the whole point. In a live Paris to Lyon diesel call on 25 November 2026, the top station sat 75 m from the route line and cost 9.7 minutes to reach, because 75 m away on the far side of a motorway is not the same as 75 m away by road. On Oxford to Manchester the opposite happened: an Asda 1,148 m off the line cost no detour at all, because it lies on the way into the destination. A crow-flies ranking gets both of them wrong.

Candidates are pre-filtered along the corridor with a straight-line lower bound that cannot overestimate a real detour, so nothing reachable is dropped before costing. Then the 25 candidates **nearest the route by that bound** go through the matrix, and the response says so in `candidates.selection: "nearest-by-lower-bound"`. Price ranks what comes back; it does not decide who gets costed. Until 5 November the cap kept the 25 cheapest instead, and on long routes that spent the whole matrix on cheap stations well off the line and returned nothing while a fresh station sat on the corridor.

## Where do the prices come from?

National open-data feeds, ingested by our `sn-fuel` crate into one normalised station-price dataset:

| Source | Feed | Licence | Access |
|---|---|---|---|
| `fr` | prix-carburants "instantané" (roulez-eco.fr) | Licence Ouverte | open, no key |
| `de` | Tankerkönig `list.php` | CC BY 4.0 | free API key |
| `uk-fuelfinder` | statutory Fuel Finder API (fuel-finder.service.gov.uk) | statutory open data | OAuth registration credentials |
| `uk` | retailer endpoints of the closed CMA interim scheme, kept as a fallback | retailers' own feeds | open, no key |

The UK has two sources, they are never merged, and the attribution tells you which one answered. The statutory Fuel Finder feed is the primary source and is preferred. Its endpoint refuses our hosted gateway's datacentre address, so it is fetched from outside the datacentre and the snapshot pushed in, and the gateway's 10-minute refresh uses it while it is under three hours old. Otherwise UK prices fall back to the retailer feeds, which our box can reach for some retailers and not others. That is what answered on 25 November: the `coverage` block named seven retailers (Asda, Rontec, Esso, Applegreen, Moto, Jet and Morrisons) and 1,374 UK stations, set `uk_partial: true`, and the response credited `UK retailer scheme (CMA)`, which is who that data belongs to.

Every source product is mapped onto one small set of codes: `diesel` (the default), `petrol_95`, `petrol_98`, `premium_diesel`, `e85` and `lpg`, with the friendly aliases `petrol`, `unleaded`, `e10`, `super_unleaded`, `e5`, `b7` and `sdv` accepted on the wire. Where a feed publishes both an E5 and an E10 price for the same grade, the E10 blend wins, because that is the standard 95 RON product.

Refresh is the operator's fetch timer, not a stream (Tankerkönig's terms require at least 5 minutes between polls), so the API is exactly as fresh as the last `sn-fuel fetch` snapshot.

## What does a result look like?

Here is a real call on 25 November 2026, diesel from Berlin to Hamburg with a 15-minute detour budget:

```sh
curl -fsS -X POST "https://api.mapmap.ai/v1/fuel/along" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"origin": {"lat": 52.52, "lon": 13.405}, "destination": {"lat": 53.5511, "lon": 9.9937},
       "fuel": "diesel", "max_detour_minutes": 15}'
```

And the answer, trimmed to the first two of five results and without the `coverage` block:

```json
{
  "fuel": "diesel",
  "costing": "auto",
  "route": {
    "duration_s": 10465.541, "distance_m": 289584.0, "length_m": 289266.0,
    "detour_baseline_s": 10462.0, "detour_baseline_m": 289588.0
  },
  "max_detour_minutes": 15.0,
  "candidates": { "considered": 563, "costed": 25, "cap": 25, "selection": "nearest-by-lower-bound" },
  "baseline": {
    "EUR": { "value": 1.979, "brand": "ARAL", "name": "Aral Tankstelle",
             "station_id": "e78510fb-5292-4c50-837f-f55a17a4111a",
             "updated_at": "2026-11-25T16:30:39.133151714Z", "stale": false }
  },
  "results": [
    { "station_id": "92b37d44-73f5-417a-a838-e3c8ca480433", "source": "de",
      "brand": "Freie", "name": "Großtankstelle Kurt Meinen + Söhne",
      "lat": 53.56529, "lon": 10.0413,
      "price": { "value": 1.949, "currency": "EUR",
                 "updated_at": "2026-11-25T16:30:39.133151714Z",
                 "fetched_at": "2026-11-25T16:30:39.133151714Z" },
      "stale": false, "detour_minutes": 2.9, "detour_s": 176.0, "detour_km": 1.58,
      "along_route_position": 0.983, "off_route_m": 501.0, "saving_per_litre": 0.03 },
    { "station_id": "005056ba-7cb6-1ed2-bceb-ad79c434cd45", "source": "de",
      "brand": "STAR", "name": "star Tankstelle", "lat": 53.555, "lon": 10.01002,
      "price": { "value": 1.959, "currency": "EUR",
                 "updated_at": "2026-11-25T16:30:39.133151714Z",
                 "fetched_at": "2026-11-25T16:30:39.133151714Z" },
      "stale": false, "detour_minutes": 0.5, "detour_s": 29.0, "detour_km": 0.05,
      "along_route_position": 0.996, "off_route_m": 387.0, "saving_per_litre": 0.02 }
  ],
  "say": "Cheapest diesel is Freie, three cents a litre below the best price on your route, and it adds three minutes.",
  "fuel_attribution": "Fuel prices: tankerkoenig.de CC BY 4.0 (DE)"
}
```

Read the top two results together and the ranking argues with itself: the first is 0.03 EUR a litre cheaper for 2.9 minutes, the second 0.02 EUR cheaper for 29 seconds. On a 60-litre fill that is 1.80 EUR against 1.20 EUR, and a driver in a hurry takes the second. The API's job is to hand you both numbers rather than to hide the second one behind a price sort. Pass `fill_litres` and each result also carries `saving_total`, the per-litre saving multiplied out. `say` is the whole answer as one spoken line, ready for a voice client.

`baseline` is the cheapest station within 150 m of the route geometry that also passed the detour filter, the "just pull in" option, so a saving is never quoted against a station the results could not contain. It is kept per currency, so a route across a border never subtracts pence from cents. When no station sits on the route itself there is no baseline and no `saving_per_litre`.

Defaults and caps: `max_detour_minutes` defaults to 10 and is capped at 120, `max_results` defaults to 5 and is capped at 25, `fill_litres` is capped at 1000.

## Does a truck profile change the answer?

Yes. Pass `costing: "truck"` with an `adr` vehicle profile and the route, the detour matrix and therefore the whole ranking respect dimensional and ADR restrictions, in the same costing that our [truck routing with dimensions enforced in costing](/news/truck-routing-dimensions) uses. The Berlin to Hamburg call above, repeated as a 40-tonne hazmat vehicle at 4 m with tunnel code C and `fill_litres: 400`, took 12,089 s against the car's 10,466 s, considered 464 stations rather than 563, and costed every detour at truck speeds: the same Freie station now cost 4.7 minutes rather than 2.9, and its 0.03 EUR a litre came back as a `saving_total` of 12 EUR.

That is the case where this endpoint is worth wiring in. A car saving 1.80 EUR is noise. A tanker fleet saving 12 EUR a fill, on a stop the router has costed with the vehicle's own restrictions, is a line on a budget.

## What does the call cost?

A flat block of 10 calls of its class, whatever the fan-out, because one request triggers up to one internal route and two matrix calls that are not metered again. At the entry band that is 0.5p for a standard request and 10p when the body carries truck costing or an `adr` profile, which classifies as Premium exactly like `/matrix`. Rates step down with monthly volume; [/pricing](/pricing) is authoritative.

## What it does not do

**It only covers countries with a statutory or open price feed.** France, Germany and the United Kingdom, and that is the list. All three are live on our hosted gateway. Anywhere outside them the request still succeeds and returns nothing, with a `note` that says why. Feature-detect, do not assume.

**UK coverage can be partial, and the response says so.** When the Fuel Finder snapshot is stale and the retailer fallback answers, forecourts run by retailers outside that list are simply not in the dataset. The `coverage.statement` names the retailers and their station counts, so an empty UK answer reads as "none from these retailers", never "no fuel here". Show it with any UK result. We learned why the hard way: for the first weeks UK routes returned zero candidates with a 200 because the fetch script's UK leg appended a file nothing ever wrote, while every operational signal looked healthy. Hence `coverage` on every response, and a plain-language `note` naming the cause on every empty one, never a bare `[]`.

**Prices are as reported by the retailer.** We publish what the feed says, and a feed can be wrong, rounded oddly, or attached to a forecourt that closed at lunchtime. Every price carries its source `updated_at` verbatim (a UK retailer feed writes `25/11/2026 08:59:36`, the German feed an ISO timestamp) and a `stale` flag. `stale` is `false` only when both the retailer's own `updated_at` and our fetch of the snapshot are within 24 hours, so a recent fetch of an old price is still stale, and a timestamp we cannot parse counts as stale. A stale price ranks below every fresh one, is never the baseline and claims no saving. A client that ignores the flag is quoting a driver a number nobody stands behind.

**The 25-candidate cap can still return an empty list.** If even the 25 stations nearest the route all fall outside your detour budget, you get zero results. Widen `max_detour_minutes` and re-ask. A journey whose matrix would span more than the engine's limit (1,500 km on motor costings on our hosted gateway, 400 km on a stock self-host) is refused with a `422 matrix-span-too-large` rather than half-answered.

**Attribution is a licence obligation, not a courtesy.** Responses that return any station carry a `fuel_attribution` string naming the sources actually matched, for example `Fuel prices: tankerkoenig.de CC BY 4.0 (DE)` or `Fuel prices: UK retailer scheme (CMA)`. Each scheme credits itself and a mixed dataset lists every source matched: crediting a statutory service for data taken from retailers' own feeds would misstate provenance, so we do not. Display the string wherever you display the prices. If you plot the stations on a map, the routing and the map both derive from OpenStreetMap, so credit © OpenStreetMap contributors as well.

**Self-hosted deployments have to opt in.** With no price dataset configured the endpoint answers `501` with `urn:sn-gateway:problem:fuel-not-enabled` and names the setting the operator needs. That is the same feature-detection contract as our other optional datasets, and it is deliberate: a silent empty list would be indistinguishable from a country with no cheap fuel.

## Try it

The tool is on the hosted MCP server at `https://mcp.mapmap.ai/mcp`, which needs no key to connect. Point Claude, Cursor or your own agent at it and ask for the cheapest diesel between two places, then read `detour_minutes` before you believe the ranking. The full parameter list is in the [MCP tool reference](/docs/mcp), the HTTP contract is in [cheapest fuel along a route](/docs/analysis#cheapest-fuel-along-a-route-post-v1fuelalong), and the matrix that prices every candidate is the same one described in [our matrix API post](/news/matrix-api).
