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

# Migrate to environments

> Migrate a project from the fixed development, staging, and production environments to the environments system, which starts with main and lets you create additional…

Migrate a project from the fixed `development`, `staging`, and `production` environments to the [environments system](/docs/documentation/deploy/environments/overview), which starts with `main` and lets you create additional environments. Existing projects keep their original behavior until you opt in.

After migration, the legacy aliases stop working. Update every integration that addresses those aliases as part of the migration.

**Warning:** 
  Migrating without updating your integrations will break your live agent for users. Update every integration that uses the legacy aliases before, or immediately after, you migrate.

<a id="update-the-chat-widget" />

## 1. Update the chat widget

If you've embedded the chat widget on your website, replace your snippet with the new default below (don't forget to fill in your project's ID). The new snippet doesn't include `versionID`, which means the widget routes each new session according to the [traffic split](/docs/documentation/deploy/environments/traffic-split) configured in **Settings** → **Environments**. For most projects, this is exactly what you want: it automatically respects A/B tests and gradual rollouts.

```javascript
<script type="text/javascript">
  (function(d, t) {
      var v = d.createElement(t), s = d.getElementsByTagName(t)[0];
      v.onload = function() {
        window.voiceflow.chat.load({
          verify: { projectID: 'YOUR_PROJECT_ID' },
          url: 'https://general-runtime.voiceflow.com',
          voice: {
            url: "https://runtime-api.voiceflow.com"
          }
        });
      }
      v.src = "https://cdn.voiceflow.com/widget-next/bundle.mjs"; v.type = "text/javascript"; s.parentNode.insertBefore(v, s);
  })(document, 'script');
</script>
```

You can also find your project's code snippet in the **Widget** tab.

If you'd rather pin the widget to a specific environment (for example, to load a non-production environment on a staging site), set `versionID` to that environment's alias. See our [chat widget API documentation](/docs/documentation/deploy/widget/web-chat-api#choosing-which-environment-the-widget-loads) for more information.

<a id="update-your-agent-runtime-calls" />

## 1. Update your Agent runtime calls

If you're calling the [Agent runtime](/docs/api-reference/conversations-api/overview) directly, update any request that passes `environment: 'production'` by choose one of these options:

- Updating it to use `environment: 'main'` instead.
- Using the [traffic split](https://docs.voiceflow.com/documentation/deploy/environments/traffic-split) feature by migrating to the new [start session](/docs/api-reference/v4interact/start-session-with-traffic-split) and [interact](/docs/api-reference/v4interact/interact-stream) endpoints. This is a more intensive process than switching the environment to `main`, but will give you the ability to A/B test changes prior to release.

For requests that pass `'staging'` or `'development'`, choose whichever option fits best:

- Point them at `'main'` to keep using the same default.
- Point them at a new environment you create for staging or development work.

<a id="migrate-your-project" />

## 1. Migrate your project

Once your integrations are ready, open **Settings** → **General** in your project and scroll to the **Danger zone** section. Click **Migrate** next to **Migrate to environments** to switch your project over.

Migrate the project after updating integrations to use the new environments.

  ![Danger zone settings with Migrate to environments](/docs/images/Migration.png)

## After you migrate

Your agent keeps serving users from `main` by default. Now you can:

- [Iterate without disturbing live traffic](/docs/documentation/deploy/environments/overview) by cloning `main` into a new environment and editing freely.
- [Split traffic](/docs/documentation/deploy/environments/traffic-split) across environments to A/B test a change against `main` on real conversations.
- [Compare versions side by side](/docs/documentation/deploy/environments/version-history) and revert, clone, or [merge](/docs/documentation/deploy/environments/merging) from any point in history.
