# @degenai/cli

AI image generation, upscaling, and editing — paid per call in USDC on Base via [x402](https://x402.org). No accounts, no API keys, no signups. Just a Base wallet with USDC.

## Install

```bash
npm install -g @degenai/cli
```

Requires Node.js 18+.

## Quick start

```bash
# 1. Set a Base wallet (HOT wallet — fund with $5–10 only, never your main wallet)
export DEGENAI_PRIVATE_KEY=0x...                    # macOS / Linux
$env:DEGENAI_PRIVATE_KEY = "0x..."                  # Windows PowerShell

# 2. Verify setup, balances, and API reachability
degenai init

# 3. Generate — cheapest first
degenai generate -p "neon cyberpunk cat" --flow -m nano-banana -a 16:9 -o cat.png   # $0.005
degenai generate -p "neon cyberpunk cat" -o cat.png                                  # $0.015 (default)
```

That's it — payment, image, save. No further setup.

### Two cheap paths

- **`nano-banana` or `pro` via the Flow path — $0.005 per image (cheapest).** Add `--flow` plus `-m nano-banana` or `-m pro`, plus `-a 16:9 / 9:16 / 4:3 / 3:4`. Always 1K. The CLI validates these constraints **before** sending payment, so no USDC is spent on a misconfigured call.
- **`gpt-image-2` — $0.015 per image (default).** Plain `degenai generate -p "…"` with no extra flags hits `gpt-image-2`. Any aspect ratio, 1K.

## Windows PowerShell users

If `degenai --version` prints `UnauthorizedAccess` / `running scripts is disabled on this system`, your PowerShell is blocking unsigned `.ps1` shims that npm installs. Two options:

- **Use Git Bash / cmd / Windows Terminal with bash** — the CLI works there with no changes.
- **Or unblock PowerShell once (per-user, safe):**
  ```powershell
  Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
  ```

This is a Windows-wide policy, not a `@degenai/cli` issue — it affects all globally-installed npm CLIs the same way.

## Hot-wallet warning

`DEGENAI_PRIVATE_KEY` is read on every command. **Use a dedicated wallet** with only enough USDC for what you intend to spend (a few dollars). Never paste your main / hardware-wallet private key. If the env var leaks (shell history, CI logs, malicious package), the funds in that wallet are lost.

## Commands

### `degenai init`
Setup check: validates `DEGENAI_PRIVATE_KEY`, derives your address, queries USDC + ETH balances on Base, and confirms the API is reachable.

### `degenai pricing`
Lists current per-service pricing from the live API.

### `degenai generate`
```bash
degenai generate -p "<prompt>" [--flow] [-m <model>] [-a <ratio>] [-r <res>] [-i <input>] [-o <out>]
```
- `--flow` — **$0.005** path. Requires `-m nano-banana` or `-m pro`, and `-a 16:9 / 9:16 / 4:3 / 3:4`. Always 1K.
- `-m, --model` — default `gpt-image-2` ($0.015). Others: `nano-banana` ($0.05) · `seedream` ($0.10) · `pro` ($0.15) · `gpt-image` ($0.15)
- `-a, --aspect` — `Auto` (default), `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, …
- `-r, --resolution` — `1K` (default), `2K`, `4K` (4K only on `pro`; ignored on `--flow`)
- `-i, --image` — input image for img2img; repeat flag for multiple inputs

### `degenai upscale`
```bash
degenai upscale -i in.png -s 4 -o big.png        # 2x ($0.05) or 4x ($0.10)
```

### `degenai remove-bg`
```bash
degenai remove-bg -i in.png -o transparent.png   # $0.02
```

### `degenai magic-eraser`
```bash
degenai magic-eraser -i in.png -k mask.png -o out.png   # $0.02 (white in mask = erase)
```

## Environment variables

| Variable | Required | Default | Purpose |
|---|---|---|---|
| `DEGENAI_PRIVATE_KEY` | yes (except `pricing` / `init` info) | — | Base wallet that pays via x402 |
| `DEGENAI_API_URL` | no | `https://aibasegen.vercel.app` | Override API host (self-hosted / staging) |
| `BASE_RPC_URL` | no | `https://mainnet.base.org` | Custom Base RPC for `init` balance checks |

## How payment works

Each command opens an HTTPS request to the API, receives an [`HTTP 402 Payment Required`](https://x402.org) response with payment requirements, signs an EIP-3009 USDC `transferWithAuthorization` with your private key, retries the request with the signed `X-PAYMENT` header, and the server settles on Base before returning your result. You only pay on success — settlement runs before the expensive AI work, and the response is HTTP-streamed back. Powered by [`@x402/fetch`](https://www.npmjs.com/package/@x402/fetch).

## Web playground & alternatives

- Browser (no CLI, no private key paste): https://aibasegen.vercel.app
- MCP server (Claude / Cursor): coming soon

## License

MIT
