Rate this page:

Function Request Flow

The best way to understand how Twilio Functions works is to start by understanding the HTTP request flow and how Twilio ultimately executes your code. Twilio Functions is designed to handle as much of the infrastructure work of building a web app as possible. For Twilio Functions, this work begins at the front door handling the HTTP request for your Function and continues through the pipeline up to your code.

Functions Request Flow

  1. Every Function invocation begins with an HTTP client issuing a request to your Function. For most Functions, the HTTP client is the Twilio Voice or Messaging API responding to an incoming phone call or text message.
  2. The Twilio Function Gateway receives this request and attempts to validate it. If your Function has Signature Validation enabled, the Function 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 Function Gateway has accepted the HTTP request, it will normalize 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 code you have provided. When your Function completes executing, it can emit a response using the callback method provided. The emitted response will be transmitted to the Function Gateway.
  5. Upon receiving the result from your Function, the Function Gateway will construct an HTTP response and return it to the HTTP client.

Supported requests

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

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

Request limitations

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 Time-out response.
  • Path parameter support: Twilio Functions does not provide support for path parameters. This means that you can’t use the URL to pass information into your application. It is recommended that you use either a GET or POST request.
  • Maximum response size: Twilio Functions have a constrained response size of 4MB.
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Community Forums or browsing the Twilio tag on Stack Overflow.


        Thank you for your feedback!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more