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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
U
Unit 42
T
Tailwind CSS Blog
罗磊的独立博客
WordPress大学
WordPress大学
小众软件
小众软件
Recent Announcements
Recent Announcements
博客园 - 聂微东
Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
V
V2EX
博客园 - 三生石上(FineUI控件)
I
InfoQ
雷峰网
雷峰网
G
Google Developers Blog
阮一峰的网络日志
阮一峰的网络日志
B
Blog
腾讯CDC
A
About on SuperTechFans
博客园 - 叶小钗

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 LaunchDarkly Optimizely Reflag Statsig Server-side vs Client-side
OpenFeature
Vercel · 2026-04-03 · via Flags SDK Documentation

OpenFeature is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution. The Flags SDK OpenFeature adapter allows you to use the Flags SDK with any OpenFeature provider.

If there is a native Flags SDK adapter for your provider, we recommend using that instead. Native Flags SDK adapters finely tune the SDK for your flag provider, optionally integrate with Edge Config and Flags Explorer, and are configured for Edge Runtime compatibility where possible. See available adapters

The @flags-sdk/openfeature package provides an adapter for loading flags from OpenFeature.

Learn more about Adapters

Clone the OpenFeature template


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

npm i @flags-sdk/openfeature @openfeature/server-sdk

The command also installs the @openfeature/server-sdk peer dependency, as the OpenFeature adapter depends on the OpenFeature Node.js SDK.


Import the createOpenFeatureAdapter function from @flags-sdk/openfeature and create an adapter instance with your OpenFeature client.

For usage with regular providers, pass the client directly:

import { createOpenFeatureAdapter } from "@flags-sdk/openfeature"

OpenFeature.setProvider(new YourProviderOfChoice())
const openFeatureAdapter = createOpenFeatureAdapter(OpenFeature.getClient());

For usage with async providers, pass an init function, and return the client:

import { createOpenFeatureAdapter } from "@flags-sdk/openfeature"

// pass an init function, and return the client
const openFeatureAdapter = createOpenFeatureAdapter(async () => {
  const provider = new YourProviderOfChoice()
  await OpenFeature.setProviderAndWait(provider);
  return OpenFeature.getClient();
});
Option keyTypeDescription
clientClient | (() => Promise<Client>)OpenFeature client

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

Use the identify function to determine the Evaluation Context.

import type { Identify } from "flags";
import { dedupe, flag } from "flags/next";
import type { EvaluationContext } from "@openfeature/server-sdk";

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);

  const context: EvaluationContext = {
    targetingKey: user.id,
    // .. other properties ..
  };

  return context;
}));

const openFeatureAdapter = createOpenFeatureAdapter(async () => {
  const provider = new YourProviderOfChoice()
  await OpenFeature.setProviderAndWait(provider);
  return OpenFeature.getClient();
});

export const exampleFlag = flag<boolean, EvaluationContext>({
  key: "example-flag",
  identify,
  defaultValue: false,
  adapter: openFeatureAdapter.booleanValue(),
});

Learn more about identify


The OpenFeature adapter provides methods for evaluating flags.

booleanValue

export const exampleFlag = flag<boolean, EvaluationContext>({
  key: 'example-flag',
  identify,
  defaultValue: false,
  adapter: openFeatureAdapter.booleanValue(),
});
  • identify must return the Evaluation Context.
  • defaultValue must be provided when used with the OpenFeature adapter.

stringValue

export const exampleFlag = flag<string, EvaluationContext>({
  key: 'example-flag',
  identify,
  defaultValue: "",
  adapter: openFeatureAdapter.stringValue(),
});
  • identify must return the Evaluation Context.
  • defaultValue must be provided when used with the OpenFeature adapter.

numberValue

export const exampleFlag = flag<number, EvaluationContext>({
  key: 'example-flag',
  identify,
  defaultValue: -1,
  adapter: openFeatureAdapter.numberValue(),
});
  • identify must return the Evaluation Context.
  • defaultValue must be provided when used with the OpenFeature adapter.

objectValue

export const exampleFlag = flag<YourCustomObjectType, EvaluationContext>({
  key: 'example-flag',
  identify,
  defaultValue: {},
  adapter: openFeatureAdapter.objectValue(),
});
  • identify must return the Evaluation Context.
  • defaultValue must be provided when used with the OpenFeature adapter.

client

When the openFeatureAdapter was created synchronously, this contains the OpenFeature client.

openFeatureAdapter.client;

When the openFeatureAdapter was created asynchronously, this is an async function which returns the OpenFeature client returned by the init function.

await openFeatureAdapter.client();

The OpenFeature adapter does not integrate with Edge Config directly.

We recommend using a native Flags SDK adapter for your provider instead of using the OpenFeature adapter. Native Flags SDK adapters finely tune the SDK for your flag provider, optionally integrate with Edge Config and Flags Explorer, and are configured for Edge Runtime compatibility where possible. See available adapters.

If no native Flags SDK adapter is available, your OpenFeature provider might still allow you to configure Edge Config integration.


The Flags Explorer is a tool for viewing and overriding flags.

All feature flags using the Flags SDK can be overwritten by the Flags Explorer.

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

import { getProviderData, createFlagsDiscoveryEndpoint } from 'flags/next';
import * as flags from '../../../../flags';

export const GET = createFlagsDiscoveryEndpoint(async (request) => {
  return getProviderData(flags);
});

Edge Runtime compatibility

The OpenFeature provider of your choice may not be compatible with Edge Runtime, which can prevent usage in Routing Middleware and Edge Functions. This depends on the provider you use OpenFeature with.

Flags Explorer metadata

Due to limitations in the OpenFeature specification, the @flags-sdk/openfeature adapter is not capable of providing additional metadata like descriptions and available options to the Flags Explorer. Flags Explorer can still display the descriptions and options you define when declaring feature flags in code.


Read more about OpenFeature, Flags SDK, and the OpenFeature Node.js SDK.

Learn more about Adapters

Clone the OpenFeature template

Learn more about the Flags Explorer

Learn more about the OpenFeature Node.js SDK