Skip to main content

Documentation 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-js is a unified JavaScript/TypeScript SDK that wraps MTA’s real-time feeds into one consistent, easy-to-use interface. Whether you’re building a transit tracker, a commute planner, or a live arrival board, mta-js gives you subway arrivals, bus vehicle positions, service alerts, and geolocation-based stop lookups—all through a single MTA client.

Get up and running

1

Install the package

Add mta-js to your project using your preferred package manager.
npm install mta-js
Using Next.js with Turbopack? Add mta-js to transpilePackages. The SDK publishes TypeScript source, and this tells Next to compile it instead of treating node_modules/mta-js/index.ts as an unknown module type.
next.config.mjs
/** @type {import("next").NextConfig} */
const nextConfig = {
  transpilePackages: ["mta-js"],
}

export default nextConfig
2

Get your API key from mtaapi.dev

Get an API key from mtaapi.dev — our hosted MTA API. One key, all endpoints, no setup.
  1. Sign up at mtaapi.dev.
  2. Copy your API key from the dashboard.
  3. Add it to your project as an environment variable:
.env
MTA_API_KEY=your_api_key_here
Never commit your API key to version control. Store it in an environment variable and load it at runtime. See Authentication for more detail.
3

Initialize the client

Import MTA and create a client instance by passing your apiKey.
import { MTA } from 'mta-js'

const mta = new MTA({ apiKey: process.env.MTA_API_KEY })
With an apiKey set, requests are routed to https://www.mtaapi.dev/api/v1 automatically. You only configure it once.
4

Fetch real-time data

Call mta.subway.arrivals() with a stop ID and route to get real-time arrival predictions.
import { MTA } from 'mta-js'

const mta = new MTA({ apiKey: process.env.MTA_API_KEY })

// Next A trains at Howard Beach
const arrivals = await mta.subway.arrivals({
  stopId: 'A27',
  route: 'A'
})

console.log(arrivals)
A successful response is an array of Arrival objects:
[
  {
    "mode": "subway",
    "route": { "id": "A", "shortName": "A", "color": "#0039A6" },
    "stop": { "id": "A27", "name": "Howard Beach-JFK Airport", "displayName": "Howard Beach–JFK Airport" },
    "direction": "north",
    "destination": "Inwood-207 St",
    "displayDirection": "toward Inwood-207 St",
    "arrivalTime": "2026-05-29T18:32:00.000Z",
    "minutes": 4,
    "tripId": "AFA25GEN-1037-Sunday-00_106200_A..N70R",
    "realtime": true,
    "source": "mta-gtfs-rt"
  },
  {
    "mode": "subway",
    "route": { "id": "A", "shortName": "A", "color": "#0039A6" },
    "stop": { "id": "A27", "name": "Howard Beach-JFK Airport", "displayName": "Howard Beach–JFK Airport" },
    "direction": "north",
    "destination": "Inwood-207 St",
    "displayDirection": "toward Inwood-207 St",
    "arrivalTime": "2026-05-29T18:47:00.000Z",
    "minutes": 19,
    "tripId": "AFA25GEN-1037-Sunday-00_109800_A..N70R",
    "realtime": true,
    "source": "mta-gtfs-rt"
  }
]

What you can build

Subway arrivals

Real-time arrival times for any subway stop and route.

Bus tracking

Live vehicle positions for any bus route.

Service alerts

Delays, planned work, and service changes in real time.

Nearby stops

Find subway and bus stops near any latitude/longitude.

Trip direction

Resolve a rider’s destination into the right north/south direction.

API Reference

Full SDK method reference with parameters and response types.
Prefer to call MTA feeds directly instead of using the hosted API? See Direct MTA feeds and self-hosting.