Skip to main content

Google Flights

Empower your agents to search for flight options, prices, and schedules through Google Flights, powered by SerpApi.

This guide will walk you through obtaining a SerpApi key, configuring the SVAHNAR tool, and building flight search workflows.

💡 Core Concepts

To configure this tool effectively, you need to understand the underlying capabilities, the trip type model, and the full parameter set available for filtering.

1. What can this tool do?

The Google Flights tool queries Google Flights via SerpApi to search real-time flight availability, pricing, and schedules across airlines worldwide.

CapabilityDescription
One-way searchSearch for one-way flights between two airports.
Round trip searchSearch for round trips with a configurable return date.
Multi-city searchSearch for multi-leg itineraries.
Cabin class filteringFilter by Economy, Premium Economy, Business, or First Class.
Passenger configurationSpecify adults, children, and infants separately.
Airline include/excludeRestrict or exclude specific airlines or alliances.
Stop filteringLimit results to nonstop, 1-stop, or 2-stop flights.
Price capSet a maximum ticket price to filter out expensive options.
Duration & layover limitsFilter by max flight duration and layover time windows.
Emissions filterLimit results to lower-emissions flight options.
note

This tool is read-only. It searches and returns flight options — it does not book tickets, process payments, or interact with airline reservation systems.

2. Authentication

This tool uses a SerpApi API Key — a static key passed with every request.

  • No OAuth required: Generate a key once from the SerpApi dashboard and paste it into SVAHNAR. No per-user login flow needed.
  • Rate limits: SerpApi enforces monthly search credit limits based on your plan. Each tool call consumes one search credit.
  • Maintenance: API keys do not expire automatically. They are invalidated only if manually rotated from the SerpApi dashboard.
tip

If you already use the Google Jobs or Google Finance tools, your SerpApi key is the same — one key works across all SerpApi-powered tools in SVAHNAR.

3. Trip Type Model

The type parameter controls the entire search structure. Set it correctly before configuring any other fields.

typeTrip Typereturn_date Required
1Round tripYes
2One wayNo
3Multi-cityNo
caution

For round trips (type: 1), return_date is mandatory. Omitting it will cause the query to fail or return incorrect results.

4. Parameter Reference

Core Search Parameters

ParameterTypeRequiredDescriptionExample
departure_idstringYesDeparture airport IATA code."DEL", "JFK"
arrival_idstringYesArrival airport IATA code."DXB", "LAX"
outbound_datestringYesDeparture date in YYYY-MM-DD format."2025-12-24"
return_datestringRequired if type: 1Return date in YYYY-MM-DD format."2026-01-02"
typeintYes1 = Round trip, 2 = One way, 3 = Multi-city.2
travel_classintNo1 = Economy, 2 = Premium Economy, 3 = Business, 4 = First.1
currencystringNo3-letter ISO currency code for prices."USD", "INR"
enginestringNoMust be "google_flights" when specified."google_flights"

Passenger Parameters

ParameterTypeDefaultDescription
adultsint1Number of adult passengers.
childrenint0Number of child passengers.
infants_in_seatint0Infants occupying their own seat.
infants_on_lapint0Infants travelling on a lap.

Sorting & Filter Parameters

ParameterTypeDescriptionExample
sort_byint1 = Top picks, 2 = Price, 3 = Departure time, 4 = Arrival time, 5 = Duration, 6 = Emissions.2
stopsint0 = Any, 1 = Nonstop only, 2 = 1 stop or fewer, 3 = 2 stops or fewer.1
max_priceintMaximum ticket price in the specified currency.500
bagsintNumber of carry-on bags.1
max_durationintMaximum total flight duration in minutes.300
layover_durationstringMin and max layover in minutes — "min,max"."90,300"
emissionsintSet to 1 to restrict to lower-emissions flights only.1
outbound_timesstringDeparture/arrival time window — "HH,HH" (dep only) or "HH,HH,HH,HH" (dep + arr)."4,18"
return_timesstringReturn leg time window — same format as outbound_times. Only used when type: 1."6,22"
include_airlinesstringComma-separated IATA airline codes or alliance names to include."AI,6E", "ONEWORLD"
exclude_airlinesstringComma-separated IATA codes or alliances to exclude."UA,SKYTEAM"
exclude_connsstringComma-separated airport IATA codes to avoid as layover points."ORD,DFW"

Airline Alliance Codes for include_airlines / exclude_airlines:

AllianceCode
Star AllianceSTAR_ALLIANCE
SkyTeamSKYTEAM
OneworldONEWORLD

🔑 Prerequisites

Create a SerpApi Account

  1. Go to https://serpapi.com and sign up for an account.
  2. SerpApi offers a free tier with 100 searches/month — sufficient for development and light agent usage.
  3. For production workloads or high-frequency flight monitoring, select a paid plan based on your expected monthly query volume.

Get Your API Key

  1. After signing in, go to your SerpApi Dashboard.
  2. Copy the API Key shown on the dashboard.
caution

Never commit this key to version control or hardcode it in config files. Use SVAHNAR Key Vault (${serpapi_key}) to reference it safely. If you already use other SerpApi tools in SVAHNAR, the same key applies — no separate account needed.


⚙️ Configuration Steps

Add the Tool in SVAHNAR

  1. Open your SVAHNAR Agent Configuration.

  2. Add the Google Flights tool and enter your SerpApi credentials:

    • api_key — your SerpApi API key
  3. Save the configuration.

Verify the Connection

To confirm your API key is working:

  1. Trigger a test agent run with a simple one-way payload:
{
"departure_id": "DEL",
"arrival_id": "BOM",
"outbound_date": "2025-12-24",
"type": 2,
"currency": "INR"
}
  1. A valid response will return a list of available flights with airlines, prices, and durations.
  2. If you receive an Invalid API key error, verify the key was copied in full from your SerpApi dashboard.
  3. If you receive a credits exhausted error, your monthly search quota has been reached.

📚 Practical Recipes (Examples)

Recipe 1: Flight Search Agent

Use Case: An agent that finds the best flight options based on the user's travel preferences.

create_vertical_agent_network:
agent-1:
agent_name: flight_search_agent
LLM_config:
params:
model: gpt-4o
tools:
tool_assigned:
- name: GoogleFlights
config:
api_key: ${serpapi_key}
agent_function:
- You are a flight search assistant.
- Ask the user for origin airport, destination airport, travel date, trip type (one-way or round trip), number of passengers, and preferred cabin class.
- For round trips, also ask for the return date.
- Construct the payload using the correct IATA airport codes. Set 'type' to 2 for one-way or 1 for round trip.
- Set 'sort_by' to 2 (Price) by default unless the user prefers fastest or best-ranked results.
- Return the top 5 options — airline, departure time, arrival time, stops, duration, and price.
incoming_edge:
- Start
outgoing_edge: []

Recipe 2: Budget Flight Finder Agent

Use Case: An agent that searches for the cheapest nonstop flights under a user-defined price cap.

create_vertical_agent_network:
agent-1:
agent_name: budget_flight_finder
LLM_config:
params:
model: gpt-4o
tools:
tool_assigned:
- name: GoogleFlights
config:
api_key: ${serpapi_key}
agent_function:
- You are a budget travel assistant.
- Ask the user for their route, travel date, and maximum budget.
- Set 'stops' to 1 (Nonstop only) and 'max_price' to the user's budget.
- Set 'sort_by' to 2 (Price) to surface cheapest options first.
- Set 'currency' to match the user's preferred currency.
- If no nonstop options exist under the budget, retry with 'stops' set to 2 (1 stop or fewer) and notify the user.
- Return results with airline, price, duration, and number of stops clearly labelled.
incoming_edge:
- Start
outgoing_edge: []

Recipe 3: Business Travel Planner Agent

Use Case: An agent that finds premium cabin round trips with airline preferences and layover constraints.

create_vertical_agent_network:
agent-1:
agent_name: business_travel_planner
LLM_config:
params:
model: gpt-4o
tools:
tool_assigned:
- name: GoogleFlights
config:
api_key: ${serpapi_key}
agent_function:
- You are a business travel planning assistant.
- Ask for the route, outbound date, return date, and any airline preferences (specific airlines or alliances).
- Set 'type' to 1 (Round trip), 'travel_class' to 3 (Business) or 4 (First) based on user preference.
- Set 'layover_duration' to '60,240' to avoid very short connections and excessively long layovers.
- Use 'include_airlines' if the user has a preferred airline or alliance (e.g., ONEWORLD or STAR_ALLIANCE).
- Use 'exclude_conns' to avoid any connection airports the user wants to skip.
- Set 'sort_by' to 5 (Duration) to prioritize fastest itineraries. Return top 3 options with full itinerary details.
incoming_edge:
- Start
outgoing_edge: []

💡 Tip: SVAHNAR Key Vault

Never hardcode your api_key in plain text files. Use SVAHNAR Key Vault references (e.g., ${serpapi_key}) to keep credentials secure. The same SerpApi key used for Google Jobs and Google Finance works here — no separate credential needed.

💡 Tip: Indian Route Searches

For domestic Indian flights and routes to/from India, always set currency: "INR" and use the correct IATA codes. Common Indian airport codes:

CityAirportIATA Code
DelhiIndira Gandhi InternationalDEL
MumbaiChhatrapati Shivaji Maharaj InternationalBOM
BangaloreKempegowda InternationalBLR
HyderabadRajiv Gandhi InternationalHYD
ChennaiChennai InternationalMAA
KolkataNetaji Subhas Chandra Bose InternationalCCU
PunePune AirportPNQ
AhmedabadSardar Vallabhbhai Patel InternationalAMD

🚑 Troubleshooting

  • Invalid API key Error

    • Your SerpApi key is incorrect or was not copied in full. Go to your SerpApi Dashboard, copy the key again, and update it in SVAHNAR Key Vault.
  • Credits Exhausted Error

    • Your monthly SerpApi search quota has been reached. Each Google Flights query consumes one credit.
    • Upgrade your plan at serpapi.com/pricing or reduce query frequency. Avoid running broad searches for date ranges — each date requires a separate query.
  • No Flights Returned

    • Verify the departure_id and arrival_id are valid IATA airport codes — not city names or full airport names. "Delhi" will not work; "DEL" will.
    • Check that outbound_date is a future date in YYYY-MM-DD format. Past dates return no results.
    • If stops: 1 (nonstop only) returns nothing, the route may have no direct flights — retry with stops: 2.
  • Round Trip Returns No Results

    • Ensure return_date is set when type: 1. Omitting it for a round trip query causes incorrect or empty results.
    • Verify return_date is after outbound_date.
  • Prices Showing in Wrong Currency

    • Always set the currency field explicitly using a valid 3-letter ISO 4217 code — e.g., "INR", "USD", "EUR". Without it, SerpApi defaults to USD.
  • outbound_times or return_times Not Filtering Correctly

    • The time window format is "HH,HH" for departure window only, or "HH,HH,HH,HH" for departure + arrival window. Values are in 24-hour format — e.g., "6,22" means 06:00 to 22:00.
    • return_times is only applied when type: 1 (round trip). It has no effect on one-way searches.
  • engine Field Causing Errors

    • If specified, engine must be exactly "google_flights". Any other value routes to a different SerpApi engine and returns unexpected data. When in doubt, omit the field entirely — it defaults correctly.