🧭 OSRM Routing API

Driving distance, travel time and the route line between places. Built on OSRM, with a safe fallback so your app never gets stuck.

Quick start

  1. Ask the administrator for an API key (support@example.com). It looks like osrm_live_… and is shown only once, so keep it safe.
  2. Send it in the Authorization header with every request.
  3. Ask for a route:
curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://www.api.fastride.pk/v1/route?from=31.5204,74.3587&to=33.6844,73.0479"

Answer:

{ "distance_km": 294.48, "duration_min": 298.2, "geometry": null, "source": "osrm" }

Base URL: https://www.api.fastride.pk/v1 · Everything is https, JSON in and out, lat,lng order for the coordinates you send.

Authentication

Every request needs your API key. Use either header (the first is preferred):

Authorization: Bearer osrm_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X-Api-Key: osrm_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Keep the key secret. Do not put it in a public web page or in code you share. Call the API from your server or from an app you control. If a key leaks, ask the administrator to revoke it and issue a new one.

Route

GET or POST /v1/route

The driving distance and time between two places, or through several places in order (pickup → stop → drop-off).

ParameterRequiredDescription
fromyes*Start as lat,lng, e.g. 31.5204,74.3587
toyes*End as lat,lng
pointsyes*Instead of from/to: 2 to 10 points, lat,lng separated by semicolons: 31.52,74.35;32.1,73.9;33.68,73.04
geometryno1 to also get the line to draw on a map (GeoJSON). Default 0.

* send either from and to, or points. With POST you can send JSON instead:

POST /v1/route
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY

{ "points": [[31.5204, 74.3587], [32.1, 73.9], [33.6844, 73.0479]], "geometry": true }

Health

GET /v1/health – is the routing server up?

{ "status": "ok", "osrm": "up", "time": "2026-11-16T10:00:00+00:00" }

If osrm is down, route requests still work but answer with a straight-line estimate ("source": "estimate").

Usage

GET /v1/usage – your limits and what is left. These calls count as requests too.

{
  "user": "Acme Delivery",
  "limits":    { "per_minute": 60, "per_day": 5000, "per_month": 100000 },
  "used":      { "last_minute": 3, "today": 120, "this_month": 4310 },
  "remaining": { "per_minute": 57, "today": 4880, "this_month": 95690 }
}

0 in a limit means unlimited (and remaining is then null).

Response format

FieldTypeMeaning
distance_kmnumberRoad distance in kilometres (2 decimals).
duration_minnumberExpected driving time in minutes. OSRM knows no live traffic, so its time is increased by a traffic factor (default 1.25).
geometryobject | nullWith geometry=1: a GeoJSON LineString. Its coordinates are [lng, lat] (GeoJSON order), unlike the lat,lng you send.
sourcestringosrm = a real road route. estimate = the routing server did not answer, so the straight-line distance × 1.35 at 25 km/h was used. Treat estimates as approximate.

Every response has these headers: X-RateLimit-Limit, X-RateLimit-Remaining, X-Quota-Daily-Remaining, X-Quota-Monthly-Remaining.

Errors

Errors are JSON with a machine-readable code:

{ "error": { "code": "rate_limited", "message": "Too many requests: your limit is 60 per minute. ..." } }
HTTPcodeWhat to do
401missing_keySend your key in the Authorization header.
401invalid_key / revoked_keyThe key is wrong or was revoked. Ask for a new one.
403account_suspendedYour account is suspended. Contact the administrator.
404unknown_actionUse route, health or usage.
422bad_points / bad_coordinateCheck the coordinates: lat,lng, latitude −90…90, longitude −180…180, between 2 and 10 points.
429rate_limitedToo many requests this minute. Wait for Retry-After seconds.
429daily_quota_exceeded / monthly_quota_exceededYour quota is used up. It resets at midnight (daily) or on the 1st (monthly).

Limits & quotas

Each account has three limits, set by the administrator: requests per minute, per day and per month. Only successful requests (status below 400) count. Check /usage or the response headers to see where you stand. All keys of one account share the same limits.

Need more? Ask the administrator to raise your limits.

Code examples

# distance and time
curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://www.api.fastride.pk/v1/route?from=31.5204,74.3587&to=33.6844,73.0479"

# with the line to draw on a map
curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://www.api.fastride.pk/v1/route?from=31.5204,74.3587&to=33.6844,73.0479&geometry=1"

# through three places
curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://www.api.fastride.pk/v1/route?points=31.52,74.35;32.1,73.9;33.68,73.04"
const res = await fetch('https://www.api.fastride.pk/v1/route?from=31.5204,74.3587&to=33.6844,73.0479&geometry=1', {
  headers: { Authorization: 'Bearer ' + process.env.OSRM_API_KEY },   // call from your server, not from a public web page
});
if (!res.ok) throw new Error((await res.json()).error.message);
const route = await res.json();
console.log(route.distance_km, 'km', route.duration_min, 'min', route.source);
import os, requests

r = requests.get("https://www.api.fastride.pk/v1/route",
                 params={"from": "31.5204,74.3587", "to": "33.6844,73.0479", "geometry": 1},
                 headers={"Authorization": "Bearer " + os.environ["OSRM_API_KEY"]}, timeout=15)
r.raise_for_status()
route = r.json()
print(route["distance_km"], "km", route["duration_min"], "min", route["source"])
$ch = curl_init('https://www.api.fastride.pk/v1/route?from=31.5204,74.3587&to=33.6844,73.0479');
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('OSRM_API_KEY')]]);
$route = json_decode(curl_exec($ch), true);
echo $route['distance_km'] . ' km, ' . $route['duration_min'] . ' min';

// Laravel:  Http::withToken(env('OSRM_API_KEY'))->get('https://www.api.fastride.pk/v1/route', ['from' => '31.5204,74.3587', 'to' => '33.6844,73.0479'])->json();
final res = await http.get(
  Uri.parse('https://www.api.fastride.pk/v1/route?from=31.5204,74.3587&to=33.6844,73.0479&geometry=1'),
  headers: {'Authorization': 'Bearer $apiKey'},
);
final route = jsonDecode(res.body);
final km = route['distance_km'];
// route['geometry']['coordinates'] is a list of [lng, lat] pairs for a polyline

Try it

The answer appears here.
The key is only used in your browser to make this one request. It is never stored.

Good practice

  • Check source. If it is estimate, show the number as approximate or retry a little later.
  • Cache answers for popular routes for a few minutes: it saves your quota.
  • Handle 429 by waiting for the Retry-After seconds, never by retrying in a tight loop.
  • Draw the line only when you need it (geometry=1 makes the answer larger).
  • Keep the key in an environment variable or a secrets store, never in source code.

Support

Questions, more quota or a new key? Write to support@example.com. Please include your account email and, for a problem, the time of the request and the error code.

Machine-readable description: openapi.json (OpenAPI 3)