> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyway.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Anyway CLI

> Terminal interface for the Anyway merchant platform — manage products, payment links, orders, and more from your terminal or agent environment

<CardGroup cols={1}>
  <Card title="@anyway-sh/cli on npm" icon="npm" href="https://www.npmjs.com/package/@anyway-sh/cli">
    View package on npm
  </Card>
</CardGroup>

## Installation

```bash theme={null}
npm install -g @anyway-sh/cli
```

## Quick Start

```bash theme={null}
# Authenticate (opens browser)
anyway login

# Create a product with payment link
anyway products create --name "My Product" --price 29.99

# Get JSON output (for agent/automation use)
anyway products create --name "My Product" --price 29.99 --format json
```

## Authentication

The CLI uses three auth modes, depending on the command:

* **Merchant auth** (`anyway login`) — JWT-based; required by most commands (products, orders, wallets, dashboard, developer, traces, and the merchant-side agent-wallet operations like `create` / `list` / `reset`).
* **Agent key** (`ANYWAY_AGENT_WALLET_KEY` env var or a local record from `wallets agents import`) — P-256 keypair-based; used by the agent-runtime commands under `wallets agents` (`whoami` / `history` / `policies` / `pay` / `sign`), by `superapi call`, and by `import` itself. These do NOT need `anyway login`.
* **Local** — file-only operations on `~/.anyway/agents/*`, used by `default` and `forget`.

### Merchant login

```bash theme={null}
anyway login              # Open browser to authenticate
anyway logout             # Clear stored credentials
anyway whoami             # Show current session info
```

First-time login opens a browser window to complete authentication. Credentials are stored at `~/.anyway/credentials.json` and auto-refreshed.

For headless environments (SSH / CI / agents), `anyway login --non-interactive` runs a **non-blocking** device flow instead of opening a browser:

```bash theme={null}
# 1. Begin — prints a verification URL + status summary and exits immediately (does NOT block).
anyway login --non-interactive
# 2. Open the printed verification_uri in a browser and authorize.
# 3. Resume — waits ~60s for approval, then exits with status approved | pending | expired | denied.
anyway login --non-interactive --continue   # call again while "pending"
anyway login --non-interactive --restart     # discard a stuck/expired session and start over
```

`--continue` / `--restart` imply `--non-interactive`, and a non-TTY stdin (piped / CI / agent) selects it automatically — so the flag is optional in those environments. Output follows `--format` as with any command: add `--format json` for a single JSON line (the default is a readable summary). An `anyway login --token <b64>` paste path remains as a fallback.

### Agent runtime auth (for AI agents)

If you're running the CLI as an AI agent that already owns an [Agent Wallet](/features/agent-wallet), set the key bundle from the dashboard's reveal dialog as an env var — no `anyway login` needed:

```bash theme={null}
export ANYWAY_AGENT_WALLET_KEY="eyJwcml2YXRl..."
```

Or persist the same bundle locally and let the CLI use it as the default signing identity:

```bash theme={null}
anyway wallets agents import --token <bundle>
```

Then these commands work directly against the agent-runtime endpoints (`/v1/agent-wallet/*`):

```bash theme={null}
anyway wallets agents whoami                          # Confirm agent identity + wallet
anyway wallets agents policies                        # Read spending limits
anyway wallets agents history                         # Recent activity
anyway superapi call "<SuperAPI x402 URL>" -y          # Pay and call with the Agent Wallet Key
anyway wallets agents pay --to <0x...> --amount 1.50  # Sign a USDC payment authorization
anyway wallets agents sign --typed-data-file <path>   # Sign arbitrary EIP-712 typed data
```

Add `--format json` for machine-parseable output. See [`wallets agents`](#wallets-agents) below for the full surface (including merchant-only operations like `create`).

## Commands

### `products`

```bash theme={null}
anyway products list
anyway products list --status active --page 1 --size 20
anyway products get <productId>
anyway products create --name <name> --price <amount> [--currency usd] [--description <desc>]
anyway products create --name <name> --price <amount> --type recurring --interval month
anyway products update <productId> --name <name> [--description <desc>]
anyway products archive <productId>
anyway products publish <productId>
anyway products payment-links <productId>
```

Creating a product automatically creates a payment link. The payment link URL is returned in the output.

### `orders`

```bash theme={null}
anyway orders list
anyway orders list --status paid --page 1 --size 20
anyway orders list --product <productId> --from 2024-01-01 --to 2024-12-31
```

### `wallets`

```bash theme={null}
anyway wallets balance
anyway wallets transactions
anyway wallets transactions --limit 50
anyway wallets credit balance
anyway wallets credit history
```

### `wallets agents`

Manage [Agent Wallets](/features/agent-wallet) and operate as an agent runtime. Twelve subcommands across three independent auth paths — pick the column that matches what you have.

| Command                                                            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                          | Auth                                                                     |
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `create [--name <n>] [--non-interactive] [--continue] [--restart]` | Create a new agent wallet. Interactive opens the dashboard for Privy signing and saves the verified key locally. `--non-interactive` runs the same non-blocking begin / continue / restart device flow as login (see [Merchant login](#merchant-login)) — the session and its ephemeral decryption key persist under `~/.anyway/device/` so `--continue` can run in a fresh process. A non-TTY stdin selects the non-interactive flow automatically. | merchant                                                                 |
| `list [--local] [--offline] [--format=table\|json]`                | Without `--local`: merchant view of every agent wallet plus the org-level Anyway Credits pool. With `--local`: only the agent records you've imported locally; each row is refreshed by hitting the agent-runtime endpoint with that agent's key. Add `--offline` to skip the network and show file state only. Agent wallet balances do not include Anyway Credits.                                                                                 | merchant (default) / agent key (`--local`) / local (`--local --offline`) |
| `reset <agentId> [--non-interactive] [--continue] [--restart]`     | Rotate this agent's signing key in place (same `agentId`, refreshed key). `--non-interactive` (also implied by a non-TTY stdin) runs the same non-blocking begin / continue / restart device flow as `create`; on approval it verifies and replaces the local key for that agent id.                                                                                                                                                                 | merchant                                                                 |
| `import --token <bundle>` (alias: `adopt`)                         | Verify an Agent Wallet Key bundle and save/replace the local record in `~/.anyway/agents/`                                                                                                                                                                                                                                                                                                                                                           | agent key                                                                |
| `whoami [<agentId>]`                                               | Server's view of this agent (id, name, wallet id, wallet address, public key) plus the org credit pool when available                                                                                                                                                                                                                                                                                                                                | agent key                                                                |
| `credit-balance [<agentId>]`                                       | Read the org-level Anyway Credits pool available to this agent for SuperAPI/x402 payments. Credits are org-level USD credits, not wallet USDC, and are spent before wallet USDC.                                                                                                                                                                                                                                                                     | agent key                                                                |
| `history [<agentId>] [--limit N]`                                  | Activity log for the agent (default 50, max 200)                                                                                                                                                                                                                                                                                                                                                                                                     | agent key                                                                |
| `policies [<agentId>]`                                             | Spending policies attached to the agent's wallet                                                                                                                                                                                                                                                                                                                                                                                                     | agent key                                                                |
| `pay --to <0x> --amount <usdc>`                                    | Sign a USDC payment authorization for x402 `PAYMENT-SIGNATURE`                                                                                                                                                                                                                                                                                                                                                                                       | agent key                                                                |
| `sign --typed-data-file <path>`                                    | Sign arbitrary EIP-712 typed data                                                                                                                                                                                                                                                                                                                                                                                                                    | agent key                                                                |
| `default <agentId>` (alias: `use`)                                 | Set the default local agent record                                                                                                                                                                                                                                                                                                                                                                                                                   | local                                                                    |
| `forget <agentId> [--yes]`                                         | Delete the local agent record                                                                                                                                                                                                                                                                                                                                                                                                                        | local                                                                    |

**Auth modes:**

* **merchant** — needs `anyway login`. These commands manage the wallet itself (`create` / `list` (default) / `reset`) and require browser interaction for `create` / `reset` (they cannot be completed by an AI agent alone — share the printed URL with the wallet owner). `list --local` does not need merchant auth — see below.
* **agent key** — needs `ANYWAY_AGENT_WALLET_KEY` env var **or** a record imported via `import`. `import` verifies the bundle through `GET /v1/agent-wallet`, saves it locally, and replaces a stale local key after dashboard reset. Use this in agent runtimes (Claude / Codex / CI). Does NOT need `anyway login`.
* **local** — touches only `~/.anyway/agents/*`. No network, no auth.

### `superapi`

```bash theme={null}
anyway superapi call "https://marketplace-prod.anyway.sh/v1/api/x402/twit-sh/tweets/search?words=bitcoin&count=5"
anyway superapi call "<SuperAPI x402 URL>" --body '{"query":"..."}'
```

`superapi call` is the wrapped x402 purchase path for agent runtimes. It sends the initial request, decodes the `PAYMENT-REQUIRED` challenge, shows the quote, signs with the selected Agent Wallet after confirmation, retries with `PAYMENT-SIGNATURE`, and prints the API result. Use `--yes` or `-y` to skip the prompt in CI/agent runtimes. It uses agent-key auth and does not need `anyway login`. Agent Wallet is the default payment source; `--pay-with agent-wallet` is accepted for compatibility but is not required.

Anyway Credits are org-level USD credits, not wallet USDC. For SuperAPI/x402, Org Credits are spent first and wallet USDC is used only after Org Credits are insufficient. Before reporting "insufficient funds", check credits with the auth mode you actually have: `anyway wallets credit balance` for merchant login, or `anyway wallets agents credit-balance` for an agent runtime with `ANYWAY_AGENT_WALLET_KEY` / an imported key. `anyway login` does not authorize `wallets agents credit-balance`.

Each command's `--help` prints its full flag list, examples, and auth requirement — e.g. `anyway wallets agents pay --help` shows the lower-level `--format json` output used as inputs when manually assembling an x402 `PAYMENT-SIGNATURE` envelope. For the end-to-end CLI purchase path, see [SuperAPI → By Anyway CLI](/features/super-api#quick-start).

### `dashboard`

```bash theme={null}
anyway dashboard templates
anyway dashboard query <templateId>
anyway dashboard query <templateId> --days 30
```

### `traces`

```bash theme={null}
anyway traces status
anyway traces list
anyway traces list --limit 50
```

### `developer`

```bash theme={null}
anyway developer keys list
anyway developer keys list --type sdk_key
anyway developer keys create --name <name>
anyway developer keys delete <keyId>
```

### `chat`

```bash theme={null}
anyway chat                          # Interactive chat with AI agent
anyway chat "what's my revenue?"     # Single-shot query
anyway chat --session <sessionId>    # Continue an existing session
```

## Global Options

| Option     | Values                 | Default | Description   |
| ---------- | ---------------------- | ------- | ------------- |
| `--format` | `table`, `json`, `csv` | `table` | Output format |

## Scripting & Automation

All commands support `--format json` for machine-readable output and return non-zero exit codes on failure. This applies to both merchant-mode and agent-mode commands.

```bash theme={null}
# Create product and capture output
result=$(anyway products create --name "API Product" --price 49.99 --format json)
payment_link=$(echo $result | jq -r '.paymentLink.paymentLinkUrl')

# List orders as CSV
anyway orders list --format csv > orders.csv
```
