Scripting and CI
Drive the anlyon CLI from scripts and CI jobs with JSON output, exit codes, environment variables and idempotency keys.
A script that runs an action has to know what happened: did it succeed, is it waiting for a person, or might it have acted without saying so? Guessing from human-readable text is how a job retries a refund that already went through. The CLI answers in a form a script can branch on: one JSON document on stdout, a stable exit code, and an idempotency key that makes a re-run return the recorded result instead of acting twice.
The flags, JSON shapes and exit codes on this page are the machine contract. Human-readable output may change in any release. Build scripts on --json and exit codes.
Get JSON output
Add --json to any command. stdout then carries exactly one JSON document, so you can pipe it straight to jq or JSON.parse.
| Command returns | stdout with --json |
|---|---|
| A list | {"data": [...], "nextCursor": string | null, "total"?: number} |
| One object | {"data": {...}} |
actions invoke |
{"data": <invocation>, "idempotencyKey": "...", "nextStep"?: "..."} |
anlyon actions invoke refund_payment --data '{"charge":"ch_123","amount":1200}' --yes --json
Abridged:
{
"data": {
"id": "inv_...",
"actionName": "refund_payment",
"status": "pending_approval",
"responseStatus": null,
"error": null,
"approvalId": "apr_...",
"createdAt": "2026-10-27T10:02:11.000Z",
"completedAt": null
},
"idempotencyKey": "cli_...",
"nextStep": "Waiting for a human decision. Check with `anlyon invocations get <id>`, or re-run with --wait."
}
The objects under data are the API’s own objects, so their fields match the API reference. nextStep is present when the status is not succeeded.
Read stdout and stderr
-
Results go to stdout. Progress, hints, warnings and errors go to stderr. A script can read stdout without filtering anything out.
-
An error is one JSON object on stderr with
--json:{"error": {"code": "ENVIRONMENT_MISMATCH", "message": "...", "exitCode": 10, "hint": "Use a profile or API key bound to that environment."}}status(the HTTP status),requestIdandhintare present when they apply.codeis a stable string: one of the CLI’s own codes below, or the API’s error code, such asAUTHORIZATION_ERROR. -
Output is redacted. API keys, tokens and
Bearervalues are masked before anything is printed, including inside an error the server sent back. -
An empty list prints nothing on stdout without
--json, andNo results.on stderr. With--jsonit prints{"data": [], ...}.
The CLI’s own error codes:
| Code | Exit | Meaning |
|---|---|---|
USAGE |
2 | Bad flags, arguments or --input, or a write without --yes outside a terminal. Nothing was sent. |
NOT_LOGGED_IN |
3 | The profile has no stored credential. |
SESSION_EXPIRED |
3 | The browser login expired or was revoked. |
ENVIRONMENT_MISMATCH |
10 | --environment does not match the credential. |
BINDING_CHANGED |
10 | The profile’s credential now resolves elsewhere than at login. |
API_URL_MISMATCH |
10 | ANLYON_API_URL differs from the profile’s API. |
TIMEOUT |
9 | --timeout elapsed. |
ACTION_UNKNOWN |
13 | A write was cut off before its reply. It may have reached Anlyon. |
APPROVAL_NOT_PENDING |
6 | approvals approve or deny on an approval that is already decided or expired. Nothing was sent. |
CANCELLED |
130 | Ctrl-C. |
ABORTED |
1 | You answered something other than y to a confirmation. Nothing was sent. |
UNEXPECTED |
1 | An error with no more specific code. Set ANLYON_DEBUG=1 to print its stack trace. |
Read the exit code
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error (unexpected, or no more specific code) |
| 2 | Usage: bad flags, arguments or --input. Nothing was sent |
| 3 | Not logged in, or the credential expired, was revoked or was rejected (401) |
| 4 | Permission denied: missing scope or role (403) |
| 5 | Not found in this workspace or environment (404) |
| 6 | Rejected by the server as invalid or conflicting (400, 409, 422) |
| 7 | Rate limited or over quota (429) |
| 8 | Server error or unreachable (5xx, network) |
| 9 | --timeout elapsed. A write cut off before its reply exits 13 instead |
| 10 | Target mismatch: --environment, a changed binding, or an API origin override |
| 11 | Needs a server endpoint that is not available. Nothing was sent. No current command uses it |
| 12 | Action accepted, not finished: waiting for approval or still running |
| 13 | Outcome unknown: the action may have taken effect, or a write was cut off before its reply. Do not retry with a new key |
| 14 | Action did not succeed: failed, denied, or its approval expired |
| 15 | Waiting for a person’s sign-off: the change loosens a guardrail, so a CLI login or an API key cannot apply it. The link is printed |
| 130 | Cancelled (Ctrl-C). A write cut off before its reply exits 13 instead |
A code is never reused for a different meaning. anlyon doctor exits 1 when a check fails and 0 otherwise. anlyon packs exercise exits 0 when every step succeeded and 1 otherwise.
Codes 12 and 14 come from actions invoke. Code 13 comes from actions invoke, from approvals approve when the approved action then ran with an unknown outcome, and from any write cut off before its reply. Each needs a different decision:
- 12, still in progress. Nothing failed. The action waits for a person, or is still running. Check later with
anlyon invocations get <id>, or invoke with--wait <duration>to follow it. - 13, outcome unknown. The provider may or may not have acted. Do not run it again with a new idempotency key: that can do the work twice. Reconcile with the provider first. Re-running with the same
--idempotency-keyis safe: it returns the recorded result. See When the outcome is unknown. - 14, did not succeed. It failed, a reviewer or policy denied it, or its approval expired.
data.statussays which.
Page through a list
List commands return 20 items by default. --limit takes 1 to 100. Pass the previous page’s nextCursor to --cursor. nextCursor is null on the last page.
anlyon invocations list --status unknown --limit 100 --json > page1.json
anlyon invocations list --status unknown --limit 100 --json \
--cursor "$(jq -r .nextCursor page1.json)" > page2.json
A cursor is opaque and bound to the list that issued it. Passing it to another command exits 2. --limit and --cursor on a command that is not a list also exit 2.
Pass options as JSON
--input <file|-> reads a command’s options as one JSON object, from a file or from stdin with -. Keys are the command’s option names, plus limit and cursor for lists. Flags on the command line win. An unknown key exits 2, so a typo cannot widen or narrow what a command does. A repeatable flag takes a list of strings.
echo '{"status":"pending","origin":"human","limit":50}' | anlyon approvals list --input - --json
For actions invoke, --input is the action input itself, as an alternative to --data:
anlyon actions invoke send_email --input ./email.json --yes --json
Set the environment variables
| Variable | Purpose |
|---|---|
ANLYON_API_KEY |
API key for automation. Profiles are ignored while it is set. Combining it with --profile or ANLYON_PROFILE exits 2. |
ANLYON_API_URL |
API origin for ANLYON_API_KEY and new logins. Default https://api.anlyon.com. ANLYON_BASE_URL is accepted too. https, or http to localhost only. |
ANLYON_PROFILE |
Profile for this shell. |
ANLYON_CONFIG_DIR |
Config directory. Default $XDG_CONFIG_HOME/anlyon when XDG_CONFIG_HOME is set, ~/.config/anlyon otherwise, and %APPDATA%\anlyon on Windows. |
ANLYON_CREDENTIAL_STORE |
auto (default), keychain, or file (unencrypted, opt-in). |
ANLYON_NO_BROWSER |
1 prints login and consent URLs instead of opening a browser. |
ANLYON_DEBUG |
Any value prints the stack trace of an UNEXPECTED error on stderr. |
Run the CLI in GitHub Actions
This workflow invokes a refund with an API key kept as a repository secret, waits up to 15 minutes for an approval, and branches on the exit code.
name: Refund a charge
on:
workflow_dispatch:
inputs:
charge:
description: Charge id
required: true
amount:
description: Amount in cents
required: true
jobs:
refund:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install the Anlyon CLI
run: npm install -g @anlyonhq/cli@0.3.0
- name: Refund via Anlyon
env:
ANLYON_API_KEY: ${{ secrets.ANLYON_API_KEY }}
CHARGE: ${{ inputs.charge }}
AMOUNT: ${{ inputs.amount }}
run: |
set +e
anlyon actions invoke refund_payment \
--data "{\"charge\":\"$CHARGE\",\"amount\":$AMOUNT}" \
--idempotency-key "refund-$CHARGE-${{ github.run_id }}" \
--environment production \
--wait 15m --yes --no-input --json > result.json
code=$?
set -e
case "$code" in
0) echo "Refund succeeded." ;;
12) echo "::warning::Still waiting for approval $(jq -r .data.approvalId result.json). Re-run this job to read the outcome." ;;
13) echo "::error::Outcome unknown. Reconcile with Stripe before re-running. Keep the same idempotency key."; exit 1 ;;
14) echo "::error::Refund did not succeed: $(jq -r .data.status result.json)."; exit 1 ;;
*) exit "$code" ;;
esac
What each part does:
ANLYON_API_KEYcomes from a secret, never from the repository. Create it in the production environment with onlyactions:invokeandactions:read(--waitreads the invocation while it waits), and with Require an end user off. See API keys and scopes.@anlyonhq/cli@0.3.0pins the version, so a new release cannot change the job’s behaviour on its own.--idempotency-keyincludes the workflow run id. Re-running the job reuses the run id, so the re-run returns the recorded invocation as it is now instead of refunding twice. That is also how a job that exited 12 reads the outcome later.--environment productionasserts the key belongs to production. If it does not, the command exits 10 before anything is sent.--wait 15mfollows an approval to its outcome. If nobody decides in 15 minutes, the command exits 12. The default--timeoutbecomes the wait plus 1 minute.--yesconfirms the write. Without it, a write outside a terminal exits 2 and sends nothing.--no-inputmakes sure the CLI never waits on a prompt.set +estops the shell from failing the step before the exit code can be read.- The input arrives through
env, not pasted into the script, so a workflow input cannot inject shell commands.
Make writes safe to repeat
actions invoke, actions declare, approvals approve and approvals deny carry an idempotency key: yours from --idempotency-key, or one the CLI generates (cli_<uuid>) and prints. A key is 8 to 255 letters, digits, ., _, : or -.
anlyon actions invoke refund_payment --data '{"charge":"ch_123","amount":1200}' \
--idempotency-key refund-ch_123 --yes --json
- Derive the key from the operation, not the attempt.
refund-ch_123makes a re-run safe. A key built from a timestamp makes every run a new refund. - Same key, same request: Anlyon answers from the recorded invocation as it is now. It is not executed, admitted or charged again.
- Same key, different input, or a different credential: the API answers
409 idempotency_key_reuse, and the CLI exits 6. After you rotate a CI key, re-running an old job with its old key gets this answer. - A retry while the first request is still running can get
409 idempotency_request_in_progress(exit 6). Wait, then re-run with the same key. - The CLI’s own retries reuse the key. A request that times out or gets a 429, 500, 502, 503 or 504 answer is tried up to 3 times in all, with the same key.
- For an approval, a re-run after the decision was recorded exits 6, because the approval is no longer pending.
connections add, connections reconnect and packs install confirm but take no idempotency key. Run anlyon packs plan first: it shows what an install would create, skip or refuse. packs exercise gives every call the key exercise-<run>-<step>.
Stop a command, or time it out
--timeout <duration>gives up after500ms,30s,2mor1h. A bare number is seconds. The maximum is 24 hours. The default is 60 seconds, 10 minutes forauth login, and the wait plus 1 minute when a command has--wait.- Ctrl-C cancels the request in flight and exits 130. A second Ctrl-C exits at once.
- A write cut off before its reply exits 13, not 9 or 130. The request may have reached Anlyon. The error names the idempotency key: re-run with it to read the recorded result.
Rely on the machine contract
- Versioning. The CLI is versioned on its own, apart from the SDK and the API. While it is 0.x, a minor release may add commands, flags, JSON fields and exit codes. It may also remove or rename one, change the meaning of an exit code, or change the shape of an existing
--jsonfield, and each such change carries a changelog entry marked Breaking. From 1.0, those are major-version changes only. - Pin it. Install a fixed version in CI and upgrade on purpose.
- SDK. Each build bundles one
@anlyonhq/sdk, shown byanlyon --version. - Server. Every command that talks to Anlyon first calls
GET /api/v2/auth/identityandGET /api/v2/environmentto resolve its target. Browser login also uses OAuth discovery at/.well-known/oauth-protected-resource/mcp. - Config.
config.jsoncarries aversion. A CLI refuses a config version it does not know rather than rewriting it.

