# Runtime Handler

The Runtime Handler is a necessary dependency for any Twilio Function to be able to execute. It bootstraps the environment for your Function, manages the initialization of the Twilio client, injects the [Runtime Client](/docs/serverless/functions-assets/client) into scope for your convenience, and other critical functions.

> \[!NOTE]
>
> This is different from [https://www.npmjs.com/package/@twilio/runtime-handler](https://www.npmjs.com/package/@twilio/runtime-handler) which is used for local development, but we will do our best to keep the version numbers up to date and in sync. This allows for a better local development experience, like using `npm install`.

## Versions

> \[!NOTE]
>
> We follow the principle of [Semantic Versioning](https://semver.org/) to the best of our ability. We will only introduce breaking changes in major releases, new functionality in minor releases, and backwards compatible bug fixes in patch releases.

| Release Version | Description                                                                                                                                                                                                                                     |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 2.0.1           | No changes for the end user. This is the new default version                                                                                                                                                                                    |
| 2.0.0           | Node.js 18 is the new default                                                                                                                                                                                                                   |
| 1.3.1           | Minor bump. No changes for the end user                                                                                                                                                                                                         |
| 1.3.0           | Local development changes for Node.js 16 support                                                                                                                                                                                                |
| 1.2.5           | Updated local development dependencies                                                                                                                                                                                                          |
| 1.2.4           | Local development downstream dependencies update to remove vulnerable dependencies                                                                                                                                                              |
| 1.2.3           | Local development changes for Node.js 14 support                                                                                                                                                                                                |
| 1.2.2           | Bug fixes for local development. Same functionality as `1.2.1`                                                                                                                                                                                  |
| 1.2.1           | Adds better auto complete in local development when using TypeScript. **Currently being rolled out as new default.**                                                                                                                            |
| 1.2.0           | Adds support for accessing and modifying incoming [headers and cookies](/docs/serverless/functions-assets/functions/headers-and-cookies) from the new `event.request` object                                                                    |
| 1.1.3           | Bug fixes and minor improvements                                                                                                                                                                                                                |
| 1.1.2           | Accessing `SERVICE_SID` or `ENVIRONMENT_SID` environment variables in [local development](/docs/labs/serverless-toolkit/general-usage#how-to-use-service_sid-and-environment_sid-in-local-development) will now cause a warning to be displayed |
| 1.1.1           | Bug fixes and minor improvements                                                                                                                                                                                                                |
| 1.1.0           | The Twilio library is now lazy-loaded to improve the cold start time of Functions                                                                                                                                                               |
| 1.0.2           | Provides fixes for bugs in the local development environment                                                                                                                                                                                    |
| 1.0.1           | The **previous default version**, initial release of the Runtime Handler                                                                                                                                                                        |

### Preview Versions

> \[!WARNING]
>
> The following versions are available as a preview of upcoming versions. **They are not meant for production and might contain breaking changes between releases.**
>
> Previews are not covered by Twilio support agreements, and will not be supported via chat or paid phone support until after production launch. Twilio's engineers may handle customer help requests for some previews to improve those products for general availability release. Because our engineering team handles these help requests, responses may take longer.

There are currently no preview versions available.

### Default Runtime Handler Version

For projects where you don't have a specific Runtime Handler version specified, for example, new projects that you created through the Console, you might receive new Runtime Handler versions as we roll them out gradually to the customer base.

Follow the instructions below to pin the relevant version that you want to use. For new projects created through the Twilio Console, you'll see the default version of the Runtime Handler appear in the [Dependencies](/docs/serverless/api/resource/build) section after you have deployed to your project for the first time.

## Managing Versions

It is important to set the correct version of the Runtime Handler, especially if you want to take advantage of the latest features. The process of setting the version varies depending on whether you're developing using the [Console](https://www.twilio.com/console/functions/overview) or programmatically, such as with the [Serverless Toolkit](/docs/labs/serverless-toolkit) or via the [Serverless API](/docs/serverless/api). All methods are described below.

> \[!WARNING]
>
> The version of Runtime Handler must be **exact**, such as `1.2.1`. Version ranges are not supported.
>
> For example, attempting to use `latest` or `^1.0.1` will fail when attempting to deploy

## Twilio Console

If you created your Function using the [Console](https://www.twilio.com/console/functions/overview), you can set the version of `@twilio/runtime-handler` via the Console UI. To begin, navigate to the Function Editor for the Service that you want to update. Then complete the following steps:

1. Under **Settings**, click on **Dependencies**. This will open a new tab in the editor, which contains a list of your Node version and all npm modules and their versions
2. Click the **Edit** button for `@twilio/runtime-handler`, enter your desired version, and click **Update**
3. When ready, click the **Deploy All** button to deploy your Service with the updated Runtime Handler in place

![Steps to set the Runtime Handler version to 1.1.0 in Twilio Functions dependencies.](https://docs-resources.prod.twilio.com/a6fb907d1ad1f5735b4b0455d05e32161ad2db8e67e472e8b45ff5db27d32e9b.png)

## Serverless Toolkit

If you created and maintain your Function using the [Serverless Toolkit](/docs/labs/serverless-toolkit), you can use your CLI to update the version of Runtime Handler.

**Note:** This process requires at least version `2.1.0` of `@twilio-labs/plugin-serverless` or `3.1.0` of `twilio-run`

1. Open your project directory in your terminal and run the following command with your intended version: `npm install @twilio/runtime-handler@<version> --save-exact`

* For example: `npm install @twilio/runtime-handler@1.2.1 --save-exact`

2. Once ready to deploy your changes, run `twilio serverless:deploy` to deploy your Service with the new Runtime Handler version in effect

## Serverless API

In order to specify your project's Runtime Handler version using the API, you can pass the version as part of your regular [Dependencies](/docs/serverless/api/resource/build) when creating a Build.

```json
{
  "name": "@twilio/runtime-handler",
  "version": "1.2.1"
}
```

This will avoid any unexpected changes to the version your deployments will be using.

To verify which version a specific Build is using, you can inspect the `dependencies` field of a particular Build [via the Serverless API](/docs/serverless/api/resource/build#fetch-a-build-resource).
