# CLI

> The ai command: models, routes, trying a task, keys, limits, usage and calls.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://ai.docs.sypnia.com/tools/cli/

For agents: npx @sypnia/ai <command> (command ai once installed). Sign-in shared with npx @sypnia/app login (device flow, ~/.config/sypnia); self-hosted: SYPNIA_AI_URL + SYPNIA_AI_TOKEN. Commands: link --project; models [--task]; tasks; routes pull|diff|apply|history|rollback --to; try <task> <text> [--case --file]; keys create <name> --scope call|read|admin [--credits-per-day] | list | revoke; provider-keys add openrouter|bedrock | list | remove (Cloud); origins add|list|remove; limits show|set; usage --by case|task|key|end-user|model --since [--csv]; calls [--case --status] | call <id>; cache purge --task; end-users delete <id>. Global --project, --json. Exit codes 0 ok, 1 error, 2 usage, 3 needs a person's approval.

```bash
npx @sypnia/ai <command>
```

Installed globally (`npm i -g @sypnia/ai`), the command is `ai`. It uses the sign-in that every Sypnia command line shares: `npx @sypnia/app login`. Against a self-hosted gateway, set `SYPNIA_AI_URL` and `SYPNIA_AI_TOKEN`.

| Command                                                                   | Does                                                                             |
| ------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `ai link --project <ref>`                                                 | link this folder to a project (writes `project` in `sypnia.toml`)                |
| `ai models [--task <task>]`                                               | the catalog, with prices                                                         |
| `ai tasks`                                                                | the project's tasks and the model of each                                        |
| `ai routes pull` / `diff` / `apply`                                       | read the project's routes into the `[ai]` table of `sypnia.toml`, compare, apply |
| `ai routes history` / `rollback --to <version>`                           | versions of the routes, and going back                                           |
| `ai try <task> "<text>" [--case <id>] [--file <path>]`                    | one call, with its cost and timing                                               |
| `ai keys create <name> --scope call\|read\|admin [--credits-per-day <n>]` | a key; printed once                                                              |
| `ai keys list` / `revoke <id>`                                            | keys and their last use                                                          |
| `ai provider-keys add openrouter\|bedrock` / `list` / `remove`            | your own provider keys **\[Cloud]**                                              |
| `ai origins add <url>` / `list` / `remove`                                | sites allowed to use browser tokens                                              |
| `ai limits show` / `set <scope> <kind> <value>`                           | limits                                                                           |
| `ai usage --by case\|task\|key\|end-user\|model --since 30d [--csv]`      | usage                                                                            |
| `ai calls [--case <id>] [--status error]` / `ai call <id>`                | recent calls and one call in detail                                              |
| `ai cache purge --task <task>`                                            | empty a route's cache                                                            |
| `ai end-users delete <id>`                                                | forget a person of your app                                                      |

Every command takes `--project` and `--json`. Exit codes: `0` done, `1` error, `2` wrong usage, `3` needs a person's approval.
