# Functions & secrets

> Server-side code for your project — write or AI-generate edge functions, deploy them, watch their logs, and store API keys as encrypted secrets.

Source: https://knowledge.estage.com/cloud/functions/
Part of the ESTAGE knowledge base (https://knowledge.estage.com). Full corpus: https://knowledge.estage.com/llms-full.txt

---
Some things can't (or shouldn't) happen in the visitor's browser: sending emails, talking to
third-party APIs with secret keys, processing data on a schedule. That's what **Functions**
are for — small pieces of server-side code that run in your Dedicated Cloud.

## The Functions tab

The left rail lists your functions with a status dot (**green** = live, gray = draft). Select
one — or click **New function** — to open the editor.

### Writing a function

- **Name** it (lowercase letters, digits, dashes — e.g. `send-welcome-email`).
- Functions are TypeScript and can span **multiple files** — tabs across the top, `index.ts`
  is the entry point, **Add File** for more.
- Don't write code? Use the **Ask AI to write a function** bar: describe the job (*"send a
  welcome email when a user signs up"*) and it generates the code.

### Deploying and testing

- **Deploy** (top-right) pushes the function live.
- The **Invoke** card shows the one-liner your site uses to call it.
- **Recent invocations** at the bottom shows the function's logs — every run with its
  timestamp and output — with a **Refresh** button. Your first stop when a function isn't
  doing what you expect.

:::tip
As with tables, you usually don't create functions by hand — just describe the
backend feature you want in the chat ([building with AI](/cloud/building-with-ai/))
and it deploys what the feature needs. The editor is there for inspecting, tweaking,
and building your own.
:::

## Secrets

Functions often need API keys — for an email service, a payment provider, an external API.
Never paste keys into code; store them in the **Secrets** tab:

- Add name/value pairs (names auto-uppercase, e.g. `RESEND_API_KEY`) and **Save secrets**.
- Values are **encrypted and never shown again** after saving — the list displays masked
  values only. To change one, save a new value under the same name; to remove it, delete it.

Inside a function, a secret is read by name — the Functions editor's Secrets card shows the
exact snippet and how many secrets you have defined.
