Meridian Atlas for servers (TypeScript)

@meridianatlas/api calls the Meridian Atlas service from your own servers: routes with turn-by-turn guidance, multi-stop routes, route matrices, traffic on a route, Places, speed cameras, roads near a point, navigation legs and stop order optimisation. Node.js 20 or later (any runtime with fetch works).

Shell
npm install ./meridianatlas-api-0.1.0-rc.6.tgz   # the release archive

Getting started

TypeScript
import { AtlasClient } from "@meridianatlas/api";

const atlas = new AtlasClient({
  apiKey: process.env.ATLAS_API_KEY!,  // a server key
  baseUrl: process.env.ATLAS_BASE_URL, // unset: https://api.meridianatlas.dev (ATLAS_DEFAULT_BASE_URL)
});

const result = await atlas.route({
  origin: [-2.2426, 53.4808],
  destination: [-2.1165, 53.5444],
  profile: "quickest",
  traffic: "aware",
});

console.log(result.data.distanceMetres, result.usage.units);
for (const step of result.data.guidance) console.log(step.atMetres, step.instruction);

Use a server key and keep it in a secret store, never in an app or a web page. App keys (made in Atlas Studio for named iOS and Android apps) are refused here with app_not_allowed: the mobile SDKs send the app identity they need. The base URL defaults to https://api.meridianatlas.dev. That domain isn't live yet: until it is, beta partners set ATLAS_BASE_URL to the address Meridian gave them. It must use HTTPS; plain HTTP is accepted only for localhost, 127.0.0.1 and [::1], for development. Every request sends your key as X-Atlas-Key and the package version as Atlas-Client: typescript/0.1.0-rc.6.

Every call returns { data, usage }: usage.units and usage.operation say what was charged, and usage.requestId identifies the request for support.

What it does

MethodKey featureCharged
route(request)core_routingone route (a reroute inside a navigation leg: none, under navigation)
orderedMultiStopRoute(request)core_routingone route per leg
routeMatrix(request)route_matrixone unit per resolved cell (a pair with no route is free)
trafficAdvisory(request)trafficone advisory
autocomplete, searchText, searchNearby, place, placePhotoplacesone call each
cameraWindow(request)safety_camerasone call
roadsNearby(centre, radiusM)road_attributesone lookup
startNavigationLeg(destination), endNavigationLeg(legId, reason)navigationone leg (a multi-stop route: one per stop, atlasMultiStopLegDestinations); ending is free
submitStopOptimization, stopOptimizationStatus, stopOptimizationResultfleet_optimizationone unit per stop in the job

Routes come back with guidance (each step has atMetres and a ready-to-speak instruction, with lanes and signposts), speedSections and the route polyline. Lane advice says where it comes from (mapped, inferred or none); a missing lane instruction is never guessed.

Turn-by-turn guidance to one destination is one leg. Start a leg when guidance starts, send its legId with each reroute to the same destination, and end it on arrival:

TypeScript
const { data: leg } = await atlas.startNavigationLeg([-2.638245, 53.541728]);
await atlas.route({ origin: here, destination: [-2.638245, 53.541728], profile: "quickest", legId: leg.legId });
await atlas.endNavigationLeg(leg.legId, "arrived");

A reroute must keep the leg's destination (within 50 m), and a leg lasts 24 hours (leg.expiresAt). A new destination is a new leg: otherwise the reroute fails with leg_destination_mismatch, and one with an ended or expired leg with leg_invalid.

A multi-stop route is a leg per stop, as the Atlas SDK sessions register them: the first when guidance starts, each later one when the driver leaves the stop before it, each ended on arrival. A run stopped at a stop never starts, and is never charged, the next leg. A reroute heads for the next stop with that stop's leg:

TypeScript
import { atlasMultiStopLegDestinations } from "@meridianatlas/api";

const { data: run } = await atlas.orderedMultiStopRoute({ requestId: "run-17", profile: "quickest", stops });
const legs = atlasMultiStopLegDestinations(run); // [{ legIndex, stopId, destination }], one per stop after the first
const { data: first } = await atlas.startNavigationLeg(legs[0].destination);

Roads near a point

TypeScript
const { data } = await atlas.roadsNearby([-2.2426, 53.4808], 1000); // radius 50 to 2000 m
for (const road of data.roads) console.log(road.name, road.ref, road.maxspeed); // "Deansgate", "A56", "30 mph"

Speed limits are as OpenStreetMap tags them; null is unknown, never a guess.

Places

Reuse one session token from the first keystroke to the pick, and ask only for the fields the screen needs:

TypeScript
const sessionToken = crypto.randomUUID();
const suggestions = await atlas.autocomplete(
  { input: "coffee near Wigan", sessionToken },
  { fields: ["suggestions.placePrediction.placeId", "suggestions.placePrediction.text"] },
);
// A suggestion is a placePrediction (a place to pick) or a queryPrediction (a search to run).
const prediction = suggestions.data.suggestions.find((s) => s.placePrediction)?.placePrediction as { placeId: string } | undefined;
if (prediction) {
  const place = await atlas.place(prediction.placeId, { fields: ["id", "displayName", "formattedAddress", "location", "photos"], sessionToken });
  const [photo] = (place.data.photos ?? []) as Array<{ id: string }>;
  if (photo) await atlas.placePhoto(prediction.placeId, photo.id, { maxWidthPx: 800 });
}

Text and nearby search page with nextPageToken: pass it back as pageToken unchanged. Place IDs are stable. Cache photos by their ETag and show the attribution returned with the place.

Errors

A refusal from the service is an AtlasApiError; a request that got no answer is an AtlasTransportError. code is the same on every Atlas SDK:

CodeMeaning
missing_api_keyThe key passed to AtlasClient is empty (an AtlasConfigurationError, thrown before sending)
invalid_requestThe request was refused as malformed
invalid_api_keyThe key is wrong, revoked or expired
capability_requiredThe key doesn't have this feature; capability names it
app_not_allowedAn app key, which only works from the apps listed on it
billing_inactive, usage_policy_required, usage_allowance_exhaustedThe account can't be charged for this call
rate_limitToo many requests; retryAfterSeconds says when to try again
outside_coverageThe origin or destination is outside the area Atlas routes (the UK at launch)
route_unresolvedNo route between those points
leg_invalid, leg_destination_mismatch, leg_not_foundThe navigation leg can't be used: start a new one
wrong_service_addressSomething answered at baseUrl, but not the Atlas service
request_timeout, network_errorNo answer in time, or no connection (AtlasTransportError)
invalid_responseThe answer couldn't be read
service_errorAnything else; status has the HTTP status

serverCode keeps the service's own code (for example validation or billing_required), and requestId identifies the request for support. Every message says what to fix and ends with a link to the code's entry in Errors; retryable says whether trying again later can work (no connection, a timeout, a rate limit after retryAfterSeconds, a 5xx).

TypeScript
import { AtlasApiError, AtlasTransportError } from "@meridianatlas/api";

try {
  await atlas.routeMatrix(request);
} catch (error) {
  if (error instanceof AtlasApiError && error.code === "capability_required") {
    console.error(`Turn on ${error.capability} for this key`);
  } else if (error instanceof AtlasTransportError) {
    console.error(error.code); // request_timeout or network_error
  } else {
    throw error; // your own cancellation stays an AbortError
  }
}

Retries, deadlines and cancellation

Billed calls send an Idempotency-Key. Pass { idempotencyKey } (a UUID) and use the same one when you retry, so a request that did arrive counts once; traffic uses its requestId. Every request has a 30-second deadline by default: set timeoutMs on the client (1 to 300000) or on one call. Pass the AbortSignal of the request you are serving as signal, so Atlas work stops when your caller goes away. Redirects are refused, so the key never follows one, and answers are limited to 4 MiB (photos 16 MiB).

Opt-in methods

resolveArrivalCandidate and arrivalCandidateApproach answer where to stop at a large destination (an airport, a hospital); they work only for accounts set up for them. route with ferryMode: "historical_replay" and a past departureTime replays ferry timetables; current ferry crossings are not planned yet.

Proposal · draft