---
name: azrouter
description: |
  Chat with AI models (GPT, Claude, Gemini, Grok, Qwen, Kimi, GLM, Mistral),
  generate images and videos, turn text into speech, embed text and call any
  azrouter API endpoint with the `azrouter` CLI, billed to the user's azrouter
  balance. Use when: "generate an image", "draw", "make a picture of", "make a
  video", "read this aloud", "text to speech", "embed these", "ask
  GPT/Claude/Gemini/Grok …", "get a second opinion from another model",
  "summarize this PDF with a model", "describe this image", "which models are
  cheapest", "how much have I spent on azrouter", "what is my azrouter
  balance", "call the azrouter API". NOT for: editing images locally, or
  calling other providers' own APIs.
allowed-tools: Bash
---

# azrouter

Runs the `azrouter` CLI. It is also installed as `az` when no other `az` is on the machine, but always type
`azrouter`: on many machines `az` is the Azure CLI.

## Economy models first

Use `<id>:economy` wherever the model has it (nearly every model: text, image, video, speech, embeddings); without `-m`
the CLI picks it for you. Some keys are limited to economy models: any other id answers 403 and the message names the
`:economy` id to use. An economy text model takes text only: for `-f` images or files or `--tools`, name the model
without `:economy` (some models refuse those either way, and a key limited to economy models cannot).

## Step 0: bootstrap

Before any other command:

1. If `azrouter` is not on `PATH`, install it:
   - macOS, Linux, WSL: `curl -fsSL https://azrouter.dev/install.sh | sh` (installs `~/.local/bin/azrouter`; if the
     shell still cannot find it, run `~/.local/bin/azrouter`).
   - Windows PowerShell: `irm https://azrouter.dev/install.ps1 | iex` (installs
     `%LOCALAPPDATA%\Programs\azrouter\azrouter.exe`).
2. If a command says `not logged in` or `your API key was not accepted`, ask the user for an API key from
   https://azrouter.dev/dashboard/keys, then save it without echoing it back: `printf '%s\n' "$KEY" | azrouter login`.
   Or the user runs `azrouter login` and pastes it. `AZROUTER_API_KEY` in the environment works too.

## UX rules

1. Be concise: give the saved file's path, or the model's answer. No raw JSON in chat unless asked.
2. Reply in the user's language. Commands and flags stay English.
3. Don't narrate the plumbing ("calling the API", "polling").
4. Never print or repeat the user's API key.
5. Pick a sane default and run. Ask only when something essential is missing.
6. Every call is billed to the user's balance: run a request once, and never loop retries.

## Commands

| Task | Command |
|---|---|
| Chat | `azrouter chat "explain TCP slow start in 3 lines"` (default model `openai/gpt-6-luna:economy`) |
| Chat with a model | `azrouter chat "…" -m anthropic/claude-sonnet-5.5:economy` |
| System prompt | `azrouter chat "…" -s "You are a terse reviewer."` (or `-s @system.md`) |
| Prompt from a file | `azrouter chat @prompt.md` |
| Chat about piped text | `cat notes.md \| azrouter chat "summarize this"` |
| Attach files | `azrouter chat "what is in these?" -f photo.jpg -f report.pdf` (images, PDFs, audio, text, code) |
| JSON answer | `azrouter chat "list 3 colors" --response-format json` or `--schema @schema.json` |
| Tool calls | `azrouter chat "weather in Bangkok?" --tools @tools.json` → prints the model's tool calls as JSON |
| Other request fields | `azrouter chat "…" -p temperature=0.2 -p reasoning_effort=low` (or `--body @body.json`) |
| Image | `azrouter image "a red bicycle on a beach at golden hour"` → prints the saved file's path |
| Image to a file | `azrouter image "logo of a fox" -o fox.png` (never replaces a file; `--force` does) |
| Image from reference images | `azrouter image "the same cube in a forest" -m google/gemini-3.1-flash-image:economy -i ref.png` (repeat `-i`, up to 10; `-m x-ai/grok-imagine-image-2.0:economy`: one 1:1 image) |
| Video | `azrouter video "waves at sunset"` → submits, waits (up to 20 min), saves, prints the path |
| Video, Seedance (per video token) | `azrouter video "a fox runs through snow" -m bytedance/seedance-2.0-mini:economy --resolution 720p --ratio 16:9 --seconds 5` |
| Video from a first frame | `azrouter video "she turns and smiles" -m bytedance/seedance-2.0-mini:economy --image frame.png` (or an `https://` URL; `--no-audio` for no sound) |
| Video from an input video | `azrouter video "she dances" -m kwaivgi/kling-v2.6-motion-control --video https://example.com/dance.mp4 --image person.png` (CLI 1.1.14) |
| Save a video that was cut off | `azrouter video --resume` (the last one started, billed already; makes no new one) |
| Text to speech | `azrouter speak "Your parcel is out for delivery." -o parcel.mp3` (`-v VOICE` picks a voice) |
| Speech to text | `azrouter transcribe meeting.mp3` (says so when no such model is on sale) |
| Embeddings | `azrouter embed "The quick brown fox"` → one JSON array; `--lines` for one per line of input |
| Any endpoint | `azrouter api /v1/models`, `azrouter api POST /v1/embeddings -d @body.json` |
| Models + prices | `azrouter models` (`--type text\|image\|video\|audio\|embedding`, `--cheap`, `--json`) |
| Balance | `azrouter balance` |
| Spend per day and model | `azrouter usage` (`--days 30`, `-m MODEL`) |
| Keys | `azrouter keys` (keys are made and revoked at https://azrouter.dev/dashboard/keys) |
| Update | `azrouter update` (it also updates itself once a day) |

Every command takes `--json` for machine-readable output, and `--help` for all of its flags. Exit codes: 0 OK, 1 failed
(the message on stderr says why and what to do), 2 a usage error.

## Workflows

**Chat.** Run `azrouter chat "<prompt>"`; the answer streams to stdout. Pass long input on stdin or as `@file`, not in
the argument. Choose `-m` by the task: a frontier model (`anthropic/claude-opus-5.5:economy`, `openai/gpt-6.1-sol:economy`,
`google/gemini-4-argon:economy`) for hard reasoning, a cheap one (`openai/gpt-6-luna:economy`, `qwen/qwen3.8-flash:economy`,
`anthropic/claude-haiku-5.5:economy`) for bulk or simple work. At a terminal it shows the model's price first.

**Attachments.** `-f FILE` sends a file with the prompt: images as images, PDFs and other documents as files, audio as
audio, text and code as text. Use a model whose input takes that kind: `azrouter models --json` lists each model's
`input` (`text`, `image`, `file`, `audio`, `video`). A model whose lower price covers text only refuses attachments and
tools: the error says so; pick another model.

**Structured output.** `--response-format json` asks for a JSON object; `--schema @schema.json` for JSON that matches
a JSON Schema. With `--json`, `azrouter` prints `{"model", "content", "tool_calls", "finish_reason", "usage", "price"}`;
`content` is the model's text (the JSON answer, as a string).

**Tool calls.** `--tools @tools.json` takes an OpenAI-style `tools` array. The answer is not streamed: its text, then
`{"tool_calls": [...]}` with each call's `id`, `function.name` and `function.arguments` (a JSON string). To answer a
call, send the whole conversation with `--body @conversation.json` holding `messages` (the tool results as
`{"role": "tool", "tool_call_id": …, "content": …}`).

**Image.** Run `azrouter image "<prompt>"`. It saves the image in the current directory (or `-o FILE`) and prints the
path; show the user that path, and open or read it with your image tools when they want to see it. Without `-m` it
uses the lowest-priced image model on sale (with one `-i`, Grok Imagine Image 2.0; with more, Nano Banana 2). Nano Banana 2
(`google/gemini-3.1-flash-image`) takes up to 10 reference images and Grok Imagine Image 2.0 (`x-ai/grok-imagine-image-2.0`)
one of exactly 1:1, included in the per-image price (more than one needs CLI 1.1.14: `azrouter update`): `-i FILE` (or
`--image`; repeat it, in order), a PNG, JPEG or WebP file, sent as the API's `images` field (a `data:` URL), for example
`azrouter image "the same cube in a forest" -m google/gemini-3.1-flash-image:economy -i ref.png`. Recraft's tools work on one
`-i` image: `recraft/remove-background` removes its background, `recraft/crisp-upscale` upscales it to twice its width and
height; their prompt is required but not used. GPT Image 2 (`openai/gpt-image-2`) accepts `--size` and quality.
GPT Image 1.5 (`openai/gpt-image-1.5`) is retired by OpenAI on 2026-12-01: use `openai/gpt-image-2:economy` instead
(`--size 1024x1536` portrait, `1536x1024` landscape, `1024x1024` square). A 400 "The provider refused the image request"
is that one prompt refused, not a broken model: change the prompt and keep GPT Image 2. Other image models take no
reference image; check each model's page for its supported options and prompt limit.

**Video.** Run `azrouter video "<prompt>"`. It waits for the video and prints the saved file's path; tell the user it
can take a few minutes. Veo 3.1 Lite (`google/veo-3.1-lite`) makes one 8-second 720p clip and Gemini Omni Flash
(`google/gemini-omni-1.1-flash`, and Gemini Omni 1.2 Flash, `google/gemini-omni-1.2-flash`) one 4-second 720p clip, each with sound
from a text prompt, billed per second.
Gemini Omni 1.2 Flash also comes at three other sizes, a model each: `google/gemini-omni-1.2-flash-360p`, `-1080p` and `-4k`
(its 1080p and 4K are Google's 720p clip, upsampled by Google), each one 4-second clip with sound.
Wan 3.0 (`alibaba/wan-3.0`) makes one 4-second 720p clip with sound from a text prompt.
Other per-second models (Kling, Wan, HappyHorse, Grok Imagine Video, Gen-4 Turbo, PixVerse V6, Seedance 1.0 Pro, Hailuo 02) also make
one clip of one size and length; the model's page says which, and some have no sound. Kling's motion control models
(`kwaivgi/kling-v2.6-motion-control`, `kwaivgi/kling-v3.0-motion-control`) and Wan 2.2 Animate Move
(`alibaba/wan-2.2-animate-move`) move the person in an image as a video does: `-m` with `--video URL` (the `https://` URL of
an MP4 file of at most 32 MB, longer than 4 and at most 5 seconds) and `--image FILE|URL`; Wan 2.7 edits a video with
`--video URL` alone. `--video` needs CLI 1.1.14 (`azrouter update`).
Seedance 2.0 and 2.0 mini (`bytedance/seedance-2.0`, `bytedance/seedance-2.0-mini`) are billed per video
token and take flags: `--seconds` 4 to 15 (5 when left out), `--resolution` 480p or 720p (1080p on 2.0 only; 720p when
left out), `--ratio` 21:9, 16:9, 4:3, 1:1, 3:4, 9:16 or `adaptive` (16:9 when left out, the first frame's with an image),
`--image FILE|URL` for a first frame (PNG, JPEG or WebP up to 18 MB, or an `https://` URL) and `--no-audio`. Such a
video's tokens are width × height × (24 × seconds + 1) / 1024 at its resolution's price per 1M video tokens: a
5-second 720p 16:9 video is 108,900 tokens. `azrouter models --type video` shows each resolution's price and what a
5-second video costs; at a terminal the command shows the video's price before it starts. A video is billed once it
starts: if the command says it is billed and kept for a day (not ready, could not be checked or downloaded, stopped),
run the `azrouter video --resume` line it prints (it saves that same video), never a new `azrouter video` for the same prompt.

**Speech.** `azrouter speak "<text>"` saves an MP3 and prints its path; long text goes in as `@script.txt` or on stdin.
It is billed per character. `azrouter transcribe FILE` prints what is said in an audio file.

**Embeddings.** `azrouter embed "<text>"` prints the vector as one JSON array. `--lines` embeds each line of the input
(one array per line, in order); `--json` adds the model, dimensions and token count.

**Anything else.** `azrouter api [METHOD] PATH` calls any endpoint (`/v1/...` on https://api.azrouter.dev,
`/api/...` on https://azrouter.dev) with the user's key and prints the answer as it comes. `-d` takes a JSON body
(inline, `@file` or `@-` for stdin); `-F key=value` sends a form (`-F file=@audio.mp3`). Use it for a new endpoint or a
field the commands above have no flag for. The API is OpenAI-compatible (`/v1/chat/completions`, `/v1/responses`,
`/v1/embeddings`, `/v1/audio/speech`, `/v1/images/generations`, `/v1/videos`) and Anthropic-compatible
(`/v1/messages`); https://azrouter.dev/docs has every endpoint.

**Picking a model by price.** `azrouter models --json` gives every model on sale with its `type`, `input`,
`input_per_mtok` / `output_per_mtok` (USD per million tokens), `per_image`, `per_second`, `per_mchars`,
`video_per_mtok` (USD per million video tokens at each resolution), `price_covers` and `other_requests`. When
`price_covers` is set, that price covers only some requests: `text` (text only, no tools or coding agents), `image` (one
image a request), `video` (one video a request) or `video-token` (one video a request, billed per video token); the
model's other requests cost `other_requests`, or are refused when it is null. `azrouter models --cheap --type text` lists the
cheapest first. Always call a model by its `id`.

**Money.** Prices are in USD. If a command says `not enough balance`, tell the user to top up at
https://azrouter.dev/dashboard/credits. `azrouter balance` shows what is left; `azrouter usage` what was spent, per day
and model.

See `references/troubleshooting.md` for every error and what to do about it.
