Functions
Turn your words into logic that runs in the cloud
Last updated
Turn your words into logic that runs in the cloud
Last updated
Functions let you make backends to power your projects. Here's why they're powerful:
Turn your words into logic. Describe the inputs, logic, and outputs. Create turns it into code that runs.
Separate concerns. You can split up defining your UI from defining the core business logic of your tool.
Reusable. Once perfected, you can use your Function across any page or component.
Composable. Your function can use any of our built in Integrations, Databases or even other Functions.
Secrets. Functions run in the cloud so you can securely store API keys, passwords, and other secrets with our new Secrets Manager. Create will know how to use them when generating your Function.
Use External APIs. Functions can connect with (almost) any external API. You can include your own API keys as Secrets - so you can make your own integrations. Integrate with Stripe, Hubspot, and 1000s more.
With Functions, you can build powerful and flexible logic for your projects.
You make a new Function from the dashboard or the project menu.
Describe the inputs (if any), what you want the Function to do, and the outputs (if any)
Create will generate a flow diagram for your Function's logic that you can inspect. You can also read the code with the "View Code" button. If something is not quite right, add details and re-generate.
Test your Function with sample inputs and verify that the outputs are what you expect.
Use your Function in any Page, Component, or other Functions.
You can test Functions with sample inputs from the Test tab.
After you define your inputs, you can enter them either as a Form or JSON.
In this example, there is 1 input called query
for a Function that performs search. Create guesses a placeholder based on your Function definition that you should update or can use.
Hit "Run function" with inputs entered to test the function.
You'll see a history of previous tests. Tests can either be "Pending", "Running", "Completed", or "Error".
In each test run, you'll see the inputs and outputs/errors.
Outputs will be shown as a JSON object. If the outputs do not match the shape that you expect, add more details on how you would like outputs to be formatted/structured, and re-generate the function.
If there's an Error, you should see a generated English description of what the error likely is; along with the "View Code" button, this description can help you re-generate your Function to fix the Error.
Functions have a max limit of 5 mins to complete their work before they time out. You can call functions within functions to chain them together if you need longer running executions.
If you need help getting your Function to work, join our Discord and post in the "help-me-build" channel.
You can use Functions in Pages, Components, and even other Functions.
Similar to Integrations, press "/" or open the "Add-ons" menu to include a Function in your prompt.
When you generate your prompt with your Function referenced, Create figure outs how to hook your Function up to the page, component, or function based on your description, the function inputs, and the function outputs.
If it's not working well, add more details to your prompt on exactly how you want it to interact.
If you need help getting your Function integrated into your page, component, or function, join our Discord and post in the "help-me-build" channel.
Your Function can take advantage of our built in Integrations and Databases.
Press "/" or open the "Add ons" menu to reference an integration or database. Add a description of how you'd like to to use it.
The most powerful feature of Functions is that they can use External APIs. This allows you to make your own "integrations" - make a Function that uses the API how you'd like, and then use that Function in other pages, components, and functions.
To use an External API:
If the API needs authentication via token, username, or password, be sure to store it as a well-named Secret. Note: for now, Functions cannot use External APIs that authenticate via OAuth as there's not a secure way to store the OAuth token (and it will expire)
Tell your Function to use the API you want. Create will figure out how to integrate your secret. If you need more specifics, copy and paste the docs of your API.
Test your Function. Note: for now, Create needs to perform tests against your live API so make sure API calls you tell Create to make are safe.
Here are some common APIs and where to find your API keys:
Stripe: How to get your API Key
Twilio: How to get your API Key
Sendgrid: How to get your API Key
MailGun: How to get your API Key
HubSpot: How to get your API key
Here is an in-depth YouTube video tutorial on how to connect to an external API, using the Exa AI Search API:
You can also use Zapier, Make, and other platforms that connect to APIs by using their "webhook" triggers. Here's a YouTube video with the steps:
If you include a Function in a pages, components, or another function, they use the version of your Function that existed when you first referenced it in their prompt. As you make updates to your Function, you need to hit the refresh button on the Function reference in the places it's used. This allows you to control when the integrations should use the latest version of your function.
When you want to go live with your app so that your users can use it, similar to pages, you need to Publish your Functions. This locks the current version of the Function as the "Published" version. Your app uses the Published version of the Function, and you can make future iterations on the Function with confidence it won't break the app. If you make upgrades that you want to roll out to the app, you can update the published version of the Function.
To publish, choose a route for the function. You can also turn Functions on or off.