apidata.one docs Get a key

Building with AI

Most sites on this API are written with an AI tool: Claude, ChatGPT, Cursor, Lovable and others. These docs are made for that. This page gives you a prompt to paste, the files to hand your tool, the patterns it should produce, and what to check in what it wrote.

What to give your tool

File What it is
https://docs.apidata.one/llms-full.txt Every page of these docs in one text file. Give it this when the tool can read a long file
https://docs.apidata.one/llms.txt An index: each page with one line about it and a link
https://docs.apidata.one/openapi.json The API as an OpenAPI 3.1 document: every endpoint, parameter, answer and error
Any page with .md in place of .html That page as plain Markdown

Build with a test key first. The sandbox answers exactly like live, costs nothing, and has a listing for every awkward case.

The prompt

Paste this before you describe the site you want. It states the rules a site on this API must keep.

You are building a real-estate search site on the apidata.one API (https://api.apidata.one/v1).
Read https://docs.apidata.one/llms-full.txt before writing code, and follow these rules exactly.

KEYS
- There are two keys. The secret key (sk_...) stays on the server, in an environment variable.
  It never appears in browser code, in a page, in a NEXT_PUBLIC_ or VITE_ variable, or in git.
- The publishable key (pk_...) is the only key allowed in browser code. Use it only for what
  must run in the browser: a moving map, a search box that completes, a favorite button.
- Every request sends "Authorization: Bearer <key>". The key picks the environment: _test_ keys
  reach the sandbox, _live_ keys reach real listings. The host and the paths never change.

PAGES
- Build listing pages and search pages ON THE SERVER with the secret key, so that they work
  without scripts and search engines can read them. Do not build a browser-only app.
- A listing's page address is built from its listingKey, and the listing is looked up by
  listingKey alone: /listing/{listingKey}/{words}. Take the words from the listing's "slug"
  field. Never build an address from the street address.
- Treat listingKey as text, never as a number.

A VISITOR'S OWN DATA (favorites, saved searches, saved shapes)
- The API never trusts a visitor's identity sent from the browser. Give each signed-in visitor
  an opaque ID (a UUID; never an email address or a phone number).
- On the server: the secret key plus the header "X-Client-Id: <that ID>".
- In the browser: the publishable key plus "X-Client-Token", a short-lived token the server
  mints for that visitor with POST /v1/client-tokens. Add a server route that mints it for
  the signed-in visitor, and refresh it before it expires (15 minutes by default).
- Send an "Idempotency-Key" header (a new UUID for each action) on every POST that saves
  something.

WHAT EVERY PAGE WITH A LISTING MUST SHOW
- Every answer with listings has a "compliance" object beside "data". Show its texts as given:
  copyright, accuracy and lastUpdated on every page with a listing; idxSource, personalUse and
  availability on the home page or every search page; advertisingBrokerage.name on every page
  with a listing. Never hard-code these texts: read them from the answer each time.
- Every listing card shows attribution.listOfficeName. A listing's detail page shows the
  listing office's name with its phone or email in the top quarter of the page, in the same
  size and colour as the other details.
- Closed listings show compliance.closed.label and both of its statements. Coming Soon listings
  show compliance.comingSoon.label.
- Photos are shown whole: CSS "object-fit: contain", never "cover". Never crop, overlay, filter
  or otherwise alter a photo. Use the photo URLs the API returns, with a plain <img> tag, and
  do not pass them through an image optimizer or a CDN that keeps its own copies.
- When a listing has addressDisplay "withheld", its address is null. Show the listing's
  addressNotice instead, and never show, guess or rebuild the address anywhere: not in the
  page, its title, its URL, its meta tags, its structured data or on a map.
- A field that is null or missing must not be shown and must not be computed (for example days
  on market or price history for a Coming Soon listing, or a hidden price).

FRESHNESS AND REMOVAL
- Do not store listings in your own database. Fetch them from the API when a page is built.
  A built page may be kept for a few minutes to answer quickly. Never show one that is more
  than 12 hours old.
- Handle the notice "listing.removed" (by webhook, or by reading GET /v1/events every minute):
  delete every stored copy of the listings it names, and answer 410 Gone for their pages.
- A 404 with error.code "listing_not_found" means the listing is gone: show a "no longer
  available" page.
- A 500 with error.code "data_stale" means live data is temporarily stopped: show "temporarily
  unavailable" and never a stored copy.

ERRORS AND LIMITS
- Every error is JSON: { "error": { "code", "message", "fix", "docs", "requestId" } }. Decide
  by error.code, never by the message text. Log requestId.
- 429 "rate_limited" and 500 "temporarily_unavailable" or "data_stale" carry a Retry-After
  header: wait that long, then retry. Most HTTP libraries do not retry a 500 by themselves.
- An HTML page with status 502, 503 or 504 is not from the API: retry after a few seconds.
- In the browser, call the API once when the visitor stops typing or stops moving the map
  (wait about 250 ms), and cancel the call that is no longer needed.

TEST AGAINST THE SANDBOX
- Use the test keys. Check these fixed listings: SBX900000001 (hidden address), SBX900000003
  (Coming Soon, no photos), SBX900000004 (Closed), SBX900000008 (prices not shown),
  SBX900000009 (150 photos), SBX900000024 (not served: 404).

The patterns, in Fastify

A plain Node server that builds its pages. Nothing here needs a build step.

A listing page, built on the server:

import Fastify from 'fastify';

const API = 'https://api.apidata.one/v1';
const secret = { Authorization: `Bearer ${process.env.APIDATA_SECRET_KEY}` }; // server only
const app = Fastify();

app.get('/listing/:listingKey/:words?', async (request, reply) => {
  const r = await fetch(`${API}/listings/${encodeURIComponent(request.params.listingKey)}`, { headers: secret });
  if (r.status === 404) return reply.code(404).type('text/html').send(notAvailablePage());
  if (!r.ok) {
    return reply.code(503).header('Retry-After', r.headers.get('retry-after') ?? '300')
      .type('text/html').send(unavailablePage());
  }
  const { data: listing, compliance } = await r.json();
  return reply.type('text/html').send(listingPage(listing, compliance)); // escape every value
});

A client token for the signed-in visitor, so that the browser can save a favorite with the publishable key:

app.post('/api/client-token', async (request, reply) => {
  const visitor = await signedInVisitor(request); // your own sign-in
  if (!visitor) return reply.code(401).send();
  const r = await fetch(`${API}/client-tokens`, {
    method: 'POST',
    headers: { ...secret, 'Content-Type': 'application/json' },
    body: JSON.stringify({ clientId: visitor.opaqueId }), // a UUID of yours, never an email address
  });
  if (!r.ok) return reply.code(502).send();
  return (await r.json()).data; // { token, expiresAt }
});
// In the browser: the publishable key and the visitor's token.
async function saveFavorite(listingKey) {
  const { token } = await (await fetch('/api/client-token', { method: 'POST' })).json();
  return fetch('https://api.apidata.one/v1/favorites', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer pk_test_…',
      'X-Client-Token': token,
      'Content-Type': 'application/json',
      'Idempotency-Key': crypto.randomUUID(),
    },
    body: JSON.stringify({ listingKey }),
  });
}

The same patterns, in Next.js

Many tools write Next.js. The rules are the same; these are the places it goes wrong.

A listing page is a server component. It runs on the server only, so the secret key is safe there:

// app/listing/[listingKey]/[[...words]]/page.jsx
import { notFound } from 'next/navigation';

export const dynamic = 'force-dynamic'; // build from the API on each request: no stored copy

export default async function ListingPage({ params }) {
  const { listingKey } = await params;
  const r = await fetch(`https://api.apidata.one/v1/listings/${encodeURIComponent(listingKey)}`, {
    headers: { Authorization: `Bearer ${process.env.APIDATA_SECRET_KEY}` },
    cache: 'no-store',
  });
  if (r.status === 404) notFound();
  if (!r.ok) throw new Error('listings are temporarily unavailable'); // shown by error.jsx
  const { data: listing, compliance } = await r.json();
  return (
    <main>
      <h1>{listing.address ? listing.address.line1 : listing.addressNotice}</h1>
      <p>
        Listed by {listing.attribution.listOfficeName}
        {listing.attribution.listOfficePhone ? `, ${listing.attribution.listOfficePhone}` : ''}
      </p>
      {listing.photos.items.map((photo) => (
        // A plain <img>: the API's own URL, shown whole.
        <img key={photo.mediaKey} src={photo.urls.medium ?? photo.urls.full} alt="" style={{ objectFit: 'contain' }} />
      ))}
      <footer>
        <p>{compliance.advertisingBrokerage.name}</p>
        <p>{compliance.copyright} {compliance.accuracy}</p>
        <p>{compliance.lastUpdated}</p>
      </footer>
    </main>
  );
}

The client token comes from a route handler:

// app/api/client-token/route.js
import { NextResponse } from 'next/server';

export async function POST(request) {
  const visitor = await signedInVisitor(request); // your own sign-in
  if (!visitor) return new NextResponse(null, { status: 401 });
  const r = await fetch('https://api.apidata.one/v1/client-tokens', {
    method: 'POST',
    headers: { Authorization: `Bearer ${process.env.APIDATA_SECRET_KEY}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ clientId: visitor.opaqueId }),
    cache: 'no-store',
  });
  if (!r.ok) return new NextResponse(null, { status: 502 });
  return NextResponse.json((await r.json()).data, { headers: { 'Cache-Control': 'no-store' } });
}

Where Next.js sites go wrong:

Check what the tool wrote

The compliance guide and an SEO-friendly site explain each rule, and the sample site at demo.apidata.one follows all of them.

This page as Markdown