Skip to content
oslew
Get a free key

APIs

Public transit API

A public transit journey planner API works out how to get from one point to another by bus, metro, tram or train: walk to a stop, ride, change, ride again, walk on. oslew plans journeys over GTFS timetables with the RAPTOR algorithm and returns the fastest journey for each number of changes, alongside the stops near any point and the next departures from any platform. Times come from the timetable unless an operator applies a GTFS-Realtime feed, which is part of Enterprise.

Last reviewed

Three endpoints answer the three questions a transit feature asks. GET /v1/stops finds the stops near a point and the routes that call at each. GET /v1/departures lists what leaves a given stop next. GET /v1/journeys plans a trip from one point to another. All three read GTFS feeds — the files agencies publish their stops, routes and timetables in — and answer only where a feed for the area is loaded.

Stops near a point

/v1/stops?at=lat,lon returns boarding stops nearest first, within radius_m of the point in a straight line (at most 5 km), with the routes calling at each. Each route carries its short and long name and its GTFS mode code — tram, metro, rail, bus, ferry and the rarer ones a feed may use — which your interface should map to an icon, falling back to a generic one for codes it does not know. Platforms of one station are listed as separate stops, because trips call at platforms rather than at stations.

Departures from a stop

/v1/departures takes either a stop id from the stops answer or a point, in which case it answers for the single nearest boarding stop — at a station with a platform per direction, that is one direction only. It lists departures at or after time (now by default) in order, each with route, headsign, trip_id, the scheduled time and, where realtime data applies, the delay. A station board is therefore one stops request followed by one departures request per platform.

Journeys, one per number of changes

/v1/journeys?from=lat,lon&to=lat,lon plans the trip. It searches the timetable with RAPTOR (Delling, Pajor and Werneck), which works in rounds: the first round finds everything reachable on one vehicle, the second everything reachable with one change, and so on, keeping the earliest arrival at every stop in each round. The answer is the set of journeys where none is beaten on both arrival time and number of changes, earliest first — perhaps an early arrival with two changes, a later one with one, and a later one again with none.

Three parameters bound the search: max_transfers (at most 6 transfers), walk_m, the straight-line distance a rider will walk to the first stop and from the last (at most 2 km), and limit (at most 10 journeys). Each journey is a list of legs, walk and ride alternating, beginning and ending with a walk. A ride leg names the route as riders know it, the headsign, the trip_id that departures and realtime updates share, the board and alight times, and the number of stops travelled. When both ends are within walking distance of each other, walking the whole way is one of the answers.

Timetables, service days and time zones

Every time is unix seconds, and every answer carries timezone, the feed’s own zone. Format times in that zone, not the server’s and not the viewer’s device, or a rider elsewhere sees the wrong hour. The time zone API is the tool if you need the zone of an arbitrary point.

GTFS timetables run on service days that do not end at midnight: a train at ten past one after a Wednesday evening is part of Wednesday’s service. A request is answered from the service day of its time and the day before, so late trains are found. The next service day is not searched: after the last train of the night the answer is empty, a 200 meaning nothing leaves in time, and you should ask again with a morning time.

Realtime delays, with an operator

Where an operator has applied a GTFS-Realtime feed for a timetable — the Enterprise operator product, described under operator feeds — departures and journeys use the delayed times. A delay reported at one stop carries forward along the trip until the feed says otherwise; a stop the feed marks as skipped can be neither boarded nor left there; and a late train can make a connection the timetable says it would miss. The live field then carries the realtime feed’s own timestamp. Two caveats matter. A delay of zero means only that the feed said nothing about that trip, which may or may not mean it is on time. And Operator feeds — live traffic and GTFS-Realtime — live only in the memory of the pod that received them. Behind a load balancer one answer can carry delays and the next none; live on each answer is how you tell.

Only trip updates are read. Vehicle positions and service alerts in a realtime feed are not applied, so a cancelled line announced only as an alert still appears in the plan.

Caveats, stated plainly

  • A journey never combines two feeds; a trip across two agencies’ networks is not found.
  • Walking legs are straight lines at a fixed walking pace, not routed along streets, so real walks are longer — most where streets are sparse. For the true path of a walk leg, ask the routing API with profile=walking.
  • No time is added to change. A connection can be timed to the second; if riders need a margin, drop journeys whose change is tighter than you allow.
  • The planner boards a trip at the first stop along its line that the walk reaches, and does not yet prefer a later stop of the same trip that walks less, so the first walk can be longer than a rider would choose.
  • Route and stop references inside a journey are indexes into the loaded feed, not the agency’s own ids; match them to other answers by route short name and stop position instead.
  • Without an operator’s realtime feed, every time is the timetable’s.

Coverage and licence

Which places are covered depends entirely on which agencies’ feeds are loaded. The number of feeds in the released store is published once measured: ⟦pending:coverage.transit.feeds⟧. Each feed keeps the terms it was ingested with, so transit answers are licensed under the operator’s own terms (for example “BART developer terms”), and provenance on every answer names the feed. Read that agency’s terms before you redistribute timetable data; the licensing page sets out how per-result licences work.

What it costs

Stops, departures and journeys belong to the routing product, and each request is one request against the routing rate. On the Routing plan, $299 a month, that is 5 requests a second sustained, burst 25; the pricing page lists the faster plans. Applying realtime feeds is an operator action with its own rate on Enterprise, 10 requests a second sustained, burst 20.

Bottom line

Use stops and departures for a live board, and journeys for getting somewhere. Show every journey in the answer, format times in the feed’s zone, add your own change margin, and say plainly when times are timetable-only — which is always the case unless an operator’s realtime feed is in force.

Questions

Which cities and agencies does the transit API cover?

Whichever GTFS feeds are loaded into the store. Each agency’s timetable is ingested on its own, under its own terms, and every answer names the feed it came from. Where no loaded feed has stops within walking distance of both ends of a journey, the request is refused with an error that says so rather than returning an empty plan.

Does the transit API show live delays?

Only where an operator has applied a GTFS-Realtime feed for that timetable, which is part of the Enterprise operator product. Departures and journeys then use the delayed times, and the live field carries the realtime feed’s timestamp. Without one, live is null and every time is the timetable’s. Vehicle positions and service alerts are not applied either way.

Why does the planner return more than one journey?

Because the fastest journey is not always the one a rider wants. The answer holds the earliest arrival for each number of changes and drops any journey that another beats on both counts — arriving no later with no more changes. Show them all and let the rider choose between arriving sooner and changing less.

Can one journey use two different agencies?

No. Each request is answered from one feed: the one whose stops are closest to both ends. A trip that needs one agency’s train and another agency’s bus is not found. Stops from every loaded feed are merged when you search for stops near a point, but journeys stay within a single feed.

How do I display departure times correctly?

Convert the unix times with the feed’s own time zone, which every answer carries in timezone — not the server’s zone and not the viewer’s device. Timetables also run on service days that pass midnight, so a train leaving after midnight may belong to the previous day’s service and is still returned.

Browse every page →