# mv.secrets

> The secrets methods of @morevoice/sdk: Secret names available to tools and flows (values are never returned).

Secret names available to tools and flows (values are never returned). These methods are on `mv.secrets`, where `mv` is your client (see [the Node.js SDK](https://docs.morevoice.ai/sdk/node/#connect)). Each one returns the response object and throws when the API answers with an error.

## `delete()`

**Delete a secret.** Flows that still reference {{secret.NAME}} then get an empty value. Needs a live key.

```ts
mv.secrets.delete(name: SecretsDeleteData["path"]["name"], options?: RequestOptions): Promise<SecretsDeleteResponse>
```

`DELETE /secrets/{name}` · [API reference](https://docs.morevoice.ai/api/operations/secrets_delete/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | yes | The secret's name. |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options.headers["Idempotency-Key"]` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

`DeletedSecret`:

| Field | Type | Description |
| --- | --- | --- |
| `object` | `"secret"` | Always `secret`. |
| `name` | `string` | — |
| `deleted` | `true` | — |

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const deletedSecret = await mv.secrets.delete("name_123");
console.log(deletedSecret);
```

## `list()`

**List secrets.** Names and update times only, most recently changed first: values are never returned.

```ts
mv.secrets.list(query?: NonNullable<SecretsListData["query"]>, options?: RequestOptions): PagedList<SecretsListResponse["data"][number], NonNullable<SecretsListData["query"]>>
```

`GET /secrets` · [API reference](https://docs.morevoice.ai/api/operations/secrets_list/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `query.limit` | `integer` | no | How many objects to return, 1–100 (default 20). |
| `query.starting_after` | `string` | no | A cursor (`next_cursor`) or object ID: return the objects after it (older). |
| `query.ending_before` | `string` | no | A cursor or object ID: return the objects before it (newer). |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

A [`PagedList`](https://docs.morevoice.ai/sdk/typescript/pagination/): `await` it for the first page, `for await` it for every item.

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

for await (const secret of mv.secrets.list()) {
	console.log(secret);
}
```

## `set()`

**Create or replace a secret.** Sets the value of {{secret.NAME}} (creating it, or replacing the value). Write-only: the value is encrypted at rest and never returned. Flows and providers pick the new value up within seconds. Needs a live key.

```ts
mv.secrets.set(name: SecretsSetData["path"]["name"], body: SecretsSetData["body"], options?: RequestOptions): Promise<SecretsSetResponse>
```

`PUT /secrets/{name}` · [API reference](https://docs.morevoice.ai/api/operations/secrets_set/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | yes | The secret's name. |
| `body.value` | `string` | yes | The value (up to 8 KB). Write-only: it is encrypted at rest and never returned. |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

`Secret`:

| Field | Type | Description |
| --- | --- | --- |
| `object` | `"secret"` | Always `secret`. |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `name` | `string` | Referenced as {{secret.NAME}} in flow API nodes and messaging settings. |
| `updated` | `string` | An ISO-8601 timestamp in UTC. |

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const secret = await mv.secrets.set("name_123", {
	value: "sk_live_…",
});
console.log(secret);
```
