How to Use Hostinger API CLI

Quick guide on how to install and use Hostinger API CLI.

Updated 1 week ago

A quick, step-by-step guide to install the Hostinger-API Command-Line Interface, connect it to your account, and run the most common VPS commands.

Step 1 – Download & Install the CLI

  1. Install Go and clone the repository:
    apt install golang-go
    
    git clone --depth 1 https://github.com/hostinger/api-cli /tmp/api-cli
  2. Navigate into the project folder:
    cd /tmp/api-cli
  3. Build the binary and move it to your system path:
    go build -o /usr/local/bin/hapi 
    
    chmod 0755 /usr/local/bin/hapi
  4. Return to your home directory and verify the installation:
    cd ~
    
    hapi --help
  5. If `hapi –help` returns the command list, the CLI is installed correctly.

Step 2 – Authenticate with Your API Token

Generate your API token at https://hpanel.hostinger.com/api.

You can pass credentials either through a config file or environment variables.

Option A – Config file (persistent)

wget https://raw.githubusercontent.com/hostinger/api-cli/main/hapi.yaml -O ~/.hapi.yaml
  1. Edit the file and paste your token under api_token.
  2. Run any command – the CLI will automatically read ~/.hapi.yaml.

Option B – Environment variable (current session only)

export HAPI_API_TOKEN=<paste_your_token_here>
Note: this resets when you close the terminal. Use Option A for a permanent setup.

Step 3 – Working with VPS Instances

The vps sub-command groups everything related to virtual machines:

hapi vps vm list                 # List all VPS
hapi vps vm get    <vm_id>       # Detailed info for one VPS
hapi vps vm start  <vm_id>       # Power-on
hapi vps vm stop   <vm_id>       # Graceful shutdown

Use --format json to pipe data into scripts or dashboards.

Tip: The CLI mirrors Hostinger API endpoints, so everything you can do in developers.hostinger.com is possible via hapi.

Official documentation

API reference – https://developers.hostinger.com

You’re all set!

You can now automate routine VPS tasks, integrate Hostinger operations into CI/CD pipelines, or simply manage servers faster from your terminal. Happy scripting! 🎉