# Search flights (/flights/search)

Name a trip with GET or POST, choose how long to wait, and shape the answer. With a full example and a real response.

A search names one trip and answers with priced itineraries. You choose how long the call waits, and how the answer is filtered, sorted and trimmed.

## Make a search [#make-a-search]

`GET /v1/flights/search` is the main form: a search changes nothing, so the whole request fits in a URL. This one asks for a round trip for two adults and one result.

<Tabs items={["curl","JavaScript","Python"]}>
<Tab value="curl">
```bash
curl -sS "https://api.voyagelabs.ai/v1/flights/search?origin=SFO&destination=NRT&depart_date=2027-02-09&return_date=2027-02-16&adults=2&limit=1" \
  -H "X-API-Key: $VOYAGE_LABS_API_KEY"
```
</Tab>

<Tab value="JavaScript">
```js title="search.mjs"
const params = new URLSearchParams({
  origin: "SFO",
  destination: "NRT",
  depart_date: "2027-02-09",
  return_date: "2027-02-16",
  adults: "2",
  limit: "1",
});

const response = await fetch(
  `https://api.voyagelabs.ai/v1/flights/search?${params}`,
  { headers: { "X-API-Key": process.env.VOYAGE_LABS_API_KEY } },
);
const body = await response.json();

if (body.error) {
  throw new Error(`${body.error.code}: ${body.error.message}`);
}
console.log(body.data.status, body.data.counts.found, "itineraries found");
```
</Tab>

<Tab value="Python">
```python title="search.py"
import os

import requests

response = requests.get(
    "https://api.voyagelabs.ai/v1/flights/search",
    params={
        "origin": "SFO",
        "destination": "NRT",
        "depart_date": "2027-02-09",
        "return_date": "2027-02-16",
        "adults": 2,
        "limit": 1,
    },
    headers={"X-API-Key": os.environ["VOYAGE_LABS_API_KEY"]},
    timeout=40,
)
body = response.json()

if "error" in body:
    raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")
print(body["data"]["status"], body["data"]["counts"]["found"], "itineraries found")
```
</Tab>
</Tabs>

By default the call waits for the complete answer, for up to 30 seconds, so give your HTTP client a timeout longer than that. The Python example uses 40 seconds.

This is the answer to that request, made with a test key. The link tokens are shortened here; real ones are much longer.

```json title="Response"
{
  "data": {
    "search_id": "srch_17a3c431-779c-4a88-9ebf-5f4b1eee0736",
    "status": "complete",
    "query": {
      "origin": "SFO",
      "destination": "NRT",
      "depart_date": "2027-02-09",
      "return_date": "2027-02-16",
      "adults": 2,
      "children": 0,
      "infants": 0,
      "cabin": "economy",
      "currency": "USD"
    },
    "pricing": { "priced_at": "2026-12-06T20:46:06.727Z", "age_s": 0, "refreshing": false },
    "counts": { "found": 6, "matched": 6, "returned": 1 },
    "next_cursor": "c_eyJvIjoxLCJzIjoiMTdhM2M0MzEtNzc5Yy00YTg4LTllYmYtNWY0YjFlZWUwNzM2IiwidiI6ImJlc3R8fCJ9",
    "airlines": [
      { "code": "ZG", "name": "ZIPAIR", "results": 1, "from": 1445.02, "best_link": "itinerary" },
      { "code": "UA", "name": "United", "results": 1, "from": 2792.18, "best_link": "itinerary" },
      { "code": "JL", "name": "JAL", "results": 2, "from": 2808.18, "best_link": "itinerary" },
      { "code": "NH", "name": "ANA", "results": 1, "from": 2823.38, "best_link": "flights_selected" },
      { "code": "AS", "name": "Alaska", "results": 1, "from": 2920.18, "best_link": "itinerary" }
    ],
    "results": [
      {
        "id": "it_U0ZPLk5SVC4yMDI3MDIwOS4yMDI3MDIxNi4yLjAuMC5ZLlVTRHxaRzI1QDAyMDksWkcyNkAwMjE2",
        "airlines": [{ "code": "ZG", "name": "ZIPAIR" }],
        "price": { "total": 1445.02, "per_adult": 722.51, "currency": "USD" },
        "stops": 0,
        "total_duration_min": 1230,
        "slices": [
          {
            "direction": "outbound",
            "origin": "SFO",
            "destination": "NRT",
            "depart": "2027-02-09T15:45:00",
            "depart_utc": "2027-02-09T23:45:00Z",
            "arrive": "2027-02-10T19:55:00",
            "arrive_utc": "2027-02-10T10:55:00Z",
            "duration_min": 670,
            "stops": 0,
            "flights": ["ZG25"]
          },
          {
            "direction": "return",
            "origin": "NRT",
            "destination": "SFO",
            "depart": "2027-02-16T21:25:00",
            "depart_utc": "2027-02-16T12:25:00Z",
            "arrive": "2027-02-16T13:45:00",
            "arrive_utc": "2027-02-16T21:45:00Z",
            "duration_min": 560,
            "stops": 0,
            "flights": ["ZG26"]
          }
        ],
        "fare": {
          "family": "STANDARD",
          "cabins": ["Economy"],
          "refundable": true,
          "changeable": false,
          "carry_on_included": true,
          "checked_bag_included": false,
          "seats_left": 6
        },
        "booking_links": {
          "supplier": { "url": null, "available": false, "lands_on": null },
          "airline": {
            "url": "https://api.voyagelabs.ai/r/al_sE0Iy5Op1B…",
            "available": true,
            "lands_on": "booking_page",
            "airline": "ZG"
          },
          "google_flights": {
            "url": "https://api.voyagelabs.ai/r/al_-v1RAtbiIi…",
            "available": true,
            "lands_on": "itinerary"
          }
        }
      }
    ]
  },
  "meta": { "request_id": "req_4252794c71f0", "mode": "test" }
}
```

`counts.found` is every itinerary in the search, `matched` is what is left after your filters, and `returned` is how many are in this response. `next_cursor` fetches the next page. [How flight search works](/flights#what-one-result-holds) explains each field of a result.

## The trip [#the-trip]

These fields name the trip. They decide which stored search answers the request.

<TypeTable type={{"origin":{"type":"string","description":"3-letter airport code.","required":true},"destination":{"type":"string","description":"3-letter airport code, different from origin.","required":true},"depart_date":{"type":"string","description":"YYYY-MM-DD. Not in the past, and at most 11 months ahead.","required":true},"return_date":{"type":"string","description":"YYYY-MM-DD, on or after depart_date. Leave it out for a one-way trip."},"adults":{"type":"integer","description":"Travellers aged 12 and over, 1 to 9.","default":"1"},"children":{"type":"integer","description":"0 to 8. Adults and children together are at most 9.","default":"0"},"infants":{"type":"integer","description":"0 to 4, and at most one per adult.","default":"0"},"cabin":{"type":"string","description":"economy, premium_economy, business or first.","default":"economy"},"currency":{"type":"string","description":"3-letter currency code. Prices come back in it.","default":"USD"}}} />

A trip is one-way or a round trip. Multi-city trips are not supported: a trip with more than one destination is refused with `invalid_parameter`. Travellers are counted, not described: the API takes no ages or names.

## Shape the answer [#shape-the-answer]

These fields filter, sort and trim the answer for this one response.

<TypeTable type={{"max_stops":{"type":"integer","description":"0 to 3. Keeps itineraries with at most this many stops in each direction."},"airlines":{"type":"string","description":"2-character airline codes, comma separated, such as NH,JL. Keeps itineraries sold entirely by these airlines."},"sort":{"type":"string","description":"best balances price, total duration and stops. price is cheapest first. duration is shortest first.","default":"best"},"limit":{"type":"integer","description":"Results in this response, 1 to 50.","default":"10"},"cursor":{"type":"string","description":"The next_cursor of the previous page."},"detail":{"type":"string","description":"summary, or full for every flight segment, layover and fare.","default":"summary"},"fares":{"type":"integer","description":"Fares per result, 1 to 10. Read only when detail is full.","default":"3"}}} />

`data.airlines` always lists every airline in the whole search, cheapest first, so you can offer airline filters without guessing codes.

## Fields that start a supplier search, and fields that do not [#fields-that-start-a-supplier-search-and-fields-that-do-not]

The trip fields decide which stored search answers. The shape fields never cause a supplier search. In detail:

- **The same trip fields reach the same stored search.** While its answer is fresh, every request for that trip is answered from it, whatever its `sort`, `max_stops`, `airlines`, `limit` or `detail`. A `GET` and a `POST` for the same trip reach the same search.
- **A trip with no fresh stored answer starts a supplier search.** A stored answer under 4 minutes old is used as it is. One up to 30 minutes old is used at once and searched again behind the reply, with `pricing.refreshing` set to `true`. An older one is searched again first.
- **Shape fields only reshape the stored answer.** Changing them filters, sorts and trims the same itineraries again. It never asks the supplier for more.
- **`max_age_s` can start a supplier search.** It sets the oldest price you accept, in seconds (0 to 86,400). A stored answer older than that is searched again before the reply; `max_age_s=0` always searches again. If no new search can start just then, the request is refused with `search_capacity` rather than answered with older prices.
- **`wait_ms` and `response_mode` change only when you are answered**, never what is searched. See the next section.

<Callout type="info" title="Reshape a search without searching again">
Every call to `GET` or `POST /v1/flights/search` without a `cursor` counts toward your key's new-trips limit, even when it is answered from a stored search. To sort, filter, page or read one result again, use [`GET /v1/flights/search/{search_id}`](/flights/read-a-search), which counts only toward your requests. See [Rate limits and usage](/rate-limits).
</Callout>

## Choose how long to wait [#choose-how-long-to-wait]

| `response_mode` | What you get |
| --- | --- |
| `complete` (default) | One JSON answer when the search is complete, or after 30 seconds with what has arrived, whichever comes first. |
| `partial` | One JSON answer when the search is complete, or after `wait_ms` with what has arrived, whichever comes first. Without a `wait_ms`, that is 8 seconds. |
| `stream` | Server-sent events, as itineraries arrive. |

`wait_ms` (0 to 30,000 milliseconds) answers with whatever has arrived by then, even when you leave `response_mode` out. A search that is still running when you are answered carries on, and the answer has `status` `partial`, possibly with no results yet. Read the rest by `search_id`, as [Read a search](/flights/read-a-search) shows. A trip searched recently answers at once in every mode.

To stream, send `response_mode=stream`, `stream=1` or the header `Accept: text/event-stream`. Each `results` event carries the whole answer so far, shaped by your filters, sort and limit, so keep only the latest. The stream ends with one `complete` event or one `error` event, and sends a comment line every 15 seconds to keep the connection open. A request refused before the search starts, such as one with a bad field or a bad key, is answered as plain JSON, not as a stream.

## Search with a JSON body [#search-with-a-json-body]

`POST /v1/flights/search` takes the same fields as a JSON object of up to 16 KB. It returns the same answer as the `GET` form.

```json title="A round trip, with flat fields"
{
  "origin": "SFO",
  "destination": "NRT",
  "depart_date": "2027-02-09",
  "return_date": "2027-02-16",
  "adults": 2
}
```

A body can also name the trip as `legs`, one entry per direction: one leg for a one-way trip, or two that return to the start for a round trip. A mistake inside a leg is reported with the leg's own name, such as `legs[1].date`. Traveller counts can also go in a `passengers` object.

```json title="The same trip, with legs"
{
  "legs": [
    { "origin": "SFO", "destination": "NRT", "date": "2027-02-09" },
    { "origin": "NRT", "destination": "SFO", "date": "2027-02-16" }
  ],
  "passengers": { "adults": 2 }
}
```

<Tabs items={["curl","JavaScript","Python"]}>
<Tab value="curl">
```bash
curl -sS "https://api.voyagelabs.ai/v1/flights/search" \
  -H "X-API-Key: $VOYAGE_LABS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"origin":"SFO","destination":"NRT","depart_date":"2027-02-09","return_date":"2027-02-16","adults":2,"limit":1}'
```
</Tab>

<Tab value="JavaScript">
```js title="search-body.mjs"
const response = await fetch("https://api.voyagelabs.ai/v1/flights/search", {
  method: "POST",
  headers: {
    "X-API-Key": process.env.VOYAGE_LABS_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    origin: "SFO",
    destination: "NRT",
    depart_date: "2027-02-09",
    return_date: "2027-02-16",
    adults: 2,
    limit: 1,
  }),
});
const body = await response.json();
console.log(body.data?.search_id ?? body.error);
```
</Tab>

<Tab value="Python">
```python title="search_body.py"
import os

import requests

response = requests.post(
    "https://api.voyagelabs.ai/v1/flights/search",
    json={
        "origin": "SFO",
        "destination": "NRT",
        "depart_date": "2027-02-09",
        "return_date": "2027-02-16",
        "adults": 2,
        "limit": 1,
    },
    headers={"X-API-Key": os.environ["VOYAGE_LABS_API_KEY"]},
    timeout=40,
)
body = response.json()
print(body["data"]["search_id"] if "data" in body else body["error"])
```
</Tab>
</Tabs>

A body that is not a JSON object, or is over 16 KB, is refused with `invalid_body`.

## When a search is refused [#when-a-search-is-refused]

A field that is missing, malformed or out of range is refused with HTTP `400` and `invalid_parameter`. `param` names the field, and `message` says what is allowed.

```json title="Response: origin left out"
{
  "error": {
    "code": "invalid_parameter",
    "message": "origin must be a 3-letter airport code such as SFO.",
    "param": "origin",
    "retry": "never",
    "request_id": "req_b5737a1edf58"
  }
}
```

Branch on `error.code`, never on the wording of `message`. [Errors](/errors) lists every code and what to do about it.

<Cards>
<Card title="Read a search" href="/flights/read-a-search" description="Wait for a partial search, then sort, filter and page it." />

<Card title="Send travellers to book" href="/flights/booking-links" description="What each booking link opens, and what to tell the traveller." />

<Card title="Search reference" href="/api-reference/flights/search" description="Every parameter, response field and error." />
</Cards>