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

# CLI

> Install the official AnyAPI CLI, manage auth, discover APIs, and run SKUs from your terminal.

The official AnyAPI CLI is the npm package `anyapi-cli` with the `anyapi` binary.
Use it to install agent skills, register MCP, mint or store a key, discover APIs, and
run SKUs from a terminal.

## Install

Run the one-line setup:

```bash theme={"dark"}
npx -y anyapi-cli@latest init
```

`anyapi init` installs the AnyAPI agent skills into detected agents, offers MCP
registration, and mints a free trial key if no key is available.

For a global binary:

```bash theme={"dark"}
npm i -g anyapi-cli
anyapi init
```

Repo: [github.com/getanyapi-com/cli](https://github.com/getanyapi-com/cli)

## Commands

| Command                                                                                                     | What it does                                                                                                            |
| ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `anyapi signup [--label <label>] [--show-key]`                                                              | Mints a free trial key, saves it locally, and prints trial guidance. The secret is hidden unless you pass `--show-key`. |
| `anyapi connect`                                                                                            | Starts an OAuth flow to connect a wallet and upgrade past the trial (anyapi-cli >= 0.3.0).                              |
| `anyapi login --api-key aa_live_...`                                                                        | Stores an existing dashboard key locally.                                                                               |
| `anyapi search <query>`                                                                                     | Searches the public catalog and prints matching SKUs, names, and USD price terms.                                       |
| `anyapi list [--category <category>]`                                                                       | Lists catalog APIs, optionally filtered by category.                                                                    |
| `anyapi describe <sku>`                                                                                     | Prints the authenticated API definition, including schemas and USD pricing.                                             |
| `anyapi run <sku> --input '<json>' [-i file] [--fields a,b] [--max-items N] [--summary] [-o path] [--json]` | Runs an API with JSON input.                                                                                            |
| `anyapi balance`                                                                                            | Prints the remaining USD balance for the active key.                                                                    |
| `anyapi init [--all] [--yes]`                                                                               | Installs bundled agent skills, shows or applies MCP setup snippets, and mints a free trial key if none is stored.       |
| `anyapi setup skills`                                                                                       | Installs only the bundled skills.                                                                                       |

`anyapi search` uses the dedicated ranked catalog search. `anyapi list` only
browses the catalog and accepts an optional category. Both commands display the
customer-safe USD offer returned by discovery; they never expose an internal
accounting unit or upstream provider.

Static discovery pricing is nested. `pricing.from` is either a flat offer
(`model`, `unit: "request"`, `maxUsd`) or a linear offer (`model`, `unit`,
`baseUsd`, `perUnitUsd`, `maxUsd`). `pricing.failoverMaxUsd` is the greatest
fallback ceiling. The optional `failover` boolean reports whether AnyAPI currently
has an alternate route. Use the displayed unit when estimating a linear call, or
run `anyapi describe <sku>` to inspect the complete offer before execution.

## Gateway and CLI responsibilities

The gateway owns input validation, provider normalization, pricing, lane order,
routing, failover, health semantics, and billing. The CLI is a thin transport and
presentation adapter. It projects the discovery fields it displays, tolerates safe
new fields, and preserves input and output schemas as opaque JSON.

Treat `pricing.from`, `pricing.failoverMaxUsd`, `failover`, and lane order as
gateway-published facts. The CLI does not derive them from one another or repair
their relationships.

## Authentication

The CLI resolves auth in this order:

1. `--api-key` flag
2. `ANYAPI_API_KEY` environment variable
3. `~/.anyapi/config.json`
4. Interactive self-signup for commands that require auth

Application code should read `ANYAPI_API_KEY`. Do not make production app code depend
on `~/.anyapi/config.json`.

## Self-signup

Use `anyapi signup` to call the same self-signup endpoint documented in
[Let your agent onboard itself](/docs/agent-self-signup):

```bash theme={"dark"}
npx -y anyapi-cli@latest signup --label my-agent
```

This mints a free trial key, stores it in `~/.anyapi/config.json`, and prints trial
guidance. It does not print the secret key unless you pass `--show-key`. The trial key
carries a budget of about \$0.15, creates no account, and self-expires in 7 days.

## Run output

By default, `anyapi run` writes JSON to:

```text theme={"dark"}
.anyapi/<sku>-<timestamp>.json
```

The command prints the output path, `costUsd`, and item count. Use `--json` to print the
response JSON to stdout instead, or `-o path` to choose the output file.

The gateway normalizes the successful response. The CLI preserves the `output` object
as customer data instead of recursively deleting or rewriting its keys.

## Context-budget flags

Use these flags when a result would be too large for an agent context window:

| Flag            | Effect                                                 |
| --------------- | ------------------------------------------------------ |
| `--fields a,b`  | Keeps only selected keys on each result item.          |
| `--max-items N` | Caps returned rows.                                    |
| `--summary`     | Returns a structural outline instead of the bulk data. |

These flags trim only what is returned to you. They do not change the amount charged.
`costUsd` reflects the full result the API produced.

## 402 and upgrading past the trial

A free trial key is capped at about \$0.15 of requests. When the trial budget is spent, a
run returns `402 trial_cap_reached`. To keep going, connect a wallet (anyapi-cli >= 0.3.0):

```bash theme={"dark"}
anyapi connect
```

This starts an OAuth flow with a localhost callback and prints a single consent URL. Hand
that URL to a human: they open it, sign in at the
[dashboard](https://getanyapi.com/dashboard/authorize), set a spend limit, and approve. The
CLI then holds an OAuth access token and the agent keeps working on the same session.

If a human already has a funded account, they can create a full, non-expiring key at the
[dashboard](https://getanyapi.com/dashboard/keys) and store it with
`anyapi login --api-key aa_live_...` instead.
