Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Function Request Flow


To understand how Twilio Functions works, first review the HTTP request flow and how Twilio executes your code. Twilio Functions handles most web-app infrastructure so that you can focus on application logic. This process starts at the front door—handling the incoming HTTP request—and continues through the pipeline to your Function code.

HTTP client sends request to Twilio Functions Gateway, which validates and invokes Twilio Function, returning a response.
  1. An HTTP client sends a request to your Function. For most Functions, the client is the Twilio Voice or Messaging API responding to an incoming phone call or text message.
  2. The Twilio Functions Gateway receives this request and attempts to validate it. If your Function has Signature Validation enabled, the Functions Gateway will attempt to validate the signature. If the request or the Twilio Signature are invalid, the request is rejected with an HTTP 400 response.
  3. After the Functions Gateway accepts the request, it normalizes the request into a payload for your Function. The normalized request is provided to your Function as two arguments: context and event. Once the payload has been constructed, it is used to invoke your Function.
  4. At invocation, your Function begins executing the handler code that you have provided. When your Function completes executing, it can emit a response using the callback method. The emitted response will be transmitted to the Function Gateway.
  5. After your Function returns a result, the Functions Gateway constructs an HTTP response and returns it to the client.

Supported requests

supported-requests page anchor

Twilio Functions only supports HTTP requests. Twilio Functions responds to three HTTP verbs: GET, POST, and OPTIONS. PUT and DELETE are not supported.

For POST requests, Twilio Functions natively supports the application/json and application/x-www-form-urlencoded content types. This means that JSON bodies and form and query parameters will be normalized into the event parameter.

GET requests that include a body

get-requests-that-include-a-body page anchor

If a GET request includes a body, Twilio Functions returns an HTTP 403 Forbidden response back to the client.


There are several important limitations to Twilio Functions that you should consider when designing your application:

  • Execution time: Twilio Functions execute for at most 10 seconds. Any Function that exceeds the 10-second limit will be terminated, and the client will receive an HTTP 504 Gateway Timeout response.
  • Path parameter support: Twilio Functions does not provide support for path parameters. You must provide query parameters or JSON in order to pass information into your application.
  • Maximum response size: Twilio Functions have a constrained response size of 4 MB.
  • Maximum request size: Twilio Functions accepts payloads up to 1 MB, including headers and cookies.

Now that you understand the request flow, learn about the execution process, the handler method, and how to build responses.