惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
LangChain Blog
WordPress大学
WordPress大学
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
MyScale Blog
MyScale Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
P
Proofpoint News Feed
D
DataBreaches.Net

Flags SDK Documentation

Global Config Bulk Evaluation Evaluation Context Precompute GrowthBook Hypertune PostHog Split Evaluation Context Quickstart Precompute Evaluation Context Quickstart Precompute GrowthBook Hypertune PostHog Split Proxy Dashboard Pages Marketing Pages Dashboard Pages Marketing Pages Data Locality Providers Optimizely Reflag Statsig Server-side vs Client-side Flags as Code
LaunchDarkly
Vercel · 2026-04-03 · via Flags SDK Documentation

The LaunchDarkly provider contains support for LaunchDarkly's feature flags.

The @flags-sdk/launchdarkly package provides

  • An adapter for loading flags from LaunchDarkly.
  • A getProviderData function for use with the Flags Explorer

Learn more about Adapters

Learn more about the Flags Explorer


The LaunchDarkly provider is available in the @flags-sdk/launchdarkly module. Install it with

npm install @flags-sdk/launchdarkly

Import the default adapter instance ldAdapter from @flags-sdk/launchdarkly:

import { ldAdapter } from '@flags-sdk/launchdarkly';

If you need a customized setup, you can import createLaunchDarklyAdapter from @flags-sdk/launchdarkly and create an adapter instance with your settings:

import { createLaunchDarklyAdapter } from '@flags-sdk/launchdarkly';

const customLdAdapter = createLaunchDarklyAdapter({
  projectSlug: process.env.LAUNCHDARKLY_PROJECT_SLUG,
  clientSideId: process.env.LAUNCHDARKLY_CLIENT_SIDE_ID,
  edgeConfigConnectionString: process.env.EDGE_CONFIG,
});
Option keyTypeDescription
projectSlugstringLaunchDarkly project slug
clientSideIdstringLaunchDarkly client-side ID
edgeConfigConnectionStringstringEdge Config connection string

The default LaunchDarkly adapter configures itself based on the following environment variables:

  • LAUNCHDARKLY_CLIENT_SIDE_ID (required)clientSideId
  • LAUNCHDARKLY_PROJECT_SLUG (required)projectSlug
  • EDGE_CONFIG (required)edgeConfigConnectionString

LaunchDarkly relies on an LaunchDarkly Evaluation Context object to evaluate the flags for a given request.

Use the identify function to determine a LaunchDarkly Evaluation Context.

import { dedupe, flag } from "flags/next";
import type { Identify } from "flags";
import { ldAdapter, type LDContext } from "@flags-sdk/launchdarkly";

const identify = dedupe((async ({ headers, cookies }) => {
  // Your own logic to identify the user
  // Identifying the user should rely on reading cookies and headers only, and
  // not make any network requests, as it's important to keep latency low here.
  const user = await getUser(headers, cookies);

  return {
    key: user.userID,
    // ... other properties
  };
}) satisfies Identify<LDContext>);

export const exampleFlag = flag<boolean, LDContext>({
  key: "example-flag",
  identify,
  adapter: ldAdapter.variation(),
});

Learn more about identify


The LaunchDarkly adapter provides a method for evaluating flags.

variation

export const exampleFlag = flag<boolean, LDContext>({
  key: 'example-flag',
  identify,
  adapter: ldAdapter.variation(),
});

The identify function must return the Evaluation Context.

ldClient

The adapter exposes the LaunchDarkly client it uses internally through the ldClient property.

import { ldAdapter } from '@flags-sdk/launchdarkly';

ldAdapter.ldClient;

The LaunchDarkly adapter loads the configuration from Edge Config.

Edge Config is a global, ultra-low latency store which uses active replication and is specifically designed for serving feature flag configuration.

The default LaunchDarkly adapter, exported as ldAdapter, will automatically connect to Edge Config required environment variabless are set.


Initializing

The Flags SDK automatically initializes the LaunchDarkly client when a flag is evaluated.

If you want to initialize the LaunchDarkly client before the first flag is used, you can call ldAdapter.ldClient.waitForInitialization() manually.

import { ldAdapter } from '@flags-sdk/launchdarkly';

// Somewhere in your server-side code
await ldAdapter.ldClient.waitForInitialization();

LaunchDarkly Vercel SDK

The adapter uses the LaunchDarkly Vercel SDK (@launchdarkly/vercel-server-sdk) internally, which is designed for usage with Edge Config.


View and override your LaunchDarkly flags using the Flags Explorer.

To make Flags Explorer aware of your LaunchDarkly flags, you need to provide a route which Flags Explorer will load your flags metadata from.

Use the getProviderData function in your Flags API endpoint to load and emit your LaunchDarkly data. Accepts an options object with the following keys.

Options keyTypeDescription
apiKeystringLaunchDarkly API Key
environmentstringLaunchDarkly environment
projectKeystringLaunchDarkly project key
import { getProviderData, createFlagsDiscoveryEndpoint } from 'flags/next';
import { getProviderData as getLaunchDarklyProviderData } from '@flags-sdk/launchdarkly';
import { mergeProviderData } from 'flags';
import * as flags from '../../../../flags';

export const GET = createFlagsDiscoveryEndpoint(async (request) => {
  return mergeProviderData([
    getProviderData(flags),
    getLaunchDarklyProviderData({
      apiKey: process.env.LAUNCHDARKLY_API_KEY,
      projectKey: process.env.LAUNCHDARKLY_PROJECT_KEY,
      environment: process.env.LAUNCHDARKLY_ENVIRONMENT,
    }),
  ]);
});

Read more about LaunchDarkly, Flags SDK, and the LaunchDarkly adapter.

Learn more about the Flags Explorer