API Hop

गाइड

Google Flights API Python Guide: $0.0003/Req पर

QPX बंद होने के बाद Python में Google Flights API कैसे use करें: search, autocomplete और deals endpoints $0.0003/req में, code और pricing math के साथ।

समीक्षित:

Google ने 2018 में अपना official QPX Express flight API बंद कर दिया था और अब developers के लिए कोई public self-serve Google Flights API नहीं देता। API Hop Google Flights Data API के ज़रिए तीन synchronous GET endpoints—flight search, airport autocomplete और deals discovery—फ्लैट $0.0003 प्रति सफल request ($0.30 प्रति 1,000 calls) पर मिलते हैं, जो SerpApi subscriptions से करीब 30x सस्ते हैं। इससे आप 10 मिनट से कम में Python में fare trackers और travel agents बना सकते हैं।

मुख्य बातें

  • कोई Official Public Google Flights API नहीं है: Google ने April 2018 में QPX Express बंद कर दिया था। बिना enterprise GDS contracts या टूटने वाले headless scrapers के fare monitoring और itinerary comparison के लिए एक managed REST data API सीधे structured Google Flights results देता है।
  • $0.0003 प्रति call वाले तीन GET Endpoints: GET /v1/google-flights/search, GET /v1/google-flights/autocomplete, और GET /v1/google-flights/deals सभी पर बिना किसी monthly fee के $0.0003 प्रति सफल call (300 credits) लगते हैं।
  • सख्त Trip-Type और Token नियम: Round trips (type=1) में return_date ज़रूरी है, one-way queries (type=2) में return_date मना है, और multi-city searches (type=3) में multi_city_json के अंदर 2 से 5 legs चाहिए। departure_token और booking_token को कभी एक साथ न भेजें, और ध्यान रखें कि हर token lookup एक अलग billable request है।
  • Failed Calls Refund; Empty Results Bill: Upstream errors और 60-second timeouts पर बिना automatic retry के आपका credit hold release हो जाता है। लेकिन results: [] लौटाने वाला सफल response भी एक $0.0003 call के रूप में bill होता है।
  • $10 Minimum Top-Up में 33,333 Searches: API Hop Pricing page पर $10 का prepaid balance कभी expire नहीं होता और बिना overseas credit card के USDT/USDC crypto के साथ Brazil PIX और Indonesia QRIS/GoPay/DANA को भी support करता है।

2026 में Google Flights Data पाने के 5 तरीके

पाँच मुख्य flight-data विकल्पों में onboarding barriers, billing models और engineering trade-offs की तुलना करें (2026-11-28 को verified):

Access RouteAccess Barrier और FocusBilling Model10,000 Searches का अनुमानित खर्चमुख्य Limitation
SerpApi (engine=google_flights)Self-serve signupMonthly subscription (Developer $75/mo 5,000 के लिए, Production $150/mo 15,000 के लिए)$100.00–$150.00बचा हुआ monthly quota expire हो जाता है; round-trip leg selection में extra calls लगते हैं
SearchApi / FlightPowersSelf-serve signupTiered plans (SearchApi ~$4.00/1K; FlightPowers ~$10/2,500 searches)~$40.00अभी भी monthly plans या fixed credit bundles से बंधा है
Open-Source fast_flights (Python)Free GitHub libraryFree library + खुद manage किए जाने वाले residential proxies$0 (+ $10–$40+/mo proxies)Cloud data-center IPs बार-बार block होते हैं और DOM टूटने का जोखिम रहता है
Duffel / Amadeus (NDC / GDS)Business verification (live ticketing पर केंद्रित)Per-booking fees या tiered search contractsAirline contract के अनुसार बदलता हैभारी onboarding; Google Flights price insights और explore feeds नहीं मिलते
API Hop Google Flights APISelf-serve, तुरंत Bearer keyPay-as-you-go $0.0003 / सफल call ($0 monthly fee)$3.00सिर्फ Read-only fare और itinerary data (सीधा ticket checkout नहीं); token steps client संभालता है

शुरू करने से पहले की तैयारियाँ

पहली query चलाने से पहले तीन चीज़ें तैयार रखें:

  1. API Hop Key: API Hop Pricing page पर account बनाकर key generate करें। Billing prepaid pay-as-you-go ($10 minimum top-up, non-expiring credits) है और इसके लिए किसी US credit card या corporate KYC की ज़रूरत नहीं है—यह USDT/USDC crypto के साथ Brazil PIX और Indonesia QRIS, GoPay और DANA स्वीकार करता है।
  2. Local Runtime: requests installed वाला Python 3.9+, या सामान्य curl।
  3. Contract Bookmarks: सभी 35+ query parameters, currency codes और validation rules देखने के लिए Google Flights API Overview और Google Flights Endpoint Reference खुले रखें।
pip install -U requests
export APIHOP_API_KEY="sk-your-apihop-key"

सभी Google Flights endpoints बिना किसी request body के GET query parameters लेते हैं और Authorization: Bearer से authenticate होते हैं। JFK से LAX की एक one-way search ($0.0003/call) चलाएँ:

curl --get "https://api.apihop.ai/v1/google-flights/search" \
  -H "Authorization: Bearer $APIHOP_API_KEY" \
  --data-urlencode "departure_id=JFK" \
  --data-urlencode "arrival_id=LAX" \
  --data-urlencode "outbound_date=2026-12-12" \
  --data-urlencode "type=2" \
  --data-urlencode "currency=USD"

अपेक्षित response envelope जो native precision बनाए रखता है (यह ढाँचा उदाहरण के लिए है; live payloads में ताज़ा results दिखते हैं, और खाली match पर results array खाली आता है):

{
  "success": true,
  "request_id": "req_01j9flights...",
  "data": {
    "format": "json",
    "content": {
      "results": []
    }
  }
}

छोटा Python Example

import os
import requests

resp = requests.get(
    "https://api.apihop.ai/v1/google-flights/search",
    headers={"Authorization": f"Bearer {os.environ['APIHOP_API_KEY']}"},
    params={"departure_id": "JFK", "arrival_id": "LAX", "outbound_date": "2026-12-12", "type": "2", "currency": "USD"},
    timeout=60,
)
resp.raise_for_status()
payload = resp.json()
print("request_id:", payload.get("request_id"), "keys:", list(payload.get("data", {}).get("content", {}).keys()))

अपेक्षित output: request_id: req_... keys: [...] जो content के अंदर की top-level keys दिखाता है।

Step-by-Step Guide: Autocomplete, Filtered Search और Deals

Travel apps और AI booking assistants आम तौर पर इन तीनों endpoints को जोड़ते हैं: शहर के नाम को IATA codes में बदलना, filtered itineraries खोजना और सस्ते flexible destinations तलाशना।

Step 1: /autocomplete से Airport Codes निकालें ($0.0003/call)

कभी भी "New York" जैसे free-text शहर के नाम सीधे /search को न भेजें। पहले GET /v1/google-flights/autocomplete call करें ताकि 3-letter IATA airport codes (JFK) या Google Travel entity IDs (/m/02_286) मिल सकें। Country-level entries हटाने के लिए exclude_regions=true जोड़ें:

import os
import requests

r = requests.get(
    "https://api.apihop.ai/v1/google-flights/autocomplete",
    headers={"Authorization": f"Bearer {os.environ['APIHOP_API_KEY']}"},
    params={"query": "New York", "exclude_regions": "true", "limit": 5, "language": "en"},
    timeout=60,
)
r.raise_for_status()
print("Autocomplete X-Request-Id:", r.headers.get("X-Request-Id"), "status:", r.json().get("success"))

अपेक्षित output: Autocomplete X-Request-Id: ... status: True। अब आप /search पर departure_id या arrival_id में comma-separated codes जैसे JFK,LGA,EWR भेज सकते हैं।

Step 2: Cabin और Airline Filters के साथ Round-Trip Fares खोजें ($0.0003/call)

GET /v1/google-flights/search 30 से ज्यादा filters support करता है जिनमें stops=1 (nonstop), travel_class (economy, premium_economy, business, first), alliance codes (STAR_ALLIANCE, SKYTEAM, ONEWORLD) और carry-on bags (जो adults + children + infants_in_seat से ज्यादा नहीं हो सकते) शामिल हैं:

import os
import requests

params = {
    "departure_id": "SFO",
    "arrival_id": "NRT",
    "outbound_date": "2026-12-10",
    "return_date": "2026-12-20",
    "type": "1",
    "adults": 1,
    "travel_class": "economy",
    "stops": 1,
    "sort_by": "price",
    "currency": "USD",
    "zero_trace": "true",
}
r = requests.get(
    "https://api.apihop.ai/v1/google-flights/search",
    headers={"Authorization": f"Bearer {os.environ['APIHOP_API_KEY']}"},
    params=params,
    timeout=60,
)
r.raise_for_status()
print("Search success:", r.json().get("success"), "req:", r.headers.get("X-Request-Id"))

अपेक्षित output: Search success: True req: ...। zero_trace=true भेजने से gateway sensitive enterprise queries के लिए source या parsed artifacts को archive नहीं करता।

Step 3: /deals से Flexible Destinations खोजें ($0.0003/call)

जब travelers बिना तय destination के किसी hub से सबसे सस्ती जगहें देखना चाहें, तो GET /v1/google-flights/deals call करें। इसमें departure_id ज़रूरी है, जिसके साथ या तो natural-language query (जैसे "Week long trip to a city with great food") दें या travel_duration (1 एक हफ्ता, 2 वीकेंड, 3 दो हफ्ते) और max_price लगाएँ:

import os
import requests

r = requests.get(
    "https://api.apihop.ai/v1/google-flights/deals",
    headers={"Authorization": f"Bearer {os.environ['APIHOP_API_KEY']}"},
    params={
        "departure_id": "JFK",
        "travel_duration": 2,
        "stops": 1,
        "max_price": 450,
        "currency": "USD",
        "limit": 10,
    },
    timeout=60,
)
r.raise_for_status()
print("Deals status:", r.json().get("success"), "req:", r.headers.get("X-Request-Id"))

अपेक्षित output: Deals status: True req: ...। ध्यान दें कि travel_duration को query या exact dates के साथ मिलाकर नहीं भेजा जा सकता। पूरे parameter rules Google Flights Endpoint Reference में देखें।

पूरा Working Example: Airport Resolve करें, Fares खोजें, Retry करें और JSON सेव करें

यह production-ready Python script origin city को resolve करती है, 429/5xx exponential backoff के साथ round-trip fares लाती है, JSON response सेव करती है और सटीक request spend बताती है:

import json
import os
import time
import requests

API_KEY = os.environ["APIHOP_API_KEY"]
BASE_URL = "https://api.apihop.ai/v1/google-flights"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}


def call_flights(path: str, params: dict, max_retries: int = 3) -> dict:
    for attempt in range(max_retries):
        resp = requests.get(f"{BASE_URL}{path}", headers=HEADERS, params=params, timeout=60)
        req_id = resp.headers.get("X-Request-Id")
        if resp.status_code == 200:
            body = resp.json()
            if body.get("success") is False:
                raise RuntimeError(f"API business error: {body} (req={req_id})")
            return body
        if resp.status_code in (429, 500, 502, 503, 504) and attempt < max_retries - 1:
            wait = 2 ** (attempt + 1)
            print(f"[Retry {attempt + 1}] HTTP {resp.status_code}, sleep {wait}s (req={req_id})")
            time.sleep(wait)
            continue
        resp.raise_for_status()
    raise RuntimeError("Max retries exceeded")


def search_route(origin_city: str, dest_iata: str, out_date: str, ret_date: str | None = None):
    requests_used = 0
    ac = call_flights("/autocomplete", {"query": origin_city, "exclude_regions": "true", "limit": 3})
    requests_used += 1
    content_ac = ac.get("data", {}).get("content", {})
    print(f"Resolved origin '{origin_city}' keys: {list(content_ac.keys())}")

    # In production parse the top IATA from content_ac; using JFK here as an example
    search_params = {
        "departure_id": "JFK",
        "arrival_id": dest_iata,
        "outbound_date": out_date,
        "currency": "USD",
        "sort_by": "price",
        "type": 1 if ret_date else 2,
    }
    if ret_date:
        search_params["return_date"] = ret_date

    flights = call_flights("/search", search_params)
    requests_used += 1

    out_file = f"flights_JFK_{dest_iata}_{out_date}.json"
    with open(out_file, "w", encoding="utf-8") as f:
        json.dump(flights, f, ensure_ascii=False, indent=2)

    cost = requests_used * 0.0003
    print(f"Saved {out_file} | Requests: {requests_used} | Est. Cost: ${cost:.4f}")


if __name__ == "__main__":
    search_route("New York", "LAX", "2026-12-12", "2026-12-19")

अपेक्षित output: Resolved origin 'New York' keys: [...] प्रिंट होता है, flights_JFK_LAX_2026-12-12.json बनता है, और Requests: 2 | Est. Cost: $0.0006 दिखता है।

Round-trip outbound results में हर flight option के साथ एक departure_token आता है। उससे मेल खाने वाली return legs या अंतिम booking_token checkout links पाने के लिए, ताज़ा token के साथ GET /v1/google-flights/search पर सभी मूल itinerary parameters दोहराएँ:

import os
import requests

# Each token lookup counts as one separate $0.0003 request
r = requests.get(
    "https://api.apihop.ai/v1/google-flights/search",
    headers={"Authorization": f"Bearer {os.environ['APIHOP_API_KEY']}"},
    params={
        "departure_id": "JFK",
        "arrival_id": "LAX",
        "outbound_date": "2026-12-12",
        "return_date": "2026-12-19",
        "type": "1",
        "departure_token": "PASTE_FRESH_DEPARTURE_TOKEN_HERE",
    },
    timeout=60,
)
print("HTTP:", r.status_code)

दो नियम याद रखें: पहला, एक request में departure_token और booking_token साथ नहीं चल सकते। दूसरा, tokens जल्दी expire होते हैं, इसलिए हमेशा ताज़ा response से ही सटीक string कॉपी करें।

Error Handling

तेज़ diagnostics के लिए हर call पर X-Request-Id response header log करें:

HTTP Statusमतलब और आम कारणसही Action
400Validation failure (जैसे type=2 के साथ return_date, unsupported html/output/no_cache, दोनों tokens साथ, >9 travelers)Google Flights Endpoint Reference में नियम चेक करें
401Authorization: Bearer key गायब या गलतAPIHOP_API_KEY environment variable चेक करें
402Prepaid credits कम हैंAPI Hop Pricing page पर top up करें
403इस API key के लिए gateway access मना हैDashboard में key permissions चेक करें
405GET-only endpoint पर POST या request body भेजा गयाQuery parameters के साथ GET और body = null इस्तेमाल करें
429Rate या concurrency limit पूरी हुईPacing delays और 2s / 4s exponential backoff जोड़ें
5xx / 60s timeoutUpstream या service failure (hold release, कोई bill नहीं)1–2 बार retry करें और X-Request-Id संभालें

आम समस्याएं और सावधानियाँ

  1. type=2 के साथ return_date भेजना या type=1 में छोड़ देना: Validation के तहत type=1 में return_date ज़रूरी है और type=2 में return_date मना है। type छोड़ देने पर gateway return_date की मौजूदगी से खुद round-trip या one-way समझ लेता है।
  2. /deals पर travel_duration को query या exact dates के साथ मिलाना: travel_duration (1/2/3) सिर्फ flexible date discovery के लिए है और query या fixed outbound_date/return_date के साथ भेजने पर 400 आता है।
  3. html, output, json_restrictor, या no_cache जैसे generic SERP flags भेजना: ये चारों parameters स्पष्ट रूप से unsupported हैं और तुरंत HTTP 400 rejection देते हैं।
  4. US economy routes के बाहर exclude_basic=true लगाना: Documentation के अनुसार exclude_basic=true के लिए country=us (default) और travel_class=economy (default) ज़रूरी हैं।
  5. departure_token और booking_token दोनों साथ भेजना: Contract NOT (departure_token AND booking_token) लागू करता है और हर token call पर मूल departure_id, arrival_id व date fields दोहराने की माँग करता है।

Cost Estimation

API Hop के $0.0003 प्रति सफल request ($0.30 प्रति 1,000 calls) rate की तुलना SerpApi के monthly plans ($75/mo में 5,000 calls = $0.015/call; $150/mo में 15,000 calls = $0.010/call) के साथ चार real-world workloads पर देखें:

$$\text{Task Cost} = (N_{\text{autocomplete}} + N_{\text{search}} + N_{\text{deals}} + N_{\text{token}}) \times $0.0003$$

WorkloadCost FormulaAPI Hop SpendSerpApi Plan Est. (Ref.)
यह Tutorial Script चलाना (1 autocomplete + 1 search)2 × $0.0003$0.0006 (<0.1 cent)कम से कम $75/mo plan ज़रूरी
20 Routes का Daily Fare Monitor (मासिक)20 × 30 days = 600 × $0.0003$0.18 / month$75 / month (Developer tier)
AI Travel Assistant (300 searches + 100 deals/दिन)400 × 30 = 12,000 × $0.0003$3.60 / month$150 / month (Production 15K tier)
OTA Fare Calendar (2,000 date-matrix queries/दिन)60,000 × $0.0003$18.00 / monthबड़ा enterprise tier ($600+/mo)

API Hop Pricing page पर $10 minimum top-up से 33,333 Google Flights requests चलती हैं और credits कभी expire नहीं होते। यही balance API Hop Data API Catalog—जिसमें Google Hotels, Airbnb और Google Travel Explore शामिल हैं—और DeepSeek व Claude जैसे LLMs पर भी चलता है, जिससे पूरा trip planner बन जाता है।

आगे किन बातों पर नज़र रखें

  • deep_search Compatibility: deep_search=true और false दोनों ही अंदर से पूरी streaming search चलाते हैं, इसलिए पुराने integrations में किसी extra parameter tuning की ज़रूरत नहीं है।
  • Two-Step Round-Trip Token Budgets: Outbound flights, return flights (departure_token), और checkout links (booking_token) लाने में कुल 3 /search calls (कुल $0.0009) लगती हैं। Duplicate charges से बचने के लिए एक जैसे route lookups को Redis में cache करें।

FAQ

क्या Google Flights API free है?

नहीं। Google ने April 2018 में अपना official developer QPX Express API बंद कर दिया था और कोई free self-serve Google Flights API नहीं देता। fast_flights जैसी community Python libraries install करने में free हैं, लेकिन cloud IP से सीधी scraping अक्सर block हो जाती है। बिना monthly fee के भरोसेमंद REST access के लिए API Hop Pricing page पर $10 का non-expiring top-up हर call को $0.0003 पर रखता है—इस tutorial को चलाने का खर्च सिर्फ $0.0006 आता है।

API Hop Google Flights API की pricing कैसे काम करती है?

इसमें कोई monthly subscription नहीं है। GET /v1/google-flights/search, GET /v1/google-flights/autocomplete और GET /v1/google-flights/deals सभी $0.0003 प्रति सफल request (300 credits, या $0.30 प्रति 1,000 calls) चार्ज करते हैं। Token lookups (departure_token या booking_token) और खाली सफल results पर 1 request bill होता है, जबकि failed या timed-out upstream calls पर credit hold release हो जाता है।

क्या यह API सीधे airline tickets book या issue कर सकता है?

नहीं। Google Flights Data API केवल fare discovery, flight schedules और booking_token links के लिए read-only है। अगर आपके product को passenger PNR creation और payment checkout चाहिए, तो fare search के साथ Duffel या Amadeus जैसा NDC या GDS ticketing API जोड़ें।

/search को सीधे "New York" भेजने के बजाय /autocomplete की ज़रूरत क्यों है?

/search departure_id और arrival_id को सख्ती से 3-letter uppercase IATA airport codes (जैसे JFK) या Google Travel के /m/ या /g/ entity IDs के खिलाफ validate करता है। सादा शहर का नाम भेजने पर HTTP 400 मिलता है, इसलिए पहले /autocomplete ($0.0003) call करने से सही multi-airport identifiers मिल जाते हैं।

बिना US credit card के कौन-से payment methods supported हैं?

API Hop बिना US credit card या business KYC के दुनिया भर में self-serve prepaid top-ups support करता है। API Hop Pricing page पर आप USDT/USDC crypto के साथ-साथ Brazil PIX और Indonesia QRIS, GoPay, और DANA जैसे regional wallets से भी pay कर सकते हैं।

Verification note: 3 Google Flights endpoint paths, validation rules और $0.0003 प्रति सफल request का rate 2026-11-28 को API Hop reference docs और public market pricing से verify किए गए (account-specific rates मान्य होंगे)।