Blog / API guides

Google Flights Scraper or API: What You Get

A Google Flights scraper has to fill in a search the way a person would, wait for fares to load, and read price, airline, stops, times and emissions off every result card. You maintain the form logic, the parsing and the waiting. The alternative is 9 Google Flights endpoints that take the search as query parameters and return each flight as JSON at 1 credit per successful call. This post compares the two on a recorded one-way JFK to LAX search, works out the cost per route tracked, and gives a verdict per use case.

What does a Google Flights scraper have to rebuild?

A flight search page is an application, not a document, so a scraper for it is closer to a test script than a parser. It has to set the route, the date, the passenger counts, the cabin and any stop filter, start the search, wait until results finish loading, and then read each result card. The description here is general engineering for any interactive fare search, not a claim about how Google Flights is built.

Four parts carry most of the upkeep:

Search state

Every combination of route, date, passengers, cabin and filters is a different search. A scraper has to reproduce that state through the page, usually by driving a headless browser, and has to confirm the page actually applied it. A search that silently fell back to one adult in economy looks like valid data.

The result-card parser

Each card mixes a price string, an airline name, departure and arrival times, a duration like "6 hr 24 min", a stop count and often an emissions note. All of it is display text you turn into numbers, and any layout change can move or rename it without an error.

Waiting

Fare searches take seconds, not milliseconds. A scraper needs a rule for when the results are complete, a timeout, and a retry policy, and each browser session it holds open costs memory while it waits.

The hand-off

A tracker that finds a fare often needs the booking options behind it. On a page that means clicking through and parsing a second view; in code it means keeping some reference to the result you clicked. Read Google's terms before you automate any of this, and if you hit blocks or challenge pages, stop rather than work around them.

What does the one-way endpoint return for JFK to LAX?

One call to the one-way endpoint runs a full search and returns each flight with its fare, carrier, stops, duration, emissions and legs already typed. The required parameters are origin and destination (up to 3 characters each) and departure_date. It costs 1 credit per successful call, and the one-way endpoint page lists all 24 of its parameters.

curl "https://api.perceptlayer.com/v1/google-flights/one-way?origin=JFK&destination=LAX&departure_date=2026-12-15" \
  -H "X-API-Key: $API_KEY"

This is the recorded response, trimmed to the second flight and the search metadata:

{
  "flights": [
    …
    {
      "price": 189,
      "currency": "USD",
      "total_duration_minutes": 378,
      "stops": 0,
      "airline_name": "Delta",
      "emissions": {
        …
        "co2_kilograms": 244,
        …
        "typical_co2_kilograms": 344,
        "difference_percent": -29
      },
      "booking_token": "CjRISVFvemhYdy1QZTBBQTR3SXdCRy0tLS0tLS0tLWVqY3J5N0FBQUFBR3JhOFJBQUFyOGdBEgVETDc3MxoLCJiTARACGgNVU0Q4HHCYkwE=",
      "legs": [
        {
          "airline": "DL",
          "flight_number": "773",
          "departure_airport": "JFK",
          "arrival_airport": "LAX",
          "departure_time": "2026-12-15T09:00:00",
          "arrival_time": "2026-12-15T12:18:00",
          "duration_minutes": 378
        }
      ]
    }
  ],
  "search_metadata": {
    "origin": "JFK",
    "destination": "LAX",
    "departure_date": "2026-12-15",
    "passengers": {
      "adults": 1,
      "children": 0,
      …
    },
    "cabin_class": "Economy",
    "exclude_basic": false,
    "max_stops": "Any number of stops",
    "sort_by": "Top Flights",
    …
    "currency": "USD",
    "response_time_ms": 5598
  }
}

The search_metadata block answers the scraper's search-state problem: it records the passengers, cabin, stop filter, sort and currency the search ran with, so you can store it next to the fares and check it on every run. The first flight in the same response is a JetBlue nonstop at 179 USD with co2_kilograms: 426 and difference_percent: 24, so the two results differ by 10 USD and 182 kg of estimated CO2.

How do the scraper's form controls map to parameters?

Each control a scraper would set on the page has a query parameter on the one-way endpoint, with its allowed values listed in the catalogue. That turns the search state into a URL you can log, diff and replay. The table covers the parameters a fare tracker reaches for first; round trips use the same names on /v1/google-flights/round-trip, plus return_date.

What a scraper would set Parameter Allowed values or type
From, to origin, destination string, up to 3 characters
Date departure_date string
Passengers adults, children, infants_in_seat, infants_on_lap integer
Cabin cabin_class economy, premium_economy, business, first
Stops max_stops any, nonstop, one_or_fewer, two_or_fewer
Sort sort_by top_flights, cheapest, departure_time, arrival_time, duration, emissions
Airlines airlines[] list of 2-character strings
Time windows departure_time_min, departure_time_max, arrival_time_min, arrival_time_max integer
Price and duration caps max_price, max_duration_minutes integer
Currency, language, country currency, hl, gl string

If your input is a city name rather than an airport code, /v1/google-flights/autocomplete takes q, and the airports endpoint needs no parameters.

A tracker that reads only recorded fields

This Python sketch runs the recorded search with a nonstop filter and prints one line per flight. It reads only fields that appear in the recording, and its timeout sits well above the recorded 5,598 ms:

import os

import requests

resp = requests.get(
    "https://api.perceptlayer.com/v1/google-flights/one-way",
    params={
        "origin": "JFK",
        "destination": "LAX",
        "departure_date": "2026-12-15",
        "max_stops": "nonstop",
        "sort_by": "cheapest",
    },
    headers={"X-API-Key": os.environ["API_KEY"]},
    timeout=60,
)
resp.raise_for_status()
body = resp.json()
meta = body["search_metadata"]
print(meta["cabin_class"], meta["max_stops"], meta["currency"])

for f in body["flights"]:
    legs = "+".join(leg["airline"] + leg["flight_number"] for leg in f["legs"])
    co2 = f.get("emissions", {}).get("difference_percent")
    print(f["price"], f["currency"], f["airline_name"], legs,
          f["stops"], "stops", f["total_duration_minutes"], "min", co2, "% CO2")

How should you read the times and durations?

Read the times as local clock times and the durations as the real elapsed minutes, and never derive one from the other. In the recording, the JetBlue leg departs at 2026-12-15T08:01:00 and arrives at 2026-12-15T11:25:00, which is 3 hours 24 minutes on the clock, yet duration_minutes is 384, or 6 hours 24 minutes. The three-hour gap is the difference between New York and Los Angeles time.

The timestamps carry no UTC offset, so a scraper or a pipeline that subtracts them gets the wrong duration on every coast-to-coast flight. Use total_duration_minutes and each leg's duration_minutes for elapsed time, and if you need absolute timestamps, attach the airports' time zones yourself. For multi-leg itineraries, legs[] lists each flight with its own departure_airport, arrival_airport and flight_number, so connections come out as rows rather than as text you split.

The booking_token covers the scraper's hand-off problem. Each flight carries one, and /v1/google-flights/booking-details takes a booking_token together with origin, destination, departure_date, airline and flight_number, so the names match the one-way fields. Try a recorded token on the booking details endpoint in the playground before you build on that step.

How do a scraper and the endpoints compare?

A scraper costs engineering time and browser hours and carries breakage and blocking risk; the endpoints cost a credit per search and return typed fields. The table compares them for a recurring fare tracker that checks a fixed set of routes and dates every day.

DIY fare scraper Google Flights endpoints
Setup Headless browser, form-filling script, card parser, storage, monitoring API key in the X-API-Key header
Search state Set through the page; must be verified each run Query parameters, echoed back in search_metadata
Fare fields Parsed from price, duration and stop text price, currency, stops, total_duration_minutes, airline_name
Emissions Parsed from a note, if shown emissions with co2_kilograms, typical_co2_kilograms, difference_percent
Connections Split from card text legs[] with airline, flight number, airports, times, minutes
Booking hand-off Click through and parse a second view booking_token per flight; names match booking-details
Slow searches A browser held open per search One HTTP call; recorded response_time_ms of 5598
When the page changes Your scripts break, often silently You read named JSON fields
Cost Hosting, browser time and your time 1 credit per successful call; failed calls cost 0

What does a tracked route cost?

On the endpoints, the unit of cost is one route on one departure date: each one-way search is 1 credit, however many flights it returns. A tracker's bill is routes × dates × checks a day. Round trips cost the same 1 credit per call on /v1/google-flights/round-trip.

Plan Calls a day Credits over 30 days
1 route, next 30 departure dates, once a day 1 × 30 = 30 900
5 routes, next 30 dates, once a day 5 × 30 = 150 4,500
20 routes, next 60 dates, once a day 20 × 60 = 1,200 36,000

The 100 free credits on signup cover the first three days of the first plan. Over 30 days the first two plans fit inside the Starter pack's 10,000, and the third inside the Build pack's 50,000. Before you multiply calls by dates, look at /v1/google-flights/date-range and /v1/google-flights/calendar, which take a start and end date in one call; check in the playground whether their output covers your question, because that changes the arithmetic. See pricing for what credits cost.

Plan for the time a search takes as well as its price. At the recorded 5,598 ms, a loop that waits for each call before sending the next manages about one call every 5.6 seconds, below even the free 1 request a second. To use a paid rate of 5 a second you need several requests in flight. Set client timeouts well above the search time: requests have no idempotency key, so a call whose reply you abandoned may have succeeded and been billed. The rate limits docs cover the per-minute headers.

Which route should you choose?

Choose by how many route-date pairs you watch and what you do with the fares. For one trip you're planning yourself, search in a browser and skip both routes.

  • A daily fare tracker for a fixed set of routes: use one-way or round-trip on a schedule and store price, currency, stops, legs[].flight_number and the full search_metadata with the run date. Budget routes × dates credits per day.
  • Finding the cheapest date in a window: start with date-range or calendar rather than one call per date, and confirm their fields in the playground.
  • Comparing emissions across carriers: read emissions.difference_percent per flight; the recorded route shows -29 and 24 for two nonstops 10 USD apart.
  • An agent that answers "when should I fly" questions: connect it through MCP, as the AI agents docs describe, so it calls the search instead of driving a browser.
  • Comparing Google Flights with another fare source: Flight API: Google Flights and Kiwi Data as JSON puts the two side by side.
  • Learning browser automation: practise on a site built for it, not a live fare search.

To check the fields for your own routes, run one-way with your airports in the playground on the Google Flights API page, then get a free API key when they fit.

APIs in this post

Frequently asked questions

Is scraping Google Flights allowed?

That depends on Google's terms of service and the law where you operate, so read the terms and get legal advice for commercial use. Don't get around blocks, challenges or other protections. Fares, schedules and emissions estimates are not personal data, but keep any traveller details your own product collects separate from what you fetch.

How much does a Google Flights API call cost?

Each of the 9 Google Flights endpoints costs 1 credit per successful call. A one-way search for one route and one date is 1 credit whatever the number of flights returned, so tracking 5 routes across 30 dates once a day is 150 credits a day. Failed calls cost nothing and return X-Credits-Used: 0.

Why doesn't arrival time minus departure time match the duration?

The departure_time and arrival_time values are local clock times without a UTC offset. On the recorded JFK to LAX flight the clock shows 3 hours 24 minutes while duration_minutes is 384, because Los Angeles is three hours behind New York. Use the duration fields for elapsed time.

How long does a flight search take?

The recorded one-way search reported response_time_ms of 5598 in its search_metadata, so plan for searches measured in seconds. Set your client timeout well above that, because an abandoned request may still have succeeded and been billed. To run many searches quickly, keep several requests in flight within your account's rate limit.

What happens when a call fails?

You get an HTTP status and a JSON body with an error code, message and request_id, and no credits are debited. Invalid parameters return 422, a rate-limited call returns 429 with a Retry-After header, and source_error comes back as 502. The errors docs list every code.

  1. Flight API: Google Flights and Kiwi Data as JSON

    Compare Google Flights and Kiwi.com flight search as JSON: price, stops, duration, CO2 or baggage per itinerary, date-range calls, 1 credit per route per date.

  2. Booking.com Scraper or API: What You Get

    A Booking.com scraper vs 11 endpoints at 1 credit a call: one recorded Paris prices call returned 25 hotels, about 0.04 credits per hotel price.

  3. Vrbo Scraper or API: What You Get

    A Vrbo scraper vs 6 endpoints at 1 credit a call: a recorded Lake Tahoe search with stay_total, nightly_original and rating, and the cost per listing.

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.