# Environment-based Evaluation

> For AI agents: a documentation index is available at [/llms.txt](/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

Statsig SDKs let you set the environment tier for your app during initialization. Setting the environment tier 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 the SDK downloads based on the environment.
2. **Environment tier at SDK initialization**: This defines how Statsig evaluates rules 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).

> **Note:**
>
> If the environment tier is unset, all checks and event logs default to "production."

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.

   ![Feature Gate](https://docs.statsig.com/images/tutorials/environments/environments-feature-gate.png)
2. **Specify environments**: When configuring the rule, check the **Specify Environments** box and select the environments you want to target. By default, Statsig enables rules for all environments unless you specify otherwise.

   ![Specify Environment](https://docs.statsig.com/images/tutorials/environments/environments-specify.png)
3. **Save your settings**: After saving, the environments where you enabled the rule appear below the rule name.

   ![Enabled Environments](https://docs.statsig.com/images/tutorials/environments/environments-enabled.png)

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**.

![Edit Rule](https://docs.statsig.com/images/tutorials/environments/environments-edit-rule.png)

---

## Configuring environments

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

### Steps to add or edit environments

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

   ![Project Settings](https://docs.statsig.com/images/tutorials/environments/environments-project-settings.png)
2. Click **Edit** to add new environments or reorder the existing ones using drag-and-drop.

   ![Edit Environments](https://docs.statsig.com/images/tutorials/environments/environments-edit-environments.png)

> **Note:**
>
> Reordering environments doesn't affect any rule logic, but it helps convey the rollout hierarchy (e.g., development → staging → production) to your teams.

---

## 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.

   ![Generate API Key](https://docs.statsig.com/images/tutorials/environments/environments-generate-key.png)

> **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.

---
