> ## Documentation Index
> Fetch the complete documentation index at: https://docs.autoposting.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI Installation

> Install the Autoposting CLI, configure your API key, and verify the connection.

## Prerequisites

* [Node.js](https://nodejs.org) 20 or later

## Install

<Tabs>
  <Tab title="npm">
    ```bash theme={null}
    npm install -g @autoposting.ai/cli
    ```
  </Tab>

  <Tab title="npx (one-shot)">
    ```bash theme={null}
    npx @autoposting.ai/cli posts list
    ```
  </Tab>
</Tabs>

Both `autoposting` and `ap` (short alias) are available after install.

## Setup

<Steps>
  <Step title="Authenticate">
    Set your API key via environment variable or browser login:

    <Tabs>
      <Tab title="Environment Variable">
        ```bash theme={null}
        export AUTOPOSTING_API_KEY=sk-social-your-key
        ```

        Add to your shell profile (`~/.zshrc`, `~/.bashrc`) for persistence.
      </Tab>

      <Tab title="Browser Login">
        ```bash theme={null}
        ap auth login
        ```

        Opens your browser for authentication. Credentials are stored in `~/.config/autoposting/credentials.json` with `0600` permissions. Use `--profile <name>` to keep several accounts, and `--api-key <key>` to store a key without the browser flow.
      </Tab>
    </Tabs>

    **Auth priority:**

    ```
    --api-key flag  >  AUTOPOSTING_API_KEY env  >  ~/.config/autoposting/credentials.json
    ```

    <Note>
      The CLI talks to `https://app.autoposting.ai/api-proxy` by default. Override it with the
      `AUTOPOSTING_BASE_URL` environment variable (or `ap auth login --base-url`) for staging or self-hosted backends.
    </Note>
  </Step>

  <Step title="Verify">
    ```bash theme={null}
    ap doctor
    ```

    Checks CLI version, Node.js version, authentication, and API connectivity.

    ```bash theme={null}
    ap whoami
    ```

    Shows which auth method is active and the associated workspace.
  </Step>

  <Step title="Shell Completions (optional)">
    <Tabs>
      <Tab title="zsh">
        ```bash theme={null}
        ap completion zsh >> ~/.zshrc
        source ~/.zshrc
        ```
      </Tab>

      <Tab title="bash">
        ```bash theme={null}
        ap completion bash >> ~/.bashrc
        source ~/.bashrc
        ```
      </Tab>

      <Tab title="fish">
        ```bash theme={null}
        ap completion fish > ~/.config/fish/completions/ap.fish
        ```
      </Tab>

      <Tab title="PowerShell">
        ```powershell theme={null}
        ap completion powershell >> $PROFILE
        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>

## CI/CD Usage

For CI/CD pipelines, use the `AUTOPOSTING_API_KEY` environment variable with `--json` and `--quiet` flags:

```yaml theme={null}
# GitHub Actions
- name: Announce release
  run: |
    npm install -g @autoposting.ai/cli
    ap posts create \
      --brand my-brand \
      --text "v${{ github.ref_name }} is live!" \
      --platforms x,linkedin \
      --json
  env:
    AUTOPOSTING_API_KEY: ${{ secrets.AUTOPOSTING_API_KEY }}
```

## Exit Codes

| Code | Meaning              |
| ---- | -------------------- |
| 0    | Success              |
| 1    | General error        |
| 2    | Authentication error |
| 3    | Validation error     |
| 4    | Not found            |
| 5    | Rate limited         |
| 6    | Server error         |

<CardGroup cols={2}>
  <Card title="Commands" icon="terminal" href="/cli/commands">
    Full command reference with flags and examples.
  </Card>

  <Card title="MCP Setup" icon="robot" href="/mcp/setup">
    Connect AI assistants to your account.
  </Card>

  <Card title="TypeScript SDK" icon="brackets-curly" href="/sdks/typescript">
    Programmatic API access in Node.js.
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/overview">
    Explore the REST API directly.
  </Card>
</CardGroup>
