
Statsig SDKs let you set the environment tier for your app during initialization. This lets you evaluate feature gates, dynamic configs, and experiments differently in non-production environments like development or staging. Configure the appropriate environment in your code and adjust feature rules in the Statsig Console.

***

## Configure environments in the SDK

There are two key ways to set up environments within your app:

1. **Environment-specific SDK keys**: These determine which rule sets are downloaded by the SDK based on the environment.
2. **Environment tier at SDK initialization**: This defines how rules are evaluated for the app.

### 1. Environment-specific SDK keys

Environment-specific SDK keys control which rules Statsig sends to the SDK. For example, an SDK initialized with a development environment key doesn't receive rules set for staging or production environments. For more information, go to [Per-Environment API Keys](#per-environment-api-keys) below.

### 2. Environment tier parameter

SDK keys can correspond to multiple environments. Explicitly set the environment tier during SDK initialization to ensure Statsig applies the correct rules.

All SDKs accept an `SDK Key` and an optional `StatsigOptions` dictionary. The `StatsigOptions` parameter includes the `environment` key, which has a `tier` field. This tier corresponds to one of your pre-configured environments (e.g., development, staging).

{% callout type="note" %}
If the environment tier is unset, all checks and event logs default to "production."
{% /callout %}

Here's an example of setting the environment tier in your code for the **development** environment:

#### Example (JS Client SDK):

```javascript
const client = new StatsigClient(<SDK_KEY>, user, { environment: { tier: 'development' } });
```

#### Example (Node Server SDK):

```javascript
await statsig.initialize(<SDK_KEY>, { environment: { tier: 'development' } });
```

Go to your language-specific SDK documentation for details.

***

## Using environments in feature gates

To configure environment-specific rules for a feature gate, follow these steps:

1. **Create a new feature gate**: In the Statsig Console, create a new Feature Gate. For example, name it "development mode" to target only your development environment.

   {% figure %}
   ![Feature Gate](/images/tutorials/environments/environments-feature-gate.png)
   {% /figure %}

2. **Specify environments**: When configuring the rule, check the **Specify Environments** box and select the environments you want to target. By default, rules are enabled for all environments unless specified otherwise.

   {% figure %}
   ![Specify Environment](/images/tutorials/environments/environments-specify.png)
   {% /figure %}

3. **Save your settings**: After saving, the environments where the rule is enabled appear below the rule name.

   {% figure %}
   ![Enabled Environments](/images/tutorials/environments/environments-enabled.png)
   {% /figure %}

You can also filter rules by environment using the filter in the upper-right corner of the Feature Gate UI.

To edit the target environments of a rule, click **...** next to the rule name and select **Edit Rule**.

{% figure %}
![Edit Rule](/images/tutorials/environments/environments-edit-rule.png)
{% /figure %}

***

## Configuring environments

By default, Statsig provides three environments: **Development**, **Staging**, and **Production**. You can add more environments or rename the default ones, but the **Production** environment can't be deleted or modified.

### Steps to add or edit environments

1. Go to **Project Settings** → [**Environments & Keys**](https://console.statsig.com/api_keys).

   {% figure %}
   ![Project Settings](/images/tutorials/environments/environments-project-settings.png)
   {% /figure %}

2. Click **Edit** to add new environments or reorder the existing ones using drag-and-drop.

   {% figure %}
   ![Edit Environments](/images/tutorials/environments/environments-edit-environments.png)
   {% /figure %}

{% callout type="note" %}
Reordering environments doesn't affect any rule logic, but it helps convey the rollout hierarchy (e.g., development → staging → production) to your teams.
{% /callout %}

***

## Per-environment API keys

Statsig lets you create per-environment API keys to enhance security and privacy. SDKs initialized with a specific environment key only access the rules relevant to that environment.

### Steps to generate environment-specific API keys

1. Go to **Project Settings** → [**Environments & Keys**](https://console.statsig.com/api_keys).

2. Click **Generate New Key** and specify the environment for which you want to generate the API key.

   {% figure %}
   ![Generate API Key](/images/tutorials/environments/environments-generate-key.png)
   {% /figure %}

{% callout type="note" %}
The default environments (Development, Staging, and Production) share the same server and client-side API keys. You can generate new keys for custom environments as needed.
{% /callout %}

***
