> ## Documentation Index
> Fetch the complete documentation index at: https://weights.fyi/run/llms.txt

# POST /v1/workspaces

```text
POST https://weights.fyi/run/v1/workspaces
Authorization: Bearer <token>                    scope: manage
Content-Type: application/json
{"name": "<workspace>", "trace_preferences": {"log_inputs": false, "log_outputs": false}, "purge_trace_content": true, "models": ["<id>"], "issue_token": {"name": "<name>", "scopes": ["read", "submit"]}, "confidential": "shared" | "dedicated" | {"state": "revoked"}}
```

**Available since:** 2026-10-20 workspace registration from code: included in this build; see [What is live](/run/docs/what-is-live.md) for deployment status.

**Answer time:** synchronous: the workspace, its switches and its endpoints are written and come back.

Finds or creates the workspace named `name` among the key's person's workspaces (case does not matter), sets its trace switches and, as asked, enrolls a trace storage key, binds a confidential mode, removes kept content, creates model endpoints and returns an API token once. Every field is optional; an empty body locks down the key's own workspace. A repeat finds the same workspace: `201` when created, `200` when found.

Both switches default off; kept content is then removed unless `purge_trace_content` is `false`. Fields are checked before any write; tokens are issued only after every model is found. Ambiguous names and workspaces the person merely belongs to are refused.

## Request

| Name | Where | Required | Meaning |
|---|---|---|---|
| `Authorization` | header | yes | `Bearer` and your token, with the `manage` scope. |
| `name` | body | no | The workspace to find or create; the key's own workspace when omitted. |
| `trace_preferences` | body | no | `log_inputs` and `log_outputs`, both booleans; both `false` when omitted. |
| `purge_trace_content` | body | no | Remove kept inputs and outputs; `true` when both switches end off. |
| `models` | body | no | Up to 16 model ids; each gets an endpoint, as [POST /v1/endpoints](/run/docs/reference/endpoints-create.md) makes one. |
| `issue_token` | body | no | `name` and `scopes` of a key of the workspace, shown once; the scopes must be within the calling key's. |
| `cmk` | body | no | Enroll with `tenant_id`, `client_id`, `vault`, `key_name`, `key_version`; omit to keep the binding as it is. `{"state": "revoked"}` revokes it; `null` is refused. `tenant_id` and the dedicated storage identity's `client_id` are lowercase UUIDs; `vault` is 3–24 lowercase ASCII letters, digits or hyphens, starting with a letter, ending with a letter or digit, without consecutive hyphens; `key_name` is 1–127 ASCII letters, digits or hyphens; `key_version` is exactly 32 lowercase hex characters. |
| `confidential` | body | no | `"shared"` or `"dedicated"` binds a confidential mode; `{"state": "revoked"}` ends it; omit to keep it as it is; any other value is refused. It needs an active `cmk` binding (already bound, or enrolled in this call), both trace switches off and no trace destination. `dedicated`: sealed calls are served only by a pool your workspace owns, or a platform pool granted to it. `shared`: also by a pool another workspace shares with yours. Any other pool answers `403 encrypted_envelope_cross_workspace`. |
| `c2` | body | no | Bind an existing workspace's Azure VMs with `tenant_id`, `client_id` (the compute identity, never the `cmk` one), `subscription_id`, `resource_group` and `vms` (1 to 32 distinct VM names); omit to keep the binding as it is, repeat it to keep its `bound_at`. `{"state": "revoked"}` revokes it; `null` is refused. |

CMK enrollment proves wrap and unwrap access before writing anything.

New trace payloads are sealed with AES-256-GCM under fresh data keys that the fixed Key Vault version wraps; envelope bytes count toward retention limits. While the binding is revoked or Key Vault refuses, jobs still run but their content is not kept, and reads answer `403 cmk_key_refused`; every read unwraps live. Repeating enrollment preserves `bound_at` and proves access again. This covers newly retained traces, not earlier plaintext, job execution storage or exported copies. Re-enrolling a usable key restores access to matching envelopes.

While a confidential mode is bound, chat and classify calls must carry `encrypted_envelope`: a plain one answers `400 encrypted_envelope_required`, as every page batch does. Revoking it lifts that at once.

A `c2` binding lets the service start and deallocate VMs already in your subscription, never create or delete one. The compute identity first reads every VM: each must be evictable (`evictionPolicy` `Deallocate` or `Delete`) and tagged `weights.fyi-managed` = `c2` and `weights.fyi-workspace` = the workspace `id`. Each start or deallocation checks again.

## Return value

**200 OK** or **201 Created**: `workspace` as [GET /v1/workspaces](/run/docs/reference/workspaces-get.md) reads it, `created`, `trace_preferences`, `trace_sinks_count`, `governed_tracing`, `purged` (the copies removed, or `null` when no purge was asked), `endpoints` (one per model, as [GET /v1/endpoints/{endpoint}](/run/docs/reference/endpoints-get.md) shows them) and, when asked, `token` with its `note`.

## Errors

| Status | Code | When it happens | What to do |
|---|---|---|---|
| `400` | `invalid_request`, `invalid_json`, `invalid_preferences`, `workspace_name_invalid` | A field is missing, unknown or of the wrong shape. | Send the fields as described. |
| `400` | `invalid_request` | `confidential` is not one of its three values, or a mode is asked without an active `cmk` binding; `field` says `confidential`. | Enroll `cmk` first, or in the same call. |
| `400` | `invalid_preferences` | A confidential mode with a trace switch on or a trace destination present. | Turn both switches off and remove the destinations first. |
| `400` | `model_not_available` | A model in `models` is not one the workspace can run; the workspace and its switches are already written. | Pick ids from `available` and send again. |
| `401` | `unauthorized`, `invalid_token`, `token_revoked`, `token_expired` | No token, or one that does not work. | Use a valid token. |
| `403` | `scope_required` | The token lacks `manage`, or `issue_token` asks a scope it does not hold. | Use a token with `manage`; ask for scopes within it. |
| `403` | `workspace_role_required` | `name` is a workspace the person only belongs to. | Use a workspace the person owns or administers. |
| `400` | `invalid_request` | `c2` names a workspace that does not exist yet, revokes a binding never made, or shares its `client_id` with `cmk`. | Create the workspace and tag its VMs first; give each purpose its own identity. |
| `403` | `cmk_key_refused` | The workload identity cannot prove wrap and unwrap access to the exact version. No binding or token is created. | Check federation, key permissions and the enabled version. |
| `403` | `c2_target_refused` | The compute identity could not read every VM, or one is not evictable or lacks the tags. Nothing is written. | Check its federation, its read access to the VMs, their eviction policy and their tags. |
| `409` | `workspace_name_ambiguous` | Two of the person's workspaces carry `name`. | Rename one in the app, then send again. |
| `409` | `workspace_changed` | The named workspace lost its name while its VMs were being read. | Send again. |

## Examples

```sh
curl -s -X POST https://weights.fyi/run/v1/workspaces \
  -H "Authorization: Bearer $WEIGHTS_API_KEY" -H "Content-Type: application/json" \
  -d '{"name": "awow-io", "trace_preferences": {"log_inputs": false, "log_outputs": false}, "models": ["almanakje-gemma3-12b"]}'
```

```json
{"workspace": {"id": 7, "name": "awow-io", "owner_id": 1, "created_at": "2026-10-20T12:00:00Z", "cmk": null, "c2": null, "confidential": null, "trace_preferences": {"log_inputs": false, "log_outputs": false}, "trace_sinks_count": 0, "governed_tracing": true, "domains": []}, "created": true, "trace_preferences": {"log_inputs": false, "log_outputs": false}, "trace_sinks_count": 0, "governed_tracing": true, "purged": 0, "endpoints": [{"id": "ep_1", "model": "almanakje-gemma3-12b"}]}
```

## History

- 2026-10-20 workspace registration from code: added.
- 2026-10-20 Rung 1: CMK enrollment and revocation for retained trace content.
- 2026-10-20 Mode C2: binding and revocation of a workspace's own Azure VMs.
- 2026-11-16: `confidential` documented.

## See also

- [GET /v1/workspaces](/run/docs/reference/workspaces-get.md) to read the workspace back.
- [PUT /v1/trace-preferences](/run/docs/reference/trace-preferences-put.md) and [DELETE /v1/trace-content](/run/docs/reference/trace-content-delete.md), the switches and the purge on their own.
- [Teams and workspaces](/run/docs/teams.md#register-a-workspace-from-code), the topic.
