---
docId: doc_3142750faf4b4739a5a21277ee2aa611
title: Bind a secret to a function
description: "Bind an existing secret to a function slot."
api:
  group: herramientas/funciones-personalizadas
  auth: bearer
  operations:
    - operationId: bindFunctionSecret
      method: POST
      path: '/v1/tools/functions/{functionId}/secrets'
      postmanName: Bind a secret to a function
---

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

# Bind a secret to a function

Bind an existing secret to a slot in `secretSlots`. Use this when a slot in `secrets[]` is `missing`. Send the secret's `id`, not its value.

## Example

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

```bash
curl -X POST "https://api.platic.ai/v1/tools/functions/$FUNCTION_ID/secrets" \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "slot": "API_KEY",
  "secretId": "'"$SECRET_ID"'"
}'
```

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

```ts
await platic.tools.functions.bindSecret("fn_123", { slot: "API_KEY", secretId: "sec_123" });
```

</Ways.Way>
</Ways>

## Path parameters

| Parameter | Type | Description | Required |
|-----------|------|-------------|----------|
| `functionId` | string | Function ID | ✓ |

## Request body

```json
{
  "slot": "API_KEY",
  "secretId": "5d0c7a1e9b3f4a6c8e2d1f0b7a9c3e5d6f8a0b2c4d6e8f1a3b5c7d9e0f2a4b6c"
}
```

| Field | Type | Description | Required |
|-------|------|-------------|----------|
| `slot` | string | A declared slot, like `API_KEY`. `secret:API_KEY` is also accepted | ✓ |
| `secretId` | string | Secret ID, from [List secrets](/api-reference/secrets/list) or [Create a secret](/api-reference/secrets/create) | ✓ |

## Response

`data` has the complete function, with the fields of [Get a function](/api-reference/custom-functions/get#response-fields). The slot ends up in `bound`.

```json
{
  "status": "success",
  "message": "Secret bound",
  "data": {
    "id": "Hk2s9QmXc1",
    "name": "tax_id_lookup",
    "status": "draft",
    "toolName": "fn_tax_id_lookup",
    "toolId": null,
    "secrets": [
      {
        "slot": "API_KEY",
        "origin": "https://api.example.com",
        "state": "bound",
        "secretId": "5d0c7a1e9b3f4a6c8e2d1f0b7a9c3e5d6f8a0b2c4d6e8f1a3b5c7d9e0f2a4b6c"
      }
    ],
    "nextStep": "Test it with POST /v1/tools/functions/Hk2s9QmXc1/test, then publish it."
  }
}
```

Some fields are left out of the example.

## Errors

| Status | `details.code` | When |
|--------|----------------|------|
| `400` | `INVALID_REQUEST` | `slot` or `secretId` is missing, or the slot is not declared. `details.issues` has the list of problems |
| `403` | `FORBIDDEN` or `INSUFFICIENT_SCOPE` | The credential cannot use secrets or does not have write access to Integrations |
| `404` | `NOT_FOUND` | The function or the secret does not exist in this workspace |
| `501` | `FUNCTION_SECRETS_UNAVAILABLE` | Binding secrets is not available at the moment |

## Notes

- The secret is authorized only for that slot's `origin`. Platica puts it in `http.fetch` calls to that origin; the code only sees a placeholder.
- Binding another secret to the same slot replaces the previous one.
- If you later change `allowedDomains` or `secretSlots` with [Update a function](/api-reference/custom-functions/update), bind the secrets again.
- The same secret can be bound to several functions and to other tools.
