Skip to main content

Overview

createChipiServer provides a singleton ChipiServerSDK instance for server-side operations in Next.js. It ensures only one SDK instance exists across your application, with automatic config conflict detection. Import everything from @chipi-stack/nextjs/server:

Setup

Create a shared server configuration file (e.g. lib/chipi-server.ts):
apiPublicKey and apiSecretKey are both required. The function throws immediately if either is missing. Keep apiSecretKey server-only — never expose it in client bundles or NEXT_PUBLIC_* environment variables.

Functions

createChipiServer(config)

Creates or returns the singleton ChipiServerSDK instance. Returns: ChipiServerSDK

Config Conflict Detection

If createChipiServer is called a second time with a different config, it throws an error instead of silently ignoring the new config. This prevents hard-to-debug issues where different parts of your app expect different configurations.

getChipiServer()

Returns the existing singleton instance. Throws if createChipiServer has not been called yet. Returns: ChipiServerSDK

resetChipiServer()

Destroys the existing singleton instance so that a new one can be created with createChipiServer. Primarily useful for testing.

Usage in Server Components

Usage in Route Handlers

Usage in Server Actions