Aviasales API in Python: flight prices via Travelpayouts
The Travelpayouts Data API returns cached prices from Aviasales searches, not a live search. One GET request with a token in the header is enough for prices by date and route. The main risks: data can be stale or missing for rare routes, so show prices as “from” and re-check them through the link.
If you are building a site, bot or Mini App with flights, the simplest price source is the Travelpayouts Data API (Aviasales). Below is a Python example, typical requests and the limits we ran into while working on HotTrip.
What the Data API is and how it differs from live search
The Data API returns cached prices collected from Aviasales user searches. It is fast and free, but it is not the same as a real-time search:
- a price can be stale: according to third-party wrappers, data comes from searches of roughly the last two days;
- for rare routes and dates there may be no data;
- the final price on the purchase page may differ.
Travelpayouts has a separate API for live search with different access conditions; see the documentation. For a showcase “from X” and destination lists the Data API is usually enough.
What you need
- A Travelpayouts account and a token (issued in your dashboard).
- Your affiliate marker for links, if you want a commission.
- Python and the
requestslibrary.
Pass the token in the x-access-token header and keep it in an environment variable, not in code.
Prices by route and dates
The main method is GET https://api.travelpayouts.com/aviasales/v3/prices_for_dates.
import os
import requests
API = "https://api.travelpayouts.com/aviasales/v3/prices_for_dates"
TOKEN = os.environ["TRAVELPAYOUTS_TOKEN"]
def cheapest(origin: str, destination: str, month: str, limit: int = 10) -> list[dict]:
"""Cheapest offers. origin/destination: IATA codes, month: '2026-12'."""
r = requests.get(
API,
headers={"x-access-token": TOKEN},
params={
"origin": origin,
"destination": destination,
"departure_at": month,
"sorting": "price",
"unique": "false",
"currency": "rub",
"limit": limit,
},
timeout=10,
)
r.raise_for_status()
return r.json().get("data", [])
for offer in cheapest("MOW", "IST", "2026-12"):
print(offer["departure_at"][:10], offer["price"], offer.get("airline"), offer.get("transfers"))
The response is a list of offers. Each usually has a price, an airline, a departure date, the number of transfers and a link field with a relative address of the Aviasales search page. Check exact fields and current parameters in the Travelpayouts documentation: they can change.
Popular destinations from a city
For a “Where to fly” block, GET /v1/city-directions?origin=MOW¤cy=rub is convenient. It returns the destinations from a city in one request, which is faster than looping over routes yourself.
City and airport codes
Use IATA codes. MOW means Moscow as a whole (all airports), SVO is one airport. For input suggestions there is the autocomplete https://autocomplete.travelpayouts.com/places2?term=...&locale=en, which returns cities and airports.
Links and the affiliate marker
The link field contains a path: build the full address as https://www.aviasales.ru + link and add your affiliate marker. Then clicks are counted in your dashboard. For short links in Telegram the API has a method to create shortened affiliate links.
Pitfalls from practice
- Cache on your side. Store responses in a database and refresh them on a schedule instead of on every user request: it is faster and saves limits.
- Empty responses. For some routes there is no data. Show a clear message and neighbouring dates or destinations.
- Freshness. Store the time a price was received and show it as “from”. Warn that the final price on the purchase page may differ.
- Timeouts and errors. Set a timeout and retry on failure. Do not make a user wait for an external API.
- Currency and language. The
currencyparameter controls the currency of prices; for different countries store prices per currency.
Where this is used
On top of the Data API we built a portal, a Telegram bot with flight search and price subscriptions, a Mini App and an automated channel that publishes fresh offers every two hours. Details are in the HotTrip project and in Integrations and APIs and Scraping and data.
FAQ
Is a paid plan required for the Data API?
A Travelpayouts token is issued in the partner dashboard. Access conditions for different APIs change, so check the current limits in the Travelpayouts documentation.
Are Data API prices a live search?
No. They are cached data from user searches, so a price can differ from what you see at purchase.
How do I earn a commission on sales?
Add your affiliate marker to Aviasales links. Then purchases through your links are counted in the Travelpayouts dashboard.
Can I call the API directly from a browser?
Not recommended: the token would be visible to everyone. Call the API from a server and give the client only the data it needs.
Plain version for AI and reading without styling: Markdown.