Skip to main content
Zero dependencies; runs in any JS runtime with fetch (browser, Node, edge, workers).

Install

Usage

getAd resolves to RevinelAd | null; getAds to RevinelAd[] (empty when nothing is eligible; the SDK never throws on “no ads”).

Typed creative (meta)

ad.meta is keyed by each custom field’s stable machine slug (set when the publisher creates the field, e.g. bannerImage for a “Banner image” field). Pass your own interface for typesafe access:
Renaming a field’s display label never changes its slug, so your code keeps working.

Next.js / caching

Ad fetches default to next: { revalidate: 60 }, so App Router pages that call getAd/getAds stay statically renderable while the ad still refreshes every minute. (Revinel’s API edge-caches responses for ~5s anyway, so per-request rotation was always approximate.) Non-Next runtimes ignore the next key: server fetches (Node/edge) stay uncached, while browsers honor the response Cache-Control (max-age=5) and may reuse an identical request for up to ~5s, the same window the API’s edge cache already imposes. Opt out for true per-request rotation (on an already-dynamic Next page, or anywhere else):
Any explicit cache or next.revalidate you pass replaces the default entirely.
In Next.js server components, don’t wrap getAd in a try/catch that swallows every error. Errors carrying a digest property (e.g. DYNAMIC_SERVER_USAGE) are Next.js control flow, so rethrow them:

Errors

Non-2xx responses throw RevinelApiError ({ status, body }). The body is the Revinel API error envelope:
Input-validation failures use HTTP 422 with code: "INPUT_VALIDATION_FAILED" and a data.fieldErrors / data.formErrors map. For React bindings see @revinel/react.