AnyRouter

Use anyr from scripts and AI agents

Drive the AnyRouter CLI from CI, shell scripts and coding agents with JSON output on every command, JSON errors, stable exit codes and a machine-readable command list.

Every anyr command can be run without a terminal. Add --json to get output a program can parse. Errors come back as JSON with a fixed exit code, so a script or a coding agent can branch on the result without reading prose.

anyr help agents        # this guide, in the terminal

Discover the commands

anyr --help             # the everyday commands
anyr help --all         # every command, grouped
anyr commands --json    # the full command tree as JSON

anyr commands --json lists each command with its subcommands, flags, aliases, its group, and whether it has JSON output:

{
  "schema": "anyr.commands/v1",
  "commands": [
    {
      "name": "chat",
      "summary": "Ask a model: prompt, stdin or a REPL; --json for scripts",
      "group": "chat",
      "aliases": [],
      "subcommands": [],
      "flags": ["base-url", "config", "key", "model", "no-stream", "profile", "system"],
      "json": true
    }
  ],
  "exit_codes": [{ "code": 0, "name": "ok", "meaning": "success" }]
}

New fields may be added; existing fields keep their meaning while schema stays anyr.commands/v1.

JSON output

SettingEffect
--jsonJSON on stdout for any command that has a JSON form
ANYR_OUTPUT=jsonThe same as --json on every command
--quiet or ANYR_QUIET=1No update notices and no background update check
NO_COLOR=1No colour. Colour is also off whenever stdout is not a terminal

Without a terminal, anyr shows no prompts, spinners or update notices. A command that would ask before acting, such as revoking a key, fails with a usage error until you pass --yes.

Errors and exit codes

With --json, an error prints as one JSON object on stderr, and stdout stays empty:

{"error":{"code":"auth","exit":4,"message":"HTTP 401: invalid key","hint":"sign in again: anyr login"}}
ExitcodeMeaning
0okSuccess
1errorThe request or command failed
2usageBad flag, argument or subcommand. Nothing was sent
3not_foundThe model, key, id or resource does not exist
4authNo key, a rejected key, or a key without the needed scope
5rate_limitedToo many requests. Retry later

Ask a model

anyr chat "Reply with ok" --json
{"id":"req_…","model":"z-ai/glm-4.7-flash","content":"ok","finish_reason":"stop","usage":{"prompt_tokens":12,"completion_tokens":1}}
  • --json waits for the whole answer and prints one object. id is the id anyr generation <id> takes, so you can look up cost and latency afterwards.
  • --no-stream waits for the whole answer and prints only the text.
  • Piped input becomes the prompt. A lone - places it after your own words:
echo "Summarise the AnyRouter docs in one line" | anyr chat --no-stream
git diff | anyr chat "Review this diff" - --json

Authenticate without a login

Set a key in the environment; no saved login is needed:

export ANYROUTER_API_KEY=sk-ar-v1-…        # inference key
export ANYROUTER_MANAGEMENT_KEY=ak_…       # presets, provider keys, device removal
anyr whoami --json

Commands with JSON output

anyr models --json --free
anyr usage --json
anyr logs --json --status error
anyr keys list --json
anyr embed "text" --json
anyr artifact publish page.html --json
anyr api credits            # any dashboard resource; prints JSON when piped

Launchers such as anyr claude start an interactive agent and have no JSON form, but their errors still follow the JSON and exit-code rules above. Use --dry-run to see the command and environment a launch would use.

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer