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

# Erlang SDK reference

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

> [!NOTE]
>
> **Recent major versions**
>
> **Version 3 of the Erlang SDK requires Gun 2.x**. To learn more about upgrading, read [Erlang (server-side) SDK 2.x to 3.0 migration guide](/docs/sdk/server-side/erlang/migration-2-to-3.md).

This topic documents how to get started with the Erlang SDK, and links to reference information on all of the supported features.

> [!NOTE]
>
> **SDK quick links**
>
> LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:
>
> <table>
>   <thead>
>     <tr>
>       <th>Resource</th>
>       <th>Location</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>SDK API documentation</td>
>       <td>[SDK API docs](https://hexdocs.pm/launchdarkly_server_sdk/)</td>
>     </tr>
>
>     <tr>
>       <td>Supported SDK Versions</td>
>       <td>[Erlang server SDK](/docs/sdk/concepts/supported-versions.md#erlang-server-sdk)</td>
>     </tr>
>
>     <tr>
>       <td>GitHub repository</td>
>       <td>[erlang-server-sdk](https://github.com/launchdarkly/erlang-server-sdk/)</td>
>     </tr>
>
>     <tr>
>       <td>Sample applications</td>
>       <td>[Erlang](https://github.com/launchdarkly/hello-erlang/) \
>       &#x20;[Elixir](https://github.com/launchdarkly/hello-elixir)\
>       &#x20;[Phoenix](https://github.com/launchdarkly/hello-phoenix)</td>
>     </tr>
>
>     <tr>
>       <td>Published module</td>
>       <td>[Hex](https://hex.pm/packages/launchdarkly_server_sdk)</td>
>     </tr>
>   </tbody>
> </table>

## Get started

Follow the steps below to get started using the LaunchDarkly SDK in your Erlang application.

First, download the dependency using [Rebar](https://www.rebar3.org/):

```erlang title="Erlang" lines wrap theme={null}
{deps, [
  {ldclient, "3.12.0", {pkg, launchdarkly_server_sdk}}
]}.
```

Then, add it to your `app.src` file:

```erlang title="Erlang" lines wrap theme={null}
{applications,
  [kernel,
  stdlib,
  ldclient
]},
```

If you use Elixir, you can download the dependency using [Mix](https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html):

```erlang title="Elixir" lines wrap theme={null}
defp deps do
  [
    {:ldclient, "~> 3.12.0", hex: :launchdarkly_server_sdk}
  ]
end
```

> [!NOTE]
>
> **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 on the **SDK keys** page under **Settings**. To learn more about key types, read [Keys](/docs/sdk/concepts/client-side-server-side.md#keys-and-credentials).

### Initialize the client

After you install the SDK dependency, create an instance of the client. Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.

> [!TIP]
>
> **Use a single instance**
>
> The Erlang SDK supports starting multiple instances, but most use cases only need a single instance. Consider using multiple instances only if you need to simultaneously access more than one environment. Do not start an instance every time you need to make a variation or other SDK call.

Here is an example:

```erlang title="Erlang" lines wrap theme={null}
% This starts an instance with the default options
ldclient:start_instance("YOUR_SDK_KEY")

% You can also start a named instance
ldclient:start_instance("YOUR_SDK_KEY", your_instance)
```

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

### Evaluate a context

Next, check which flag variation a specific context should receive:

```erlang title="Erlang SDK v2.0+" lines wrap theme={null}
Flag = ldclient:variation(<<"example-flag-key">>, #{key => <<"example-context-key">>}, false)
```

## Transport Layer Security (TLS)

The SDK includes configuration options that allow you to set custom TLS options. If you don't set these options, then the SDK will use the Erlang/OTP defaults. The default TLS connection settings in Erlang/OTP do not validate the identity or authenticity of certificates.

If your application has existing TLS options, then you can pass them to the SDK:

```erlang title="Erlang" lines wrap theme={null}
  ldclient:start_instance(SdkKey, #{
  http_options => #{
      tls_options => YourOptions
  }}),
```

The SDK also provides helper methods to create TLS options. We recommend ensuring that the SDK is using a Certificate Authorities (CA) store that is regularly updated for production environments.

Here is a list of helper methods:

* `ldclient_config:tls_basic_options()`: This helper provides a basic TLS configuration suitable for development. It tries to use a CA store in the default location for many linux distributions (`/etc/ssl/certs/ca-certificates.crt`). If it can't find the store, then it will use the store from the `certifi` package.
* `ldclient_config:tls_basic_linux_options()`: This helper provides a basic TLS configuration for linux. It uses the CA store located at `/etc/ssl/certs/ca-certificates.crt`.
* `ldclient_config:tls_ca_certfile_options(CaStorePath)`: This helper provides a basic TLS configuration with the CA store you specify.
* `ldclient_config:tls_basic_certifi_options()`: This helper provides a basic TLS configuration that uses the `certifi` store. Because this store is from a dependency of the package, it is not maintained or updated by OS releases.
* `ldclient_config:with_tls_revocation(TlsOptions)`: This helper extends a TLS configuration with certificate revocation. Revocation is not included in the basic configuration because the Erlang/OTP does not cache revocation results. Enabling this feature incurs additional requests per request the SDK makes.

## Shut down the client

Shut down the client when your application terminates. To learn more, read [Shutting down](/docs/sdk/features/shutdown.md#erlang).

## Supported features

This SDK supports the following features:

* [SDK configuration](/docs/sdk/features/config#erlang), including
  * [Application metadata configuration](/docs/sdk/features/app-config.md#erlang)
  * [Service endpoint configuration](/docs/sdk/features/service-endpoint-configuration.md#erlang)
* [Anonymous contexts and users](/docs/sdk/features/anonymous.md#erlang)
* [Context configuration](/docs/sdk/features/context-config.md#erlang)
* [Flag variation evaluation](/docs/sdk/features/evaluating.md#erlang)
* [Flag variation evaluation details](/docs/sdk/features/evaluation-reasons.md#erlang)
* [Getting all flags](/docs/sdk/features/all-flags.md#erlang)
* [Identifying and changing contexts](/docs/sdk/features/identify.md#erlang)
* [Offline mode](/docs/sdk/features/offline-mode.md#erlang)
* [Private attributes](/docs/sdk/features/private-attributes.md#erlang)
* [Reading flags from a file](/docs/sdk/features/flags-from-files.md#erlang)
* [Relay Proxy configuration](/docs/sdk/features/relay-proxy-configuration)
  * [Using proxy mode](/docs/sdk/features/relay-proxy-configuration/proxy-mode.md#erlang)
  * [Using daemon mode](/docs/sdk/features/relay-proxy-configuration/daemon-mode.md#erlang)
* [Tracking custom events](/docs/sdk/features/events.md#erlang)
* [Shutting down](/docs/sdk/features/shutdown.md#erlang)
* [Storing data](/docs/sdk/features/storing-data#erlang)
* [Test data sources](/docs/sdk/features/test-data-sources.md#erlang)
