# Unspar CLI

The unspar CLI is a command for your terminal. With it you write and publish Unspar articles without opening the web app, and so can a script or an AI coding agent.

Web version: https://www.unspar.com/docs/cli/

Unspar researches a topic, writes an article in your voice, and publishes it to your site. Most people do this in the [web app](https://app.unspar.com/dashboard). The CLI does the same thing from a terminal. You type `unspar` and a command, like `unspar articles create`.

The CLI is for people who would rather type than click. It's also for programs that can't click at all. A GitHub Actions job can write an article with it, and so can an AI coding agent like Claude Code or Codex.

The CLI works for the same team as the web app. It sees the same projects and spends the same credits. Credits are how you pay in Unspar, and an ordinary article costs 1 credit whether you start it in the terminal or in the app. The CLI is included in every plan, including the free one. See [Credits and prices](https://www.unspar.com/docs/guides/credits-and-prices/) for the other prices.

## Install it on Linux or macOS

The installer picks the right program for your system and processor. Before it installs anything, it checks the download against a published checksum. It needs `curl` or `wget` for this, plus `sha256sum` or `shasum`.

1. Open a terminal and run the installer.

```sh
   curl -fsSL https://app.unspar.com/install.sh | sh
```

The program goes to `/usr/local/bin` if your user may write there. Otherwise it goes to `~/.local/bin` in your home folder.

2. If the installer prints `Add ... to your PATH`, add this line to `~/.zshrc` on a Mac or to `~/.bashrc` on Linux. Then open a new terminal.

```sh
   export PATH="$HOME/.local/bin:$PATH"
```

3. Check that it works.

```sh
   unspar version
```

The terminal prints the version of the CLI.

The CLI runs on Intel and AMD processors and on ARM, Apple silicon included. To install a certain version or into another folder, pass `--version` and `--dir` to the installer.

```sh
curl -fsSL https://app.unspar.com/install.sh | sh -s -- --version 0.3.1 --dir "$HOME/bin"
```

## Install it on Windows

On Windows, the installer runs in PowerShell. There is one build, for 64-bit Windows.

1. Open PowerShell and run the installer.

```powershell
   irm https://app.unspar.com/install.ps1 | iex
```

It installs `unspar.exe` into `%LOCALAPPDATA%\Programs\unspar` and adds that folder to your user PATH.

2. Open a new PowerShell window. Windows that were already open don't see the new PATH.
3. Check that it works with `unspar version`.

The one-line command can't take options. To pick a version or a folder, download the script first and run it with `-Version` and `-InstallDir`.

```powershell
irm https://app.unspar.com/install.ps1 -OutFile install.ps1
.\install.ps1 -Version 0.3.1 -InstallDir C:\tools\bin
```

## Keep it up to date

The CLI doesn't update itself. This command downloads the newest version, checks it, and replaces the program.

```sh
unspar update
```

`unspar update --check` only tells you whether a newer version exists. If you installed the CLI into a folder that belongs to root, run `sudo unspar update`. If an AI tool runs the CLI as its [local MCP server](https://www.unspar.com/docs/cli/local-mcp/), restart the tool after an update.

## Log in

The CLI needs a team API key to work for your team. An API key is a long secret that the CLI sends with each request. `unspar login` gets one through your browser and stores it on this computer.

Only the team owner and people with the **Administrator** role can approve a login, because it creates a key for the whole team. See [Teams](https://www.unspar.com/docs/guides/teams/).

1. Run the login command.

```sh
   unspar login
```

The terminal shows an address and a code, then opens the address in your browser.

```text
   Authorize at https://app.unspar.com/cli/authorize
   Enter code: WDJB-MJHT
```

2. Sign in to Unspar if the browser asks you to. The page **Approve sign-in** opens and shows a code under "Check this code in your terminal".
3. Check that this code matches the code in your terminal.
4. Choose **Approve**.

The browser then says "You can close this window and return to your terminal." The terminal confirms the login and names your team.

![Approve sign-in page with the code RPK2-8WGK, the access summary and the Approve button](https://www.unspar.com/images/docs/cli-authorize.webp)

Compare the code with the one in your terminal, then choose Approve.

If the browser didn't open, copy the address into a browser yourself. Type the code into **User code** and choose **Continue**. The code is valid for 10 minutes. After that, run `unspar login` again.

### What does Approve allow?

One click on **Approve** gives the key full access to all projects of your team for 90 days. Full access includes publishing to your outlets. An outlet is a site you connected to Unspar, like your WordPress blog. To choose less, open **Advanced settings** before you approve. These are the choices you have there:

| Setting        | Choices                                                         | Without a change |
| -------------- | --------------------------------------------------------------- | ---------------- |
| **Team**       | Each of your teams where you may create keys                    | The team shown   |
| **Access**     | **Full access**, **Read only** or **Custom**                    | **Full access**  |
| **Projects**   | **All projects, current and future** or **Only these projects** | All projects     |
| **Expiration** | **90 days** or **30 days**                                      | 90 days          |

**Read only** sees everything you can see and changes nothing. **Custom** lets you pick groups of permissions one by one. [API keys and connections](https://www.unspar.com/docs/agents/access/) explains the groups.

![Advanced settings with Access, Projects and Expiration](https://www.unspar.com/images/docs/cli-authorize-advanced.webp)

Advanced settings decide what the key may do, in which projects and for how long.

The new key shows up under **API tokens** in [Settings](https://app.unspar.com/settings). You revoke it there. When a key expires, commands stop with `token_expired`, and `unspar login` gets you a new one.

### Other ways to log in

Not every computer has a browser, and a CI job has no person to click **Approve**. These are the other ways in:

| Situation                                           | What to do                                                                                                                      |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| The computer has no browser, like a server over SSH | Run `unspar login --web --no-prompt`. It prints the address and the code without opening a browser. Approve on another device.  |
| You already created a key under **API tokens**      | Run `unspar login --api-key` and paste the key when the CLI asks. It stays hidden while you paste.                              |
| A script or a CI job runs the CLI                   | Put the key into the environment variable `UNSPAR_API_KEY`. The CLI then needs no login. See [Scripting](https://www.unspar.com/docs/cli/scripting/). |

The CLI never takes a key as a command-line argument, so a key doesn't end up in your shell history.

### Check who you are logged in as

Two commands tell you which login the CLI uses.

```sh
unspar whoami
unspar auth status
```

`whoami` shows the team and the plan. It also shows what the key can do and which projects it can reach, and `--verbose` lists each permission. `auth status` shows which key is in use and whether it works. That matters when `UNSPAR_API_KEY` is set, because the variable overrides the stored login.

`unspar logout` deletes the key from this computer. It doesn't revoke the key. Unspar accepts it until it expires or until you revoke it under **API tokens**.

## Write your first article

These steps take one article from a topic to your site. IDs in Unspar are 26-character codes like `01JX9Q3M4N5P6R7S8T9V0W1X2Y`. Replace `<project-id>` and `<article-id>` in the examples with your own.

1. Find your project. A project is one website in Unspar, with its own settings and articles.

```sh
   unspar projects list
```

The list shows each project with its ID. If you have none yet, create one under [Projects](https://app.unspar.com/projects) or with `unspar projects create`.

2. Check the price. The estimate is free and creates nothing.

```sh
   unspar api post /articles/estimate --field project=<project-id> --field "brief=How DNS caching works"
```

The answer shows the article's class and the credits it would cost.

3. Start the article. The brief is only the topic. The project's settings and its template take care of the rest.

```sh
   unspar articles create --project <project-id> --brief "How DNS caching works" --wait
```

The CLI asks first, because this spends credits. Answer yes. The CLI prints the new article with its ID and waits until Unspar has written it. Ctrl+C stops the wait, not the article.

4. Save the text as a Markdown file.

```sh
   unspar articles content <article-id> --with-images --output article.md
```

5. Publish it. The CLI asks first, because the article then leaves Unspar.

```sh
   unspar articles publish <article-id>
```

The article goes to the project's default outlet. If the project has none, add `--outlet <outlet-id>` with an ID from `unspar outlets list`. You connect outlets in the web app under [Outlets](https://app.unspar.com/outlets).

The article also shows up under [Articles](https://app.unspar.com/articles) in the web app. [Articles in the CLI](https://www.unspar.com/docs/cli/articles/) explains each of these commands and their options.

## Use more than one team or key

A profile is a name for one login and its settings. Until you create another one, everything uses the profile `default`. Profiles keep the keys of different teams apart. They also let you keep a second key with fewer rights, for example a read-only one for an AI tool.

| Command                             | What it does                                                                                 |
| ----------------------------------- | -------------------------------------------------------------------------------------------- |
| `unspar --profile <name> login`     | Logs in under a new profile and makes it the current one.                                    |
| `unspar profile use <name>`         | Switches to another profile.                                                                 |
| `unspar --profile <name> <command>` | Runs one command with another profile.                                                       |
| `unspar profile list`               | Lists all profiles and marks the current one.                                                |
| `unspar profile show <name>`        | Shows one profile's settings and whether it has a stored key. It never shows the key itself. |
| `unspar profile delete <name>`      | Removes the profile and its key from this computer. The key still works until you revoke it. |

This logs in a second team, switches back to the first and runs one command for the second:

```sh
unspar --profile second-team login
unspar profile use default
unspar --profile second-team articles list
```

## Where does the CLI keep its files?

The CLI has two files. `config.yml` holds the settings. `auth.json` holds the keys as plain text, so treat it like a password and keep it out of repositories and shared folders. Both files live in one folder:

| System  | Folder                                                          |
| ------- | --------------------------------------------------------------- |
| Linux   | `~/.config/unspar`, or `$XDG_CONFIG_HOME/unspar` if that is set |
| macOS   | `~/Library/Application Support/unspar`                          |
| Windows | `%AppData%\unspar`                                              |

`unspar config path` prints where both files are, even when one of them is broken. The `config` commands read and change the settings. They never show or set a key.

```sh
unspar config list
unspar config set profiles.default.locale de
```

The locale is the language of Unspar's messages, like error texts. It is `en` or `de`, and it doesn't change the language of your articles. `profiles.<name>.defaults.project_list_limit` sets how many rows `projects list` and `articles list` show (30 by default).

## What if something doesn't work?

Run `unspar doctor` first. It checks your settings files, your login, and whether the CLI can reach Unspar. It never changes a file, and each line is marked `OK`, `WARN`, or `FAIL`.

```sh
unspar doctor
```

This table lists the most common problems.

| Message                                                                           | What to do                                                                                                                                  |
| --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `command not found: unspar`                                                       | The program's folder isn't on your PATH. Add the `export PATH` line from the install steps and open a new terminal.                         |
| `this action needs confirmation; re-run with --force to proceed without a prompt` | Nobody could answer the CLI's question, as in a script. Add `--force` if the command should go ahead.                                       |
| `no API key found for selected profile`                                           | Run `unspar login`.                                                                                                                         |
| `token_expired` or `token_revoked`                                                | The key expired or was revoked. Run `unspar login`.                                                                                         |
| `forbidden_ability`                                                               | The key doesn't have permission for this. `unspar whoami --verbose` shows what it can do. Log in again with other choices if you need more. |
| `forbidden_project_scope`                                                         | The key is limited to other projects.                                                                                                       |
| `insufficient_credits`                                                            | `unspar credits balance` shows what you have. Add more under [Buy credits](https://app.unspar.com/credits/purchase).                        |
| `resource_not_found`                                                              | The ID is wrong, or the key can't see it.                                                                                                   |
| "None of your teams can create API keys right now"                                | Only the owner or an **Administrator** can approve. Ask one of them for a key, then run `unspar login --api-key`.                           |
| The CLI works with the wrong team                                                 | `UNSPAR_API_KEY` is probably set. `unspar auth status` shows which key is in use, and `unset UNSPAR_API_KEY` removes it.                    |

`unspar <command> --help` shows all options for a command, with examples. `--debug` writes the details of each request to stderr, with the key hidden. If you're still stuck, write to [Support](https://app.unspar.com/support). Include the command you ran and the full error message, because it contains the request ID.
