Configuration
Construct a client with required credentials and optional tuning for timeouts, caching, retries, and observability.
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 (default)
revalidate: 60, // Next.js ISR hint in seconds (default)
// Custom fetch (polyfills, edge, tests)
fetch: customFetchFn,
// Retry transient failures (5xx, network errors)
retry: {
attempts: 3, // default
delay: 500, // base delay in ms, doubles each retry (default)
},
// Debug logging (request/response details)
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:
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | string | required | Project API key (pk_live_*) |
| baseUrl | string | https://nexoflow.net | NexoFlow instance URL |
| revalidate | number | false | 60 | Default ISR cache hint (seconds) for Next.js |
| timeout | number | 15000 | Request timeout (ms) |
| fetch | typeof fetch | globalThis.fetch | Custom fetch (edge, tests, polyfills) |
| retry | object | { attempts: 3, delay: 500 } | Transient failure retries (5xx, network) |
| debug | boolean | false | Log request/response details |
| hooks | object | - | beforeRequest / afterResponse |
