Skip to content

Configuration

The SDK is designed to work optimally out of the box with minimal configuration. Only your API key is required.

Basic Configuration

import { Featsync } from '@featsync/sdk';
const featsync = new Featsync({
apiKey: 'fs_your_api_key',
});

That’s it! The SDK automatically:

  • Caches flags for 5 minutes
  • Persists to localStorage for offline support
  • Prefetches all flags on initialization
  • Uses a 5-second request timeout

Full Configuration

const featsync = new Featsync({
// Required: Your API key from the dashboard
apiKey: 'fs_your_api_key',
// Optional: Environment to evaluate (default: 'production')
environment: 'production',
});

Configuration Options

apiKey (required)

Your API key from the Featsync dashboard. Each environment has its own API key.

apiKey: 'fs_abc123...';

environment

The environment to evaluate flags against. Defaults to 'production'.

environment: 'production'; // or 'staging', 'development'

Built-in Defaults

The SDK uses optimized defaults that work well for most applications:

SettingValueDescription
Cache duration5 minutesFlags are cached to minimize API calls
Request timeout5 secondsBalanced timeout for reliability
PrefetchAlways enabledFlags load immediately on initialization
PersistenceAlways enabledlocalStorage fallback for offline support

These values are carefully chosen based on best practices and cannot be overridden.

Environment Variables

We recommend using environment variables for configuration:

const featsync = new Featsync({
apiKey: process.env.FEATSYNC_API_KEY,
environment: process.env.NODE_ENV,
});

Next.js

.env.local
FEATSYNC_API_KEY=fs_abc123...

Vite

.env
VITE_FEATSYNC_API_KEY=fs_abc123...
const featsync = new Featsync({
apiKey: import.meta.env.VITE_FEATSYNC_API_KEY,
});

Singleton Pattern

Create a single SDK instance and reuse it throughout your application:

lib/featsync.js
import { Featsync } from '@featsync/sdk';
export const featsync = new Featsync({
apiKey: process.env.FEATSYNC_API_KEY,
});
anywhere.js
import { featsync } from './lib/featsync';
if (await featsync.isEnabled('my-flag')) {
// ...
}

Next Steps