# Keys, domains and environment names

Source: https://help.ruuster.com/idx/keys-and-domains

> How your secret key works, how your pages show listings with no key in them, which domains your account accepts, how each MLS approves each domain, how to build on localhost with sandbox keys, and the environment variable names for every framework.

You get your keys from your console, under **Keys and domains**. Sandbox keys come first: they are
free, they answer from sample listings, and they work on your own computer from the first minute.
Live keys come when you go live, and they answer with your boards' real listings.

## Your secret key

There is one key you use: the secret key. It stays on your server.

| Key | Looks like | Where it goes | How it is sent |
|---|---|---|---|
| Secret | `idx_sk_…` (sandbox: `idx_sk_test_…`) | Your server only: page rendering, your listings route, sitemaps, the change feed, usage | As `Authorization: Bearer idx_sk_…` |

- Keep it in the `IDX_SECRET_KEY` environment variable on your server, out of your repository, and
  never paste it into a chat or a prompt.
- It works from any server and is never cached at the edge. Some endpoints answer only to it: the
  listing ids for sitemaps, the change feed, usage, billing and public records.
- A secret key sent in a URL answers 400 `secret_key_in_url`, and one used from a browser answers 403
  `secret_key_in_browser`. Either one flags the key, and Ruuster then refuses it until you rotate it.
- Your console also lists a second key beside each secret key, starting `idx_pk_`. New pages don't
  use it, so leave it out of your code.

## No key in your pages

Anything in a web page can be copied: open the page source and every value in it is there for anyone
to take. So your pages carry no key at all. The search box, the filters, the mortgage calculator and
the other widgets reach the Listings API in one of two ways.

### Your site has its own server: use your listings route

This is the default, for any site whose server runs JavaScript (Next.js, Astro, SvelteKit, Remix,
Node.js, Cloudflare Workers, Vercel or Netlify functions). The SDK ships a ready-made route that your pages call instead of the
Listings API. It runs on your server, adds your secret key there, and passes the answer back:

```ts
// app/api/idx/[...path]/route.ts (Next.js App Router)
import { createListingsRoute } from "@ruuster/idx/route";

export const GET = createListingsRoute({ basePath: "/api/idx" });
```

Set `IDX_SECRET_KEY` in your server's environment, then point the widgets at the route. On plain
HTML, put `data-rw-base-url="/api/idx"` on the widget element. In React, give `SearchBox`,
`MortgageCalculator` and `Filters` the prop `baseUrl="/api/idx"`, and give `ListingDetail` the
prop `apiBaseUrl="/api/idx"`.

- **It passes on only what a page may ask for:** search, a listing and its photos, history and
  similar homes, suggestions, filters and their choices, `meta`, boundaries and shapes, collections,
  rendered HTML, market numbers, the mortgage estimate, agent production, page events and the page
  beacon. Everything only a secret key may do (the listing ids, the change feed, usage, billing and
  public records) answers 404 through it.
- **It limits each visitor** to 120 requests a minute by IP address. Change it with
  `perVisitorPerMinute`.
- **It lets your CDN keep answers for a short time,** 60 seconds by default. Change it with
  `cacheSeconds` (0 turns it off).
- **It never forwards a key from the page,** so a key left in older page code goes nowhere.
- **It runs on any platform that hands you a standard `Request` and takes a `Response` back:**
  Next.js, Astro, SvelteKit, Remix, Hono, Cloudflare Workers, and Vercel or Netlify functions.

Always use this helper rather than writing your own pass-through route. A hand-written route can pass
on calls that only your secret key should make, such as your full listing ids or your usage.

### Your site is built in a page builder: use the widgets with no key

This is for sites with no server of their own, where you paste code into the page (WordPress,
Squarespace, Webflow, Wix and similar). It is also the way for a server that runs another language
(PHP, Python, Ruby, Go), where the JavaScript route can't run; that server's own calls keep using
your secret key. Set `data-rw-base-url="https://idx.ruuster.com/v1"` on the
widget element (or leave the attribute out, which means the same), and leave out any `data-rw-key`
attribute. The widgets then call `https://idx.ruuster.com/v1` with no key, and the Listings API recognizes your account from the
page's website address. For that, the address must be on your account's allowed domains (open **Keys
and domains** in your console and, under **Website addresses your pages run on**, press **Add a domain**), and approved for your MLSs (see the next
section). The limits, the caching and the display rules are the same as for every other page.

- A page on `localhost` can't be recognized by its address. While you build on your own computer,
  use your listings route with your sandbox secret key, or test on a staging address you added to
  your account.
- A sandbox account works the same way with its own domains, and answers from sample listings.

### Which one to pick

If your site's server runs JavaScript, use your listings route. If you paste code into a site
builder, or your server runs another language, use the widgets with no key.

## Approved domains, per board

Listings show only on domains that are approved, and each domain is approved per MLS board. Ruuster
records the approval for each of your domains and each of your boards; a domain approved for one
board shows only that board's listings, even when your brokerage has more.

- **An approval is for the parent domain.** Approving `example.com` covers `www.example.com`,
  `homes.example.com` and every other name under it. A shared hosting name, such as
  `jane.vercel.app` or `agent.netlify.app`, is its own domain: approving it never covers anyone else's
  site on the same host.
- **Browser calls from any other domain are refused.** A page whose domain isn't on your account, or
  isn't approved, answers 403 `origin_not_allowed`, so a copied search box or widget shows nothing.
  Answers are cached per site, so an answer made for one domain is never served to another.
- **A secret key serves one site domain.** Each site's secret key is registered to that site's
  domain, and its server-side calls answer that domain's approved boards only.
- **Every page is tracked.** Ruuster keeps a list of every domain and page where your listings are
  seen, from the browser calls and from the page beacon the widget sends. If a secret key's pages are
  reported on a domain that isn't approved for it, the key is paused at once (it answers 403
  `access_revoked`) and our team contacts you. Once the site is fixed, create a new live secret key
  under **Keys and domains**.
- **Adding a domain.** Request approval for a new domain before you launch on it. Open **Keys and
  domains** in your console, type the domain under **MLS approval for each domain**, tick each MLS
  and press **Submit request**. Until a domain is approved for a board, that board's listings don't
  show there, and the address shows sample listings.
- **Who handles a request.** Ruuster's Customer Success team. Your request reaches them as soon as
  you submit it, and they work with each MLS for you. Each board answers on its own schedule, so one
  board can approve before another. The table under **MLS approval for each domain** shows each
  board's status and date, and it changes as soon as a board is approved or declined. You can ask
  again for a board that was not approved. Questions go to `helpme@ruuster.com`.

## Domains: live, staging and localhost

- **Your live domains** are the domains your boards approved for your brokerage. Add each one to
  your account's allowed domains in your console: open **Keys and domains** and, under
  **Website addresses your pages run on**, press **Add a domain**.
- **Localhost works with your listings route,** on any port: `http://localhost:3000`,
  `http://127.0.0.1:5173` and so on, because the route calls the Listings API from your server with
  your secret key. With the sandbox secret key you build on sample listings from the first day, with
  nothing to request first.
- **Staging domains** go on the same list, such as `https://staging.example.com`, and are covered by
  your live domain's approval when they sit under it. A staging site on another domain needs its own
  approval. A wildcard is
  accepted under a domain you own, such as `https://*.example.com`. Shared hosting domains, such as a
  wildcard under `vercel.app` or `netlify.app`, are refused, because board approval is for your own
  domains. Add each preview URL you need by its full name.
- **Keep staging private.** Once it runs on a live key your staging site shows live MLS data, so put
  it behind a password, or send `X-Robots-Tag: noindex` on every response, and never list it in a
  sitemap.

## Keys in your console

Your keys live in your console under **Keys and domains**.

- **Sandbox keys** answer from sample listings. You can hold up to three pairs, and you use the
  secret key of each pair. A new secret key is shown once, when you create it. Revoke a pair you no
  longer use.
- **Live keys** appear once your go-live request is approved, a board has approved your domain and
  your first invoice is paid. **Create live keys** shows the live secret key once. Creating a new
  live secret key replaces the current one, which keeps working for 24 hours.
- **Who can see them.** Owners, admins and developers on your team. A billing member cannot.

[Your account console](https://help.ruuster.com/idx/guide-console) describes every page.

## Rotating a key

Rotate a key in your console, under **Keys and domains**.

- **A live secret key:** press **Create a new live secret key**. The new key is shown once. The old
  one keeps working for 24 hours, so you can deploy the new one first.
- **A sandbox key pair:** press **Create a new key pair**, put the new secret key in your project,
  then press **Revoke** on the old pair.

Rotate at once if a secret key was ever exposed.

## Environment variable names

Use these names everywhere, so the recipes, the examples, the SDK and the prompts all match.

| Name | Where | What it holds |
|---|---|---|
| `IDX_SECRET_KEY` | Server only | Your secret key, `idx_sk_…` |
| `IDX_BASE_URL` | Server, optional | Leave it unset; the SDK then calls the Ruuster Listings API |
| `SITE_ORIGIN` | Server | Your site's origin, such as `https://www.example.com`, for canonical links and `pageHref` |
| `SITE_NAME` | Server | Your brokerage or site name, used as the lead source in your CRM |
| `NEXT_PUBLIC_GOOGLE_MAPS_KEY` | Browser | Your own Google Maps key |
| `NEXT_PUBLIC_GOOGLE_MAP_ID` | Browser | Your Google Maps Map ID, for the price pins |
| `NEXT_PUBLIC_GTM_ID` | Browser | Your Google Tag Manager container ID, which starts with `GTM-` |
| `RUUSTER_WEBHOOK_SECRET` | Server | The signing secret of your listing-change webhook |
| `FUB_API_KEY`, `FUB_SYSTEM`, `FUB_SYSTEM_KEY` | Server | Follow Up Boss |
| `FUB_COOKIE_SECRET` | Server | A long random string that signs the cookie linking listing views to a registered visitor |
| `SIERRA_API_KEY` | Server | Sierra Interactive |
| `SURESEND_API_KEY` | Server | Sure Send |

### The browser names in each framework

Only the Google Maps values go to the browser; no Listings API key ever does. Each framework exposes
a variable to the browser through its own prefix, so rename those two to match:

| Framework | Google Maps key | Map ID |
|---|---|---|
| Next.js | `NEXT_PUBLIC_GOOGLE_MAPS_KEY` | `NEXT_PUBLIC_GOOGLE_MAP_ID` |
| Astro | `PUBLIC_GOOGLE_MAPS_KEY` | `PUBLIC_GOOGLE_MAP_ID` |
| Vite (and Remix on Vite) | `VITE_GOOGLE_MAPS_KEY` | `VITE_GOOGLE_MAP_ID` |
| Nuxt | `NUXT_PUBLIC_GOOGLE_MAPS_KEY` | `NUXT_PUBLIC_GOOGLE_MAP_ID` |
| SvelteKit | `PUBLIC_GOOGLE_MAPS_KEY` | `PUBLIC_GOOGLE_MAP_ID` |
| A plain server (Node.js, PHP, Python, Ruby, Go) | Print the Google Maps key into the page from the server | The same |

Every other name keeps the table's spelling with no prefix, which keeps it on the server. Never give
`IDX_SECRET_KEY` a browser prefix.

## Your detail-page template

Each listing's `href`, canonical link and JSON-LD URL are built from your detail-page template, such
as `https://www.example.com/homes/{slug}`. Set it once on **Website** in your console, under
**Listing page link**, or send
`detailHref` on a call (the SDK sends the `detailHref` you give `createClient`). The template takes
`{slug}`, `{id}` and `{mlsNumber}`; a path that starts with `/` is made absolute against your live
domain, the first domain on your account's allowed list that is not `localhost`.

That is why a page you run on `localhost` or on staging still shows canonical links, card links and
JSON-LD URLs on your live domain: they name the page search engines should index. `SITE_ORIGIN` does
not change them. Your own sitemaps, `robots.txt` and form checks use `SITE_ORIGIN`, so set it to the
origin each server answers on.

## Usage

Call `GET /v1/usage` with the secret key to see each key's daily quota, what it has used today and
the rate windows that apply to it. [Usage](https://help.ruuster.com/idx/usage) has the fields.
