02. Client SDK/Runtime Configuration

Client Configuration

The SDK provides zero-config defaults via environment variables, with support for custom cache strategies, timeouts, retries, and multi-tenant architectures.

CACHE STRATEGY
3-Tier
Memory · LocalStorage · Local .nx Binaries

Fine-tune how content is resolved on server renders vs client interactions with microsecond cache lookups.

Complete Cache Control

Configuration Parameters

Pass these options to new NexusClient(config) or createNexusClient(config):

ParameterTypeRequirementDescription
projectIdstringRequiredThe unique identifier of the target project node (e.g., 'prj_clx1a2b3').
apiKeystringRequiredYour public (nx_pk_...) or secret (nx_sk_...) API key.
apiUrlstringOptionalThe base URL for the NestJS Control Plane and content fetching routes.
Default: https://gnapex.com
analyticsUrlstringOptionalThe high-throughput Rust Sentry telemetry ingest endpoint.
Default: https://sentry.gnapex.com
cacheStrategy'memory' | 'localStorage' | 'none'OptionalIn-memory LRU cache, persistent browser storage, or complete network bypass.
Default: 'memory'
revalidateTimenumber | falseOptionalDefault TTL (in seconds) before content is re-fetched. 'false' caches permanently until purged.
Default: false
timeoutnumberOptionalGlobal network request timeout in milliseconds before throwing an AbortError.
Default: 10000
retriesnumberOptionalNumber of exponential backoff retry attempts for 5xx network dropouts.
Default: 3
debugbooleanOptionalEnables verbose console telemetry, cache hit/miss logs, and execution timers.
Default: false

Revalidation & Caching Mechanics

The 'Cache Forever' Default (Important)
By default, 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:

1import { createNexusClient } from "@nexushub/client";
2 
3export 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:

TENANCY / ISOLATION

Isolated Client Nodes

Each instance maintains its own LRU memory cache, backoff queue, and telemetry stream.

DATA / INDEPENDENT KEYS

Scoped Cryptography

Client A can query with public key nx_pk_alpha while Client B executes server writes with nx_sk_beta.

1import { createNexusClient } from "@nexushub/client";
2 
3export const clientEducation = createNexusClient({
4 projectId: "prj_school_101",
5 apiKey: process.env.SCHOOL_API_KEY!,
6});
7 
8export 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:

1import { nexus } from "@nexushub/client";
2 
3// Safely update config fields
4nexus.updateConfig({
5 debug: true,
6 revalidateTime: 120,
7});