MTA client — subway, bus, alerts, and stops — each covering a different aspect of NYC transit data. The subway namespace has two methods (arrivals() and direction()); the others have one each. Every namespace method is async, returns typed results, and requires only a single initialized client to access the full API surface.
Subway
subway.arrivals() — real-time arrival predictions for any subway stop and route.Direction
subway.direction() — resolve a rider’s destination to a north/south direction.Bus
bus.arrivals() and bus.vehicles() — live arrivals and vehicle positions for any MTA bus route.Alerts
alerts.current() — current service alerts including delays and planned work.Stops
stops.near() — find nearby subway and bus stops by geographic coordinates.Client initialization
Create a singleMTA instance at startup and reuse it throughout your application. The constructor accepts an options object — pass an apiKey from mtaapi.dev for the hosted API, or busTimeKey + databaseUrl to run self-hosted.
Core exported types
The following types are exported frommta-js and cover the full shape of SDK responses.
Error handling
All SDK methods throw a typedMtaError when the request fails. Wrap calls in a try/catch block and inspect the code property to handle specific failure modes.