---
title: "CLI automation and output"
description: "Run the AI Glot CLI safely in scripts and CI using JSON or NDJSON, environment credentials, profiles, exit codes and bounded retries."
canonical: "https://ai-glot.com/docs/cli/automation"
updated: "2026-08-09"
---

# CLI automation and output

The CLI prints readable tables to a terminal and JSON when output is piped, so the same command works interactively and in automation.

```bash
aiglot batches list                    # table on a terminal
aiglot batches list | jq '.data[0].id' # JSON when piped
aiglot batches list --output ndjson    # one object per line
aiglot account --json                  # explicit JSON
```

Failures go to standard error. Standard output therefore remains safe to pipe into another program.

## CI authentication

Create a dedicated, minimum-scope API key and store it in the CI provider's secret manager:

```bash
export AIGLOT_API_KEY="aig_live_…"
aiglot account --json
```

The CLI checks credentials in this order: `AIGLOT_API_KEY`, OS keychain, then its protected config file.

## Exit codes

| Code | Meaning                              |
| ---: | ------------------------------------ |
|    0 | Success                              |
|    1 | API or server error                  |
|    2 | Invalid command or arguments         |
|    3 | Authentication or permission failure |
|    4 | Resource not found                   |
|    5 | Rate limited                         |
|    6 | Resource state conflict              |

Scripts should branch on the exit code or structured `error.code`, not error-message text.

## Retries

The CLI retries `429` and temporary server failures with bounded backoff. Use `--no-retry` when the caller owns retry policy. Destructive commands never wait forever for an interactive prompt: non-interactive use must pass `--force`.

## Profiles

Use named profiles to keep credentials for different workspaces or environments separate:

```bash
aiglot --profile client-a auth login --key "$CLIENT_A_KEY"
aiglot --profile client-a account
export AIGLOT_PROFILE=client-a
```

## Environment variables

| Variable             | Purpose                               |
| -------------------- | ------------------------------------- |
| `AIGLOT_API_KEY`     | API key; overrides stored credentials |
| `AIGLOT_API_URL`     | REST base URL                         |
| `AIGLOT_MCP_URL`     | MCP base URL                          |
| `AIGLOT_AUTH_URL`    | OAuth authorization-server URL        |
| `AIGLOT_PROFILE`     | Named credential profile              |
| `AIGLOT_NO_TUI`      | Force machine-readable output         |
| `AIGLOT_NO_KEYCHAIN` | Skip the operating-system keychain    |
| `NO_COLOR`           | Disable colour and force JSON output  |

> **Warning: Do not print secrets**
>
> Avoid shell tracing around authentication and never echo `AIGLOT_API_KEY`. Redact authorization headers from CI logs and failure artefacts.
