# API reference

> Run any Lefine action from your own code over HTTPS, with an API key.

Base URL: `https://dash.lefine.ai`. Send your key as `Authorization: Bearer lfn_...`. Create keys in **Settings → API keys**; a key is shown once.

## Run an action

Every action has a name, the same names the MCP tools use. `lefine_find` lists them with their input.

```bash
curl -X POST https://dash.lefine.ai/v1/ops/strings.apps.list \
  -H "Authorization: Bearer $LEFINE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": {}}'
```

A success is `{ "ok": true, "data": ... }`. An error is `{ "ok": false, "error": { "code": "...", "message": "..." } }`.

## Routes

| Method and path | What it does |
|---|---|
| `GET /v1/me` | who the key is: user, workspace, scopes, apps |
| `POST /v1/ops/{name}` | run one action; body `{ "input": ..., "approval"?: "..." }` |
| `GET /v1/approvals/{id}` | where an approval stands |
| `POST /v1/mcp` | the same actions as MCP tools |
| `GET /health` | `{ "ok": true }` |

## Actions that need a yes

Publishing actions do not run on the first call:

1. The answer is HTTP `428` with code `APPROVAL_REQUIRED` and `approval: { id, url, expiresAt, preview }`.
2. A person opens `url` and approves.
3. Send the same action and input again with `"approval": "<id>"`. It runs once, only if the change is still what the person saw.

## Error codes

| Code | HTTP | Meaning |
|---|---|---|
| `UNAUTHORIZED` | 401 | the key is missing, revoked or expired |
| `FORBIDDEN` | 403 | the key may not do this |
| `MODULE_OFF` | 403 | the module is off in the workspace |
| `NOT_FOUND` | 404 | |
| `BAD_INPUT` | 400 | |
| `CONFLICT` | 409 | someone changed it since you read it |
| `APPROVAL_REQUIRED` / `APPROVAL_PENDING` | 428 | waits for a person |
| `APPROVAL_REFUSED` | 409 | declined, expired, used, or stale |
| `PAYMENT_REQUIRED` | 402 | the workspace has no plan |
| `RATE_LIMITED` | 429 | a connected app asked Lefine to slow down |
| `UNAVAILABLE` | 503 | a connected app did not answer; try later |
| `INTERNAL` | 500 | |

Source: https://lefine.ai/en/docs/api/
