> ## Documentation Index
> Fetch the complete documentation index at: https://docs.noteboxd.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Perfume App Architecture & Fragrance API Cost Optimization

> Build a perfume discovery website or fragrance recommendation app under $20/month using multi-note filtering, lazy caching, composite ETags, and browser-rendered bottle images.

The Noteboxd **fragrance and perfume developer API** is priced in exact micro-USD so early-stage perfume websites, scent recommendation apps, and storefront widgets can run lean — filtering server-side by notes and accords, caching within plan windows, and revalidating unchanged GET records at 50% off.

## Five ways to cut API spend

1. **Cache on demand instead of pre-syncing the whole catalogue:** Fetch and cache a fragrance only when a visitor opens or filters into it, rather than running a cron job across thousands of unviewed records.
2. **Use `GET /v2/fragrances?view=basic` for multi-note browse grids:** Filter directly by up to `5` notes and `5` accords (for example `GET /v2/fragrances?note=bergamot,vanilla&accord=woody&view=basic`) instead of pulling full detailed profiles just to filter client-side. A basic card costs `$0.005` (`50%` less than `view=detailed` at `$0.010`) and already includes `name`, `brand`, `concentration`, `launchYear`, `familyPrimary`, `communityScore`, `ratingCount`, and `imageUrl`. Load `view=detailed` only when a user opens a product detail page.
3. **Store permanent Noteboxd `id` and `slug` mappings in your app database:** You can keep bare identifiers forever under the Standard Licence and hydrate full records on demand.
4. **Use `POST /v2/fragrances/enrich` for detail pages:** One `enrich` call (`$0.050` + `$0.003`/review) replaces separate `get`, `wearing-stats`, `similar`, and `reviews` requests (`$0.084`–`$0.090`).
5. **Revalidate `GET` endpoints with `If-None-Match`:** Unchanged records cost **50% off list price** (up to `65%` off on Growth prepaid spend) both on same-day `304 Not Modified` responses and on cross-day `200 OK` refreshes (`X-Noteboxd-Revalidated: image-links-refreshed`) where only signed image links rotated.

## Budget scenarios for discovery sites

### Under `$20/month` on Pay as you go

* **Plan:** Pay as you go (`$0/mo` base, `3-day` static cache window, `2,500` distinct fragrances / 30 days).
* **Pattern:** Fetch `GET /v2/fragrances/{id}?view=detailed` (`$0.010` initial) lazily when a visitor views a fragrance or uses a note-matching filter, store `ETag` alongside the response for up to `3 days`, revalidate active items with `If-None-Match` (`$0.005` when unchanged), and render `imageUrl` directly in `<img>` tags.
* **Math:** `$20` funds **`2,000` initial detailed lookups** (`$0.010`), **`4,000` unchanged `If-None-Match` refreshes** (`$0.005`), or up to **`4,000` basic cards** (`$0.005`). Because repeated reads of the same IDs do not consume extra distinct quota, a site displaying several hundred core fragrances stays well inside the `2,500` distinct-fragrance limit.

### Keeping warm catalogues on Starter (`$49/month`) vs. Growth (`$249/month`)

* **Starter (`$49/mo`, `$60/mo` included usage, `7-day` cache window, `10,000` distinct fragrances / 30 days):**
  * Refreshing `1,000` detailed profiles weekly (`~4.3` cycles/month) via `GET` + `If-None-Match` costs **`~$21.43/month`** when records are unchanged (`~$23.57/month` assuming \~10% monthly catalogue edits, vs. `~$42.86/month` on `POST /batch`). That leaves **`~$36–$38/month`** inside Starter's `$60` included allowance for search, similarity, and community widgets.
  * Starter's `$60/month` allowance fits up to **\~2,800** unchanged warm detailed profiles (or \~1,400 at full list rate).
* **Growth (`$249/mo`, `$350/mo` included usage, `14-day` cache window, `30,000` distinct fragrances / 30 days):**
  * Halving the refresh frequency to every `14 days` (`~2.14` cycles/month) lets **`10,000` warm detailed profiles** cost **`~$107.14/month`** via `GET` + `If-None-Match` when unchanged (`~$117.86/month` @ 10% edits), fitting comfortably inside Growth's `$350` included allowance with over `$230/month` left for discovery calls.

## Reference cache helper (TypeScript)

Respect the `Cache-Control: private, max-age=...` header returned by the API so your cache TTL matches your plan and endpoint class automatically:

```typescript theme={null}
interface CachedEntry<T> {
  data: T;
  etag: string | null;
  expiresAt: number;
}

function parseMaxAgeSeconds(cacheControl: string | null): number {
  if (!cacheControl || cacheControl.includes("no-store")) return 0;
  const match = /max-age=(\d+)/.exec(cacheControl);
  return match ? Number(match[1]) : 0;
}

export async function fetchFragranceCached(
  idOrSlug: string,
  cache: Map<string, CachedEntry<unknown>>,
) {
  const key = `frag:${idOrSlug}:detailed`;
  const existing = cache.get(key);
  if (existing && Date.now() < existing.expiresAt) {
    return existing.data;
  }

  const headers: Record<string, string> = {
    Authorization: `Bearer ${process.env.NOTEBOXD_API_KEY}`,
  };
  if (existing?.etag) {
    headers["If-None-Match"] = existing.etag;
  }

  const encoded = encodeURIComponent(idOrSlug);
  const res = await fetch(
    `https://api.noteboxd.com/v2/fragrances/${encoded}?view=detailed`,
    { headers },
  );

  const ttlMs = parseMaxAgeSeconds(res.headers.get("cache-control")) * 1000;

  if (res.status === 304 && existing) {
    existing.expiresAt = Date.now() + ttlMs;
    return existing.data;
  }

  if (!res.ok) {
    throw new Error(`Noteboxd API error ${res.status}`);
  }

  const payload = await res.json();
  if (ttlMs > 0) {
    cache.set(key, {
      data: payload.data,
      etag: res.headers.get("etag"),
      expiresAt: Date.now() + ttlMs,
    });
  }
  return payload.data;
}
```

When revalidating on a new UTC day, `res.status === 200` with `X-Noteboxd-Revalidated: image-links-refreshed` is expected when the record data is unchanged and signed bottle URLs rotated — storing `payload.data` and `res.headers.get("etag")` as shown above updates your signed image links while still billing at the 50% unchanged-record discount.

## Render bottle photos directly in the browser

Do not fetch `img.noteboxd.com` URLs from backend cron jobs or image-resizing proxies. In React or Next.js, pass `imageUrl` straight to the browser:

```tsx theme={null}
<img
  src={fragrance.imageUrl}
  alt={`${fragrance.name} bottle`}
  loading="lazy"
  className="h-48 w-48 object-contain"
/>
```

If you use `next/image`, pass `unoptimized` so Next.js does not proxy `img.noteboxd.com` through `/_next/image` on your server (which can trigger HTTP `403` edge restrictions).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.