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

Source: https://botpassword.com/keys/hetzner
Last checked: 2026-11-08

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`.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Cloud API token | — | Yes | The 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.

## 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 the 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

- `HCLOUD_TOKEN`

## Gotchas

- 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.

## Using this key with AI agents (BotPassword)

- `list_credentials`: Lists the credentials this agent is granted and what it may do with each. Never values.
- `run_with`: Runs 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_request`: Makes 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_login`: Lets 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_secret`: Saves a value the agent already holds as a new vault item.

## FAQ

### 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.

## Sources

- https://docs.hetzner.com/cloud/api/getting-started/generating-api-token/
- https://docs.hetzner.cloud/reference/cloud
- https://github.com/hetznercloud/cli/blob/main/docs/reference/manual/hcloud_context_create.md
