Lefrecce APIlefrecce.it ↗
Search live Trenitalia rail journeys and resolve station IDs via the lefrecce.it API. Get fares, departure times, changes, and train legs.
What is the Lefrecce API?
The lefrecce.it API provides 2 endpoints for querying Trenitalia's Italian rail network: use search_stations to resolve any city or station name to a numeric station ID, then pass that ID to search_journeys to retrieve live journey solutions — including departure and arrival times, duration, number of changes, individual train legs, and total fare for your passenger mix.
curl -X GET 'https://api.parse.bot/scraper/def03973-366f-419a-a789-db6a0d1eca1b/search_stations?name=Firenze+S' \ -H 'X-API-Key: $PARSE_API_KEY'
Typed, relational, agent-ready
A generated client with real types, enums, and the links between objects — the structure a flat JSON response can't carry. Autocompletes in your editor and reads cleanly to coding agents.
- Fully typed · autocompletes
- Objects link to objects
- Typed errors & pagination
Typed Python client. Set up the SDK in your uv project, then pull this API’s typed client:
uv add parse-sdk uv run parse init uv run parse add --marketplace lefrecce-it-api
uv run parse add --marketplace pulls a pinned snapshot of this canonical API — it won’t change underneath you. To customize it, subscribe and swap to your own copy.
"""Walkthrough: Trenitalia journey search — find stations, then search trains."""
from parse_apis.lefrecce_it_api import LeFrecceit, InputFormatInvalid
client = LeFrecceit()
# Find the origin station by name
origin = client.stations.search(name="Firenze", limit=5).first()
if origin is not None:
print(f"Origin: {origin.name} (id={origin.station_id}, tz={origin.timezone})")
# Find the destination station by name
dest = client.stations.search(name="Roma", limit=5).first()
if dest is not None:
print(f"Destination: {dest.name} (id={dest.station_id})")
# Search journeys between the two stations
try:
for journey in origin.search_journeys(
destination_station_id=dest.station_id,
date="2026-12-01",
time="08:00",
adults=2,
limit=3,
):
print(f"\n{journey.origin} → {journey.destination}")
print(f" Departs: {journey.departure_time} Arrives: {journey.arrival_time}")
print(f" Duration: {journey.duration}, Changes: {journey.changes}")
if journey.total_price is not None:
print(f" Price: {journey.total_price.amount} {journey.total_price.currency}")
for leg in journey.legs:
print(f" {leg.origin} → {leg.destination} ({leg.train_category} {leg.train_number})")
except InputFormatInvalid as e:
print(f"Invalid input: {e.message}")
print("exercised: stations.search / search_journeys")
Looks up Trenitalia stations whose name starts with or contains the given text, exactly as the site's station autocomplete does. Returns up to 10 matching stations with the numeric station_id that search_journeys accepts as origin_station_id / destination_station_id. One round trip; an empty stations array means the site found no match for that text.
| Param | Type | Description |
|---|---|---|
| namerequired | string | Station name text to match, e.g. a city name or the start of a station name (one shape: 'Fiumicino'). |
{
"type": "object",
"fields": {
"query": "the name text that was searched",
"stations": "array of matching stations: station_id (string, numeric id used by search_journeys), name, display_name, timezone (IANA), multistation (true when the id groups several stations)"
},
"sample": {
"data": {
"query": "Firenze S",
"stations": [
{
"name": "Firenze S. M. Novella",
"timezone": "Europe/Rome",
"station_id": "830006421",
"display_name": "Firenze S. M. Novella",
"multistation": false
},
{
"name": "Firenze S. Marco Vecchio",
"timezone": "Europe/Rome",
"station_id": "830006950",
"display_name": "Firenze S. Marco Vecchio",
"multistation": false
}
]
},
"status": "success"
}
}About the Lefrecce API
Station Lookup
The search_stations endpoint accepts a partial or full station name string (e.g. "Roma" or "Fiumicino") and returns up to 10 matching stations. Each result includes a numeric station_id (the identifier search_journeys requires), a name, a display_name, and an IANA timezone. This mirrors the autocomplete behaviour on the booking site, so any query a user could type into the origin or destination field will resolve here.
Journey Search
The search_journeys endpoint takes origin_station_id and destination_station_id (both from search_stations), a travel date (ISO YYYY-MM-DD), and an optional earliest time (HH:MM, 24-hour Italian local time). Results are ordered by departure time and include ISO 8601 departure_time and arrival_time with UTC offset, a duration string, a solution_id, and an array of train legs. The total_price field covers the combined fare for the requested number of adults and children; at least one passenger must be specified.
Pagination and Filtering
Pagination is offset-based: supply offset and limit (capped at 50) to step through results. The has_more boolean indicates whether another page exists at offset + limit. Setting no_changes to true filters to direct services only — but if the route has no direct trains the response returns an empty journey array (the messages field may carry a site notice explaining why). The search_date and search_time fields in the response echo back the parameters you sent, which helps when managing concurrent requests.
Data Freshness and Coverage
Results come from Trenitalia's live availability feed, so fares and seat availability reflect real-time inventory at the moment of the request. The API covers domestic Italian Trenitalia services accessible through the lefrecce.it booking channel, including Frecciarossa, Frecciargento, Frecciabianca, and Intercity services.
The Lefrecce API is a managed, monitored endpoint for lefrecce.it — not a raw scraper you maintain. Every endpoint is automatically health-checked on a schedule, and when lefrecce.it changes and a check fails, the API is automatically queued for repair and re-verified. It is built to keep working as the site underneath it changes.
This isn't an official lefrecce.it API — it's an independent, maintained REST wrapper over public data. Where the source has no official API (or only a limited one), Parse gives you a stable contract over a source that never promised one, and keeps it current. Need a new endpoint or field? You can revise it yourself in plain English and the agent rebuilds it against the live site in minutes — contributing the change back to the shared API is free.
Will this API break when the source site changes?+
Is this an official API from the source site?+
Can I fix or extend this API myself if I need a new endpoint or field?+
What happens if I call an endpoint that has an issue?+
- Build a fare-comparison tool that checks total_price across multiple departure times for a given adult/child passenger count
- Power a journey planner widget that resolves typed station names to station_ids and returns real-time schedules
- Monitor ticket price changes on a specific route by polling search_journeys at regular intervals
- Filter to direct trains only using no_changes=true to serve travellers who want single-leg trips
- Paginate through a full day's departures using offset + limit to aggregate all available journey options
- Feed arrival_time and departure_time data into a trip-itinerary builder that chains multiple rail legs
- Alert users when new journey solutions appear on a given date by diffing solution_ids across polls
| Tier | Price | Credits/month | Rate limit |
|---|---|---|---|
| Free | $0/mo | 200 | 5 req/min |
| Hobby | $30/mo | 1,000 | 20 req/min |
| Developer | $100/mo | 5,000 | 100 req/min |
| Team | $300/mo | 20,000 | 300 req/min |
| Company | $1,000/mo | 100,000 | 500 req/min |
Each endpoint has a fixed posted price per successful call — most fall between 1 and 10 credits — shown on this API's page before you run it. Exceeding the rate limit returns a 429 response. Authenticate with the X-API-Key header.
Does Trenitalia provide an official public developer API?+
What does search_journeys return for each journey solution?+
journeys array includes a solution_id, origin, destination, departure_time and arrival_time (ISO 8601 with UTC offset), a duration string, the number of changes, an array of individual train legs, and a total_price that covers all passengers specified via adults and children.Does the API return return tickets or only outbound journeys?+
search_journeys in one direction between an origin and destination. You can fork the API on Parse and revise it to add a return-journey search that runs both directions in one call.How does pagination work, and how do I know if there are more results?+
offset and limit parameters to page through results. limit is capped at 50. The response includes a has_more boolean: when true, at least one more page exists and you can fetch it by setting offset to your current offset + limit.