Cloud and hosting

Hetzner (Cloud API tokens) API tokens: find, store, rotate, and use them safely with AI agents

Last checked 2026-11-08 against Hetzner (Cloud API tokens)'s documentation

Hetzner Cloud API tokens are generated inside a project in the Hetzner Console under Security → API tokens → Generate API token. A Hetzner Cloud token is either Read or Read & Write, belongs to the project it was generated in, and cannot be viewed again once the window is closed. The hcloud CLI reads the token from HCLOUD_TOKEN.

Hetzner (Cloud API tokens) key types

TypePrefixSecret?ScopeExpiry
Cloud API token
Sent as a Bearer token in the Authorization header.
—YesThe project it was generated in; Read (GET only) or Read & Write (GET, DELETE, PUT, POST)—

How to create a Hetzner (Cloud API tokens) key

  1. In the Hetzner Console, open your project.
  2. Go to Security in the left menu, then API tokens in the upper menu.
  3. Select Generate API token.
  4. Enter a description and choose Read or Read & Write.
  5. Copy the token into a secrets vault; it cannot be viewed again once the window is closed.

Open Hetzner (Cloud API tokens)'s key settings

Limiting what the key can do

A Hetzner Cloud token is limited to one project and to one of two permission levels: Read (only GET requests) or Read & Write (GET, DELETE, PUT and POST). Use Read tokens wherever write access is not needed, and separate projects to separate environments.

If your Hetzner (Cloud API tokens) key leaked

  1. Generate a replacement token in the same project and update HCLOUD_TOKEN and any tooling that used the old token.
  2. Remove the exposed token from the project's Security → API tokens page.
  3. Check the project for servers, volumes, networks or firewall changes you did not make.

Environment variables and CLI

Hetzner (Cloud API tokens)'s SDKs and docs read the key from HCLOUD_TOKEN.

hcloud (hcloud): hcloud context create <name> creates a context; with --token-from-env it uses HCLOUD_TOKEN without asking

Things that catch people out

  • The token cannot be viewed again once the generation window is closed.
  • Tokens are per project, so a multi-project setup needs one token per project.
  • A Read token fails write calls with token_readonly, not a 403.

Common Hetzner (Cloud API tokens) authentication errors

unauthorized

HTTP 401; the request was made with an invalid or unknown token.

token_readonly

HTTP 401; the token only has Read permission, so it can make GET requests only.

forbidden

HTTP 403; the token has insufficient permissions for this request.

Using your Hetzner (Cloud API tokens) key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Hetzner (Cloud API tokens) key, these intents fit:

IntentWhat BotPassword does
list_credentialsLists the credentials this agent is granted and what it may do with each. Never values.
run_withRuns a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
http_requestMakes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
cli_loginLets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
store_secretSaves a value the agent already holds as a new vault item.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

Where do I find my Hetzner Cloud API token?

You cannot view an existing token again. Generate a new one in your project under Security → API tokens and copy it before closing the window.

Are Hetzner API tokens per project?

Yes. A Hetzner Cloud token only works for the project it was generated in.

What permissions can a Hetzner Cloud token have?

Read (GET only) or Read & Write (GET, DELETE, PUT and POST).

What does token_readonly mean in the Hetzner Cloud API?

The token was generated with Read permission and the request tried to change something. Generate a Read & Write token for that job.

How does the hcloud CLI use my Hetzner token?

hcloud context create stores the token in a named context; with --token-from-env it reads HCLOUD_TOKEN instead of asking.

Can an AI agent use my Hetzner (Cloud API tokens) key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with list_credentials, run_with, http_request, so the agent gets the result and never the value.

Stop pasting Hetzner (Cloud API tokens) keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.