Server provider
The FlagshipServerProvider implements the OpenFeature server provider interface. The provider works in Cloudflare Workers, Node.js, and any server-side JavaScript runtime that supports the Fetch API.
Inside a Cloudflare Worker, you can pass the Flagship binding directly to the provider. This avoids HTTP overhead and is the recommended approach. Outside of Workers, initialize the provider with an app ID and account ID — each evaluation call makes an HTTP request to the Flagship evaluation endpoint.
Pass the Flagship binding directly to the provider. This is the recommended approach inside a Worker.
import { OpenFeature } from "@openfeature/server-sdk";import { FlagshipServerProvider } from "@cloudflare/flagship";
export default { async fetch(request, env) { await OpenFeature.setProviderAndWait( new FlagshipServerProvider({ binding: env.FLAGS }), );
const client = OpenFeature.getClient();
const showNewCheckout = await client.getBooleanValue( "new-checkout", false, { targetingKey: "user-42", plan: "enterprise" }, );
if (showNewCheckout) { return new Response("New checkout enabled!"); }
return new Response("Standard checkout."); },};import { OpenFeature } from "@openfeature/server-sdk";import { FlagshipServerProvider } from "@cloudflare/flagship";
export default { async fetch(request: Request, env: Env): Promise<Response> { await OpenFeature.setProviderAndWait( new FlagshipServerProvider({ binding: env.FLAGS }), );
const client = OpenFeature.getClient();
const showNewCheckout = await client.getBooleanValue( "new-checkout", false, { targetingKey: "user-42", plan: "enterprise" }, );
if (showNewCheckout) { return new Response("New checkout enabled!"); }
return new Response("Standard checkout."); },};Use an app ID, account ID, and an API token when running outside of a Worker (for example, in Node.js). The provider makes HTTP requests to the Flagship evaluation endpoint. Generate an API token from your Cloudflare account with Flagship read permissions.
import { OpenFeature } from "@openfeature/server-sdk";import { FlagshipServerProvider } from "@cloudflare/flagship";
await OpenFeature.setProviderAndWait( new FlagshipServerProvider({ appId: "<APP_ID>", accountId: "<ACCOUNT_ID>", authToken: "<API_TOKEN>", }),);
const client = OpenFeature.getClient();
const showNewCheckout = await client.getBooleanValue("new-checkout", false, { targetingKey: "user-42", plan: "enterprise",});import { OpenFeature } from "@openfeature/server-sdk";import { FlagshipServerProvider } from "@cloudflare/flagship";
await OpenFeature.setProviderAndWait( new FlagshipServerProvider({ appId: "<APP_ID>", accountId: "<ACCOUNT_ID>", authToken: "<API_TOKEN>", }),);
const client = OpenFeature.getClient();
const showNewCheckout = await client.getBooleanValue("new-checkout", false, { targetingKey: "user-42", plan: "enterprise",});| Option | Type | Required | Description |
|---|---|---|---|
binding | Flagship | No | The Flagship binding from env.FLAGS. Use this inside a Worker for best performance. Authentication is handled automatically through the binding. |
appId | string | No | The Flagship app ID from the Cloudflare dashboard. Required when not using a binding. |
accountId | string | No | Your Cloudflare account ID. Required when not using a binding. |
authToken | string | No | A Cloudflare API token with Flagship read permissions. Required when not using a binding. |
Provide either binding or appId, accountId, and authToken.
OpenFeature uses an evaluation context to pass user attributes to the flag provider. The targetingKey field is the primary user identifier.
Pass additional attributes alongside targetingKey to match targeting rules. For example, you can include plan, country, or any custom attribute your rules reference.
const value = await client.getBooleanValue("new-checkout", false, { targetingKey: "user-42", plan: "enterprise", country: "US",});const value = await client.getBooleanValue("new-checkout", false, { targetingKey: "user-42", plan: "enterprise", country: "US",});The SDK ships with two hooks that you can attach to the OpenFeature client.
- LoggingHook — Logs structured information for every evaluation.
- TelemetryHook — Captures timing and event data for observability.
import { LoggingHook, TelemetryHook } from "@cloudflare/flagship";
OpenFeature.addHooks(new LoggingHook(), new TelemetryHook());import { LoggingHook, TelemetryHook } from "@cloudflare/flagship";
OpenFeature.addHooks(new LoggingHook(), new TelemetryHook());If you use another OpenFeature-compatible provider (for example, LaunchDarkly or Flagsmith), switch to Flagship by replacing the provider initialization. No changes are needed at evaluation call sites.
// Beforeawait OpenFeature.setProviderAndWait( new LaunchDarklyProvider({ sdkKey: "..." }),);
// Afterawait OpenFeature.setProviderAndWait( new FlagshipServerProvider({ appId: "<APP_ID>", accountId: "<ACCOUNT_ID>", authToken: "<API_TOKEN>", }),);// Beforeawait OpenFeature.setProviderAndWait( new LaunchDarklyProvider({ sdkKey: "..." }),);
// Afterawait OpenFeature.setProviderAndWait( new FlagshipServerProvider({ appId: "<APP_ID>", accountId: "<ACCOUNT_ID>", authToken: "<API_TOKEN>", }),);