Journey planning
GET /v1/journeys plans a trip by public transport from one point to another: walk to a stop, ride, perhaps change, ride again, walk to the destination. It searches a loaded GTFS timetable with RAPTOR (Delling, Pajor and Werneck, 2012) and answers the fastest journey for each number of changes — so a rider can choose between arriving earlier and changing less.
curl -G "https://api.oslew.com/v1/journeys" \
-H "Authorization: Bearer $GEO_API_KEY" \
--data-urlencode 'from=37.7928,-122.3971' \
--data-urlencode 'to=37.8035,-122.2716' \
--data-urlencode 'time=1787756400' \
--data-urlencode 'limit=2'from oslew import Client
# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")
answer = client.journeys(
"37.7928,-122.3971",
"37.8035,-122.2716",
time=1787756400,
limit=2,
)import { Client } from "@oslew/client";
// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });
const answer = await client.journeys("37.7928,-122.3971", "37.8035,-122.2716", { time: 1787756400, limit: 2 });HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 291
ratelimit-reset: 1
{
"from": [
37.7928,
-122.3971
],
"to": [
37.8035,
-122.2716
],
"time": 1787756400,
"timezone": "America/Los_Angeles",
"live": null,
"journeys": [
{
"depart": 1787756445,
"arrive": 1787757604,
"duration_s": 1159,
"transfers": 0,
"walk_m": 568.7634161971366,
"legs": [
{
"mode": "walk",
"from": [
37.7928,
-122.3971
],
"to": [
37.789143,
-122.401558
],
"distance_m": 564.6342163085938,
"duration_s": 435
},
{
"mode": "ride",
"route": 7,
"route_short_name": "Red-N",
"headsign": "SFO / SF / Richmond",
"trip_id": "1965673",
"from_stop": 61,
"to_stop": 40,
"board": 1787756880,
"alight": 1787757600,
"stops": 3
},
{
"mode": "walk",
"from": [
37.803463,
-122.271596
],
"to": [
37.8035,
-122.2716
],
"distance_m": 4.129199888542818,
"duration_s": 4
}
]
}
],
"provenance": {
"name": "bart",
"release": "2026-08-19.0",
"license": "BART developer terms"
},
"took_us": 579
}A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.
From Embarcadero to downtown Oakland, leaving at or after 08:00 on a Wednesday: one journey, with no changes. Walk 565 m (435 s), board a Red-N train at 08:08, ride three stops, get off at 08:20, walk 4 m. Leave at 08:00:45, arrive at 08:20:04, 1,159 s in all. The request allowed two journeys and got one, because no journey with a change arrived any earlier.
Look at the first walk. The origin is 10 m from Embarcadero's northbound platform, where this same Red-N train calls moments later; the journey walks instead to the stop before it on the line, 565 m away. The arrival is the earliest there is, but the walk and the leaving time are not what a rider would choose. The planner boards a trip at the first stop along its line that the walk reaches, and does not yet prefer a later boarding of the same trip that walks less. Read depart and the first walk with that in mind.
Parameters
| Parameter | Default | Is |
|---|---|---|
from, to | required | The two ends, each lat,lon. |
time | now | Unix seconds: leave at or after this. |
max_transfers | 3 | The most changes a journey may make; at most 6, and larger values are held to 6. 0 allows only journeys on one vehicle. |
walk_m | 800 | How far a rider will walk to the first stop and from the last, metres in a straight line. Clamped to 0–2,000. |
limit | 5 | At most this many journeys. Clamped to 1–10. |
The fastest journey for each number of changes
The answer is a Pareto set: every journey in it is the earliest arrival for its number of changes, and a journey is left out if another arrives no later with no more changes. In order, the first arrives earliest; each after it arrives later but changes fewer times — a set of three might arrive at 08:41 with two changes, 08:47 with one and 09:02 with none. Which is best is the rider's call, so show them all rather than only the first.
Often there is only one, as in the example, because the fastest journey is also the one with fewest changes. When the two ends are within walk_m of each other, walking the whole way is one of the answers: a single walk leg, with no changes.
Walking
Walking is part of every journey, and it is simpler than riding:
- At 1.3 m/s, about 4.7 km/h, rounded up to the whole second.
- In straight lines. Walks are not routed along streets, so a real walk is longer — most where streets are few or blocks are long. For the real path of a walk leg, ask /v1/route with
profile=walkingfrom itsfromto itsto. - Within
walk_mof each end to the first and last stops. - At most 300 m to change between two stops.
- No time added to change. A connection can be timed to the second: arrive at 08:12:00, leave at 08:12:00. On a real platform, a rider can miss that. If your riders need a margin, drop journeys whose change is tighter than you allow.
Which feed answers
One feed answers each request: the one whose nearest boarding stops to the two ends are closest, added together, with both within walk_m. A journey never combines two feeds, so a trip that needs one agency's train and another's bus is not found. Where no feed has a stop within reach of both ends, the answer is a 400,no transit feed has stops within 800 m of both ends (with your walk_m). Which feed answered is in provenance, and its time zone in timezone. Coverage depends on which feeds are loaded; the examples here are BART's.
Journeys and legs
| Field of a journey | Is |
|---|---|
depart | When to leave the origin, unix seconds: the latest that still makes the first ride. Usually later than time. |
arrive | Arrival at the destination. |
duration_s | arrive − depart. |
transfers | Changes: one fewer than the rides. |
walk_m | Metres walked in all. |
legs | In order, each a walk or a ride. |
| A walk leg | Is |
|---|---|
mode | "walk". |
from, to | [lat, lon]: the origin, a stop, or the destination. |
distance_m | Straight-line metres. |
duration_s | Whole seconds at 1.3 m/s. |
| A ride leg | Is |
|---|---|
mode | "ride". |
route_short_name | The route, as riders know it. |
headsign | Where the vehicle says it is going. |
trip_id | The feed's trip_id — the same one departures and realtime updates use. |
board, alight | When it leaves the boarding stop and reaches the alighting stop, unix seconds; live when delays apply. |
stops | How many stops the ride travels. |
route | An index into the feed's routes, not its route_id. |
from_stop, to_stop | The boarding and alighting stops, as indexes into the feed's stops — not stop_ids. |
A journey starts with a walk and ends with one, even when the walk is a few metres. Between two rides there is a walk leg when the change is between two stops, and none when both rides call at the same one. A change walk that leads straight to the destination is merged into the final walk.
Since from_stop and to_stop are indexes, the positions of the stops are the easiest handle on them: the walk before a ride ends at its boarding stop, and the walk after it starts at its alighting stop. For a stop's name, ask /v1/stops at that position with a small radius_m.
Times, service days and empty answers
Times are unix seconds; show them in the feed's timezone, not the viewer's. Trips are taken from the service day of time and, for trains running past midnight, the day before — asdepartures explains. The next service day is not searched: asked after the last train of the night, the answer is journeys: [], a 200 meaning nothing leaves in time. Ask again with a time the next morning.
Live delays
Where an operator has applied a GTFS-Realtime feed for the answering feed — see operator feeds — journeys are planned on the live times: board and alight are when the vehicle will really leave and arrive, a late train can make a connection the timetable says it would miss, and a stop the feed says a trip skips can be neither boarded nor left there. live is then the realtime feed's timestamp; null means the plan is from the timetable alone. Like any realtime feed here, it is held per server, so live is how you know which one you got.
Showing an itinerary
from datetime import datetime
from zoneinfo import ZoneInfo
from oslew import Client
client = Client(base_url="https://api.oslew.com")
answer = client.journeys("37.7928,-122.3971", "37.8035,-122.2716", limit=3)
tz = ZoneInfo(answer["timezone"])
hhmm = lambda t: datetime.fromtimestamp(t, tz).strftime("%H:%M")
for j in answer["journeys"]:
changes = "no changes" if j["transfers"] == 0 else f"{j['transfers']} change(s)"
print(f"{hhmm(j['depart'])} → {hhmm(j['arrive'])}, {j['duration_s'] // 60} min, {changes}")
for leg in j["legs"]:
if leg["mode"] == "walk":
if leg["distance_m"] >= 20: # skip the few metres onto a platform
print(f" walk {leg['distance_m']:.0f} m, about {-(-leg['duration_s'] // 60)} min")
else:
print(f" {hhmm(leg['board'])} {leg['route_short_name']} towards {leg['headsign']}, "
f"{leg['stops']} stops, off at {hhmm(leg['alight'])}")import { Client } from "@oslew/client";
const client = new Client({ baseUrl: "https://api.oslew.com" });
const answer = await client.journeys("37.7928,-122.3971", "37.8035,-122.2716", { limit: 3 });
const clock = new Intl.DateTimeFormat("en-GB", { timeZone: answer.timezone, hour: "2-digit", minute: "2-digit" });
const hhmm = (t: number) => clock.format(t * 1000);
for (const j of answer.journeys) {
const changes = j.transfers === 0 ? "no changes" : `${j.transfers} change(s)`;
console.log(`${hhmm(j.depart)} → ${hhmm(j.arrive)}, ${Math.floor(j.duration_s / 60)} min, ${changes}`);
for (const leg of j.legs) {
if (leg.mode === "walk") {
if (leg.distance_m >= 20) console.log(` walk ${Math.round(leg.distance_m)} m, about ${Math.ceil(leg.duration_s / 60)} min`);
} else {
console.log(` ${hhmm(leg.board)} ${leg.route_short_name} towards ${leg.headsign}, ${leg.stops} stops, off at ${hhmm(leg.alight)}`);
}
}
}Endpoints
/v1/journeysroutingTransit directions (RAPTOR): the fastest journey for each number of transfers, with walking to, between and from the stops, live delays applied when a realtime feed is.