---
docId: doc_f79d172ff1264137a6e4e3b8c049a4bb
title: 'Secrets'
description: Store credentials encrypted in the workspace and bind them to slots of your custom APIs, MCP servers, and webhooks without exposing them.
---

<script>
  import { Ways } from '$lib/components';
</script>

# Secrets

Store an API key, token, password or signing key without putting its value in your resource configuration. [Create the secret](/api-reference/secrets/create) once and bind its `id` to a custom API, MCP server or webhook **slot**. Platica stores the encrypted value in the workspace.

## Quick example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
# 1. Create the secret
curl -X POST https://api.platic.ai/v1/secrets \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "ERP token", "kind": "bearer", "value": "my-secret-token"}'

# 2. Bind it to a slot
curl -X POST https://api.platic.ai/v1/tools/apis/$API_ID/secrets \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"slot": "auth.token", "secretId": "'"$SECRET_ID"'"}'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
// 1. Create the secret (the value goes in here and no operation returns it)
const secret = await platic.secrets.create({
  name: 'ERP token',
  kind: 'bearer',
  value: process.env.ERP_TOKEN!
});

// 2. Bind it to a slot of your API, MCP server, or webhook
await platic.tools.apis.bindSecret(apiId, { slot: 'auth.token', secretId: secret.id });

// 3. To rotate the credential without changing configurations
await platic.secrets.rotate(secret.id, process.env.ERP_NEW_TOKEN!);
```

</Ways.Way>
</Ways>

## What you need to know

- **The value goes in and never comes out:** it is only sent when you [create](/api-reference/secrets/create) or [rotate](/api-reference/secrets/rotate). If you lose it, rotate the secret.
- **Common slots:** `auth.token`, `auth.password`, `auth.value`, `encryptPayload.key`, `auth.clientSecret`, `webhook.secret`, `header:<lowercase-name>`, and `variable:<name>`. You can also bind when you create or edit the resource by sending `"secrets": { "<slot>": "<secretId>" }`.
- **Authorization per destination (`https`):** when you bind, the secret is authorized only for the resource's current `https` origin. If you edit an API or MCP server (or change a webhook's domain), the slot goes to `needs_authorization` and you must bind it again.
- **Secret states:** `active` (usable until `expiresAt`), `revoked` (blocked, record kept), and `deleting`.
- **Permissions:** with an API key you have full access; with OAuth, the secrets permissions apply (view, manage, and use) plus `platica:write`.

## Slot states

| `state` | What it means | What to do |
|---------|---------------|------------|
| `authorized` | Secret bound and ready | Nothing |
| `needs_authorization` | The configuration changed, or the secret was revoked or deleted | Bind the slot again |
| `missing` | A secret has not been bound | Bind one |
| `legacy` | Credential stored in the previous format (still works) | Optional: migrate to a secret |
| `bound` | Bound without checking authorization (only in reads with a limited role) | Nothing |

## Endpoints

| Method | Endpoint | What it does |
|--------|----------|--------------|
| `GET` | [`/v1/secrets`](/api-reference/secrets/list) | List the workspace's secrets |
| `POST` | [`/v1/secrets`](/api-reference/secrets/create) | Create a secret |
| `GET` | [`/v1/secrets/{secretId}`](/api-reference/secrets/get) | See metadata and where it is used |
| `PATCH` | [`/v1/secrets/{secretId}`](/api-reference/secrets/update) | Change the name or expiration |
| `POST` | [`/v1/secrets/{secretId}/rotate`](/api-reference/secrets/rotate) | Replace the value |
| `POST` | [`/v1/secrets/{secretId}/revoke`](/api-reference/secrets/revoke) | Revoke without deleting the record |
| `DELETE` | [`/v1/secrets/{secretId}`](/api-reference/secrets/delete) | Delete the secret and its authorizations |

## Errors

Errors follow the format in [Errors](/api-reference/errors): `{ code, error, details: { code, message, ... } }`. These are the `details.code` values of this section; each page says which ones it can answer.

| Status | `details.code` | When it happens |
|--------|----------------|-----------------|
| `400` | `INVALID_REQUEST` | The body or parameters fail validation, or the credential covers several workspaces and `workspace` is missing. `details.issues` has the list of problems |
| `401` | `UNAUTHENTICATED` | The credential is missing, revoked, or expired |
| `400` | `INVALID_EXPIRY` | `expiresAt` is not in the future |
| `400` | `INVALID_CURSOR` | `pageToken` is not a `nextPageToken` of this list |
| `403` | `FORBIDDEN` | The person behind the token cannot manage secrets |
| `404` | `SECRET_NOT_FOUND` | The secret does not exist in this workspace or was already deleted |
| `409` | `SECRET_CHANGED` | Another change arrived at the same time. Repeat the call |
| `409` | `SECRET_USE_REVOKED` | The secret is revoked, expired, or being deleted |
| `503` | `SECRET_KEYRING_UNAVAILABLE` | The secrets store is not responding. Try later |
| `503` | `OPERATION_UNCONFIRMED` | The change could not be confirmed. [Get the secret](/api-reference/secrets/get) before retrying |

AI tools are in [Secrets MCP](/mcp/tools#secrets).
