This project exposes a mix of browser-facing routes and externally protected routes.
Same-origin browser requests are allowed without an API key. External callers must present a Clerk API key token using Authorization: Bearer <key>.
Shared API protection lives in lib/api-key-auth.ts.
- Same-origin browser requests are allowed without an API key.
- Cross-origin requests must include a valid Clerk API key token.
- Unauthorized responses return
401.
Simple app health check.
Response:
"OK"Checks the departures route by calling it in-process.
Query parameters:
code- Stop code. Defaults toSOT.type-trainorbus. Defaults totrain.
Response shape:
{
"status": "ok",
"ok": true,
"responseTimeMs": 12,
"hasData": true,
"departureCount": 8,
"timestamp": "2026-05-23T00:00:00.000Z"
}Checks that the map style proxy returns a valid style document.
Response shape:
{
"status": "ok",
"ok": true,
"responseTimeMs": 8,
"hasSources": true,
"layerCount": 3,
"timestamp": "2026-05-23T00:00:00.000Z"
}Returns train or bus departures for a stop.
Query parameters:
code- Stop or location code.type-trainorbus.date- Optional date inYYYY-MM-DD.time- Optional time inHH:mm.datetime- Optional ISO datetime.pass- Set toshowto include passing services.debug- Set totruefor raw upstream data.limit- Maximum departures returned. Defaults to15.
Train response:
{
"metadata": {
"contains_cancelled_services": false,
"contains_expected_times": true,
"contains_platform_numbers": true,
"contains_delays": true
},
"attributions": [],
"departures": []
}Bus response:
{
"metadata": {
"line_names": [],
"common_name": null,
"name": null,
"long_name": null
},
"attributions": [],
"departures": []
}Common statuses:
400for missing or invalid parameters.429when rate limited.481when the requested train date is outside permitted history.
Returns visible train and bus vehicles for the current bounding box.
Query parameters:
xminyminxmaxymaxshowTrains-trueorfalse. Defaults totrue.showBuses-trueorfalse. Defaults totrue.debug- Set totruefor raw upstream payloads.
Response shape:
{
"trains": [],
"buses": []
}Train items include:
iddelaylocationrotationoperatorservicedestinationcolourpopup_data
Bus items include:
idlocationrotationservicedestinationcolourliveryIDpopup_data
Common statuses:
400for missing bounds.429when rate limited.
Returns route geometry for a train or bus vehicle.
Query parameters:
rid- Train RID.trip_id- Bus trip ID.
Response shape for trains:
{
"type": "train",
"id": "123456",
"service": "2O28",
"operator": "West Midlands Trains",
"destination": "Bromsgrove",
"path": [],
"snapped": true
}Response shape for buses:
{
"type": "bus",
"id": "577974496",
"path": [],
"snapped": false
}Common statuses:
400when both identifiers are missing.429when rate limited.
Returns active, historical, and ridden routes for an operator.
Query parameters:
code- Operator code or alias.operator- Alternate operator key.
Response shape:
[
{
"service_number": "19",
"route_name": "...",
"withdrawn": false,
"ridden": true,
"times_ridden": 4
}
]Returns vehicle summaries for an operator, combining Bustimes data with user trip history and Convex vehicle data.
Query parameters:
code- Operator code.
Response shape:
[
{
"unit_number": "1234",
"reg": "AB12CDE",
"vehicle_type": "Bus",
"ridden": true,
"times_ridden": 7
}
]Searches train units, bus vehicles, or both.
Query parameters:
q- Search term.type-train,bus, or omitted for both.
Response shape:
[
{
"id": "...",
"source": "train",
"unit_number": "...",
"unit_reg": "...",
"type": {
"type_id": "...",
"type_name": "..."
}
}
]Returns operator metadata.
Modes:
- User mode is the default and returns operators associated with the signed-in user.
all=1returns all operators.
Query parameters:
all- Set to1for full operator list.
Response shape:
{
"mode": "user",
"total": 12,
"operators": []
}Returns full trip and service details for train and bus logs.
Useful query parameters:
service_rid- Resolve a train service directly from RID.service_uid- Train UID.service_id- Bus trip identifier.trip_id- Bus trip identifier.date- Service date inYYYY-MM-DD.service_date- Alternate date parameter.type-trainorbus.debug- Set totruefor upstream payloads.show_pass- Set totrueto include passing points for trains.
Train response includes:
- service metadata
- origin and destination details
- the full route geometry
- the merged stop list
- optional debug payload
Bus response includes:
- service metadata
- origin and destination details
- the full route geometry
- the merged stop list
- optional bus and vehicle debug payloads
The API routes call these providers server-side:
- RealTimeTrains
- bustimes.org
- map-api.production.signalbox.io
These upstream calls are not intended to be called directly from the browser.
If you are integrating from outside the hosted app, call the protected routes with a Clerk API key token. If you are inside the hosted app itself, the same-origin request path is preferred and no API key is needed.