# How hotel search works (/hotels)

Search a place and dates, read the search as it fills in, then fetch one hotel's rooms and rates before you quote a price.

The Hotels Search API finds hotels with prices for a place and a stay, and gives each hotel links that open it on travel sites with the dates and guests filled in. It is read-only: it never books, holds or charges.

## The flow [#the-flow]

<Steps>
<Step>
### Search a place and dates [#search-a-place-and-dates]

Send where to look, `check_in`, `check_out` and the guests to `GET /v1/hotels/search`, or send the same fields as a JSON body with `POST`. The answer carries a `search_id` and, once the supplier has answered, the hotels.
</Step>

<Step>
### Read the search until it is complete [#read-the-search-until-it-is-complete]

If `data.status` is `running`, read the search again by its `search_id`, with `wait_ms` to hold the request until it ends. Reading a search again never runs it again, so it is also how you page through the answer and sort it another way.
</Step>

<Step>
### Fetch one hotel's rooms and rates [#fetch-one-hotels-rooms-and-rates]

A search carries one price per hotel. Before you quote a price or cancellation terms, call `GET /v1/hotels/rates/{hotel_id}` for every room and rate the hotel has for the stay, cheapest first.
</Step>

<Step>
### Send the traveller to book [#send-the-traveller-to-book]

Show the hotel's `booking_links`. The traveller opens one in their browser and books on that site.
</Step>
</Steps>

## A search as it fills in [#a-search-as-it-fills-in]

Every search has a `search_id`, such as `hs_0a29ce33d3a646fe9660`. Both states below answer with HTTP `200`.

| `status`   | What it means                                                                                            | What to do                                                                                  |
| ---------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| `running`  | The supplier has not answered yet. `hotels` is empty, `pricing` is `null`, and `retry_after_ms` is set.   | Read the search by `search_id` with `wait_ms`, or again after `retry_after_ms`.             |
| `complete` | The answer is in. `counts.found` is the number of hotels in the whole answer.                            | Page through it, sort it, or read one hotel's rates.                                        |

A search can also end without an answer. Then the search, and every later read of it, answers with an error instead: `supplier_error` (`502`), `supplier_timeout` (`504`) or `search_capacity` (`503`). That search is over; search again. [Errors](/errors) lists every code.

How long things take:

- A new search takes about 6 seconds.
- The same stay (the same place, dates, guests, currency and nationality) searched in the last 15 minutes answers at once from the stored answer, with the same `search_id`. `max_age_s` sets the oldest stored answer you accept.
- A search is kept for 24 hours. After that, reading it answers `search_not_found`.
- Reading a search again never refreshes its prices. `pricing.age_s` says how old they are. Past 900 seconds, search again before you quote a price.

## What one result is [#what-one-result-is]

Each item in `data.hotels` has three parts:

- `hotel`: the hotel's `id` and `name`, and, where known, `stars`, `rating` (guest rating out of 10), `review_count`, `address`, `city`, `country`, `latitude`, `longitude` and `photo`. Every field but `id` and `name` can be `null`.
- `offers`: in a search, one offer, the first price the supplier found in time. It is close to the hotel's cheapest and not promised to be it. From [rooms and rates](/hotels/rooms-and-rates), every offer, cheapest first.
- `booking_links`: where the stay can be booked, best first. See [Send travellers to book](/hotels/booking-links).

An offer is one price for the whole stay:

```json title="One offer"
{
  "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": []
}
```

<TypeTable type={{"total":{"type":"number","description":"The whole stay: every room, every night, taxes in."},"currency":{"type":"string","description":"The 3-letter currency of total, per_night and taxes_included."},"per_night":{"type":"number","description":"total divided by the nights of the stay."},"taxes_included":{"type":"number | null","description":"Taxes and fees already inside total. null when the supplier does not split them out."},"due_at_property":{"type":"array","description":"Charges the hotel collects itself, on top of total, such as resort fees or city taxes. Each has a description, an amount and its own currency."},"refundable":{"type":"boolean","description":"Whether the stay can be cancelled for a refund. For several rooms, true only when every room can."},"free_cancellation_until":{"type":"string | null","description":"The last moment to cancel at no charge, in UTC. null when there is none."},"board":{"type":"string","description":"The meals included, such as Room Only. board_code is its short code."}}} />

To tell a traveller what a stay costs, add `due_at_property` to `total`.

## Live and test keys [#live-and-test-keys]

A `vl_live_` key searches live prices. A `vl_test_` key costs nothing and never reaches the supplier: every search answers with the same saved San Francisco hotels, whatever place, dates or guests you send, and every rates call answers with one saved hotel, The Westin St. Francis San Francisco on Union Square (`lp19b5e`), whatever `hotel_id` you send. The `query` in the answer and the booking links follow your request. The prices, rooms and guests in the offers come from the sample, a stay of 9 to 12 February 2027 for two adults and a child of 7, so they only add up when you search that stay. `meta.mode` says which kind of key answered. See [Test mode](/test-mode).

## Which endpoint to use [#which-endpoint-to-use]

| You want to                                                                    | Call                                                                                                                                                         |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| List hotels for a place and a stay                                             | [`GET /v1/hotels/search`](/api-reference/hotels/search), or [`POST /v1/hotels/search`](/api-reference/hotels/search-with-a-body) with a JSON body           |
| Wait for a running search, get the next page or sort it another way            | [`GET /v1/hotels/search/{search_id}`](/api-reference/hotels/read-a-search)                                                                                   |
| See every room and rate of one hotel before you quote a price or its cancellation terms | [`GET /v1/hotels/rates/{hotel_id}`](/api-reference/hotels/rooms-and-rates)                                                                          |
| Check your key's limits and what it has used today                             | [`GET /v1/hotels/usage`](/api-reference/hotels/usage)                                                                                                        |

## Access [#access]

A key reaches only the products its partner account has. If your account does not have the Hotels Search API, every hotel call, `/v1/hotels/usage` included, answers `403` with the code `forbidden`:

```json title="403 Forbidden"
{
  "error": {
    "code": "forbidden",
    "message": "This request is not permitted by your partner policy or key status.",
    "retry": "never",
    "request_id": "req_54f44b10243c"
  }
}
```

The same answer comes back for a revoked or expired key, a suspended account, and a live key on an account that is not yet cleared for live prices. If your account lists the networks its keys may be used from, a request from anywhere else also answers `403` `forbidden`, with a message that says so.

## Next [#next]

<Cards>
<Card title="Search hotels" href="/hotels/search" description="Places, dates, guests, sorting and paging, and reading a search by its id." />

<Card title="Rooms and rates" href="/hotels/rooms-and-rates" description="Every room and rate of one hotel, with meals and cancellation terms." />

<Card title="Send travellers to book" href="/hotels/booking-links" description="What each booking link opens, how long it lasts and what to tell the traveller." />
</Cards>