> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hasdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Flights API

The Google Flights API provides real-time access to structured flight search results, enabling users to find flights based on various criteria.

## Get Your API Key

Sign in at [hasdata.com](https://app.hasdata.com/sign-in), go to your account settings, and copy your API key.
All requests must include your key in the `x-api-key` header.

## Request Cost and API Credits

Each request to the Google Flights API consumes **API Credits** from your account balance.

* **Cost per request:** 15 API Credits
* Credits are deducted only for successful requests.
* Your total available credits depend on your active plan.

<Tip>You can use your credits across all HasData APIs. The same credit balance is shared platform-wide.</Tip>
<Warning>**Unused credits do not roll over.** Any remaining credits expire at the end of the current billing period.</Warning>

To monitor your credit usage and remaining balance, sign in to your account dashboard at [app.hasdata.com](https://app.hasdata.com/sign-in).

## Make Your First Request

<CodeGroup>
  ```bash cURL theme={null}
  curl --request GET -G \
    --url 'https://api.hasdata.com/scrape/google/flights' \
    --data-urlencode 'departureId=LHR' \
    --data-urlencode 'arrivalId=JFK' \
    --data-urlencode 'outboundDate=2026-08-15' \
    --data-urlencode 'returnDate=2026-08-20' \
    --header 'Content-Type: application/json' \
    --header 'x-api-key: <your-api-key>'
  ```

  ```bash HasData CLI theme={null}
  hasdata google-flights \
    --departure-id LHR \
    --arrival-id JFK \
    --outbound-date 2026-08-15 \
    --return-date 2026-08-20
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios').default;

  const options = {
    method: 'GET',
    url: 'https://api.hasdata.com/scrape/google/flights',
    params: {
      departureId: 'LHR',
      arrivalId: 'JFK',
      outboundDate: '2026-08-15',
      returnDate: '2026-08-20'
    },
    headers: {'Content-Type': 'application/json', 'x-api-key': '<your-api-key>'}
  };

  try {
    const { data } = await axios.request(options);
    console.log(data);
  } catch (error) {
    console.error(error);
  }
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.hasdata.com/scrape/google/flights"

  querystring = {"departureId":"LHR","arrivalId":"JFK","outboundDate":"2026-08-15","returnDate":"2026-08-20"}

  headers = {
      "Content-Type": "application/json",
      "x-api-key": "<your-api-key>"
  }

  response = requests.get(url, headers=headers, params=querystring)

  print(response.json())
  ```

  ```php PHP theme={null}
  <?php

  $params = [
      "departureId" => "LHR",
      "arrivalId" => "JFK",
      "outboundDate" => "2026-08-15",
      "returnDate" => "2026-08-20",
  ];

  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.hasdata.com/scrape/google/flights?" . http_build_query($params),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
      "Content-Type: application/json",
      "x-api-key: <your-api-key>",
    ],
  ]);

  $response = curl_exec($curl);
  curl_close($curl);

  echo $response;
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient();

  HttpUrl url = HttpUrl.parse("https://api.hasdata.com/scrape/google/flights")
    .newBuilder()
    .addQueryParameter("departureId", "LHR")
    .addQueryParameter("arrivalId", "JFK")
    .addQueryParameter("outboundDate", "2026-08-15")
    .addQueryParameter("returnDate", "2026-08-20")
    .build();

  Request request = new Request.Builder()
    .url(url)
    .get()
    .addHeader("Content-Type", "application/json")
    .addHeader("x-api-key", "<your-api-key>")
    .build();

  Response response = client.newCall(request).execute();
  ```

  ```csharp C# theme={null}
  using System.Net.Http;
  using System.Web;

  var client = new HttpClient();

  var query = HttpUtility.ParseQueryString(string.Empty);
  query["departureId"] = "LHR";
  query["arrivalId"] = "JFK";
  query["outboundDate"] = "2026-08-15";
  query["returnDate"] = "2026-08-20";

  var url = $"https://api.hasdata.com/scrape/google/flights?{query}";

  var request = new HttpRequestMessage(new HttpMethod("GET"), url);
  request.Headers.Add("x-api-key", "<your-api-key>");

  using var response = await client.SendAsync(request);
  response.EnsureSuccessStatusCode();
  var content = await response.Content.ReadAsStringAsync();
  Console.WriteLine(content);
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'uri'

  uri = URI("https://api.hasdata.com/scrape/google/flights")
  params = {
    "departureId" => "LHR",
    "arrivalId" => "JFK",
    "outboundDate" => "2026-08-15",
    "returnDate" => "2026-08-20",
  }
  uri.query = URI.encode_www_form(params)

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri)
  request["Content-Type"] = 'application/json'
  request["x-api-key"] = '<your-api-key>'

  response = http.request(request)
  puts response.read_body
  ```

  ```rust Rust theme={null}
  use reqwest::blocking::Client;

  fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = Client::new();
      let res = client
          .get("https://api.hasdata.com/scrape/google/flights")
          .query(&[("departureId", "LHR")])
          .query(&[("arrivalId", "JFK")])
          .query(&[("outboundDate", "2026-08-15")])
          .query(&[("returnDate", "2026-08-20")])
          .header("Content-Type", "application/json")
          .header("x-api-key", "<your-api-key>")
          .send()?
          .text()?;
      println!("{}", res);
      Ok(())
  }
  ```

  ```go Go theme={null}
  package main

  import (
  	"fmt"
  	"io"
  	"net/http"
  	"net/url"
  )

  func main() {
  	params := url.Values{}
  	params.Set("departureId", "LHR")
  	params.Set("arrivalId", "JFK")
  	params.Set("outboundDate", "2026-08-15")
  	params.Set("returnDate", "2026-08-20")

  	u := "https://api.hasdata.com/scrape/google/flights?" + params.Encode()

  	req, _ := http.NewRequest("GET", u, nil)
  	req.Header.Add("Content-Type", "application/json")
  	req.Header.Add("x-api-key", "<your-api-key>")

  	res, _ := http.DefaultClient.Do(req)
  	defer res.Body.Close()

  	body, _ := io.ReadAll(res.Body)
  	fmt.Println(string(body))
  }
  ```
</CodeGroup>

## API Parameters

| Parameter            | Default Value | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| -------------------- | ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `departureId`        | LHR           | Yes      | Specifies the departure airport code (IATA) or location kgmid.<br /><br />  - **IATA Code**: A 3-letter uppercase code (e.g., SFO for San Francisco, LHR for London Heathrow). Search on [IATA](https://www.iata.org/en/publications/directories/code-search).<br />  - **Location kgmid**: A string starting with `/m/`, found in Wikidata under "Freebase ID" (e.g., `/m/02_286` for New York, NY).<br /><br />Multiple values can be separated by commas (e.g., `JFK,LGA,/m/0hptm`).<br />                                                                                                                                                               |
| `arrivalId`          | JFK           | Yes      | Specifies the arrival airport code (IATA) or location kgmid.<br /><br />  - **IATA Code**: A 3-letter uppercase code (e.g., `SFO` for San Francisco, `LHR` for London Heathrow). Search on [IATA](https://www.iata.org/en/publications/directories/code-search).<br />  - **Location kgmid**: A string starting with `/m/`, found in Wikidata under "Freebase ID" (e.g., `/m/02_286` for New York, NY).<br /><br />Multiple values can be separated by commas (e.g., `JFK,LGA,/m/0hptm`).<br />                                                                                                                                                             |
| `outboundDate`       | 2026-08-15    | Yes      | The outbound travel date in 'yyyy-MM-dd' format.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `returnDate`         | 2026-08-20    | No       | The return travel date in 'yyyy-MM-dd' format. Required when **type** is `roundTrip`.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `type`               | -             | No       | Specifies the type of flight. Options:<br /><br />  - `roundTrip` (default)<br />  - `oneWay`<br />  - `multiCity` (requires `multiCityJson` for flight details)<br /><br />For round trips, retrieve return flight details with a separate request using `departureToken`.<br />                                                                                                                                                                                                                                                                                                                                                                           |
| `multiCityJson`      | -             | No       | This parameter specifies flight details for multi-city trips. It is a JSON string containing multiple flight objects. Each object must include the following fields:<br /><br />- **departureId** – The departure airport code or location KGMID. Uses the same format as the main `departureId` parameter.<br />- **arrivalId** – The arrival airport code or location KGMID. Uses the same format as the main `arrivalId` parameter.<br />- **date** – The flight date. Uses the same format as the `outboundDate` parameter.<br />- **times** *(optional)* – The time range for the flight. Uses the same format as the `outboundTimes` parameter.<br /> |
| `gl`                 | -             | No       | The two-letter country code for the country you want to limit the search to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `hl`                 | -             | No       | The two-letter language code for the language you want to use for the search.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `currency`           | -             | No       | Parameter defines the currency of the returned prices                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `travelClass`        | -             | No       | The travel class for the flight (Economy, Premium Economy, Business, or First).<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `showHidden`         | -             | No       | Indicates whether to include hidden options in the results.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `adults`             | -             | No       | Number of adult passengers (>= 1 if specified).<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `children`           | -             | No       | Number of child passengers.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `infantsInSeat`      | -             | No       | Number of infants occupying seats.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `infantsOnLap`       | -             | No       | Number of infants sitting on an adult's lap.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `sortBy`             | -             | No       | Sort the flight results based on price, departure time, arrival time, etc.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `stops`              | -             | No       | Restrict the number of stops (layovers) in the flight itinerary.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `excludeAirlines`    | -             | No       | A comma separated list of airline codes to exclude from results. You can search for airline codes on [IATA](https://www.iata.org/en/publications/directories/code-search). For example, `UA` is United Airlines.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `includeAirlines`    | -             | No       | A comma separated list of airline codes to exclusively include in results. You can search for airline codes on [IATA](https://www.iata.org/en/publications/directories/code-search). For example, `UA` is United Airlines.<br /><br />`excludeAirlines` and `includeAirlines` parameters can't be used together.<br />                                                                                                                                                                                                                                                                                                                                      |
| `bags`               | -             | No       | Number of carry-on bags per passenger.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `maxPrice`           | -             | No       | Maximum price limit for the flight search, in the selected currency.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `outboundTimes`      | -             | No       | Set up to 4 time boundaries (2 for departure, 2 for arrival) to filter flights. Each number represents the start of an hour.<br /><br />Examples:<br />  - `6,20` → 6:00 AM - 9:00 PM departure<br />  - `1,15` → 1:00 AM - 4:00 PM departure<br />  - `7,18,2,21` → 7:00 AM - 9:00 PM departure, 2:00 AM - 10:00 PM arrival<br />                                                                                                                                                                                                                                                                                                                          |
| `returnTimes`        | -             | No       | Set up to 4 time boundaries (2 for departure, 2 for arrival) to filter return flights. Each number represents the start of an hour.<br /><br />Examples:<br />  - `6,20` → 6:00 AM - 9:00 PM departure<br />  - `1,15` → 1:00 AM - 4:00 PM departure<br />  - `7,18,2,21` → 7:00 AM - 9:00 PM departure, 2:00 AM - 10:00 PM arrival<br />                                                                                                                                                                                                                                                                                                                   |
| `lessEmissions`      | -             | No       | Prefer flight options with lower carbon emissions.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `layoverDuration`    | -             | No       | Set the maximum layover duration in minutes to filter flights. For example, `120, 360` filters layovers between 2 hours and 6 hours, while `45, 180` allows layovers from 45 minutes to 3 hours.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `includeConnections` | -             | No       | A comma separated list of specific airports to allow as connections.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `excludeConnections` | -             | No       | A comma separated list of specific airports to exclude as connections.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `maxDuration`        | -             | No       | The maximum total flight duration in minutes.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `deepSearch`         | -             | No       | Enable deep search. Returns the same results as Google Flights in a browser, but takes longer to respond. Default is `false`.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `departureToken`     | -             | No       | Used to select a flight and retrieve return flights for a round trip or the next leg of the itinerary for a multi-city trip.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `bookingToken`       | -             | No       | Used to request booking options for selected flights. This token is found in the flight results and cannot be used with `departureToken`.<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
