# AnyRouter Agent

> Run an AI coding agent backed by AnyRouter — one key, all models, no setup. npx @anyr/agent


# AnyRouter Agent

Run a fully capable AI coding agent — backed by AnyRouter — with a single command. No install required.

```bash
npx @anyr/agent
```

The agent connects through your AnyRouter key, so you get automatic failover, unified billing, and access to every model on the gateway.

## Quick start

```bash
# Start an interactive coding session
npx @anyr/agent

# Pick a specific model
npx @anyr/agent --model openai/gpt-4o

# Use the free-tier model (no credits consumed)
npx @anyr/agent --model anyrouter/free

# One-shot: print a reply and exit
npx @anyr/agent --print "Explain closures in three sentences"
```

## Authentication

The agent reads your key from the `ANYROUTER_API_KEY` environment variable.

```bash
export ANYROUTER_API_KEY=sk-ar-v1-...
npx @anyr/agent
```

Get a key at [anyrouter.dev/dashboard/keys](/dashboard/keys). The free model (`anyrouter/free`) works without spending credits — good for trying things out.

## Options

| Flag | Default | Description |
|---|---|---|
| `--model <id>` | `anyrouter/free` | Model to use for the session |
| `--print <prompt>` | — | One-shot mode: send a prompt, print the reply, and exit |
| `--web` | — | Open the AnyRouter dashboard in your browser |
| `--lang <locale>` | — | Override the display language (e.g. `en`, `ja`) |
| `--version` | — | Print the version |
| `--help` | — | Show usage |

## Choosing a model

Any model available on AnyRouter works. Some common choices:

```bash
npx @anyr/agent --model anyrouter/free          # free, no credits
npx @anyr/agent --model openai/gpt-4o-mini      # fast + affordable
npx @anyr/agent --model anthropic/claude-opus-4  # most capable
npx @anyr/agent --model anyrouter/coding         # routes to your BYOK coding model
```

Run `npx @anyr/agent --model anyrouter/free` to explore without spending credits first.

See [all available models](/models) for the full catalog.

## Print mode

`--print` sends one prompt, prints the reply, and exits — useful for scripting or quick one-liners.

```bash
# In a shell script
ANSWER=$(npx @anyr/agent --print "What is the capital of Japan?")
echo "$ANSWER"

# Pipe input
npx @anyr/agent --print "$(cat myfile.ts) — add JSDoc comments"
```

## BYOK models

If you have provider keys configured in your [BYOK settings](/dashboard/byok), you can access them via the `anyrouter/byok`, `anyrouter/coding`, or `anyrouter/agent` model IDs:

```bash
npx @anyr/agent --model anyrouter/byok    # uses your default BYOK key
npx @anyr/agent --model anyrouter/coding  # uses your BYOK coding model
npx @anyr/agent --model anyrouter/agent   # uses your BYOK agent model
```

These are dynamic presets — each resolves to whichever provider key you have configured for that slot.

## Related

- [CLI](/docs/cli.md) — `npx @anyr/cli` to launch Claude Code, Codex, and other coding tools through the gateway
- [SDK](/docs/sdk.md) — `@anyr/sdk` for building with AnyRouter in TypeScript
- [Models](/models) — full model catalog with pricing
