> For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://ibee.ai/docs/llms.txt (full text of every page: https://ibee.ai/docs/llms-full.txt). For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://ibee.ai/docs/_mcp/server.

# Read secrets from your app

> Connect applications and scripts to IBEE Secret Manager over the Vault API - the address, namespace and token every client needs, then the bao and vault CLI, bao agent, Python (hvac), Node.js and curl, with token renewal, caching, retries and rate limits.

Applications read and write secret values over the **Vault API** (OpenBao, KV version 2) at your workspace's address. Any Vault-compatible client works: the `bao` or `vault` CLI, `bao agent`, a Vault SDK such as `hvac` for Python, or plain HTTP. Every client needs three things: the **address**, the **namespace**, and a **token** from an [app credential](/docs/tools/secret-manager/app-credentials) login.

## The three values

| Value     | Environment variable                   | HTTP                                                           | Where to find it                                                                 |
| --------- | -------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| Address   | `VAULT_ADDR` (or `BAO_ADDR`)           | The base URL, for example `https://secrets.ibee.ai`            | Secret Manager → **Connect**, or `endpoint` from `GET /secret-manager/workspace` |
| Namespace | `VAULT_NAMESPACE` (or `BAO_NAMESPACE`) | `X-Vault-Namespace: acme-payments` header on **every** request | Secret Manager → **Connect**, or `namespace` from the same call                  |
| Token     | `VAULT_TOKEN` (or `BAO_TOKEN`)         | `X-Vault-Token: <token>` header                                | An app credential login (below), or a 60-second CLI session for people           |

The address uses a publicly trusted certificate over HTTPS (TLS 1.2 or 1.3), so you don't need a CA file. Send the namespace as a header, not in the path.

## Sign in

| Who                                   | How                                                                 | Token lifetime                   |
| ------------------------------------- | ------------------------------------------------------------------- | -------------------------------- |
| An application, VM, CI job or cluster | App credential: `auth/approle/login` with the Role ID and Secret ID | 1 hour, renewable up to 24 hours |
| You, trying commands                  | Secret Manager → **Connect** → **Get a 60-second CLI session**      | 60 seconds, not renewable        |

```bash
export VAULT_TOKEN=$(bao write -field=token auth/approle/login \
  role_id="$ROLE_ID" secret_id="$SECRET_ID")
```

Logins aren't billed, but they're limited to 5 per second per IP address: sign in once and reuse the token.

## The bao and vault CLI

The OpenBao CLI `bao` ([download](https://openbao.org/downloads/)) and HashiCorp's `vault` take the same commands. Choose the store with `-mount=secret` (yours) or `-mount=ibee-managed` (read only).

```bash
# Read
bao kv get -mount=secret payments/db                 # latest version
bao kv get -mount=secret -field=password payments/db  # one value
bao kv get -mount=secret -version=2 payments/db       # an older version
bao kv get -mount=secret -format=json payments/db | jq '.data.data'
bao kv list -mount=secret payments                    # names in a folder

# Write (needs a read & write credential, or a session as an editor)
bao kv put -mount=secret -cas=0 payments/stripe api_key=@./stripe-key.txt   # create only
bao kv put -mount=secret -cas=3 payments/db username=app password=@./new-password.txt  # replace version 3
bao kv patch -mount=secret payments/db port=5433      # change one key, keep the rest

# Versions
bao kv metadata get -mount=secret payments/db         # versions and settings
bao kv rollback -mount=secret -version=2 payments/db  # save version 2 as a new version
bao kv delete -mount=secret -versions=4 payments/db   # delete (undo with undelete)
bao kv undelete -mount=secret -versions=4 payments/db
```

`key=@file` reads the value from a file, which keeps it out of your shell history. `kv put` replaces **all** keys of a secret; use `kv patch` to change one.

> **Info**
>
> Each `bao kv` or `vault kv` command first checks the store's settings with a separate request. That check isn't billed, but it counts toward the 10-requests-per-second limit for writes and listing in your namespace. For a busy application, read over HTTP or an SDK instead of running the CLI in a loop.

## Keep a token fresh with bao agent

`bao agent` runs next to your application, signs in with the app credential, renews the token, and can write secrets into a file your app reads. This is the simplest choice for a long-running service on a VM.

**`/etc/bao-agent.hcl`**

```hcl title="/etc/bao-agent.hcl"
vault {
  address = "https://secrets.ibee.ai"
}

auto_auth {
  method "approle" {
    # The namespace goes on the login method; templates then read from it.
    namespace = "acme-payments"
    config = {
      role_id_file_path                   = "/etc/bao-agent/role_id"
      secret_id_file_path                 = "/etc/bao-agent/secret_id"
      remove_secret_id_file_after_reading = false
    }
  }
}

template {
  destination = "/etc/myapp/secrets.env"
  contents    = <<EOT
{{ with secret "secret/data/payments/db" }}DB_PASSWORD={{ .Data.data.password }}{{ end }}
EOT
}
```

```bash
bao agent -config=/etc/bao-agent.hcl
```

Put the Role ID and Secret ID in the two files, readable only by the agent's user.

> **Warning**
>
> Set `namespace` inside `method "approle"`. A namespace set only in the `vault {}` block isn't used for the login, and the agent gets `403` at the root namespace.

## Python (hvac)

```bash
pip install hvac
```

```python
import os

import hvac

client = hvac.Client(url=os.environ["VAULT_ADDR"], namespace=os.environ["VAULT_NAMESPACE"])
client.auth.approle.login(role_id=os.environ["ROLE_ID"], secret_id=os.environ["SECRET_ID"])

# Read once at startup and keep the values: each read is a billed operation.
secret = client.secrets.kv.v2.read_secret_version(
    path="payments/db", mount_point="secret", raise_on_deleted_version=True
)
values = secret["data"]["data"]          # {"username": "app", "password": "..."}
version = secret["data"]["metadata"]["version"]

# Write a new version (read & write credential). cas = the version you are replacing.
client.secrets.kv.v2.create_or_update_secret(
    path="payments/db", mount_point="secret",
    secret={**values, "password": "new-password"}, cas=version,
)

# Renew the token before it expires (up to 24 hours), then log in again.
client.auth.token.renew_self()
```

## Node.js

Node.js 18 or later has `fetch` built in.

```javascript
const base = process.env.VAULT_ADDR;
const ns = process.env.VAULT_NAMESPACE;

// Sign in with the app credential.
const login = await fetch(`${base}/v1/auth/approle/login`, {
  method: "POST",
  headers: { "X-Vault-Namespace": ns, "Content-Type": "application/json" },
  body: JSON.stringify({ role_id: process.env.ROLE_ID, secret_id: process.env.SECRET_ID }),
});
if (!login.ok) throw new Error(`Login failed: ${login.status}`);
const { auth } = await login.json();   // auth.client_token, auth.lease_duration (seconds)

// Read the latest version.
const res = await fetch(`${base}/v1/secret/data/payments/db`, {
  headers: { "X-Vault-Token": auth.client_token, "X-Vault-Namespace": ns },
});
if (!res.ok) throw new Error(`Secret read failed: ${res.status}`);
const { data } = (await res.json()).data;   // { username: "app", password: "..." }
```

## HTTP (curl)

Every request carries `X-Vault-Namespace`, and every request after login carries `X-Vault-Token`.

```bash
H=(-H "X-Vault-Namespace: $VAULT_NAMESPACE")

# Sign in
VAULT_TOKEN=$(curl -s -X POST "$VAULT_ADDR/v1/auth/approle/login" "${H[@]}" \
  -d "{\"role_id\": \"$ROLE_ID\", \"secret_id\": \"$SECRET_ID\"}" | jq -r '.auth.client_token')
H+=(-H "X-Vault-Token: $VAULT_TOKEN")

# Read the latest version, or ?version=2 for an older one
curl -s "$VAULT_ADDR/v1/secret/data/payments/db" "${H[@]}" | jq '.data.data'

# List a folder
curl -s "$VAULT_ADDR/v1/secret/metadata/payments?list=true" "${H[@]}" | jq '.data.keys'

# Write a new version, replacing version 3
curl -s -X POST "$VAULT_ADDR/v1/secret/data/payments/db" "${H[@]}" \
  -d '{"options": {"cas": 3}, "data": {"username": "app", "password": "new-password"}}'

# Delete and undelete versions
curl -s -X POST "$VAULT_ADDR/v1/secret/delete/payments/db" "${H[@]}" -d '{"versions": [4]}'
curl -s -X POST "$VAULT_ADDR/v1/secret/undelete/payments/db" "${H[@]}" -d '{"versions": [4]}'

# Renew the token
curl -s -X POST "$VAULT_ADDR/v1/auth/token/renew-self" "${H[@]}"
```

A read answers:

```json
{
  "data": {
    "data": { "username": "app", "password": "s3cr3t" },
    "metadata": { "version": 3, "created_time": "2026-11-25T08:00:00Z", "deletion_time": "", "destroyed": false }
  }
}
```

### Which Vault API paths you can use

| Path                                                             | Methods                                                         | For                            |
| ---------------------------------------------------------------- | --------------------------------------------------------------- | ------------------------------ |
| `/v1/secret/data/<path>`, `/v1/ibee-managed/data/<path>`         | `GET` (both); `POST`, `PUT`, `PATCH`, `DELETE` (`secret/` only) | Read and write values          |
| `/v1/secret/metadata/<path>`, `/v1/ibee-managed/metadata/<path>` | All, including `LIST`                                           | Versions, settings and listing |
| `/v1/secret/delete/<path>`, `/undelete/`, `/destroy/`            | `POST`, `PUT`                                                   | Version actions                |
| `/v1/auth/approle/login`                                         | `POST`, `PUT`                                                   | Sign in                        |
| `/v1/auth/token/lookup-self`, `/renew-self`, `/revoke-self`      | `GET` (lookup), `POST`, `PUT`                                   | Your own token                 |

Anything else, such as `sys/` or the OpenBao web UI, isn't available and answers `404`. Your token's permissions still apply on top: a read only credential can't write, and no app credential can destroy versions.

Any other Vault SDK (for example Go's `vault/api` or Spring Cloud Vault) works the same way: set the address, the namespace and AppRole login, and use the KV version 2 methods with the mount `secret`.

## Good practice for applications

* **Read once, then cache.** Read secrets at startup and keep them in memory. Re-read when you know a value changed, or every few minutes at most. Every read is a billed operation (₹4 per 10,000) and counts toward rate limits.
* **Renew, then sign in again.** Renew the token before its hour is up; after 24 hours, sign in again. `bao agent` does both for you.
* **Retry with backoff.** A `429` means a rate limit; wait at least a second and retry, with a limit on attempts. A `503` "OpenBao leader is changing; retry the request" is safe to retry. The service doesn't retry for you, and each request times out after 30 seconds.
* **Use check-and-set for writes**, so two writers can't overwrite each other.
* **Never log tokens, Secret IDs or values.**

## Rate limits

| Requests                                                                                               | Limit                                              |
| ------------------------------------------------------------------------------------------------------ | -------------------------------------------------- |
| Reading values (`GET …/data/…`) and token lookup                                                       | 100 per second, per namespace and IP address       |
| Writes, deletes, version actions, listing, metadata, token renew and revoke, and the CLI's store check | 10 per second per namespace, shared by all clients |
| Logins                                                                                                 | 5 per second per IP address                        |
| Everything in one namespace                                                                            | 500 per second                                     |
| Everything from one IP address                                                                         | 200 per second                                     |
| Request body                                                                                           | 64 KiB                                             |

See [Limits](/docs/tools/secret-manager/limits).

## Troubleshooting

| You see                                                                            | What it means                                                                  | What to do                                                                   |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- |
| `404` with an empty body                                                           | No `X-Vault-Namespace` header, or a path that isn't available (such as `sys/`) | Set `VAULT_NAMESPACE`, and use the paths above                               |
| `404` `{"errors":["namespace not found"]}`                                         | The namespace is wrong                                                         | Copy it from **Connect**                                                     |
| `403` `{"errors":["permission denied"]}`                                           | The token expired, is for another namespace, or lacks access to that path      | Sign in again; check the credential's access and folder                      |
| `400` "check-and-set parameter did not match the current version"                  | Someone saved a newer version                                                  | Read the secret again and retry with its version                             |
| `400` "check-and-set parameter required for this call"                             | The secret has **Require check-and-set** on                                    | Send `cas` (`-cas=N` in the CLI)                                             |
| `404` on a read with `deletion_time` set                                           | The latest version is deleted                                                  | Undelete it or save a new version                                            |
| `429`                                                                              | A rate limit                                                                   | Back off and retry; cache reads                                              |
| `503` "OpenBao leader is changing; retry the request"                              | A brief server handover                                                        | Retry after a moment                                                         |
| Every write answers `403` `permission denied`, but reads work, for all credentials | The workspace is read-only (restricted)                                        | See [Workspace states](/docs/tools/secret-manager/concepts#workspace-states) |
| Every read answers `403` `permission denied`                                       | The workspace is suspended                                                     | See [Workspace states](/docs/tools/secret-manager/concepts#workspace-states) |

More in [Troubleshooting](/docs/tools/secret-manager/troubleshooting).

## Related pages

* [App credentials](/docs/tools/secret-manager/app-credentials)
* [Kubernetes with External Secrets](/docs/tools/secret-manager/kubernetes)
* [Pricing](/docs/tools/secret-manager/pricing)