NexoFlow
Docs · nexoflow-sdk Configuration

Technical SEOnexoflow-sdk

Configuration

Construct a client with your site key, then tune timeouts, caching, retries and logging if you need to.

Full example

client.ts
const nf = new NexoFlow({
  // Required
  apiKey: process.env.NEXOFLOW_API_KEY!,

  // Optional
  baseUrl: "https://nexoflow.net",  // default
  timeout: 15_000,                   // 15 seconds for the whole call (default)
  revalidate: 60,                    // Next.js ISR hint in seconds (default)

  // Custom fetch (polyfills, edge, tests)
  fetch: customFetchFn,

  // Retry network errors, 5xx and 429 answers
  retry: {
    attempts: 3, // default, including the first request
    delay: 500,  // base delay in ms, doubled each retry, plus jitter (default)
  },

  // Debug logging (request/response details, keys masked)
  debug: true,

  // Lifecycle hooks
  hooks: {
    beforeRequest: ({ url, init }) => {
      console.log("Requesting:", url)
    },
    afterResponse: (res) => {
      console.log("Status:", res.status)
    },
  },
})

Options

Reference for each constructor option:

OptionTypeDefaultDescription
apiKeystringrequiredYour site key. Must start with pk_live_
baseUrlstringhttps://nexoflow.netNexoFlow's address; paths are added after it
revalidatenumber | false60Default Next.js ISR hint (seconds), sent as next.revalidate; other runtimes ignore it
timeoutnumber15000Time limit for a call in ms, retries included
fetchtypeof fetchglobalThis.fetchCustom fetch (edge, tests, polyfills)
retryobject{ attempts: 3, delay: 500 }Retries for network errors, 5xx and 429
debugbooleanfalseLog each request and response to console.debug, with the key masked
hooksobject–beforeRequest (may change the request) / afterResponse (every response, errors included)

The constructor checks its input and throws a plain Error when the key is missing or doesn't start with pk_live_, when timeout isn't a positive number, when retry.attempts isn't a positive whole number, or when retry.delay is negative.

Retries & timeouts

  • A network error, a timeout, a 5xx or a 429 is retried, up to retry.attempts tries in all.
  • The wait before each retry is retry.delay doubled each time, plus up to half again at random. On a 429, the API's Retry-After wins.
  • Other 4xx answers (400, 401, 402, 404) are thrown at once.
  • timeout covers the whole call, retries and waits included. When it runs out, the error's code is TIMEOUT.

Per-request options

Every method takes an optional last argument with a signal to cancel the call (combined with the client's timeout) and a revalidate that overrides the client's ISR hint for that call only.

per-request.ts
const controller = new AbortController()

const { data } = await nf.posts.list(
  { limit: 12 },
  { revalidate: 300, signal: controller.signal }, // this call only
)

What each request sends

Every call is a GET with these headers. The X-Request-Id is the traceId you get back, so you can find the call in your own logs.

request
GET https://nexoflow.net/api/v1/content/posts?limit=12
Authorization: Bearer pk_live_…
Accept: application/json
User-Agent: nexoflow-sdk/0.3.8
X-Request-Id: nf_…   // the traceId on the response or the error