function
what is function
dev.fun now supports vibe-coded backend logic, allowing your app to go beyond frontend interactions.
function is how you define this backend logic in your dev.fun app. It lets you write reusable functions that can be triggered by user interactions, other functions, or app state changes. Functions enable dynamic, interactive behavior—providing powerful backend capabilities for your apps, all written in natural language.
how to create a function
to add a function to your dev.fun app, simply describe to AI prompt
Example prompt:
“Create a function called rollDice that returns a random number between 1 and 6.”
This will:
Create a callable function named
rollDice
Define its logic based on your prompt
Allow you to trigger this function from buttons, other functions, or conditionals
when should I use function
use function when your app needs to run key logic in the background, instead of relying on the frontend. This helps improve security, fairness, and reusability across your app.
1. You want to protect key logic from user manipulation
Frontend logic can be tampered with—so for critical decisions like who wins a game, score calculation, or payment validation, it's safer to run that logic in a backend function.
"Create a function called
checkWinner
that compares player scores and decides the winner."
2. You want to reuse a central logic block
Functions are reusable. You can call them from multiple places (buttons, other functions, conditionals) and avoid duplicating logic in multiple parts of your app.
"A
calculateReward
function that’s used both after game win and after daily login."
3. You want to call an external API securely using an API key
You can securely store and use secrets (like API keys) inside a function, so they’re never exposed to the user’s browser.
“Call the OpenAI API using
SECRET_KEY
and return a text response.”
how to create a function to call API using API secret
function can securely make an API call with API secret. You can create your API secret under the "secret keys" in the "configuration" tab. and tell AI to use the secret to make API call.
Example prompt:
first, create MY_SECRET_KEY in the configuration tab with the API key.

then tell dev.fun AI:
“Create a function that call API https://dexscreener.com/solana/ using MY_SECRET_KEY. The expected response of the API is <JSON format API response> . Display the result on the website”
how to trigger a function
Functions can be triggered by certain action on your dev.fun app. You can link any function to a button, form, or interaction in your app.
Example prompt:
"when user click roll dice button, trigger rollDice function"
If you have a function checkWinner
, you can create another function that calls it:
“Create a function that runs
checkWinner
afterrollDice
finishes.”
This allows for chaining logic and building complex interactions step-by-step.
how to use function inputs and outputs
Functions can take inputs (e.g., a user’s name or a number) and return outputs that affect your app. You can define these inputs/outputs in the function editor or specify them in your prompt.
Example prompt:
“Create a function called
greetPlayer
that takes a name and returnsHello, {name}!
”
You can then:
Pass values into this function from inputs or other functions
Display its output in the UI or use it in other logic
how to view your functions
All your functions are visible under the “configuration” tab.

how to debug or explain a function
If you’re not sure what a function does or why it behaves a certain way, switch to “brainstorm” mode and ask the dev.fun AI to explain it.
Example:
“Explain what my
checkWinner
function does.”
The AI will describe:
What the function is doing
What inputs it uses
What it returns or affects in your app
Last updated