Client Configuration
The SDK provides zero-config defaults via environment variables, with support for custom cache strategies, timeouts, retries, and multi-tenant architectures.
“Fine-tune how content is resolved on server renders vs client interactions with microsecond cache lookups.”
Configuration Parameters
Pass these options to new NexusClient(config) or createNexusClient(config):
| Parameter | Type | Requirement | Description |
|---|---|---|---|
| projectId | string | Required | The unique identifier of the target project node (e.g., 'prj_clx1a2b3'). |
| apiKey | string | Required | Your public (nx_pk_...) or secret (nx_sk_...) API key. |
| apiUrl | string | Optional | The base URL for the NestJS Control Plane and content fetching routes. Default: https://gnapex.com |
| analyticsUrl | string | Optional | The high-throughput Rust Sentry telemetry ingest endpoint. Default: https://sentry.gnapex.com |
| cacheStrategy | 'memory' | 'localStorage' | 'none' | Optional | In-memory LRU cache, persistent browser storage, or complete network bypass. Default: 'memory' |
| revalidateTime | number | false | Optional | Default TTL (in seconds) before content is re-fetched. 'false' caches permanently until purged. Default: false |
| timeout | number | Optional | Global network request timeout in milliseconds before throwing an AbortError. Default: 10000 |
| retries | number | Optional | Number of exponential backoff retry attempts for 5xx network dropouts. Default: 3 |
| debug | boolean | Optional | Enables verbose console telemetry, cache hit/miss logs, and execution timers. Default: false |
Revalidation & Caching Mechanics
revalidateTime is false. In Next.js, this maps to cache: 'force-cache' and a ~100-year memory TTL. Content will never expire automatically unless an explicit revalidation webhook or SSE event is received.To change this behavior globally or per-request:
| 1 | import { createNexusClient } from "@nexushub/client"; |
| 2 | |
| 3 | export const nexus = createNexusClient({ |
| 4 | projectId: process.env.NEXT_PUBLIC_NEXUS_ID!, |
| 5 | apiKey: process.env.NEXT_PUBLIC_NEXUS_KEY!, |
| 6 | revalidateTime: 60, // Refresh cached content every 60 seconds |
| 7 | timeout: 5000, |
| 8 | }); |
Multi-Instance Client Isolation
If your application interacts with multiple project nodes simultaneously (e.g., an agency managing multiple customer portals), instantiate separate isolated clients:
Isolated Client Nodes
Each instance maintains its own LRU memory cache, backoff queue, and telemetry stream.
Scoped Cryptography
Client A can query with public key nx_pk_alpha while Client B executes server writes with nx_sk_beta.
| 1 | import { createNexusClient } from "@nexushub/client"; |
| 2 | |
| 3 | export const clientEducation = createNexusClient({ |
| 4 | projectId: "prj_school_101", |
| 5 | apiKey: process.env.SCHOOL_API_KEY!, |
| 6 | }); |
| 7 | |
| 8 | export const clientEcommerce = createNexusClient({ |
| 9 | projectId: "prj_store_202", |
| 10 | apiKey: process.env.STORE_API_KEY!, |
| 11 | }); |
Runtime Config Updates
Update configuration dynamically at runtime using updateConfig() without re-instantiating the client:
| 1 | import { nexus } from "@nexushub/client"; |
| 2 | |
| 3 | // Safely update config fields |
| 4 | nexus.updateConfig({ |
| 5 | debug: true, |
| 6 | revalidateTime: 120, |
| 7 | }); |