# functions

Call your other functions as typed methods — functions.mul({ a, b }) — or call HTTP functions with any client using functions.url and functions.headers.

Every function of your project is a method on `functions`:

```js
import { functions } from 'wisp';

const { product } = await functions.mul({ a: 6, b: 7 });
await functions.sendReport({ day: 'mon' }); // "send-report"
```

```python
from wisp import functions

product = functions.mul(a=6, b=7)["product"]
functions.send_report({"day": "mon"})  # "send-report"
```

## functions.&lt;name&gt;(input?, options?)

Runs the function with `input` as its input and resolves to its result — whether or not it's exposed over HTTP, whatever its method or visibility. GET functions get the input as query parameters.

- **Typed in the editor.** The console's editor types each method from the function's [input and output schemas](/functions#schemas): you get autocomplete for function names and their fields, and hover docs.
- **Names.** In JavaScript, dashed names are camelCase (`send-report` → `sendReport`); in Python, use underscores (`send_report`).
- **Errors.** When the function fails (status 400 or more) it throws a `WispError` with `status` and `body`.
- `options` takes `query`, `mode` and `timeoutMs`, as below.

`invoke`, `url` and `headers` are reserved: a function with one of those names is reached with `functions.invoke('url')`.

## functions.invoke(name, options?)

The same call, by name, without throwing — for when you want the status and headers.

| Option | Description |
| --- | --- |
| `body` | The input: `req.body` (sent as JSON). GET functions get it as query parameters. |
| `query` | Query parameters, as `req.query` |
| `mode` | `"test"` (draft) or `"live"`; defaults to the mode of the current request |
| `timeoutMs` (JS) / `timeout` (Python, seconds) | How long to wait, default 30 seconds |

Resolves to `{ status, ok, headers, body }` — `body` is the return value, parsed when JSON. It doesn't throw on errors; check `ok`. An unknown name returns `404`. `before` and `after` run as usual for HTTP functions.

## functions.url(target, query?)

The full URL of an HTTP function:

- `"orders"` — a function of this project. Add a subpath: `"orders/1042"`.
- `"other-project/orders"` — a function of another project in the same workspace.

`query` is added as query parameters. During a `?test` request the URL points at the draft.

## functions.headers()

Headers that identify your project as the caller. **Private** and **internal** functions only answer requests that carry them; for public ones they're optional. The called function sees `req.caller = { projectId, kind: "endpoint" }` and skips the API key check.

Each call is a request of its own: it's logged and uses Run credits. Guide: [Visibility and calls](/visibility-and-calling-functions).
