---
# @generated by sylphx-gen. Do not edit.
title: "Create key in Workload tenants"
description: "`access.workload_tenants.create_key` (POST /v1/access/workload/tenants/{external_tenant_id}/keys): Creates an environment key and returns HTTP 201."
type: reference
product: platform
summary: "Creates an environment key and returns HTTP 201."
nav: false
---

Creates an environment key and returns HTTP 201. Idempotency-Key is required. A replay within 24 hours returns key metadata without plaintext.

- **Path** `POST https://api.sylphx.com/v1/access/workload/tenants/external-tenant-id/keys`
- **Scope** `access:whoami`
- **Effect** `write` — a successful call changes state.
- **Collection** [workload_tenants](/docs/api/workload_tenants)
- **Host** `https://api.sylphx.com`

## Request

| Field | Type | What it is |
| --- | --- | --- |
| `external_tenant_id` | `string` | Workspace ID in the calling workload's namespace. Required. |
| `label` | `string` | Display label for the key. Required. |
| `scopes` | `string[]` | Nonempty scope set. Any scope outside the grant's ceiling is refused. Required. |

## Response

| Field | Type | What it is |
| --- | --- | --- |
| `key` | `WorkloadTenantKey` | Issued key's metadata. |
| `secret` | `string` | Plaintext credential (never returned on replay). Never returned again. |

### WorkloadTenantKey

| Field | Type | What it is |
| --- | --- | --- |
| `key_id` | `string` | Credential ID, not its secret value. |
| `label` | `string` | Caller-supplied label. |
| `scopes` | `string[]` | Exact scopes the key carries (including a registered aggregate, if requested). |
| `created_at` | `timestamp` | Key issuance time. |
| `revoked_at` | `timestamp` | Key revocation time, absent for a live key. |

## Errors

- [`UNAUTHENTICATED`](/docs/api/errors/UNAUTHENTICATED) — No valid key or token was presented.
- [`PERMISSION_DENIED`](/docs/api/errors/PERMISSION_DENIED) — The key lacks the method's permission.
- [`RESOURCE_NOT_FOUND`](/docs/api/errors/RESOURCE_NOT_FOUND) — The named Resource does not exist or is not visible.
- [`INVALID_FIELD`](/docs/api/errors/INVALID_FIELD) — A field failed validation.
- [`IDEMPOTENCY_KEY_REUSED`](/docs/api/errors/IDEMPOTENCY_KEY_REUSED) — An Idempotency-Key was reused with another body.

Every error arrives in the body [Errors](/docs/platform/errors) describes.

## Examples

**cURL**

```curl
curl -X POST "https://api.sylphx.com/v1/access/workload/tenants/external-tenant-id/keys" \
  -H "Authorization: Bearer $SYLPHX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label":"…","scopes":["…"]}'
```

**TypeScript**

```ts
const response = await sylphx.access.workloadTenants.createKey({ externalTenantId: 'external-tenant-id', label: '…', scopes: ['…'] })
```

**Rust**

```rust
let mut req = sylphx::access::CreateWorkloadTenantKeyRequest::default();
req.external_tenant_id = "external-tenant-id".to_string();
req.label = "…".to_string();
req.scopes = vec!["…".to_string()];
let response = sx.access().workload_tenants().create_key(req).await?;
```

**MCP**

```json
{ "method_id": "access.workload_tenants.create_key", "args": {"external_tenant_id":"external-tenant-id","label":"…","scopes":["…"]} }
```
