Blog / API guides

Trainline API: Train Times and Fares as JSON

Trainline's own API is sold to travel companies through Trainline Partner Solutions, with onboarding by contact and no self-serve sign-up. The Perceptlayer Trainline API is the read-only route: 14 GET endpoints return stations, journeys with times, ticket options and a fares calendar as JSON, each at 1 credit per successful call. The usual chain is stations to find the two stations, then journeys for a date or fares-calendar for a range of dates.

Is there an official Trainline API?

Yes, but not for individual developers. Trainline Partner Solutions sells the Trainline Global API to travel sellers, online travel agencies, travel management companies and corporate booking tools; Trainline's own announcements describe partners such as Egencia reaching rail content through it with one connection (Trainline Partner Solutions, 2026). Access starts with a conversation through its partnerships page, and it's built for selling tickets, not for reading prices.

For British rail, there's also open data. The National Rail Data Portal provides timetable data updated weekly and fares data updated three times a year for development and proof-of-concept work, and the Darwin feeds give real-time train running (Rail Delivery Group, 2026). If you need the published fare tables or live departures, start there: it's the source the industry uses. Regular production feeds of fares data need a licence (Rail Delivery Group, RSP data, 2026).

What neither gives you is the price a traveller sees on Trainline for a given train on a given day, including advance fares, which is what the Trainline API returns. Data is collected from publicly available sources and returned as found at the time of the call.

You need Use
To sell rail tickets in your product Trainline Partner Solutions
Timetables, published fare tables, live running in Britain National Rail Data Portal and Darwin
Journey times and prices as shown on Trainline, as JSON /v1/trainline/journeys and /v1/trainline/fares-calendar

Which Trainline endpoints are there?

Fourteen, in four groups. Stations endpoints resolve names to stations. Journeys endpoints search a route and date and then drill into one search with its search_id. Fares endpoints return prices over a date range. Railcard endpoints list cards and their discounts. All are GET and all cost 1 credit on success.

Group Endpoints Required parameters
Stations stations, stations-nearby query; station_id
Journey search journeys origin, destination, date
One search, drilled into journeys-page, journeys-return, journeys-ticket-options, journeys-price-prediction, journeys-local-transport search_id, plus a journey ID where needed
One train journeys-calling-points timetable_id, carrier, departure_time, origin, destination
Fares over dates fares-calendar, fares-calendar-times origin, destination, date_from, date_to
No parameters fares-best, cards, cards-discounts none

The full list, with each endpoint's page and playground, is on the Trainline API page. The travel APIs cover flights and hotels on the same key.

How do you find a station?

Call GET /v1/trainline/stations with query, a station or city name of up to 100 characters. limit caps the matches and locale sets the language of the names. This is the first call of every chain, because origin and destination on the journey and fare endpoints take a station, not free text. Put your key in the X-API-Key header; keys start with sk_live_, and the authentication docs cover the rest.

curl "https://api.perceptlayer.com/v1/trainline/stations?query=Manchester&limit=5" \
  -H "X-API-Key: $API_KEY"

We haven't recorded a stations response, so we can't name the field that holds the identifier to pass on as origin or destination, or show its format. Run the call in the playground on the Trainline API page first and note it. Station identifiers don't change, so look up the stations you track once and store them.

How do you search journeys for a date?

Call GET /v1/trainline/journeys with origin, destination and date. The optional parameters cover a time of day, return trips (journey_type of single, return or open_return, with return_date and return_time), passengers (adults, children, child_age), transport_mode (all, train, coach) and currency (GBP or EUR).

curl "https://api.perceptlayer.com/v1/trainline/journeys?origin=$ORIGIN&destination=$DESTINATION&date=$DATE&journey_type=single&adults=1&currency=GBP" \
  -H "X-API-Key: $API_KEY"

The shell variables stand for values you take from the stations call and a date. The date and time formats aren't documented in the endpoint definition, so check them on the Journeys endpoint page before you script it. We haven't run this request for the article.

Parameter Type Allowed values or notes
origin, destination string, required Stations from the stations endpoint
date string, required Outbound date
time string Outbound time
journey_type string single, return, open_return
return_date, return_time string For returns
adults, children integer Passenger counts
child_age integer
transport_mode string all, train, coach
currency string GBP, EUR

How do the follow-up journey endpoints use search_id?

A journey search is a session you drill into. Each follow-up endpoint takes a search_id from a journeys response: journeys-page moves to the next or previous set of times (page of next or previous, direction of outward or inward); journeys-ticket-options takes an outward_journey_id, and optionally an inward_journey_id, and returns the tickets for that pairing; journeys-return lists return options for an outward journey; and journeys-price-prediction takes a journey_id.

Every follow-up is another call at 1 credit. Fetching ticket options for ten departures on one day is one search plus ten calls, 11 credits. Without a recording we can't say how long a search_id stays valid, so run the follow-ups soon after the search and expect a stale ID to fail; failures cost nothing.

How do you get a month of fares on one route?

Use GET /v1/trainline/fares-calendar with origin, destination, date_from and date_to, plus currency if you want GBP or EUR explicitly. It returns fares across the dates in the range, which is what you want for "when is it cheapest to travel" questions. fares-calendar-times takes the same parameters and, by its name, breaks fares down by departure time.

curl "https://api.perceptlayer.com/v1/trainline/fares-calendar?origin=$ORIGIN&destination=$DESTINATION&date_from=$DATE_FROM&date_to=$DATE_TO&currency=GBP" \
  -H "X-API-Key: $API_KEY"

We haven't recorded a fares-calendar response, so check two things in the Fares Calendar playground before relying on it: whether a 30-day range comes back in one call or is cut short, and whether each day carries one cheapest fare or several. Both decide how many calls a month costs.

Two things limit what a fares calendar shows. Prices are as found at the time of the call, and advance fares change as trains fill, so a calendar is a snapshot, not a quote. And railcards and passenger types change the price a traveller pays; the Cards and Cards Discounts endpoints list the railcards Trainline offers.

What does it cost to scan a month of fares?

Every Trainline endpoint costs 1 credit per successful call, and failed calls cost nothing and return X-Credits-Used: 0. If one fares-calendar call covers a month, a month of fares on one route is 1 credit. If the range turns out to be shorter, split it, for example into weeks at about 5 calls a month. The credits docs explain billing.

Job Calls Credits
A month of fares, one route, one call 1 1
The same, split into weekly ranges 5 5
Daily journey search for 30 days, one route 30 30
One day: search plus ticket options for 10 departures 11 11
50 routes, a monthly calendar each, re-checked daily 1,500 a month 1,500

Worked example: tracking 50 routes with one fares-calendar call per route per day is 50 × 30 = 1,500 calls a month, so 1,500 credits, once you've confirmed one call covers your range. The 100 free credits you get once, after verifying an email address, cover the first 2 days of the 50-route job (2 × 50 = 100), enough to test it. A Starter pack of 10,000 credits covers the 50-route job for six months, and purchased credits last 12 months. See pricing for what credits cost.

Free accounts run at 1 request a second and paid packs at 5 or more, shared by all of an account's keys; the rate limits docs have the details. For the same snapshot-versus-quote caution applied to air fares, see flight price data for fare tracking.

Can an AI agent plan rail trips with it?

Yes. The MCP server at https://perceptlayer.com/mcp exposes search_endpoints and get_endpoint, which are free catalogue lookups, and call_endpoint, which runs a Trainline endpoint and spends 1 credit on success. An agent can resolve two station names, search journeys for a date and compare a week of fares, in four or five calls.

Tell the agent to quote prices as "seen at the time of the search", not as bookable. Our AI travel planning agent tutorial shows the pattern with flights and hotels. Setup is in the AI agents docs, and error codes are in the errors docs.

To see the real responses, get a free API key and run a stations search in the playground on the Trainline API page.

APIs in this post

Frequently asked questions

Does Trainline have a public API?

Not a self-serve one. Trainline Partner Solutions sells its Global API to travel sellers, booking tools and travel management companies, with onboarding through its partnerships team. For British timetables, published fares and live running, the National Rail Data Portal and Darwin feeds are the open-data route. For journey times and prices as Trainline shows them, the Perceptlayer Trainline API returns JSON.

How much does the Trainline API cost?

Each of the 14 Trainline endpoints costs 1 credit per successful call, and failed calls cost nothing. A fares calendar for one route can be a single call. Every account gets 100 free credits after verifying an email address, and prepaid packs start at 10,000 credits. The pricing page has what credits cost.

Can I book tickets through it?

No. The endpoints read stations, journeys, ticket options, fares and railcards; none of them books or holds a ticket. Prices are returned as found at the time of the call, and advance fares change as trains fill. To sell tickets in your own product, talk to Trainline Partner Solutions.

Which currencies are supported?

The journey and fare endpoints take an optional currency of GBP or EUR. Set it on every call so prices from different runs compare directly. Railcards change what a traveller pays; the cards and cards-discounts endpoints list the cards and discounts Trainline offers.

What happens if a call fails?

You get an HTTP status and a JSON error with a code, message and request_id, and nothing is debited. A missing origin, destination or date returns invalid_parameters (422), and a currency other than GBP or EUR does too. Rate-limited (429) and temporarily unavailable (503) responses carry Retry-After. The errors docs list every code.

  1. Depop API: Resale Listings as JSON

    Search Depop listings as JSON with brand, condition, sizes and price.amount per item; the recorded jacket search had a total_count of 6,815,522. 1 credit.

  2. Similarweb API: Website Traffic Data as JSON

    Get Similarweb traffic estimates as JSON: visits, bounce_rate, traffic_sources, top_countries and top_keywords for a domain, at 1 credit a call.

  3. StockTwits API: Symbol Streams as JSON

    Three StockTwits endpoints as JSON: a symbol's message stream with sentiment and cursor, symbol search and trending symbols, each 1 credit a call.

Start with 100 free credits

No password to set. We email you a sign-in link, and your key works on every API.

No credit card. 100 free credits on signup.