# Search hotels (/hotels/search)

Search hotels for a place and a stay, set the guests and currency, sort and page the answer, and read a running search by its id.

A search returns the hotels for one place and one stay, each with one price and its booking links. You can send it as a query string or as a JSON body; both run the same search.

## Query string or JSON body [#query-string-or-json-body]

- `GET /v1/hotels/search` takes the fields as a query string. Lists are comma-separated (`child_ages=7,4`, `hotel_ids=lp19b5e,lp5f44c`), and `rooms` is JSON text.
- `POST /v1/hotels/search` takes the same fields as a JSON object, with real lists. The body must be a JSON object of at most 16 KB, or the answer is `400` `invalid_body`.

Both answer in the same shape, and the same stay sent either way is the same search, with the same `search_id`.

```bash title="The same search as a JSON body"
curl https://api.voyagelabs.ai/v1/hotels/search \
  -H "X-API-Key: $VOYAGE_LABS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "city": "San Francisco",
    "country": "US",
    "check_in": "2027-02-09",
    "check_out": "2027-02-12",
    "rooms": [{ "adults": 2, "child_ages": [7] }]
  }'
```

## Where to look [#where-to-look]

Say where in exactly one way. Sending none, or more than one, answers `400` `invalid_parameter` with `param` set to `place`.

| Fields                                       | Meaning                                                                              |
| -------------------------------------------- | ------------------------------------------------------------------------------------ |
| `city` and `country`                         | A city by name, with its 2-letter country code, such as `US`                         |
| `latitude` and `longitude`, with `radius_km` | Hotels around a point. `radius_km` is 0.2 to 50; it is 5 when you leave it out       |
| `place_id`                                   | A Google place id, such as `ChIJIQBpAG2ahYAR_6128GcTUEo`                             |
| `hotel_ids`                                  | Up to 200 hotel ids from earlier answers, to price hotels you already know about     |

The API does not look up a place by name beyond `city` and `country`.

## The stay [#the-stay]

`check_in` is the first night and `check_out` the day of departure, both written `YYYY-MM-DD`. `check_in` may be no earlier than yesterday and no more than 500 days ahead, and a stay is 1 to 30 nights.

## Guests and rooms [#guests-and-rooms]

For one room, send `adults` (1 to 8; 2 when you leave it out) and, for children, `child_ages`. For more than one room, send `rooms` instead: a list of 1 to 8 rooms, each `{"adults": 2, "child_ages": [7]}`. Sending `rooms` together with `adults` or `child_ages` is refused, because the two could disagree.

Give each child by age, 0 to 17, with up to 6 children in a room. Ages matter: they change which rooms a hotel offers.

With several rooms, each offer prices all of them together: `total` covers every room, and `offers[].rooms` has one entry per room, in the order you sent them.

## Currency and nationality [#currency-and-nationality]

- `currency`: the 3-letter currency of the prices, `USD` when you leave it out. A charge in `due_at_property` carries its own `currency`.
- `nationality`: the guests' 2-letter country code, `US` when you leave it out. Some rates depend on it.

## Sort and page [#sort-and-page]

There are no filters by price, stars or amenities: sort and page the answer, and choose from it.

| Field    | Meaning                                                                                                            | Default |
| -------- | ------------------------------------------------------------------------------------------------------------------ | ------- |
| `sort`   | `price`: cheapest first. `rating`: best guest rating first, with unrated hotels last                               | `price` |
| `limit`  | Hotels in this response, 1 to 100                                                                                  | 20      |
| `cursor` | The `next_cursor` of the previous page                                                                             |         |

`counts.found` is the number of hotels in the whole answer and `counts.returned` the number on this page. `next_cursor` is `null` on the last page. A cursor is a position in the sorted answer, so keep the same `sort` while you follow one.

To page or sort an answer you already have, [read the search by its id](#read-a-search-by-its-id) rather than searching again.

## Waiting and freshness [#waiting-and-freshness]

| Field           | Meaning                                                                                                                                                                                  |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `response_mode` | `complete`, the default, holds the request open while the supplier answers. `partial` answers at once, often with `status` `running`; you read the rest by `search_id`.                 |
| `wait_ms`       | Exactly how long to wait for a running search, 0 to 30000. When you send it, it decides the wait.                                                                                       |
| `max_age_s`     | The oldest stored answer you accept, in seconds. `0` never takes a stored answer, though it still joins a search already running for the same stay. A whole number from `0` to `86400`; anything else answers `400` with `invalid_parameter`. A stored answer is never reused past 900 seconds, so a value above 900 acts as 900. |

Even with `complete`, a search the supplier has not finished in time answers `status` `running`. Handle both.

Every call to `/v1/hotels/search` counts toward your new searches for the minute, even when a stored answer serves it. Reading a search by its id does not. See [Rate limits](/rate-limits).

## Example [#example]

<Tabs items={["curl","JavaScript","Python"]}>
<Tab value="curl">
```bash
curl --get https://api.voyagelabs.ai/v1/hotels/search \
  -H "X-API-Key: $VOYAGE_LABS_API_KEY" \
  --data-urlencode "city=San Francisco" \
  -d country=US \
  -d check_in=2027-02-09 \
  -d check_out=2027-02-12 \
  -d adults=2 \
  -d child_ages=7 \
  -d limit=1
```
</Tab>

<Tab value="JavaScript">
```js title="search.mjs"
const url = new URL("https://api.voyagelabs.ai/v1/hotels/search");
url.search = new URLSearchParams({
  city: "San Francisco",
  country: "US",
  check_in: "2027-02-09",
  check_out: "2027-02-12",
  adults: "2",
  child_ages: "7",
  limit: "1",
}).toString();

const response = await fetch(url, {
  headers: { "X-API-Key": process.env.VOYAGE_LABS_API_KEY },
});
const body = await response.json();
if (!response.ok) {
  throw new Error(`${body.error.code}: ${body.error.message}`);
}

const { status, counts, hotels } = body.data;
console.log(status, counts.found, hotels[0]?.hotel.name);
```
</Tab>

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

import requests

response = requests.get(
    "https://api.voyagelabs.ai/v1/hotels/search",
    headers={"X-API-Key": os.environ["VOYAGE_LABS_API_KEY"]},
    params={
        "city": "San Francisco",
        "country": "US",
        "check_in": "2027-02-09",
        "check_out": "2027-02-12",
        "adults": 2,
        "child_ages": "7",
        "limit": 1,
    },
    timeout=40,
)
body = response.json()
if not response.ok:
    raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")

data = body["data"]
print(data["status"], data["counts"]["found"])
```
</Tab>
</Tabs>

This answer came from a test key, and the booking link tokens are shortened.

```json title="200 OK"
{
  "data": {
    "search_id": "hs_0a29ce33d3a646fe9660",
    "status": "complete",
    "query": {
      "place": { "kind": "city", "city": "San Francisco", "country": "US" },
      "check_in": "2027-02-09",
      "check_out": "2027-02-12",
      "rooms": [{ "adults": 2, "child_ages": [7] }],
      "currency": "USD",
      "nationality": "US",
      "nights": 3
    },
    "pricing": { "priced_at": "2026-12-06T20:40:19.471Z", "age_s": 0 },
    "counts": { "found": 24, "returned": 1 },
    "next_cursor": "c_1",
    "hotels": [
      {
        "hotel": {
          "id": "lp5f44c",
          "name": "Motel 6 San Francisco, CA – Civic Center",
          "stars": 2,
          "rating": 7.4,
          "review_count": 145,
          "address": "587 Eddy St, San Francisco, California, 94109",
          "city": "San Francisco",
          "country": "US",
          "latitude": 37.783188,
          "longitude": -122.417244,
          "photo": "https://static.cupid.travel/hotels/ex_w3296h3170x0y0-058613f1_z.jpg"
        },
        "offers": [
          {
            "rooms": [
              {
                "name": "1 King Bed | Non-Smoking",
                "room_id": 1321822334,
                "adults": 2,
                "child_ages": [7]
              }
            ],
            "board_code": "RO",
            "board": "Room Only",
            "total": 223.54,
            "currency": "USD",
            "per_night": 74.51,
            "taxes_included": 28.95,
            "due_at_property": [],
            "refundable": false,
            "free_cancellation_until": null,
            "cancellation": []
          }
        ],
        "booking_links": [
          {
            "site": "hotels_com",
            "name": "Hotels.com",
            "url": "https://api.voyagelabs.ai/r/hl_GPr_mc0vhVHege…",
            "lands_on": "property",
            "found_by": "id",
            "verified": false,
            "checked": "2026-12-05",
            "note": "The hotel's id here is worked out from ours and not confirmed, so now and then it opens a missing page."
          },
          {
            "site": "google",
            "name": "Google Hotels",
            "url": "https://api.voyagelabs.ai/r/hl__Az-XUQMD3fXhn…",
            "lands_on": "search_results",
            "found_by": "name",
            "verified": false,
            "checked": "2026-12-05",
            "note": "Finds the hotel by its name, which is right for most hotels but not all."
          },
          {
            "site": "booking_com",
            "name": "Booking.com",
            "url": "https://api.voyagelabs.ai/r/hl_TC02KWLxid5pp5…",
            "lands_on": "search_results",
            "found_by": "name",
            "verified": true,
            "checked": "2026-12-05",
            "note": "Searches by the hotel's name; the hotel is normally the first result."
          }
        ]
      }
    ]
  },
  "meta": { "request_id": "req_3af51e458995", "mode": "test" }
}
```

## Reading the answer [#reading-the-answer]

| Field            | Meaning                                                                                                                                                         |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `search_id`      | Names this search, to read it again. Kept for 24 hours                                                                                                          |
| `status`         | `complete`, or `running` while the supplier has not answered                                                                                                    |
| `retry_after_ms` | Only while `running`: when to ask again, in milliseconds                                                                                                         |
| `query`          | The stay as the service understood it, with `nights`. `query.place.kind` is the way you said where: `city`, `point`, `place` or `hotels`. A point's radius comes back as `radius_m`, in metres |
| `pricing`        | `priced_at`, when the prices were fetched, and `age_s`, how many seconds ago. `null` while `running`                                                             |
| `counts`         | `found`: hotels in the whole answer. `returned`: hotels on this page                                                                                             |
| `next_cursor`    | Pass it as `cursor` for the next page. `null` on the last page                                                                                                   |
| `hotels`         | Each hotel with one offer and its booking links. See [What one result is](/hotels#what-one-result-is)                                                            |

The full field list is in the [API reference](/api-reference/hotels/search).

## Read a search by its id [#read-a-search-by-its-id]

`GET /v1/hotels/search/{search_id}` reads a stored search. It never searches again and does not count toward your new searches. Use it to:

- wait for a running search, with `wait_ms` (0 to 30000). Without it, the read answers at once.
- get the next page, with `cursor` and `limit`.
- sort the same answer another way, with `sort`.

A search started with `response_mode=partial` usually answers before the supplier has:

```json title="200 OK, still running"
{
  "data": {
    "search_id": "hs_6bd1d8a2db5441a28623",
    "status": "running",
    "retry_after_ms": 1000,
    "query": {
      "place": { "kind": "city", "city": "San Francisco", "country": "US" },
      "check_in": "2027-02-10",
      "check_out": "2027-02-12",
      "rooms": [{ "adults": 2, "child_ages": [] }],
      "currency": "USD",
      "nationality": "US",
      "nights": 2
    },
    "pricing": null,
    "counts": { "found": 0, "returned": 0 },
    "next_cursor": null,
    "hotels": []
  },
  "meta": { "request_id": "req_6faa8e62a8fb", "mode": "test" }
}
```

While a search runs, `retry_after_ms` says when to ask again. Better still, send `wait_ms`: the read is held until the search ends and answers at that moment, or answers `running` again when the wait runs out.

<Tabs items={["curl","JavaScript","Python"]}>
<Tab value="curl">
```bash
curl --get https://api.voyagelabs.ai/v1/hotels/search/hs_6bd1d8a2db5441a28623 \
  -H "X-API-Key: $VOYAGE_LABS_API_KEY" \
  -d wait_ms=10000
```
</Tab>

<Tab value="JavaScript">
```js title="poll.mjs"
const BASE = "https://api.voyagelabs.ai";
const headers = { "X-API-Key": process.env.VOYAGE_LABS_API_KEY };

async function get(path, params) {
  const url = new URL(path, BASE);
  url.search = new URLSearchParams(params).toString();
  const response = await fetch(url, { headers });
  const body = await response.json();
  if (!response.ok) {
    // supplier_error, supplier_timeout and search_capacity end the search:
    // search again rather than reading this one.
    throw new Error(`${body.error.code}: ${body.error.message}`);
  }
  return body.data;
}

let data = await get("/v1/hotels/search", {
  city: "San Francisco",
  country: "US",
  check_in: "2027-02-10",
  check_out: "2027-02-12",
  response_mode: "partial",
});

while (data.status === "running") {
  // Held until the search ends, or for at most 10 seconds.
  data = await get(`/v1/hotels/search/${data.search_id}`, { wait_ms: "10000" });
}

console.log(`${data.counts.found} hotels, priced ${data.pricing.age_s}s ago`);
```
</Tab>

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

import requests

BASE = "https://api.voyagelabs.ai"
HEADERS = {"X-API-Key": os.environ["VOYAGE_LABS_API_KEY"]}

def get(path, params):
    response = requests.get(BASE + path, headers=HEADERS, params=params, timeout=40)
    body = response.json()
    if not response.ok:
        # supplier_error, supplier_timeout and search_capacity end the search:
        # search again rather than reading this one.
        raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")
    return body["data"]

data = get("/v1/hotels/search", {
    "city": "San Francisco",
    "country": "US",
    "check_in": "2027-02-10",
    "check_out": "2027-02-12",
    "response_mode": "partial",
})

while data["status"] == "running":
    # Held until the search ends, or for at most 10 seconds.
    data = get(f"/v1/hotels/search/{data['search_id']}", {"wait_ms": 10000})

print(f"{data['counts']['found']} hotels, priced {data['pricing']['age_s']}s ago")
```
</Tab>
</Tabs>

<Callout type="warn" title="Reading a search never refreshes its prices">
`pricing.age_s` keeps growing each time you read the same search. Past 900 seconds, search the stay again before you show a price.
</Callout>

A search is kept for 24 hours; after that, reading it answers `404` `search_not_found`. A search made with a test key cannot be read with a live key, nor the other way round.

## Next [#next]

<Cards>
<Card title="Rooms and rates" href="/hotels/rooms-and-rates" description="Every room and rate of one hotel, before you quote a price." />

<Card title="Send travellers to book" href="/hotels/booking-links" description="Show the booking links and say what they promise." />
</Cards>