{"id":292,"date":"2025-06-30T09:28:50","date_gmt":"2025-06-30T09:28:50","guid":{"rendered":"https:\/\/blog.hostinger.io\/support\/2025\/06\/30\/11679133-how-to-use-hostinger-api-cli\/"},"modified":"2026-05-26T11:51:18","modified_gmt":"2026-05-26T11:51:18","slug":"11679133-how-to-use-hostinger-api-cli","status":"publish","type":"post","link":"https:\/\/www.hostinger.com\/support\/11679133-how-to-use-hostinger-api-cli\/","title":{"rendered":"How to Use Hostinger API CLI"},"content":{"rendered":"<p class=\"no-margin\">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.<\/p><h2 id=\"h_1ce7482489\"><b>Step 1 &ndash; Download &amp; Install the CLI<\/b><code><\/code><\/h2><ol>\n<li>Install Go and clone the repository:\n<pre>apt install golang-go\r\n\r\ngit clone --depth 1 https:\/\/github.com\/hostinger\/api-cli \/tmp\/api-cli<\/pre>\n<\/li>\n<li>Navigate into the project folder:\n<pre>cd \/tmp\/api-cli<\/pre>\n<\/li>\n<li>Build the binary and move it to your system path:\n<pre>go build -o \/usr\/local\/bin\/hapi&nbsp;\r\n\r\nchmod 0755 \/usr\/local\/bin\/hapi<\/pre>\n<\/li>\n<li>Return to your home directory and verify the installation:\n<pre>cd ~\r\n\r\nhapi --help<\/pre>\n<\/li>\n<li>If `hapi &ndash;help` returns the command list, the CLI is installed correctly.<\/li>\n<\/ol><h2 id=\"h_2a9b8fdf08\"><b>Step 2 &ndash; Authenticate with Your API Token<\/b><\/h2><p>Generate your API token at https:\/\/hpanel.hostinger.com\/api.<\/p><p>You can pass credentials either through a config file or environment variables.<\/p><h3>Option A &ndash; Config file (persistent)<\/h3><pre>wget https:\/\/raw.githubusercontent.com\/hostinger\/api-cli\/main\/hapi.yaml -O ~\/.hapi.yaml<\/pre><ol>\n<li>Edit the file and paste your token under api_token.<\/li>\n<li>Run any command &ndash; the CLI will automatically read ~\/.hapi.yaml.<\/li>\n<\/ol><h3>Option B &ndash; Environment variable (current session only)<\/h3><pre>export HAPI_API_TOKEN=&lt;paste_your_token_here&gt;<\/pre><div class=\"intercom-interblocks-callout\" style=\"background-color: #e3e7fa80;border-color: #334bfa33\"><strong>Note<\/strong>: this resets when you close the terminal. Use Option A for a permanent setup.<\/div><h2 id=\"h_8f63636a62\"><b>Step 3 &ndash; Working with VPS Instances<\/b><\/h2><p class=\"no-margin\">The vps sub-command groups everything related to virtual machines:<\/p><pre><code>hapi vps vm list                 # List all VPS\r\nhapi vps vm get    &lt;vm_id&gt;       # Detailed info for one VPS\r\nhapi vps vm start  &lt;vm_id&gt;       # Power-on\r\nhapi vps vm stop   &lt;vm_id&gt;       # Graceful shutdown<\/code><\/pre><p class=\"no-margin\">Use <code>--format json<\/code> to pipe data into scripts or dashboards.<\/p><div class=\"intercom-interblocks-callout\" style=\"background-color: #e3e7fa80;border-color: #334bfa33\">\n<p class=\"no-margin\"><b>Tip:<\/b> The CLI mirrors Hostinger API endpoints, so everything you can do in <i>developers.hostinger.com<\/i> is possible via hapi.<\/p>\n<\/div><h2 id=\"h_3860f2e3ca\"><b>Official documentation<\/b><\/h2><p class=\"no-margin\">API reference &ndash; <a class=\"intercom-content-link\" href=\"https:\/\/developers.hostinger.com\" target=\"_blank\" rel=\"noopener\">https:\/\/developers.hostinger.com<\/a><br>\n&#8203;<\/p><h2 id=\"h_718b898cd2\"><b>You&rsquo;re all set!<\/b><\/h2><p class=\"no-margin\">You can now automate routine VPS tasks, integrate Hostinger operations into CI\/CD pipelines, or simply manage servers faster from your terminal. Happy scripting! &#127881;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick guide on how to install and use Hostinger API CLI.<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"include_on_kodee":true,"footnotes":""},"categories":[295],"tags":[],"class_list":["post-292","post","type-post","status-publish","format-standard","hentry","category-api"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/support\/11679133-how-to-use-hostinger-api-cli\/","default":1}],"include_on_kodee":true,"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/comments?post=292"}],"version-history":[{"count":2,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":10921,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/292\/revisions\/10921"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/media?parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/categories?post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/tags?post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}