# Saige MLS API: instructions for this project

Read these instructions and follow them for the whole project, in every answer.

Use these instructions whenever you write, change or review code that reads listings from the Saige MLS API: search pages, listing pages, area menus, maps, saved copies of listings, or anything that sends the X-API-Key header.

## Stop and ask first

Check these before you write any code. If one fails, stop and ask the user. Do not work around it.

1. The secrets SAIGE_MLS_API_KEY and SAIGE_MLS_API_URL exist in the tool's secret storage or the server environment. If they do not, ask the user to add them there. Do not ask the user to paste the key into the chat, and do not offer to store it for them.
2. If the user pastes a key into the chat, do not write it into any file, command, log or answer. Tell the user to put it into secret storage and to ask the Saige team to replace that key, because a key shown in a chat must be treated as leaked.
3. The section "Your board's rules" at the end of these instructions is filled in. If it still holds only the placeholder line, ask the user for their board's rules before you build pages that show listings. Never guess a board rule.

## Rules for the key

- Store the key in your tool's secret storage or server environment, under the name SAIGE_MLS_API_KEY. Store the service root the same way, as SAIGE_MLS_API_URL.
- Read the key only in server code: a server function, a backend function, an edge function or your own server. Browser code never calls the API.
- Never type the key into source code, a config file, page code, a .env file that is committed, a Git repository, a prompt, a chat message, a screenshot or a support ticket.
- Never print the key in logs, error messages or API answers your site sends to the browser.
- Send the key only in the X-API-Key header. Never put it in a URL.
- Use one key per site. If a key may have leaked, tell the Saige team so it is turned off and replaced, then update the secret.
- Never give the key a name that a framework sends to the browser, such as a name starting with VITE_, NEXT_PUBLIC_, PUBLIC_, REACT_APP_ or EXPO_PUBLIC_.
- Never write a key, or a made-up value shaped like one, into code as a fallback. Read process.env.SAIGE_MLS_API_KEY (or your platform's way of reading a secret), and fail with a clear error when it is missing.

## How the integration must be built

- The browser never calls the Saige MLS API. Build a server route on the user's own site (for example /api/listings and /api/listings/[listing_id]) that calls the API with the key and returns only what the page needs.
- Read the service root from SAIGE_MLS_API_URL. Never type the root address into code.
- Send every request as an HTTPS GET with the header X-API-Key: <value of SAIGE_MLS_API_KEY>.
- Treat any status other than 200 as an error. Log the status and the error value, never the key, and show the visitor a plain note.
- Retry only a 500 or a network failure, waiting 2, 4, then 8 seconds, then stop. Never retry a 401 or 403.
- Times are UTC. Convert them to the visitor's time zone before showing them. Prices are Canadian dollars.

## The API

Every path follows the service root in SAIGE_MLS_API_URL. Answers are JSON with "success": true or false.

### GET /listings

Returns one page of active listings that match the filters, newest first unless you set sort. Every filter is optional.

```bash
curl -G "$SAIGE_MLS_API_URL/listings" \
  -H "X-API-Key: $SAIGE_MLS_API_KEY" \
  --data-urlencode "neighbourhood=Kitsilano" \
  --data-urlencode "min_beds=2" \
  --data-urlencode "page_size=24"
```

Answer (shape):

```json
{
  "success": true,
  "data": [
    {
      "listing_id": "R3012345",
      "status": "Active",
      "list_price": 1899000,
      "original_list_price": 1949000,
      "property_type": "Residential",
      "property_sub_type": "Townhouse",
      "address": {
        "display_allowed": true,
        "full": "...",
        "unit_number": "...",
        "street_number": "...",
        "street_dir_prefix": "W",
        "street_name": "...",
        "street_suffix": "Avenue",
        "postal_code": "...",
        "city": "Vancouver",
        "province": "BC"
      },
      "location": { "latitude": 49.26, "longitude": -123.14 },
      "area": "Vancouver West",
      "neighbourhood": "Kitsilano",
      "bedrooms": 3,
      "bathrooms": 3,
      "living_area_sqft": 1450,
      "lot_size_sqft": null,
      "year_built": 2015,
      "strata_fee": 520,
      "tax_annual_amount": 5100,
      "tax_year": 2025,
      "parking_total": 2,
      "zoning": "...",
      "public_remarks": "...",
      "photo_count": 2,
      "photos": ["https://...", "https://..."],
      "listing_brokerage": "...",
      "list_date": "2026-11-20",
      "created_at": "2026-11-20T18:04:11Z",
      "updated_at": "2026-11-28T21:40:02Z"
    }
  ],
  "pagination": { "page": 1, "page_size": 24, "total": 31, "total_pages": 2 },
  "access": { "sample_percent": 100, "cities": ["Vancouver"], "test_key": false, "expires_at": null },
  "data_notice": "..."
}
```

### GET /listings/{listing_id}

Returns one active listing by MLS number, for a listing detail page. A 404 means the listing is no longer active or your key cannot read it: remove it from your site.

Path: listing_id: The MLS number from listing_id.

```bash
curl -G "$SAIGE_MLS_API_URL/listings/R3012345" \
  -H "X-API-Key: $SAIGE_MLS_API_KEY"
```

Answer (shape):

```json
{
  "success": true,
  "data": {
    "listing_id": "R3012345",
    "status": "Active",
    "list_price": 1899000,
    "original_list_price": 1949000,
    "property_type": "Residential",
    "property_sub_type": "Townhouse",
    "address": {
      "display_allowed": true,
      "full": "...",
      "unit_number": "...",
      "street_number": "...",
      "street_dir_prefix": "W",
      "street_name": "...",
      "street_suffix": "Avenue",
      "postal_code": "...",
      "city": "Vancouver",
      "province": "BC"
    },
    "location": { "latitude": 49.26, "longitude": -123.14 },
    "area": "Vancouver West",
    "neighbourhood": "Kitsilano",
    "bedrooms": 3,
    "bathrooms": 3,
    "living_area_sqft": 1450,
    "lot_size_sqft": null,
    "year_built": 2015,
    "strata_fee": 520,
    "tax_annual_amount": 5100,
    "tax_year": 2025,
    "parking_total": 2,
    "zoning": "...",
    "public_remarks": "...",
    "photo_count": 2,
    "photos": ["https://...", "https://..."],
    "listing_brokerage": "...",
    "list_date": "2026-11-20",
    "created_at": "2026-11-20T18:04:11Z",
    "updated_at": "2026-11-28T21:40:02Z"
  },
  "access": { "sample_percent": 100, "cities": ["Vancouver"], "test_key": false, "expires_at": null },
  "data_notice": "..."
}
```

### GET /listings/areas

Returns every city, area and neighbourhood your key can read, with its count of active listings. Use it to build area menus and to get the exact names the filters match.

```bash
curl -G "$SAIGE_MLS_API_URL/listings/areas" \
  -H "X-API-Key: $SAIGE_MLS_API_KEY"
```

Answer (shape):

```json
{
  "success": true,
  "data": [
    { "city": "Vancouver", "area": "Vancouver West", "neighbourhood": "Kitsilano", "active_listings": 0 }
  ],
  "access": { "sample_percent": 100, "cities": ["Vancouver"], "test_key": false, "expires_at": null }
}
```

### GET /health

Answers when the service is up. It needs no key, so use it to tell a network problem apart from a key problem. No key needed.

```bash
curl "$SAIGE_MLS_API_URL/health"
```

Answer (shape):

```json
{
  "success": true,
  "service": "...",
  "status": "healthy",
  "timestamp": "..."
}
```

### Query parameters of GET /listings

All are optional. Text values ignore upper and lower case, must match the whole name, and take several values split by commas.

- city (text): City. Several values split by commas. Upper and lower case do not matter; the spelling must match. Example: Vancouver
- area (text): MLS area. Get exact names from GET /listings/areas. Example: Vancouver West
- neighbourhood (text): MLS sub-area. Get exact names from GET /listings/areas. Example: Kitsilano,Fairview VW
- property_sub_type (text): Kind of home, as the property_sub_type field spells it. Example: Townhouse
- min_price (number): Lowest list price, in Canadian dollars. Example: 900000
- max_price (number): Highest list price, in Canadian dollars. Example: 2000000
- min_beds (whole number): Bedrooms, at least. Example: 2
- min_baths (whole number): Bathrooms, at least. Example: 2
- updated_since (ISO 8601 time): Only listings changed at or after this time. Use it to keep a saved copy up to date. Example: 2026-12-01T00:00:00Z
- sort (text): newest (default), updated, price_asc or price_desc. Example: price_asc
- page (whole number): Page to return. Starts at 1. Example: 2
- page_size (whole number): Listings per page, 1 to 100. Default 25. Example: 24

### The answer envelope

- data: the listing, or the list of listings or areas.
- pagination (GET /listings only): page, page_size, total, total_pages. Read every page by asking for page 1, 2, 3 and on until page equals total_pages.
- access: sample_percent (share of listings the key reads; a test key reads a fixed share), cities, test_key, expires_at.
- data_notice: text that must be shown on every page with listings.
- On errors: error and message.

### Listing fields

Any field can be null.

- listing_id (Text): MLS number. Use it to ask for one listing.
- status (Text): Always Active. Sold and expired listings are never returned.
- list_price (Number): Current asking price.
- original_list_price (Number): Asking price when the listing was first entered.
- property_type (Text): Broad kind of property, such as Residential.
- property_sub_type (Text): Kind of home, such as a house, townhouse or apartment.
- address.display_allowed (True or false): False when the listing is marked to keep its address off the internet. Every address part and the map point are then null.
- address.full (Text): Full address on one line.
- address.unit_number (Text): Unit number.
- address.street_number (Text): Street number.
- address.street_dir_prefix (Text): Direction before the street name, such as W.
- address.street_name (Text): Street name.
- address.street_suffix (Text): Street type, such as Avenue.
- address.postal_code (Text): Postal code.
- address.city (Text): City. Always filled, even when the address is hidden.
- address.province (Text): Province.
- location.latitude (Number): Map point. Null when the address is hidden.
- location.longitude (Number): Map point. Null when the address is hidden.
- area (Text): MLS area, such as Vancouver West.
- neighbourhood (Text): MLS sub-area, such as Kitsilano.
- bedrooms (Whole number): Total bedrooms.
- bathrooms (Whole number): Total bathrooms.
- living_area_sqft (Number): Finished living space in square feet.
- lot_size_sqft (Number): Lot size in square feet.
- year_built (Whole number): Year built.
- strata_fee (Number): Strata fee as listed.
- tax_annual_amount (Number): Yearly property tax.
- tax_year (Whole number): Year of tax_annual_amount.
- parking_total (Whole number): Parking spaces.
- zoning (Text): Zoning as listed.
- public_remarks (Text): The public listing description.
- photos (List of URLs): Photo addresses in listing order. The first is the cover photo.
- photo_count (Whole number): Number of photos in photos.
- listing_brokerage (Text): Brokerage that holds the listing. Show it with the listing.
- list_date (Date): Date the listing contract started.
- created_at (Time (UTC)): When the listing was first entered in the MLS system.
- updated_at (Time (UTC)): Last change to the listing.

### Area fields

- city (Text): City, as the city filter matches it.
- area (Text): MLS area, as the area filter matches it.
- neighbourhood (Text): MLS sub-area, as the neighbourhood filter matches it.
- active_listings (Whole number): Active listings your key can read in this neighbourhood right now.

### Errors

- 400 INVALID_PARAMETER: A query parameter is wrong. The message names it.
- 401 API key required: No key was sent.
- 401 Invalid API key: The key is wrong or was turned off.
- 403 KEY_EXPIRED: The key's end date has passed.
- 403 LISTINGS_NOT_ENABLED: The key has no listing access.
- 404 NOT_FOUND: The listing is no longer active, or your key cannot read it.
- 500 SERVER_ERROR: A fault on our side. Wait, then retry.

### Keeping a saved copy current

Store listings only if the user's board allows it (see "Your board's rules"). Then run two jobs:

- Every hour: GET /listings with updated_since set to the last run time minus 5 minutes and sort=updated, all pages. Save each listing by listing_id.
- Once a day: read every page of GET /listings and remove every saved listing that was not in it. A listing that sells or expires drops out of the results and never appears as a change.

## Display rules

Every page that shows listings must follow these rules. Build them in from the start.

- Show the listing_brokerage name with every listing: on each search card and on each listing page.
- Show the data_notice text from the API answer on every page that shows listings.
- When address.display_allowed is false, show no street address and no map pin for that listing, and do not look the address up anywhere else. Show the area and neighbourhood only.
- Show only listings the API returns now. When a listing drops out of the API (a 404 on GET /listings/{listing_id}, or missing from a full sync), remove it from your site.
- Show prices, photos and descriptions as the API sends them. Do not edit them, and do not mix them with listing data from another source on the same card.
- Use the MLS® and REALTOR® marks the way CREA directs: MLS® names a service REALTORS® provide, so do not use it as a general word for a listing database or in a business name, trade name or branding.

Your real estate board sets more rules for showing its listings (for example the exact notice wording, logos, how often data must refresh, and whether you may store a copy). Get the current rules from your board's member portal and from the Saige team during setup, and add them to your AI tool's instructions in the section for your board's rules. An AI tool must never guess a board rule.

## Check before you say the work is done

1. Search the whole project, including config files and the built output, for "X-API-Key" and for any long random string. The header appears only in server code, and no key value appears anywhere. If the user can share the first few characters of their key, search for those too.
2. No browser code (React components, page scripts, client bundles) calls the Saige service root.
3. No environment variable holding the key starts with VITE_, NEXT_PUBLIC_, PUBLIC_, REACT_APP_ or EXPO_PUBLIC_.
4. Every search card and listing page shows listing_brokerage.
5. Every page with listings shows data_notice.
6. A listing with address.display_allowed false shows no street address and no map pin.
7. A listing page answers with a "no longer available" page when the API returns 404, and saved copies drop removed listings.
8. Every rule in "Your board's rules" is met.

Tell the user the result of each check.

## Your board's rules

- (Add the rules your board and the Saige team gave you here, with the date you got them. Until this line is replaced, ask the user for them before building pages that show listings.)

---
Saige MLS API documentation: https://www.realsaige.com/mls-api-docs. OpenAPI file: https://www.realsaige.com/saige-mls-api-openapi.json. Reference checked December 2, 2026.
