Skip to Content

Read a search

Wait for a partial search to finish, then sort, filter, page or read one result in full, all without starting another search.

Every search has a search_id. Read it again with GET /v1/flights/search/{search_id} to get the rest of a partial search, to sort, filter or page it differently, or to read one result in full. Reading a search never starts a supplier search, and it counts only toward your key's requests, not its new trips.

What a read takes

A read takes only the fields that shape the answer. The trip is already fixed by the search.

Prop

Type

A key reads only searches made in its own mode: a test key cannot read a live key's search, and a live key cannot read a test key's.

While a search runs, its answers have status partial and a retry_after_ms hint: how many milliseconds to wait before you ask again. This is part of a real partial answer:

Partial answer (excerpt)
{
  "search_id": "srch_2795d01a-c7bf-4851-afd8-438ab774b547",
  "status": "partial",
  "retry_after_ms": 2000,
  "counts": { "found": 2, "matched": 2, "returned": 2 },
  "next_cursor": null
}

There are two ways to wait for the rest:

  • Let the read wait. Send wait_ms, up to 30,000. The read answers as soon as the search is complete, or when the wait runs out with what has arrived. This is the simplest loop, and the one below.
  • Read at once, then pause. Leave wait_ms out, and wait retry_after_ms before each read.

Read with a wait_ms of 10,000, the same search answered complete with all six itineraries:

The same search, read again (excerpt)
{
  "search_id": "srch_2795d01a-c7bf-4851-afd8-438ab774b547",
  "status": "complete",
  "counts": { "found": 6, "matched": 6, "returned": 2 },
  "next_cursor": "c_eyJvIjoyLCJzIjoiMjc5NWQwMWEtYzdiZi00ODUxLWFmZDgtNDM4YWI3NzRiNTQ3IiwidiI6ImJlc3R8fCJ9"
}

While a search is partial, you can show its results as "so far": they are real fares. Its counts and airlines are also "so far". Most itineraries arrive within the first 5 to 15 seconds, and a large route can take about 30 seconds to complete. The supplier is given 45 seconds; a search still running after that ends with supplier_timeout.

A test key replays its saved sample in well under a second, so its searches are usually complete before you read them. To see a partial answer with a test key, search with response_mode=partial&wait_ms=0.

A polling loop

This loop starts a search, then reads it until it is complete. It stops on the first error, and after a minute of its own.

poll.sh
# Needs jq. SEARCH_ID is data.search_id from your search.
BASE="https://api.voyagelabs.ai"
SEARCH_ID="srch_2795d01a-c7bf-4851-afd8-438ab774b547"

# Up to six reads, each waiting up to 10 seconds.
for attempt in 1 2 3 4 5 6; do
  body=$(curl -sS "$BASE/v1/flights/search/$SEARCH_ID?wait_ms=10000" \
    -H "X-API-Key: $VOYAGE_LABS_API_KEY")
  status=$(printf '%s' "$body" | jq -r '.data.status // .error.code')
  echo "$status"
  [ "$status" = "partial" ] || break
done

When to stop

The read answersDo this
status completeStop. The list will not change.
supplier_timeout or supplier_errorStop. That search is over, and reading it again gives the same error. Search the trip again.
search_not_foundStop. The search is no longer kept. Search the trip again.
search_capacityWait error.retry_after_s seconds, then search the trip again.
rate_limitedWait error.retry_after_s seconds, then read again.
status partial past your own deadlineStop, and show what you have as "so far".

Don't search again while a search runs

Calling GET /v1/flights/search again for the same trip answers from the same running search, but it counts toward your new-trips limit each time. Read the search_id instead.

Sort, filter and page

Once a search is complete, read it with any sort, max_stops, airlines and limit. Each read reshapes the same stored itineraries, so you can offer "cheapest", "fastest" and "nonstop only" views without searching again.

Two pages, cheapest first
curl -sS "https://api.voyagelabs.ai/v1/flights/search/srch_2795d01a-c7bf-4851-afd8-438ab774b547?sort=price&limit=2" \
  -H "X-API-Key: $VOYAGE_LABS_API_KEY"

# Then pass that answer's data.next_cursor as cursor, with the same sort.
curl -sS "https://api.voyagelabs.ai/v1/flights/search/srch_2795d01a-c7bf-4851-afd8-438ab774b547?sort=price&limit=2&cursor=c_eyJvIjoyLCJzIjoiMjc5NWQwMWEtYzdiZi00ODUxLWFmZDgtNDM4YWI3NzRiNTQ3IiwidiI6InByaWNlfHwifQ" \
  -H "X-API-Key: $VOYAGE_LABS_API_KEY"
  • A cursor belongs to one search, sort and set of filters. Send it with the same sort, max_stops and airlines as the page it came from. Sent with any others, it is refused with invalid_parameter on cursor.
  • next_cursor is null on the last page.
  • Page only a complete search. While a search is partial the list is still changing: a page can repeat or miss itineraries, and next_cursor can be null although more are coming.

Read one result in full

To show the itinerary a traveller picked, read it with itinerary_id set to that result's id, exactly as given, and detail=full. The answer holds just that result, wherever it would sort or page, with every flight segment, layover and up to fares fares (3 unless set, 10 at most).

curl -sS "https://api.voyagelabs.ai/v1/flights/search/srch_2795d01a-c7bf-4851-afd8-438ab774b547?itinerary_id=it_U0ZPLk5SVC4yMDI3MDIwOS4yMDI3MDIxNi4yLjAuMC5ZLlVTRHxaRzI1QDAyMDksWkcyNkAwMjE2&detail=full&fares=3" \
  -H "X-API-Key: $VOYAGE_LABS_API_KEY"
  • Send no cursor with it. One result is not a page, so cursor is refused. max_stops and airlines still apply, so leave them out too.
  • An id the search does not hold answers 200 with no results, not an error. Search the trip again and read the new search_id with the same itinerary_id, waiting while it is partial: the same flights on the same trip always get the same id. Only an empty answer from a complete search means those flights are no longer offered.

How long a search is kept

A search is kept for at least 30 minutes. After that, reading it answers 404 with search_not_found: search the trip again.

Reading a search never refreshes its prices: its pricing.age_s keeps growing. Before you show a price or a booking link that is more than 240 seconds old, search the trip again and read the chosen result from the new search by its itinerary_id.

On this page