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

# Secrets and rotation

A secret is a credential that a webhook tool header or an MCP server sends. You write its value
once. No operation returns the value, a hash of it or any part of it. Tools and MCP servers pin an
exact `{secret_id, version}`, and rotation adds a version without moving any pin.

```bash
export RASEN_API_BASE="https://api.rasen.ai/v1"
export RASEN_API_KEY="<your key>"
```

## 1. Store a credential

`purpose` is `webhook_tool` (a secret header of a webhook tool) or `mcp_server` (the credential of an
MCP server). The two are not interchangeable: a reference to a secret of the other purpose is
refused with `credential_unavailable`. `material_kind` is a label only; the value is sent unchanged.

```bash
curl -sS -X POST "$RASEN_API_BASE/secrets" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"purpose": "webhook_tool", "material_kind": "api_key", "name": "crm-api-key",
       "resource_key": "crm-prod", "value": "'"$CRM_API_KEY"'"}'
```

```json
{
  "id": "sec_…", "resource_key": "crm-prod", "name": "crm-api-key", "purpose": "webhook_tool",
  "material_kind": "api_key", "state": "active", "latest_version": 1, "active_version_count": 1,
  "created_at": "2026-09-29T10:00:00Z", "updated_at": "2026-09-29T10:00:00Z", "last_rotated_at": null,
  "usage": {"draft_binding_count": 0, "published_version_count": 0, "live_version_count": 0}
}
```

* Read the value from your own secret store (here `$CRM_API_KEY`). Do not write it in a script.

* After a lost answer, send the identical request with the same `Idempotency-Key`. The replay
  returns the same status and body with `Idempotent-Replayed: true` and stores nothing new. It is
  the stored answer: the secret is not read again, even if it was rotated, revoked or deleted since.

* A refused secret request stores nothing. After you fix the cause, the same request with the same
  key runs.

* `409 conflict` with `details.reason: name_taken`: another secret has that name.

* `409 resource_key_conflict` with `details.existing_id`: the secret already exists. For repeated
  setup, look it up instead of creating it again:

```bash
curl -sS "$RASEN_API_BASE/secrets?resource_key=crm-prod" -H "Authorization: Bearer $RASEN_API_KEY"
```

Then bind it to a tool header or an MCP server as `{"secret_id": "sec_…", "version": 1}` (see
[Tools and MCP servers](/guides/tools)) and publish the agent.

## 2. Read metadata

```bash
curl -sS "$RASEN_API_BASE/secrets?state=active&limit=50" -H "Authorization: Bearer $RASEN_API_KEY"
curl -sS "$RASEN_API_BASE/secrets/sec_…" -H "Authorization: Bearer $RASEN_API_KEY"
curl -sS "$RASEN_API_BASE/secrets/sec_…/versions" -H "Authorization: Bearer $RASEN_API_KEY"
curl -sS "$RASEN_API_BASE/secrets/sec_…/versions/2" -H "Authorization: Bearer $RASEN_API_KEY"
```

* Lists are newest first. Follow `next_cursor` until it is `null`.

* A secret's `state` is `revoked` when no version can be released any more.

* `last_rotated_at` stays `null` until a second version exists.

* A list refuses a query parameter it does not know (`invalid_request` naming the `field`).

* `usage` counts the current draft bindings, the retained published versions and, of those, the
  versions that are live now.

* A secret of another workspace, a telephony or import credential, and a deleted secret all answer
  `404 not_found`.

## 3. Rotate and adopt

Rotation stores new material as the next version. It changes nothing that runs: every tool, MCP
server and published agent keeps its pinned version, and calls that already started keep theirs.

```bash
curl -sS -X POST "$RASEN_API_BASE/secrets/sec_…/versions" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" -d '{"value": "'"$CRM_API_KEY_NEW"'"}'
```

```json
{"secret_id": "sec_…", "version": 2, "state": "active", "created_at": "2026-10-01T09:00:00Z",
 "revoked_at": null, "revoke_reason": null,
 "usage": {"draft_binding_count": 0, "published_version_count": 0, "live_version_count": 0}}
```

To adopt version 2:

1. Find the consumers of the old version: `GET /secrets/sec_…/references?version=1`. Each row names
   one consumer: `webhook_tool` or `mcp_tool` (the tool, with its `agent_id`) or `mcp_server` (the
   workspace connection, no agent).
2. Replace each webhook tool and each MCP server that pins version 1 with
   `{"secret_id": "sec_…", "version": 2}`. Replacing an MCP server moves every draft tool attached to
   it; you do not replace those tools.
3. Review the draft diff and publish each affected agent (the `agent_id` of each row).
4. When no live version pins version 1 (`live: false` on every `published` row), revoke version 1.

```bash
curl -sS "$RASEN_API_BASE/secrets/sec_…/references?scope=published" -H "Authorization: Bearer $RASEN_API_KEY"
```

```json
{"items": [{"secret_id": "sec_…", "version": 1, "consumer_type": "webhook_tool", "consumer_id": "tool_…",
            "agent_id": "agent_…", "scope": "published", "agent_version_id": "pub_…", "live": true}],
 "next_cursor": null}
```

`consumer_type` is `webhook_tool` or `mcp_tool` for an authored tool of an agent (in a draft or a
published version, with its `agent_id`), and `mcp_server` for the workspace MCP server connection
(`agent_id: null`). The list is open: treat a value you do not know as a consumer you must still
review.

## 4. Emergency revocation

Revoke a version when its material may be known to someone else (`compromised`), or when you decide
to stop it (`requested`). Both have the same effect.

```bash
curl -sS -X POST "$RASEN_API_BASE/secrets/sec_…/versions/1/revoke" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" -d '{"reason": "compromised"}'
```

* Every later use of version 1 is refused at once, also by live agents and by calls that are already
  running. The refused tool call shows as a refused tool outcome with `credential_unavailable`, and
  the call continues. An MCP server connection that uses the version stops using it for the rest of
  the call: every later tool call to that server in the call is refused the same way.

* MCP connections check the version before every tool call and fail closed: if the platform cannot
  confirm the version in time, for example during an outage, the connection stops using the
  credential just as if it were revoked. See
  [Credentials during calls](/guides/tools#credentials-during-calls).

* Revoking or rotating does not change which version a tool, MCP server or published version pins.

* An action that was already sent is not undone.

* Revocation cannot be undone. To recover, rotate, bind the new version and publish.

* Revoking a revoked version returns its current state; the first reason stays.

* A rollback never restores a revoked version.

## 5. Delete

```bash
curl -sS -X DELETE "$RASEN_API_BASE/secrets/sec_…" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)"
```

* `204`: every version was destroyed. The secret no longer appears, and its name and resource key
  can be used again. This cannot be undone.
* `409 deletion_blocked` with `details.reason: draft_reference`: a current draft tool or MCP server
  still pins a version. Remove or replace those references first.
* `409 deletion_blocked` with `details.reason: published_reference`: a retained published agent
  version pins a version, and a rollback could restore it. The secret is kept. For compromised
  material, revoke the version instead.
* A detached tool, a disabled MCP server and its tools do not block deletion.
* A replay of the delete answers `204` again.

## Errors to expect

| Answer                       | Meaning                                                                                                                      |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `409 credential_unavailable` | A pinned version cannot be released: revoked, destroyed, of another workspace, or of the other purpose. It has no `details`. |
| `404 not_found`              | The secret or version is not visible to this workspace, or was deleted.                                                      |
| `409 workspace_unavailable`  | The workspace is suspended: reads work, changes are refused.                                                                 |
| `409 deletion_blocked`       | See [Delete](#5-delete).                                                                                                     |