# Runtime

Run functions, read logs and metrics, and list schedules with the REST API.

## Invoke

```http
POST /api/projects/:id/functions/:function/invoke
```

Runs a function — private ones and those without HTTP included. `:function` is the name or the id. `before` and `after` can't be invoked on their own.

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `mode` | string | `test` | `test` (draft) or `live` |
| `method` | string? | the function's | Override the method |
| `subpath` | string | `""` | Path after the function name |
| `query` | object | `{}` | Query parameters |
| `headers` | object | `{}` | Headers |
| `body` | string? | `null` | Raw body (JSON text for JSON APIs) |

Returns the status, headers, body, duration and logs. Uses Run credits. Scope: `functions:invoke`.

```bash
curl -X POST https://wispfn.com/api/projects/$PROJECT/functions/orders/invoke \
  -H "Authorization: Bearer $WISP_API_KEY" -H "content-type: application/json" \
  -d '{"query": {"status": "open"}}'
```

## Logs

```http
GET /api/projects/:id/logs?limit=50&endpoint=orders&mode=live&status=5xx&q=timeout
```

| Query | Description |
| --- | --- |
| `limit` | 1–200, default 50 |
| `before` | Cursor from the previous page |
| `endpoint` | Function name or id |
| `mode` | `test` or `live` |
| `status` | `2xx`, `4xx`, `5xx` or `errors` |
| `q` | Text search |

## Metrics

```http
GET /api/projects/:id/metrics
```

Requests, status classes and durations per function, by hour or day, for up to 90 days.

## Schedules

```http
GET  /api/projects/:id/schedules
POST /api/schedules/translate     { "text": "every weekday at 9am", "timezone": "Europe/Berlin" }
```

`translate` turns plain words into a cron expression.

## Live stream

```http
GET /api/projects/:id/live
```

Recent requests for [live debugging](/logs-and-live-debugging#live-debugging).

## Purge the edge cache

```http
POST /api/projects/:id/cache/purge     { "endpointId": "e..." }
```

Leave out `endpointId` to purge every cached endpoint.
