mta-js wraps MTA’s real-time GTFS feeds into a single, consistent interface. You create oneDocumentation Index
Fetch the complete documentation index at: https://mtaapi.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
MTA client, and from it you access four namespaces—subway, bus, alerts, and stops—each responsible for a distinct slice of NYC transit data. Under the hood, the SDK fetches live protocol buffer feeds from MTA’s servers, decodes them, and returns typed JavaScript objects you can work with immediately.
The MTA client
Everything starts with a single client instance. Pass anapiKey from mtaapi.dev and the client handles authentication and request routing for you.
busTimeKey instead of apiKey. See Direct MTA feeds for the full options.
Your API key is sent with every request. Keep it in an environment variable and never commit it to source control.
Namespaces
The four namespaces cover the full scope of MTA’s publicly available real-time data. Each namespace exposes focused methods that map directly to a category of MTA feed.subway
Real-time arrival predictions for subway stops (
subway.arrivals()), plus a destination-to-direction resolver (subway.direction()) that turns a rider’s destination into a north/south direction.bus
Live vehicle positions for bus routes. Returns the current geographic location and status of every active bus on a given route.
alerts
Active service alerts for subway and bus. Includes delays, planned work, elevator outages, and emergency notices.
stops
Stop discovery by geolocation. Given a latitude and longitude, returns nearby subway and bus stops sorted by distance.
Data freshness
All four namespaces draw from MTA’s GTFS Realtime (GTFS-RT) feeds—standardized protocol buffer streams that MTA publishes continuously. Subway arrival feeds typically refresh every 30 seconds. Bus position feeds update every 30 to 60 seconds. Alert feeds update as changes are published by MTA operations staff. When you call any method on the client, mta-js fetches the latest available snapshot of the relevant feed and returns it decoded. The SDK does not maintain a persistent connection or push updates to your application—you are responsible for polling at an appropriate interval for your use case.Error handling
mta-js throws typed errors when a request fails, a feed is unavailable, or you pass invalid parameters. Wrap your calls in atry/catch block to handle these cases gracefully.