# Serverless API

The Serverless API lets you deploy Twilio Functions and Assets programmatically.

## Getting started

To deploy Functions and Assets, use the [Serverless Toolkit](/docs/labs/serverless-toolkit), which gives you an installable development Environment from which to build and deploy everything you need.

To test out the API, see the [Quickstart guide](/docs/serverless/api/quickstart).

## API reference

The API includes the following resources:

* [Service](/docs/serverless/api/resource/service)
* [Function](/docs/serverless/api/resource/function)
* [Function Version](/docs/serverless/api/resource/function-version)
* [Function Version Content](/docs/serverless/api/resource/function-version/content)
* [Asset](/docs/serverless/api/resource/asset)
* [Asset Version](/docs/serverless/api/resource/asset-version)
* [Variable](/docs/serverless/api/resource/variable)
* [Build](/docs/serverless/api/resource/build)
* [Build Status](/docs/serverless/api/resource/build/build-status)
* [Environment](/docs/serverless/api/resource/environment)
* [Deployment](/docs/serverless/api/resource/deployment)
* [Logs](/docs/serverless/api/resource/logs)

The following animation shows the relationship and purpose for each resource:&#x20;

![Animation showing serverless API services as containers for functions and assets.](https://docs-resources.prod.twilio.com/c5bc8be9c26ae60858dd4aa79fa8ed5695fc8f6bd0c95bbe6b114f7e184c735d.gif)

## Understanding domains

The API gives you control over the domains that serve your Functions and Assets after deployment. The domain structure is as follows:

```javascript
https://[service unique name]-[random characters]-[optional domain suffix].twil.io/
```

For example, a [Service](/docs/serverless/api/resource/service) with the unique name `thanos` can create the following domains by specifying a domain suffix (or leaving it blank) when creating an [Environment](/docs/serverless/api/resource/environment):

```javascript
https://thanos-3432.twil.io/       // Environment domain suffix left blank
https://thanos-3432-dev.twil.io/   // Environment domain suffix = dev
https://thanos-3432-test.twil.io/  // Environment domain suffix = test
https://thanos-3432-stage.twil.io/ // Environment domain suffix = stage
```

## Retention policy

The following entities are retained for up to 7 days and then deleted:

* [Functions](/docs/serverless/api/resource/function) that have no [Function Versions](/docs/serverless/api/resource/function-version).
* [Assets](/docs/serverless/functions-assets/assets) that have no [Asset Versions](/docs/serverless/api/resource/asset-version).
* [Function versions](/docs/serverless/api/resource/function-version) or [Asset Versions](/docs/serverless/api/resource/asset-version) that aren't part of a [build](/docs/serverless/api/resource/build) or of an active [deployment](/docs/serverless/api/resource/deployment).

The following entities are retained for up to 30 days and then deleted:

* Logs, including those generated by the `console.log()`, `console.info()`, `console.warn()`, and `console.error()` methods

> \[!NOTE]
>
> This policy doesn't affect active Deployments. It only applies to users working with the API, Serverless Toolkit, or the UI editor. It does not apply to Functions (Classic) and Assets (Classic).

Data generated by the underlying Twilio products that you invoke using Functions, such as SMS or Voice calls, is retained or deleted according to each product's data-retention policy. For details, refer to the individual product documentation, such as [the SMS developer quickstart](/docs/messaging/quickstart) and [call resource retention for Voice](/docs/voice/api/call-resource#call-resource-retention).

## Limitations and limits

### Limitations

* Functions and Assets created by the API are not reflected in the Classic UI for those products. You cannot use the API to read Functions or Assets created with the Classic UI. The two systems are separate.
* There is no `GET` operation for Asset Versions. You cannot retrieve the asset file content itself through the API.
* `GET` requests to functions that include a body are rejected with a `403` status code.

### Limits

* An account can have up to 50 [Services](/docs/serverless/api/resource/service).
* A Service can have up to 25 [Environments](/docs/serverless/api/resource/environment).
* A [Build](/docs/serverless/api/resource/build) can contain up to 100 [Function Versions](/docs/serverless/api/resource/function-version).
* A Build can contain up to 1,000 public or protected [Asset Versions](/docs/serverless/api/resource/asset-version).
* A Build can contain up to 50 private Asset Versions.
* A Build can have up to 512 MB of [dependencies](/docs/serverless/functions-assets/functions/dependencies). If you hit this limit, remove non-essential libraries if using the Console UI, or mark development-only dependencies as `devDependencies` when using the [Serverless Toolkit](/docs/labs/serverless-toolkit).
* An account can start up to 100 Builds per hour.
* Builds without an active deployment are deleted after 7 days.
* Function Versions that are not part of any Build and are older than 7 days are deleted.
* Asset Versions that are not part of any Build and are older than 7 days are deleted.
* Functions that do not have any Function Versions and are older than 7 days are deleted.
* Assets that do not have any Asset Versions and are older than 7 days are deleted.
* Function execution time is limited to 10 seconds.
* An account can execute up to 30 Functions concurrently. If you regularly reach this concurrency limit, contact [Twilio Support](https://help.twilio.com/) to request an increase.

Maximum file size per asset when using the API:

| Asset type | Maximum size |
| ---------- | ------------ |
| Public     | 25MB         |
| Protected  | 25MB         |
| Private    | 10MB         |
