# Functions

A project is a set of functions. Each one can answer HTTP requests, run on a schedule and be a tool for AI agents — or any mix of the three.

Every piece of code in a project is a **function**: one source file with a `handler`. What it's for is a matter of settings, not of a different kind of thing:

| Option | What it does |
| --- | --- |
| **API** | A public URL — `https://<project>.fn.wispfn.com/<name>` with one method — that apps, scripts and webhooks call over HTTPS. It's also in the project's [OpenAPI document](#openapi). |
| **MCP** | Offers it as a tool to AI agents through the project's [MCP server](/mcp-server-for-your-project), described by its input and output schemas. |
| **Schedule** | Runs it on its own — every 15 minutes, every Monday at 9am. See [Schedules](/schedules). |
| **Library** | Lets your other functions call it from code, like a shared helper: only this project's (private) or any project's in the workspace (internal). See [Visibility and calls](/visibility-and-calling-functions). |

Tick any mix in the function's **Settings**; each option you tick shows its own settings below. A function without an API is background work or a helper: syncs, reports, cleanups, reminders — only what you ticked (and the console) can run it.

Two names are special: [`before` and `after`](/before-and-after) run around every HTTP function and are never exposed themselves.

## Write a handler

```js JavaScript
export async function handler(req) {
  const name = req.query.name ?? 'world';
  return { status: 200, body: { message: `Hello, ${name}!` } };
}
```

```python Python
def handler(req):
    name = req["query"].get("name", "world")
    return {"status": 200, "body": {"message": f"Hello, {name}!"}}
```

`async def handler` works in Python too. See [Request and response](/api/request-and-response) for every field. Functions without HTTP get their input as the JSON body (`req.body`); their method is always `POST`.

## In the console

The **Functions** list shows every function with icons for what it does:

| Icon | Meaning |
| --- | --- |
| `GET` `POST` … | Exposed over HTTP with this method |
| ƒ | Not exposed over HTTP |
| 🔒 | Private: not callable by anyone on the internet (private, internal, or HTTP off) |
| 🕒 | Has a schedule (highlighted when it's on) |
| 🔌 | An MCP tool (highlighted when the project's MCP server is on) |

`before` and `after` appear in the list too, with a shield icon.

## Names and subpaths

A function's name is one URL segment: lowercase letters, digits, `-` and `_`. For HTTP functions, anything after it arrives as `req.subpath`:

```text
GET /orders/1042/items   →  function "orders", req.subpath = "/1042/items"
```

## Methods

An HTTP function answers one method — `GET`, `POST`, `PUT`, `PATCH` or `DELETE`. To read and create orders, use two functions (for example `GET /orders` and `POST /create-order`). CORS and `OPTIONS` preflight requests are handled for you.

## Schemas

Each function can declare an **input schema** and an **output schema** (JSON Schema). The input schema describes query parameters (for `GET` and `DELETE`) or JSON body fields (everything else). The assistant writes them for you and keeps them in sync. They document your API and describe the function as an MCP tool.

## Settings

| Setting | What it does |
| --- | --- |
| Name and description | Renaming changes the URL. |
| API | Method, example request and [edge caching](/edge-caching) for `GET`. |
| MCP | The input and output schemas of the tool (they also type the function in the editor). |
| Schedule | When it runs. See [Schedules](/schedules). |
| Library | Private (this project) or internal (the workspace). Always on when the API is. |
| Limit | Per-function call limit, in the project settings. See [Rate limits](/rate-limits). |

## OpenAPI

Every project publishes an [OpenAPI 3.1](https://spec.openapis.org/oas/v3.1.0) document of its functions with an API, built from their schemas:

```text
https://<project>.fn.wispfn.com/openapi.json         the published version
https://<project>.fn.wispfn.com/openapi.json?test    the draft
```

Use it to generate clients, import the API into Postman or Insomnia, or put a gateway in front of it. When the project requires [API keys](/api-keys), the document declares them. Find the link under **Connect → API**.

## Limits

| Limit | Value |
| --- | --- |
| Run time per request | 15 seconds |
| Memory | 256 MB |
| Request and response size | 6 MB |
| Disk | Temporary `/tmp` only — use [storage](/storage) for anything that must persist |

## Edit code yourself

Open a function and edit it in the editor. Saving creates a new draft version, just like a change from the assistant. You can also edit locally and push with the [CLI](/cli).
