> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> This topic explains how to configure various LaunchDarkly SDKs.

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## Overview

This topic explains how to configure various LaunchDarkly SDKs. It gives code samples for each SDK that include different configuration examples. This feature is available for client-side, server-side, and edge SDKs.

## Customize the SDK

You can use the configuration feature to configure certain aspects of your SDK, including flush intervals, timeout periods, and client connect parameters.

You can disable the publication of events for testing purposes. We strongly recommend against disabling events for any other reason because many features depend on regularly receiving analytics events, including targeting rules, flag statuses, and the **Contexts** or **Users** lists. To learn more, read [Analytics events](/sdk/concepts/events).

Details about each SDK's configuration are available in the SDK-specific sections below:

* [Client-side SDKs](#client-side-sdks)
* [Server-side SDKs](#server-side-sdks)
* [Edge SDKs](#edge-sdks)

## Client-side SDKs

This feature is available in the following client-side SDKs:

* [.NET (client-side)](#net-client-side)
* [Android](#android)
* [C++ (client-side)](#c-client-side)
* [Electron](#electron)
* [Flutter](#flutter)
* [iOS](#ios)
* [JavaScript](#javascript)
* [Node.js (client-side)](#nodejs-client-side)
* [React Native](#react-native)
* [Roku](#roku)

### .NET (client-side)

<Accordion title="Expand .NET (client-side) code sample">
  <Note title="The .NET (client-side) SDK uses a mobile key">
    The .NET (client-side) SDK uses a mobile key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to create a custom configuration object to pass custom parameters to the client. With it, we've configured the event queue flush frequency.

  You can configure `Configuration.Builder`:

  <CodeGroup>
    ```csharp title=".NET SDK v4.0 (C#)" theme={null}
          var config = Configuration
              .Builder("example-mobile-key", ConfigurationBuilder.AutoEnvAttributes.Enabled)
              .Events(Components.SendEvents().FlushInterval(TimeSpan.FromSeconds(2)))
              .Build();
          LdClient client = LdClient.Init(config, context);
    ```

    ```csharp title=".NET SDK v3.0 (C#)" theme={null}
          var config = Configuration
              .Builder("example-mobile-key")
              .Events(Components.SendEvents().FlushInterval(TimeSpan.FromSeconds(2)))
              .Build();
          LdClient client = LdClient.Init(config, context);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`Configuration`](https://launchdarkly.github.io/dotnet-core/pkgs/sdk/client/api/LaunchDarkly.Sdk.Client.Configuration.html).
</Accordion>

### Android

<Accordion title="Expand Android code sample">
  <Note title="The Android SDK uses a mobile key">
    The Android SDK uses a mobile key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  In the Android SDK, most of the configuration properties are grouped into areas of functionality, each of which has its own builder class that is only available if you are using that functionality. The basic areas of functionality are [data source](https://launchdarkly.github.io/android-client-sdk/com/launchdarkly/sdk/android/LDConfig.Builder.html#dataSource\(com.launchdarkly.sdk.android.subsystems.ComponentConfigurer\)), [events](https://launchdarkly.github.io/android-client-sdk/com/launchdarkly/sdk/android/LDConfig.Builder.html#events\(com.launchdarkly.sdk.android.subsystems.ComponentConfigurer\)), [networking](https://launchdarkly.github.io/android-client-sdk/com/launchdarkly/sdk/android/LDConfig.Builder.html#http\(com.launchdarkly.sdk.android.subsystems.ComponentConfigurer\)), and [service URIs](https://launchdarkly.github.io/android-client-sdk/com/launchdarkly/sdk/android/LDConfig.Builder.html#serviceEndpoints\(com.launchdarkly.sdk.android.integrations.ServiceEndpointsBuilder\)).

  This code sample shows you how to configure the client connect and flush interval parameters:

  <CodeGroup>
    ```java title="Java" theme={null}
          LDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled)
              .mobileKey("example-mobile-key")
              .http(
                Components.httpConfiguration()
                .connectTimeoutMillis(5000)
              )
              .events(
                Components.sendEvents()
                .flushIntervalMillis(5000)
              )
              .build();
    ```

    ```kotlin title="Kotlin" theme={null}
          val ldConfig: LDConfig = LDConfig.Builder(AutoEnvAttributes.Enabled)
              .mobileKey("example-mobile-key")
              .http(
                Components.httpConfiguration()
                .connectTimeoutMillis(5000)
              )
              .events(
                Components.sendEvents()
                .flushIntervalMillis(5000)
              )
              .build();
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDConfig.Builder`](https://launchdarkly.github.io/android-client-sdk/com/launchdarkly/sdk/android/LDConfig.Builder.html).
</Accordion>

### C++ (client-side)

<Accordion title="Expand C++ (client-side) code sample">
  <Note title="The C++ (client-side) SDK uses a mobile key">
    The C++ (client-side) SDK uses a mobile key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to configure the event queue capacity and flush interval parameters:

  <CodeGroup>
    ```cpp title="C++ SDK v3.0 (native)" theme={null}
          auto config_builder = client_side::ConfigBuilder("example-mobile-key");
          config_builder.Events()
              .Capacity(1000)
              .FlushInterval(std::chrono::seconds(30));
          auto config = config_builder.Build();
          if (!config) {
              /* an error occurred, config is not valid */
          }
    ```

    ```c title="C++ SDK v3.0 (C binding)" theme={null}
          LDClientConfigBuilder builder = LDClientConfigBuilder_New("example-mobile-key");
          LDClientConfigBuilder_Events_Capacity(builder, 1000);
          LDClientConfigBuilder_Events_FlushIntervalMs(builder, 30 * 1000);
          LDClientConfig config;

          LDStatus status = LDClientConfigBuilder_Build(builder, &config);

          if (!LDStatus_Ok(status)) {
              /* an error occurred, config is not valid */
          }
    ```

    ```c title="C SDK v2.x (native)" theme={null}
          struct LDConfig *config = LDConfigNew("example-mobile-key");
          LDConfigSetEventsCapacity(config, 1000);
          LDConfigSetEventsFlushIntervalMillis(config, 30000);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`ConfigBuilder`](https://launchdarkly.github.io/cpp-sdks/libs/client-sdk/docs/html/classlaunchdarkly_1_1config_1_1shared_1_1builders_1_1ConfigBuilder.html). To learn more about the event queue capacity and flush interval parameters specifically, read [`EventsBuilder`](https://launchdarkly.github.io/cpp-sdks/libs/client-sdk/docs/html/classlaunchdarkly_1_1config_1_1shared_1_1builders_1_1EventsBuilder.html).
</Accordion>

### Electron

<Accordion title="Expand Electron code sample">
  <Warning title="Electron SDK credentials">
    The Electron SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in client-side code. Do not embed a server-side SDK key in a client-side application. You can find client-side IDs and project keys in **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).

    If you connect the Electron SDK to the `ldcli` dev-server for local testing, use your **project key** instead of a client-side ID. Set all service endpoints to `http://localhost:8765`. If you use a client-side ID, the SDK connects to LaunchDarkly rather than the dev-server, which can produce CORS errors (especially from the renderer process).
  </Warning>

  This code sample shows you how to create a custom configuration object to pass custom parameters to the client:

  <CodeGroup>
    ```js title="JavaScript" theme={null}
          const options = {
            allAttributesPrivate: true
          };
          const client = LDElectron.initializeInMain('example-client-side-id', user, options);

    ```

    ```ts title="TypeScript" theme={null}
          import * as LDElectron from 'launchdarkly-electron-client-sdk'

          const options: LDElectron.LDOptions = { allAttributesPrivate: true };
          const client = LDElectron.initializeInMain('example-client-side-id', user, options);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDOptions`](https://launchdarkly.github.io/electron-client-sdk/interfaces/_launchdarkly_electron_client_sdk_.ldoptions.html).
</Accordion>

### Flutter

<Accordion title="Expand Flutter code sample">
  <Warning title="Flutter SDK credentials">
    The Flutter SDK v4 uses either a **mobile key** or a **client-side ID**, depending on your target platform. For Windows, macOS, Linux, Android, or iOS, use a mobile key. For **web builds**, use a client-side ID.

    You can find client-side IDs, mobile keys, and project keys in **Project settings** on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).

    If you connect a **Flutter web** app to the `ldcli` dev-server for local testing, use your **project key** instead of a client-side ID, and set all service endpoints to `http://localhost:8765`. If you use a mobile key or client-side ID, the app connects to LaunchDarkly rather than the dev-server, which can result in CORS errors.
  </Warning>

  The Flutter SDK version 4 uses either a mobile key or a client-side ID, depending on the platform that you build for. You can set these in the `LAUNCHDARKLY_MOBILE_KEY` and `LAUNCHDARKLY_CLIENT_SIDE_ID` environment variables, and then use the `CredentialSource` helper to select your credential and provide it to your configuration. `CredentialSource` expects one of the two environment variables to be set, but not both.

  This code sample shows you how to configure the credential, automatic environment attributes, and evaluation reasons options:

  <CodeGroup>
    ```dart title="Flutter SDK v4" theme={null}
          final config = LDConfig(
            CredentialSource.fromEnvironment(),
            AutoEnvAttributes.enabled,
            dataSourceConfig: DataSourceConfig(
              evaluationReasons: true
            ),
          );
    ```

    ```dart title="Flutter SDK v3.x" theme={null}
          LDConfig ldConfig = LDConfigBuilder('example-mobile-key', AutoEnvAttributes.Enabled)
              .evaluationReasons(true)
              .build();
    ```

    ```dart title="Flutter SDK v2.x" theme={null}
          LDConfig ldConfig = LDConfigBuilder('example-mobile-key')
              .evaluationReasons(true)
              .build();
    ```
  </CodeGroup>

  The credential and automatic environment attributes configuration options are required. All other configuration options are optional and use default values if not set.

  To learn more about the specific configuration options available in this SDK, read [`LDConfig`](https://pub.dev/documentation/launchdarkly_flutter_client_sdk/latest/launchdarkly_flutter_client_sdk/LDConfig-class.html).
</Accordion>

### iOS

<Accordion title="Expand iOS code sample">
  <Note title="The iOS SDK uses a mobile key">
    The iOS SDK uses a mobile key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to configure the client connection timeout and event flush interval parameters:

  <CodeGroup>
    ```swift title="Swift" theme={null}
          var ldConfig = LDConfig(mobileKey: "example-mobile-key", autoEnvAttributes: .enabled)
          ldConfig.connectionTimeout = 10.0
          ldConfig.eventFlushInterval = 30.0
    ```

    ```objectivec title="Objective-C" theme={null}
          LDConfig *ldConfig = [[LDConfig alloc] initWithMobileKey:@"example-mobile-key" autoEnvAttributes:AutoEnvAttributesEnabled];
          ldConfig.connectionTimeout = 10.0;
          ldConfig.eventFlushInterval = 30.0;
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDConfig`](https://launchdarkly.github.io/ios-client-sdk/Structs/LDConfig.html).
</Accordion>

### Java

Script

<Accordion title="Expand JavaScript code sample">
  <Warning title="JavaScript SDK credentials">
    The JavaScript SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in client-side code. Do not embed a server-side SDK key in a client-side application. You can find client-side IDs and project keys in **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).

    If you connect the JavaScript SDK to the `ldcli` dev-server for local testing, use your project key instead of a client-side ID. Set all service endpoints to `http://localhost:8765`. If you use a client-side ID, the SDK connects to LaunchDarkly rather than the dev-server, which can result in CORS errors.
  </Warning>

  This code sample shows you how to create a custom configuration object to pass custom parameters to the client:

  <Warning title="The initialization method changed in v4.0 of the JavaScript SDK">
    Version 4.0 of the JavaScript SDK does not use the `initialize` method from earlier versions. To learn more, read [Client initialization](/sdk/client-side/javascript/migration-3-to-4#client-initialization).
  </Warning>

  <CodeGroup>
    ```js title="JavaScript SDK v4.x" theme={null}
          const options = { allAttributesPrivate: true };
          const client = createClient('example-client-side-id', context, options);
          client.start();

          const result = await client.waitForInitialization({ timeout: 5 });
          if (result.status === 'complete') {
            // Client initialized successfully
          } else if (result.status === 'failed') {
            // Client failed to initialize
            console.error('Initialization failed:', result.error);
          } else if (result.status === 'timeout') {
            // Initialization timed out
            console.error('Initialization timed out');
          }
    ```

    ```js title="JavaScript SDK v3.x" theme={null}
          const options = { allAttributesPrivate: true };
          const client = LDClient.initialize('example-client-side-id', context, options);

          try {
            await client.waitForInitialization(5);
            proceedWithSuccessfullyInitializedClient();
          } catch(err) {
            // Client failed to initialize or timed out
            // variation() calls return fallback values until initialization completes
          }
    ```

    ```ts title="JavaScript SDK v3.x (TypeScript)" theme={null}
          import * as LDClient from 'launchdarkly-js-client-sdk';

          const options: LDClient.LDOptions = { allAttributesPrivate: true };
          const client = LDClient.initialize('example-client-side-id', context, options);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDOptions`](https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/interfaces/LDOptions.html).
</Accordion>

### Node.js (client-side)

<Accordion title="Expand Node.js (client-side) code sample">
  <Warning title="Node.js (client-side) SDK credentials">
    The Node.js (client-side) SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in client-side code. Do not embed a server-side SDK key in a client-side application. You can find client-side IDs and project keys in **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).

    If you connect the Node.js (client-side) SDK to the `ldcli` dev-server for local testing, use your **project key** instead of a client-side ID. Set all service endpoints to `http://localhost:8765`. If you use a client-side ID, the SDK connects to LaunchDarkly rather than the dev-server, which can result in CORS errors.
  </Warning>

  This code sample shows you how to create a custom configuration object to pass custom parameters to the client:

  <CodeGroup>
    ```js title="Node.js SDK v3.0 (JavaScript)" theme={null}
          const options = {
            flushInterval: 10000, // milliseconds
            allAttributesPrivate: true
          };

          const client = LDClient.initialize('example-client-side-id', context, options);
          try {
            await client.waitForInitialization(5);
            // initialization succeeded, flag values are now available
          } catch (err) {
            // initialization failed or did not complete before timeout
          }
    ```

    ```ts title="Node.js SDK v3.0 (TypeScript)" theme={null}
          import * as LDClient from 'launchdarkly-node-client-sdk';

          const options: LDClient.LDOptions = {
            flushInterval: 10000, // milliseconds
            allAttributesPrivate: true,
          };
          const client = LDClient.initialize('example-client-side-id', context, options);
          try {
            await client.waitForInitialization(5);
            // initialization succeeded, flag values are now available
          } catch (err) {
            // initialization failed or did not complete before timeout
          }
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDOptions`](https://launchdarkly.github.io/node-client-sdk/interfaces/LDOptions.html).
</Accordion>

### React Native

<Accordion title="Expand React Native code sample">
  <Note title="The React Native SDK uses a mobile key">
    The React Native SDK uses a mobile key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to create a configuration object to pass configuration parameters to the client.

  The configuration object can include a variety of options. In version 10 of the SDK, all properties are optional.

  In versions 9 and earlier, `mobileKey` was a required property, but all other properties were optional. Additionally, in versions 9 and earlier we recommend setting a timeout parameter when you call `configure`. If the client receives flag values before the timeout, the returned promise will resolve. Otherwise, it will be rejected.

  <Warning title="Always include a timeout parameter in v9 and earlier when calling configure">
    In versions 9 and earlier, do not configure your SDK to initialize without a timeout parameter. Doing so will cause your app never to load if there is a connectivity problem. We recommend setting a timeout for no more than 1-5 seconds. To learn more, read [React Native SDK reference](/sdk/client-side/react/react-native).
  </Warning>

  Here is an example:

  <CodeGroup>
    ```ts title="React Native SDK v10" theme={null}
          import { type LDOptions } from '@launchdarkly/react-native-client-sdk';

          const options = {
            withReasons: true,
          };

          const client = new ReactNativeLDClient('example-mobile-key', AutoEnvAttributes.Enabled, options);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDOptions`](https://launchdarkly.github.io/js-core/packages/sdk/react-native/docs/interfaces/LDOptions.html).
</Accordion>

### Roku

<Accordion title="Expand Roku code sample">
  <Note title="The Roku SDK uses a mobile key">
    The Roku SDK uses a mobile key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to create a configuration object:

  <CodeGroup>
    ```brightscript title="BrightScript" theme={null}
          ' for a legacy Roku application
          config = LaunchDarklyConfig("example-mobile-key")

          ' for a SceneGraph Roku Application
          config = LaunchDarklyConfig("example-mobile-key", CLIENT_SCENEGRAPH_NODE)

    ```
  </CodeGroup>

  We support the following configuration options for both SceneGraph and non-SceneGraph usage:

  <CodeGroup>
    ```brightscript title="BrightScript" theme={null}
          config.setAppURI(String)

          config.setEventsURI(String)

          config.setStreamURI(String)


          config.setPollingIntervalSeconds(Integer)

          config.setOffline(Boolean)


          config.addPrivateAttribute(String)

          config.setAllAttributesPrivate(Boolean)


          config.setEventsCapacity(Integer)

          config.setEventsFlushIntervalSeconds(Integer)


          config.setLogger(Object)

          config.setLoggerNode(Dynamic)

          config.setStoreBackend(Object)

          config.setStoreBackendNode(Dynamic)


          config.setStreaming(Boolean)

          config.setLogLevel(Integer)


          config.setUseEvaluationReasons(Boolean)

          config.setApplicationInfoValue(String, String)
    ```
  </CodeGroup>
</Accordion>

## Server-side SDKs

This feature is available for the following server-side SDKs:

* [.NET (server-side)](#net-server-side)
* [Apex](#apex)
* [C++ (server-side)](#c-server-side)
* [Erlang](#erlang)
* [Go](#go)
* [Haskell](#haskell)
* [Java](#java)
* [Lua](#lua)
* [Node.js (server-side)](#nodejs-server-side)
* [PHP](#php)
* [Python](#python)
* [Ruby](#ruby)
* [Rust](#rust)

### .NET (server-side)

<Accordion title="Expand .NET (server-side) code sample">
  <Note title="The .NET (server-side) SDK uses an SDK key">
    The .NET (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object:

  <CodeGroup>
    ```csharp title="C#" theme={null}
          var config = Configuration.Builder("YOUR_SDK_KEY")
              .Events(
                  Components.SendEvents().FlushInterval(TimeSpan.FromSeconds(2))
              )
              .StartWaitTime(TimeSpan.FromSeconds(5))
              .Build();
          var client = new LdClient(config);
    ```
  </CodeGroup>

  To learn more about the specific configuration that are available in this SDK, read [`ConfigurationBuilder`](https://launchdarkly.github.io/dotnet-core/pkgs/sdk/server/api/LaunchDarkly.Sdk.Server.ConfigurationBuilder.html).
</Accordion>

### Apex

<Accordion title="Expand Apex code sample">
  This code sample shows you how to configure the client to redact all user attributes in events:

  <CodeGroup>
    ```java title="Apex" theme={null}
          LDConfig config = new LDConfig.Builder()
              .setAllAttributesPrivate(true)
              .build();
    ```
  </CodeGroup>

  To learn more about the specific configuration options available for this SDK, read [`LDConfig.Builder`](https://github.com/launchdarkly/apex-server-sdk/blob/master/doc.md#class-ldconfigbuilder).
</Accordion>

### C++ (server-side)

<Accordion title="Expand C++ (server-side) code sample">
  <Note title="The C++ (server-side) SDK uses an SDK key">
    The C++ (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to configure the event queue capacity and flush interval parameters:

  <CodeGroup>
    ```cpp title="C++ SDK v3.0 (native)" theme={null}
          auto config_builder = server_side::ConfigBuilder("YOUR_SDK_KEY");
          config_builder.Events()
              .Capacity(1000)
              .FlushInterval(std::chrono::seconds(30));
          auto config = config_builder.Build();
          if (!config) {
              /* an error occurred, config is not valid */
          }
    ```

    ```c title="C++ SDK v3.0 (C binding)" theme={null}
          LDServerConfigBuilder builder = LDServerConfigBuilder_New("YOUR_SDK_KEY");
          LDServerConfigBuilder_Events_Capacity(builder, 1000);
          LDServerConfigBuilder_Events_FlushIntervalMs(builder, 30 * 1000);
          LDServerConfig config;

          LDStatus status = LDServerConfigBuilder_Build(builder, &config);

          if (!LDStatus_Ok(status)) {
              /* an error occurred, config is not valid */
          }
    ```

    ```c title="C SDK v2.x (native)" theme={null}
          struct LDConfig *config = LDConfigNew("YOUR_SDK_KEY");
          LDConfigSetEventsCapacity(config, 1000);
          LDConfigSetEventsFlushInterval(config, 30000);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available for this SDK, read [`ConfigBuilder`](https://launchdarkly.github.io/cpp-sdks/libs/server-sdk/docs/html/classlaunchdarkly_1_1config_1_1shared_1_1builders_1_1ConfigBuilder.html). To learn more about the event queue capacity and flush interval parameters specifically, read [`EventsBuilder`](https://launchdarkly.github.io/cpp-sdks/libs/server-sdk/docs/html/classlaunchdarkly_1_1config_1_1shared_1_1builders_1_1EventsBuilder.html).
</Accordion>

### Erlang

<Accordion title="Expand Erlang code sample">
  <Note title="The Erlang SDK uses an SDK key">
    The Erlang SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters when the client starts with the `Options` map parameter. The code in this example turns off streaming, so the SDK connects to LaunchDarkly through polling.

  To pass custom parameters:

  <CodeGroup>
    ```erlang title="Erlang" theme={null}
          % Specify options
          ldclient:start_instance("YOUR_SDK_KEY", #{stream => false})

          % With a custom instance name
          ldclient:start_instance("YOUR_SDK_KEY", your_instance, #{stream => false})
    ```
  </CodeGroup>

  To learn more about the specific configuration options available for this SDK, read [`ldclient_config`](https://hexdocs.pm/launchdarkly_server_sdk/ldclient_config.html).
</Accordion>

### Go

<Accordion title="Expand Go code sample">
  <Note title="The Go SDK uses an SDK key">
    The Go SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object. The code in this sample configures the event flush interval parameter.

  To pass custom parameters:

  <CodeGroup>
    ```go title="Go SDK v6.0" theme={null}
          import (
              "time"

              ld "github.com/launchdarkly/go-server-sdk/v6"
              "github.com/launchdarkly/go-server-sdk/v6/ldcomponents"
          )

          var config ld.Config

          config.Events = ldcomponents.SendEvents().FlushInterval(10*time.Second)

          client, _ := ld.MakeCustomClient("YOUR_SDK_KEY", config, 5*time.Second)
    ```
  </CodeGroup>

  To learn more about the specific configuration options available for this SDK, read [`Config`](https://pkg.go.dev/github.com/launchdarkly/go-server-sdk/v7#Config).
</Accordion>

### Haskell

<Accordion title="Expand Haskell code sample">
  <Note title="The Haskell SDK uses an SDK key">
    The Haskell SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object. This example configures the event queue capacity and flush interval parameters.

  To pass custom parameters:

  <CodeGroup>
    ```haskell title="Haskell" theme={null}
          {-# LANGUAGE OverloadedStrings #-}

          import LaunchDarkly.Server.Config

          import Data.Function ((&))

          config :: Config
          config = (makeConfig "YOUR_SDK_KEY")
              & configSetEventsCapacity 1000
              & configSetFlushIntervalSeconds 30
    ```
  </CodeGroup>

  To learn more about the specific configuration properties that are available in this SDK, read [`Config`](https://launchdarkly.github.io/haskell-server-sdk/LaunchDarkly-Server-Config.html).
</Accordion>

### Java

<Accordion title="Expand Java code sample">
  <Note title="The Java SDK uses an SDK key">
    The Java SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

  In this example, we've configured two properties for HTTP (the connect and socket timeouts), and one property for analytics events (the event flush interval).

  To pass custom parameters:

  <CodeGroup>
    ```java title="Java" theme={null}
          LDConfig config = new LDConfig.Builder()
            .http(
              Components.httpConfiguration()
                .connectTimeout(Duration.ofSeconds(3))
                .socketTimeout(Duration.ofSeconds(3))
            )
            .events(
              Components.sendEvents()
                .flushInterval(Duration.ofSeconds(10))
            )
            .build();
          LDClient client = new LDClient("YOUR_SDK_KEY", config);
    ```
  </CodeGroup>

  To learn more about the specific configuration properties that are available in this SDK, read [`LDConfig.Builder`](https://launchdarkly.github.io/java-core/lib/sdk/server/com/launchdarkly/sdk/server/LDConfig.Builder.html).
</Accordion>

### Lua

<Accordion title="Expand Lua code sample">
  <Note title="The Lua SDK uses an SDK key">
    The Lua SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

  <Warning title="Finish setting up your configuration client before you call `LDClientInit`">
    You must finish setting up your configuration object before you call `clientInit`. If you initialize the client before configuration is complete, the SDK will not use anything you provide after initialization.
  </Warning>

  Here, we've configured the event queue capacity and flush interval parameters:

  <CodeGroup>
    ```lua title="Lua SDK v2" theme={null}
          local config = {
              events = {
                  capacity = 1000,
                  flushIntervalMilliseconds  = 30000
              }
          }

          -- This blocks for 1 second to initialize
          local client = ld.clientInit("YOUR_SDK_KEY", 1000, config)
    ```

    ```lua title="Lua SDK v1.x" theme={null}
          local config = {
              key                 = "YOUR_SDK_KEY",
              eventsCapacity      = 1000,
              eventsFlushInterval = 30000
          }

          local client = ld.clientInit(config, 1000)
    ```
  </CodeGroup>

  To learn more about the specific configuration properties that are available in this SDK, read [`clientInit`](https://launchdarkly.github.io/lua-server-sdk/modules/launchdarkly-server-sdk.html#clientInit).
</Accordion>

### Node.js (server-side)

<Accordion title="Expand Node.js (server-side) code sample">
  <Note title="The Node.js (server-side) SDK uses an SDK key">
    The Node.js (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object:

  <CodeGroup>
    ```ts title="Node.js SDK v8.x (TypeScript)" theme={null}
          import * as ld from '@launchdarkly/node-server-sdk';

          const options: ld.LDOptions = {
            timeout: 3,
          };
          const client = ld.init('YOUR_SDK_KEY', options);
    ```

    ```js title="Node.js SDK v7.x (JavaScript)" theme={null}
          const options = {
            timeout: 3
          };
          client = ld.init('YOUR_SDK_KEY', options);
    ```

    ```ts title="Node.js SDK v7.x (TypeScript)" theme={null}
          import * as ld from 'launchdarkly-node-server-sdk';

          const options: ld.LDOptions = {
            timeout: 3,
          };
          const client = ld.init('YOUR_SDK_KEY', options);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDOptions`](https://launchdarkly.github.io/js-core/packages/sdk/server-node/docs/interfaces/LDOptions.html).
</Accordion>

### PHP

<Accordion title="Expand PHP code sample">
  <Note title="The PHP SDK uses an SDK key">
    The PHP SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample uses the `cache` option, which passes as an array to the client constructor. There are a few additional options you can set in this array.

  We've set the client connect timeout to three seconds in addition to providing a custom cache storage provider.

  <Warning title="Sending events in PHP">
    The LaunchDarkly SDK sends data back to our server to record events from track and variation calls. On our other platforms, this data is sent asynchronously, so that it adds no latency to serving web pages. PHP's shared-nothing architecture makes this difficult.

    By default, LaunchDarkly forks an external process that executes `curl` to send this data. In practice, we've found that this is the most reliable way to send data without introducing latency to page load times. If your server does not have `curl` installed, or has other restrictions that make it impossible to invoke `curl` as an external process, you may need to implement a custom `EventProcessor` to send events to LaunchDarkly.
  </Warning>

  Here is an example:

  <CodeGroup>
    ```php title="PHP" theme={null}
          $client = new LaunchDarkly\LDClient("YOUR_SDK_KEY", ["cache" => $cacheStorage, "connect_timeout" => 3]);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read the SDK API documentation for the [`LDClient` constructor](http://launchdarkly.github.io/php-server-sdk/classes/LaunchDarkly-LDClient.html#method___construct).
</Accordion>

### Python

<Accordion title="Expand Python code sample">
  <Note title="The Python SDK uses an SDK key">
    The Python SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object:

  <CodeGroup>
    ```python title="Python" theme={null}
          config = Config(sdk_key='YOUR_SDK_KEY', http=HTTPConfig(connect_timeout=5))
          ldclient.set_config(config)
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`ldclient.config`](https://launchdarkly-python-sdk.readthedocs.io/en/latest/api-main.html#module-ldclient.config).
</Accordion>

### Ruby

<Accordion title="Expand Ruby code sample">
  <Note title="The Ruby SDK uses an SDK key">
    The Ruby SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to configure the behavior of the client by creating a custom configuration object.

  The client constructor takes a configuration object as an optional parameter. In this example, we've set the connection timeout to LaunchDarkly to one second, and the read timeout to two seconds.

  To create a custom configuration object:

  <CodeGroup>
    ```ruby title="Ruby" theme={null}
          config = LaunchDarkly::Config.new({connect_timeout: 1, read_timeout: 2})
          client = LaunchDarkly::LDClient.new("YOUR_SDK_KEY", config)
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`Config`](https://launchdarkly.github.io/ruby-server-sdk/LaunchDarkly/Config).
</Accordion>

### Rust

<Accordion title="Expand Rust code sample">
  <Note title="The Rust SDK uses an SDK key">
    The Rust SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Note>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object:

  <CodeGroup>
    ```rust title="Rust" theme={null}
          let config = ConfigBuilder::new("YOUR_SDK_KEY")
            .offline(true)
            .build();
          let client = Client::build(config).unwrap();
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`Config`](https://docs.rs/launchdarkly-server-sdk/latest/launchdarkly_server_sdk/struct.Config.html).
</Accordion>

## Edge SDKs

This feature is available in the following edge SDKs:

* [Akamai](#akamai)
* [Cloudflare](#cloudflare)
* [Fastly](#fastly)
* [Vercel](#vercel)

### Akamai

<Accordion title="Expand Akamai code sample">
  <Warning title="Akamai SDK credentials">
    The Akamai SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in edge code. Do not embed a server-side SDK key in an edge application.

    You can find client-side IDs in **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Warning>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

  <CodeGroup>
    ```ts title="Akamai SDK" theme={null}
          import { init, LDOptions, BasicLogger } from '@launchdarkly/akamai-server-edgekv-sdk';

          const options: LDOptions = {
            logger: BasicLogger.get(),
            cacheTtlMs: 200,
          };

          const ldClient = init({
            sdkKey: 'example-client-side-id',
            namespace: 'your-edgekv-namespace',
            group: 'your-edgekv-group-id',
            options: options,
          });
    ```

    ```ts title="Akamai SDK, if using your own feature store" theme={null}
          // If you are using your own feature store,
          // make sure to import 'init' from the 'akamai-server-base-sdk'
          // rather than from 'akamai-server-edgekv-sdk'

          import { init, EdgeProvider, LDOptions, BasicLogger } from '@launchdarkly/akamai-server-base-sdk';

          // When using your own feature store, you must create a new class that
          // implements EdgeProvider. To learn more, read
          // https://launchdarkly.com/docs/sdk/edge/akamai#getting-started
          class FeatureStore implements EdgeProvider {
            async get(rootKey: string): Promise<string> {
              return flagData;
            }
          }

          const options: LDOptions = {
            logger: BasicLogger.get(),
            cacheTtlMs: 200,
          };

          const ldClient = init({
            sdkKey: 'example-client-side-id',
            featureStoreProvider: new FeatureStore(),
            options: options,
          });
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDOptions`](https://launchdarkly.github.io/js-core/packages/sdk/akamai-edgekv/docs/types/LDOptions.html). For additional discussion of the `cacheTtlMs` option, read [Understand resource limits and caching options](/sdk/edge/akamai#understand-resource-limits-and-caching-options).
</Accordion>

### Cloudflare

<Accordion title="Expand Cloudflare code sample">
  <Warning title="Cloudflare SDK credentials">
    The Cloudflare SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in edge code. Do not embed a server-side SDK key in an edge application.

    You can find client-side IDs in **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Warning>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

  Versions 1 and 2 of the Cloudflare SDK only support the logger configuration option. Versions 2.3.0 and later also support an events configuration option.

  <CodeGroup>
    ```typescript title="Cloudflare SDK v2.3.0+ (TypeScript)" theme={null}
          import { BasicLogger, init, LDOptions } from '@launchdarkly/cloudflare-server-sdk';

          const options: LDOptions = {
            logger: new BasicLogger({ destination: console.log }),
            sendEvents: true, // default is false
          };

          client = init('example-client-side-id', env.LD_KV, options);
    ```

    ```typescript title="Cloudflare SDK v2.2 and earlier (TypeScript)" theme={null}
          import { BasicLogger, init, LDOptions } from '@launchdarkly/cloudflare-server-sdk';

          const options: LDOptions = {
            logger: new BasicLogger({ destination: console.log }),
          };

          client = init('example-client-side-id', env.LD_KV, options);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read the [SDK's API docs](https://launchdarkly.github.io/js-core/packages/sdk/cloudflare/docs/types/LDOptions.html).
</Accordion>

### Fastly

<Accordion title="Expand Fastly code sample">
  <Warning title="Fastly SDK credentials">
    The Fastly SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in edge code. Do not embed a server-side SDK key in an edge application.

    You can find client-side IDs in **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Warning>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

  <CodeGroup>
    ```ts title="TypeScript" theme={null}
          import { KVStore } from 'fastly:kv-store';
          import { init, LDOptions } from '@launchdarkly/fastly-server-sdk';

          const KV_STORE_NAME = 'launchdarkly';
          const EVENTS_BACKEND_NAME = 'launchdarkly';
          const store = new KVStore(KV_STORE_NAME);

          async function handleRequest(event: FetchEvent) {
            const ldClient = init('example-client-side-id', store, {
              eventsBackendName: EVENTS_BACKEND_NAME,
            });

            await ldClient.waitForInitialization();

            ...
          }
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`FastlySDKOptions`](https://launchdarkly.github.io/js-core/packages/sdk/fastly/docs/types/FastlySDKOptions.html).
</Accordion>

### Vercel

<Accordion title="Expand Vercel code sample">
  <Warning title="Vercel SDK credentials">
    The Vercel SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in edge code. Do not embed a server-side SDK key in an edge application.

    You can find client-side IDs in **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
  </Warning>

  This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

  Version 1 of the Vercel SDK only supports the logger configuration option. Versions 1.2.0 and later also support an events configuration option.

  <CodeGroup>
    ```typescript title="Vercel SDK v1.2.0+" theme={null}
          import { createClient } from '@vercel/edge-config';
          import { BasicLogger, init, LDOptions } from '@launchdarkly/vercel-server-sdk';

          const edgeConfigClient = createClient(process.env.EDGE_CONFIG);

          const options: LDOptions = {
            logger: new BasicLogger({ destination: console.log }),
            sendEvents: true, // default is false
          };

          client = init('example-client-side-id', edgeConfigClient, options);
    ```

    ```typescript title="Vercel SDK v1.0" theme={null}
          import { createClient } from '@vercel/edge-config';
          import { BasicLogger, init, LDOptions } from '@launchdarkly/vercel-server-sdk';

          const edgeConfigClient = createClient(process.env.EDGE_CONFIG);

          const options: LDOptions = {
            logger: new BasicLogger({ destination: console.log }),
          };

          client = init('example-client-side-id', edgeConfigClient, options);
    ```
  </CodeGroup>

  To learn more about the specific configuration options available in this SDK, read [`LDOptions`](https://launchdarkly.github.io/js-core/packages/sdk/vercel/docs/types/LDOptions.html).
</Accordion>
