Files
2026-09-17 09:38:07 +02:00

2.5 KiB

@vercel/flags-core

The core evaluation engine for Vercel Flags, the feature flag platform built into Vercel. This package provides direct access to the flag evaluation client, data fetching, and an OpenFeature provider.

For Next.js and SvelteKit applications, use the Flags SDK with @flags-sdk/vercel provider instead. Use @vercel/flags-core when you need lower-level control, are working with an unsupported framework, or want to use the OpenFeature standard.

Installation

npm i @vercel/flags-core

Usage

Create a shared client at module scope, but evaluate flags inside a request handler when using Vercel OIDC authentication. evaluate() and bulkEvaluate() initialize the client automatically on first use; you do not need to call initialize() first.

For example, in an Express app deployed to Vercel:

import express from 'express';
import { createClient } from '@vercel/flags-core';

const app = express();
const client = createClient(); // Uses Vercel OIDC; does not initialize yet.

app.get('/api/feature', async (_req, res) => {
  const result = await client.evaluate<boolean>('show-new-feature', false);
  res.json({ enabled: result.value });
});

export default app;

Outside Vercel, pass an SDK key explicitly: createClient(process.env.FLAGS).

Evaluation Metrics

To associate evaluation metrics with an environment, pass the metricEnvironment option:

const client = createClient(process.env.FLAGS!, {
  metricEnvironment: 'preview',
});

This option is sent only to the metrics ingestion endpoint. It does not select the environment used for flag evaluation.

Configuration version headers

The header source reads x-vercel-flags-config-versions or flags-config-versions, with the x-vercel- header taking precedence when both are present.

OpenFeature

An OpenFeature-compatible provider is available at @vercel/flags-core/openfeature:

import { OpenFeature } from '@openfeature/server-sdk';
import { VercelProvider } from '@vercel/flags-core/openfeature';

await OpenFeature.setProviderAndWait(new VercelProvider());
const client = OpenFeature.getClient();

Documentation