Rate this page:

Run Function

Run function widget


Run Function allows you to execute Twilio Functions (lightweight, serverless pieces of code that run in the Twilio cloud) within your Flow. Use this Widget to write business logic that works alongside Studio Widgets to fully realize your application.

When you invoke a Function, you have two possible options for using variables: (1) you can pass Flow variables as parameters into a Function (e.g., and (2) you may set Flow variables with data returned from the Function (TwiML or JSON can be returned).

Note: For unique use cases, the Run Function widget can return custom TwiML to enhance your Studio Flow.

Required Configuration

The only required configuration for a Function Widget is the URL of the Function you would like to call. You may select it from a dropdown or search for the Function by name.

Functions are organized by the service they were created in. For Functions created via the Classic Console UI, select the "Default" service. For Functions created via the Serverless API, or as part of a Runtime Service, select the service and environment where the Function was deployed.

Run Function can only invoke Public or Protected Functions. Learn more about Function Visibility.





Function URL

The URL of the Function you’d like to invoke. The Function must be either Public or Protected.

Hello SMS


Optional Configuration

There are several optional configurations for the Function Widget:




Function Parameters

Zero or more extra parameters that will be passed to the Function expressed as key/value pairs. String literals and variables are supported.


Using a Function:

The example below is of a Function that uses data sent from Twilio Studio's Run Function Widget and responds with JSON.


This Widget has two events that trigger transitions.




A successful return (HTTP 20X)


The Function does not successfully return (or has an error)


The HTTP response from the Function must return a 2xx status code within 10 seconds, and the response body must not exceed 64kB.

Response Recommendation Notes
Status Code 200 or 204 3xx redirection is supported. 4xx or 5xx status code will transition to failed in the widget.
Content Type application/json Content-Type header is not required if Status Code is 204 No Content. Other content types are supported, such as plain text or XML. But only application/json objects (e.g. {"foo":"bar"}) will be automatically parsed into Studio variables.
Body valid JSON Body content must match the Content-Type header.
Response Time 10 seconds or less Since Twilio Functions support up to a 10 second execution limit, Studio will timeout the request at 10 seconds and transition to failed in the widget.
Response Size Maximum 64kb Studio can only process responses up to 64kB.



If your function returns Twiml, the twiml will be returned to the calling client.


If your function returns valid JSON, you will be able to access it via widgets.MY_WIDGET_NAME.parsed.

For example, if you return: { "message": "Hi", "person": { "name": "Bob", "age": 40 } }, you can reference that data in subsequent widgets as:



For all return types, you will have access to the following variables:




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. Please select the reason(s) for your feedback or provide additional information about how we can improve:

        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