Vercel SDK reference
Read time: 1 minute
Last edited: May 17, 2023
Development work on the Vercel SDK is ongoing. Elements of the Vercel SDK may change without notice, including becoming backwards incompatible.
Overview
This topic documents how to get started with the Vercel SDK, and links to reference information on all of the supported features.
LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
Resource | Location |
---|---|
SDK API documentation | SDK API docs |
GitHub repository | LaunchDarkly Vercel SDK |
Configure the Vercel integration to use this SDK successfully. To learn more, read Vercel.
The Vercel integration is available to customers on an Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.
Getting started
To install and configure the Vercel SDK in an existing project:
After you complete the Creating a Vercel integration process, follow these instructions to start using the LaunchDarkly Vercel SDK.
First, install the Vercel SDK as a dependency in your application using your application's dependency manager.
Here's how:
yarn add @launchdarkly/vercel-server-sdk
Next, import the LaunchDarkly client in your application code:
import init from '@launchdarkly/vercel-server-sdk';import { createClient } from '@vercel/edge-config';
After you install and import the SDK, create an edge client using your Edge Config ID. Then, initialize an LDClient
using your LaunchDarkly client-side SDK key and this edge client.
Here's how:
const edgeClient = createClient(process.env.EDGE_CONFIG);const ldClient = init('sdk-key-123abc', edgeClient);await ldClient.waitForInitialization();
After you initialize the client, wait for the waitForInitialization
function to resolve. When waitForInitialization
is resolved, the client can serve feature flags.
Using the client, you can check which variation a particular context will receive for a given feature flag. In your Vercel Edge application, place the client.variation
code so that it is invoked as needed.
Here is an example:
const ldContext = {kind: 'org',key: 'org-key-123abc',someAttribute: 'example-attribute-value',};const flagValue = await ldClient.variation('flag-key-123abc', ldContext, true);
Promises and async
All asynchronous SDK methods that return a Promise
are compatible with then/catch
or async/await
. You can use either.
Shutting down
Lastly, shut down the client when your application terminates. To learn more, read Shutting down.
Supported features
This SDK supports the following features: