# Prompts API

## Inspect declared and effective scoped prompt delegation

`GET /api/v1/admin/prompt-delegations` · operation `getPromptDelegations`

Global administrator only. This policy never grants membership or custom-role authority. Scoped action switches and team/organization plans remain separate ceilings. Responses are private, no-store.

**Authentication:** `adminSession`

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Bounded policy, finite action catalog, sources and current write capability; no prompt content or credential. | `application/json`: [PromptDelegationCatalog](/docs/api/schemas/p/#promptdelegationcatalog) |
| `400` | Malformed, duplicate, unknown or noncanonical fields | — |
| `401` | Console session required | — |
| `403` | Global administrator and current classified write rights required | — |
| `404` | Management feature unavailable | — |
| `409` | Stale global version, changed declared base or reference conflict; review and reload | — |
| `422` | Invalid delegation or owner-team reference | — |
| `503` | Storage or post-commit synchronization unavailable | — |


## Replace the complete prompt delegation override

`PUT /api/v1/admin/prompt-delegations` · operation `putPromptDelegations`

Global administrator only. This policy never grants membership or custom-role authority. Scoped action switches and team/organization plans remain separate ceilings. Responses are private, no-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: [PromptDelegationWrite](/docs/api/schemas/p/#promptdelegationwrite)

**Responses**

| Status | Description | Body |
|---|---|---|
| `204` | Committed; GET a fresh catalog before another mutation. | — |
| `400` | Malformed, duplicate, unknown or noncanonical fields | — |
| `401` | Console session required | — |
| `403` | Global administrator and current classified write rights required | — |
| `404` | Management feature unavailable | — |
| `409` | Stale global version, changed declared base or reference conflict; review and reload | — |
| `413` | Request exceeds the bounded policy body limit. | — |
| `422` | Invalid delegation or owner-team reference | — |
| `503` | Storage or post-commit synchronization unavailable | — |


## Remove the override and restore the admitted declared policy

`DELETE /api/v1/admin/prompt-delegations` · operation `revertPromptDelegations`

Global administrator only. This policy never grants membership or custom-role authority. Scoped action switches and team/organization plans remain separate ceilings. Responses are private, no-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: [PromptDelegationGuard](/docs/api/schemas/p/#promptdelegationguard)

**Responses**

| Status | Description | Body |
|---|---|---|
| `204` | Committed; GET a fresh catalog before another mutation. | — |
| `400` | Malformed, duplicate, unknown or noncanonical fields | — |
| `401` | Console session required | — |
| `403` | Global administrator and current classified write rights required | — |
| `404` | Management feature or override unavailable | — |
| `409` | Stale global version, changed declared base or reference conflict; review and reload | — |
| `413` | Request exceeds the bounded policy body limit. | — |
| `422` | Invalid delegation or owner-team reference | — |
| `503` | Storage or post-commit synchronization unavailable | — |


## Adopt a reviewed declared prompt delegation base

`POST /api/v1/admin/prompt-delegations/adopt-base` · operation `adoptPromptDelegationBase`

Global administrator only. This policy never grants membership or custom-role authority. Scoped action switches and team/organization plans remain separate ceilings. Responses are private, no-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: [PromptDelegationGuard](/docs/api/schemas/p/#promptdelegationguard)

**Responses**

| Status | Description | Body |
|---|---|---|
| `204` | Committed; GET a fresh catalog before another mutation. | — |
| `400` | Malformed, duplicate, unknown or noncanonical fields | — |
| `401` | Console session required | — |
| `403` | Global administrator and current classified write rights required | — |
| `404` | Management feature unavailable | — |
| `409` | Stale global version, changed declared base or reference conflict; review and reload | — |
| `413` | Request exceeds the bounded policy body limit. | — |
| `422` | Invalid delegation or owner-team reference | — |
| `503` | Storage or post-commit synchronization unavailable | — |


## GET /api/v1/admin/prompts

`GET /api/v1/admin/prompts` · operation `promptsList`

prompt_registry and prompts:read required. Global admin sees metadata including retained tombstones. With prompt_scoped_read, named user/team_viewer/team_admin sees only enabled prompts owned by active memberships intersected with ingress memberships, filtered in SQL before pagination and YAML merge. Any persisted/current YAML fingerprint mismatch hides the ID from scoped reads. No template bodies or variables in inventory; no implicit inference integration. With prompt_entitlements enabled, scoped reads additionally require the owning team plan right prompt_scoped_read in the same transaction. Unentitled teams are filtered before pagination and YAML merge; list may be empty, individual reads return 404, storage/serialization failure returns 503. Global admin and mutation/render permissions remain independent.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `offset` | query | integer, default `0`, min 0, max 1000 | Prompts to skip before this page (0-1000). |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Up to 50 metadata entries; private, no-store. | `application/json`: [PromptInventory](/docs/api/schemas/p/#promptinventory) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |


## GET /api/v1/admin/prompts/{id}

`GET /api/v1/admin/prompts/{id}` · operation `promptsDetail`

Explicit private template detail. Global admin or opt-in prompt_scoped_read with prompts:read and current active owner membership required; foreign, disabled, deleted or base-changed resources return 404 to scoped callers. Values used for rendering are never stored. YAML without a stored revision is an unpublished draft with resource version/revision zero. base_fingerprint is the current YAML fingerprint, empty for console-only entries. With prompt_entitlements enabled, scoped reads additionally require the owning team plan right prompt_scoped_read in the same transaction. Unentitled teams are filtered before pagination and YAML merge; list may be empty, individual reads return 404, storage/serialization failure returns 503. Global admin and mutation/render permissions remain independent.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Draft definition and metadata, private/no-store. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature or prompt unavailable | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `entry` ([PromptEntry](/docs/api/schemas/p/#promptentry), required)
  - `prompt` ([PromptDefinition](/docs/api/schemas/p/#promptdefinition), required)
  - `published_revision` (integer or null, required, min 1, max 100)


## PUT /api/v1/admin/prompts/{id}

`PUT /api/v1/admin/prompts/{id}` · operation `promptsSave`

Global administrator and prompt_management required. Creates an immutable draft revision, never implicitly publishes. Owner team is immutable, must be active, and new IDs/revisions are bounded to 1000/100. Requires same origin and CSRF. YAML change must be explicitly reviewed via expected_base_fingerprint. JSON max 256 KiB, unique keys, UTF-8, unknown fields rejected. Existing global administrator behavior is preserved. With prompt_scoped_write, existing named user/team_admin writers additionally need the owner team's explicit prompts:write delegation, current custom ceiling and applicable plan/license. Scoped saves are draft-only: no disable, resurrection, implicit publication withdrawal or YAML drift reconciliation. Live ownership is checked before scoped base/version diagnostics; foreign IDs remain404.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: [PromptMutationGuard](/docs/api/schemas/p/#promptmutationguard) and object
  - All of (1): [PromptMutationGuard](/docs/api/schemas/p/#promptmutationguard)
  - All of (2): object
    - `prompt` ([PromptDefinition](/docs/api/schemas/p/#promptdefinition), required)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | New resource version and current_revision, private/no-store | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `409` | Resource version, base fingerprint, ownership, inactive owner or capacity conflict | — |
| `413` | JSON exceeds 256 KiB | — |
| `422` | Unsupported template/profile or invalid variables schema | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |


## DELETE /api/v1/admin/prompts/{id}

`DELETE /api/v1/admin/prompts/{id}` · operation `promptsRevert`

Global administrator and prompt_management required. Requires CSRF. Restores the current YAML as a new unpublished revision, or retains a console-only tombstone/history with immutable owner. Never automatically publishes a previous base or physically deletes history. Scoped user/team_admin additionally require explicit prompts:delete delegation and prompt_scoped_write. Withdrawing an existing publication also requires prompts:publish, prompt_scoped_publish and the applicable plan rights. Scoped drift/recovery and operator-bound publication invalidation are refused; foreign IDs remain404 before same-owner diagnostics. Availability transitions atomically advance the shared control version to fence pre-admitted model writers.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: [PromptMutationGuard](/docs/api/schemas/p/#promptmutationguard)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Resource version and lifecycle result, private/no-store | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature or prompt unavailable | — |
| `409` | Version, fingerprint, owner or revision capacity conflict | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |


## GET /api/v1/admin/prompts/{id}/versions

`GET /api/v1/admin/prompts/{id}/versions` · operation `promptsVersions`

prompt_registry and prompts:read required. Global admin or opt-in active team-scoped reader. At most 100 immutable revision metadata entries, without template bodies; scoped responses omit administrative actor/request_id. Current disabled/deleted/inactive-owner/base-changed resources return 404 scoped; private/no-store. With prompt_entitlements enabled, scoped reads additionally require the owning team plan right prompt_scoped_read in the same transaction. Unentitled teams are filtered before pagination and YAML merge; list may be empty, individual reads return 404, storage/serialization failure returns 503. Global admin and mutation/render permissions remain independent.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Revision metadata and effective entry. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature or prompt unavailable | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `items` (array of [PromptRevision](/docs/api/schemas/p/#promptrevision), required, max items 100)
  - `entry` ([PromptEntry](/docs/api/schemas/p/#promptentry), required)


## GET /api/v1/admin/prompts/{id}/versions/{revision}

`GET /api/v1/admin/prompts/{id}/versions/{revision}` · operation `promptsVersion`

Explicit historical body read, prompt_registry and prompts:read required; private/no-store. Global admin can read after logical deletion. Opt-in scoped readers require current enabled resource, active immutable owner membership and matching YAML fingerprint; foreign/revision ownership mismatch returns 404. Scoped responses omit administrative actor/request_id. No render or publication rights. With prompt_entitlements enabled, scoped reads additionally require the owning team plan right prompt_scoped_read in the same transaction. Unentitled teams are filtered before pagination and YAML merge; list may be empty, individual reads return 404, storage/serialization failure returns 503. Global admin and mutation/render permissions remain independent.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `revision` | path | integer, required, min 1, max 100 |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Immutable definition with revision metadata. | `application/json`: [PromptRevision](/docs/api/schemas/p/#promptrevision) and object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature, prompt or revision unavailable | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: [PromptRevision](/docs/api/schemas/p/#promptrevision) and object
  - All of (1): [PromptRevision](/docs/api/schemas/p/#promptrevision)
  - All of (2): object
    - `prompt` ([PromptDefinition](/docs/api/schemas/p/#promptdefinition))


## GET /api/v1/admin/prompts/{id}/metrics

`GET /api/v1/admin/prompts/{id}/metrics` · operation `promptMetrics`

Prompt revision on traffic (T186.013). Requires prompt_registry, prompt_tracking and usage_analytics, a session that may read the prompt (a global administrator, or a member of the owning team with prompt_scoped_read) and analytics:read; under feature_plan_entitlements the owning team's plan must include prompt_tracking (403 entitlement_forbidden). Reads the requests of the prompt's team that recorded the prompt, in the organization the team is in now, over from/to (RFC 3339, at most 90 days; default the last 24 hours): per revision (0 is a request that named the prompt without one) the requests, errors, error rate, average, p50 and p95 latency, input and output tokens, the known cost with priced and unpriced requests (usage_valuation; unknown cost is never zero) and the requests per source (rendered, declared, system); a daily series per revision; with evaluation_results and evals:read, the results of every evaluator per revision (results, pass, fail, pass_rate over pass plus fail, mean_score), from both result engines; with evals and evals:read, the experiments of the team that ran the prompt. A prompt the session may not read answers 404 prompt_not_found. Private, no-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `from` | query | string (date-time) |  |
| `to` | query | string (date-time) |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | The prompt's traffic per revision. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | prompt_tracking, usage_analytics or the registry is off (feature_disabled), or the prompt is not readable (prompt_not_found) | — |
| `422` | The read ran past its time limit (query_too_costly) | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `prompt_id` (string, required)
  - `team` (string, required)
  - `from` (string (date-time), required)
  - `to` (string (date-time), required)
  - `cost_visible` (boolean, required) — usage_valuation is on: cost_usd, priced_requests and unpriced_requests are read
  - `truncated` (boolean, required)
  - `revisions` (array of object, required)
    - `revision` (integer, required, min 0, max 100)
    - `requests` (integer, required)
    - `errors` (integer, required)
    - `error_rate` (number, required)
    - `avg_latency_ms` (number, required)
    - `p50_latency_ms` (number, required)
    - `p95_latency_ms` (number, required)
    - `input_tokens` (integer, required)
    - `output_tokens` (integer, required)
    - `cost_usd` (string) — Exact decimal sum of the known valuations
    - `priced_requests` (integer, required)
    - `unpriced_requests` (integer, required)
    - `sources` (object, required) — Requests per source: rendered, declared, system
      - any other key: integer
  - `series` (array of object, required)
    - `day` (string, required)
    - `revision` (integer, required)
    - `requests` (integer, required)
  - `evaluations` (array of object)
    - `revision` (integer, required)
    - `evaluation` (string, required)
    - `evaluator_id` (string)
    - `results` (integer, required)
    - `pass` (integer, required)
    - `fail` (integer, required)
    - `pass_rate` (number or null, required)
    - `mean_score` (number or null, required)
  - `evaluations_error` (string, one of `"invalid_query"`, `"unavailable"`)
  - `experiments` (array of object)
    - `id` (string, required)
    - `name` (string, required)
    - `prompt_revision` (integer, required)
    - `status` (string, required)
    - `total` (integer, required)
    - `done` (integer, required)
    - `created_at` (string (date-time), required)


## POST /api/v1/admin/prompts/{id}/versions/{revision}/render

`POST /api/v1/admin/prompts/{id}/versions/{revision}/render` · operation `promptsRenderRevision`

Prompt variants in the Playground (T186.013b). Requires playground, playground_prompts, playground_prompt_variants and prompt_registry, prompts:read, CSRF, and a session that may read the prompt (a global administrator, or a member of the owning team with prompt_scoped_read); a typed revision also needs prompt_json_schema. Renders any stored revision, published or not, locally in one pass: no provider call, nothing persisted or logged. The Playground's Compare sends each rendered column with X-Gateway-Prompt-Id and X-Gateway-Prompt-Revision declared. Four concurrent heavy operations per process. A prompt or revision the session may not read answers 404 prompt_not_found. Private, no-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `revision` | path | integer, required, min 1, max 100 |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `variables` (object) — Values are validated by the revision's schema profile; flat_strings_v1 requires strings.
    - any other key: any

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Rendered messages, not a model inference response. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | A flag is off (feature_disabled), or the prompt or revision is not readable (prompt_not_found) | — |
| `422` | Variables violate the revision's profile or output bounds | — |
| `503` | Storage unavailable or local heavy-operation capacity reached | — |

Response `200` fields:

- `application/json`: object
  - `id` (string, required)
  - `team` (string, required)
  - `revision` (integer, required)
  - `content_hash` (string, required)
  - `messages` (array of [PromptMessage](/docs/api/schemas/p/#promptmessage), required, max items 32)


## GET /api/v1/admin/prompts/{id}/requests/{request_id}/variables

`GET /api/v1/admin/prompts/{id}/requests/{request_id}/variables` · operation `promptRequestVariables`

Reopen a request in the Playground (T186.013b). Requires playground, playground_prompts, playground_prompt_variants, prompt_registry and prompt_tracking, and the sent content view (content_sent:read) of the request's team. The request must be one the session may read (its teams, or its organization for an organization administrator) and must have recorded this prompt with a revision. Answers the revision and the variables read back from the request's captured sent messages against that revision's template; reading the capture is a content read whose audit row (content_capture.read) is committed before the content is decrypted; a failed audit returns 503 and nothing. When the content was not captured, was truncated, or does not follow the template, variables is empty and missing says why. Private, no-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `request_id` | path | string, required, max length 128 |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | The request's prompt revision and variables. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | The session cannot read the sent content of the request's team (content_forbidden) | — |
| `404` | A flag is off (feature_disabled), or no request of the session's teams recorded this prompt revision (request_not_found) | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `prompt_id` (string, required)
  - `revision` (integer, required, min 1, max 100)
  - `source` (string, required, one of `"rendered"`, `"declared"`, `"system"`)
  - `team` (string, required)
  - `request_id` (string, required)
  - `variables` (object, required)
    - any other key: string
  - `missing` (string) — Why no variables were read back


## POST /api/v1/admin/prompts/{id}/versions/{revision}/improve

`POST /api/v1/admin/prompts/{id}/versions/{revision}/improve` · operation `promptImprove`

Improve (T186.013b). Requires prompt_improve, prompt_registry and prompt_management, prompts:manage, CSRF and a session that may save the prompt (a global administrator, or a member of the owning team with prompt_scoped_write whose current delegation lets it write the prompt, 403 prompt_action_forbidden otherwise); under plan entitlements the owning team's plan must include prompt_improve (403 entitlement_forbidden). Sends the revision's messages, its declared variables and the optional note to the chat alias the owning team chose (409 improve_not_configured without one; there is no default) as a helper call of that team (helper_kind prompt_improve, parent the console request), recorded and priced like every call. Answers the suggested messages only when they keep the same number of messages and roles, use every declared variable and add none (422 improve_unusable otherwise). Nothing is saved: accepting is an ordinary PUT of the prompt, a new draft. Private, no-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `revision` | path | integer, required, min 1, max 100 |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `note` (string, max length 2000)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | The suggestion. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | A flag is off (feature_disabled), or the prompt or revision is not one the session may improve (prompt_not_found) | — |
| `409` | The team chose no alias (improve_not_configured), or its alias is no longer an enabled chat alias (improve_model_unavailable) | — |
| `422` | The model's answer is not a usable revision (improve_unusable) | — |
| `502` | The team's call was refused or failed (improve_failed); only its status and error code are relayed | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `id` (string, required)
  - `team` (string, required)
  - `revision` (integer, required)
  - `model` (string, required)
  - `request_id` (string, required) — The helper call's request ID
  - `messages` (array of [PromptMessage](/docs/api/schemas/p/#promptmessage), required, max items 32)
  - `rationale` (string, required, max length 2000)


## GET /api/v1/admin/prompt-improve

`GET /api/v1/admin/prompt-improve` · operation `promptImproveSettings`

The Improve alias of each team the session reads (every team for a global administrator) and the teams whose choice it may change. Requires prompt_improve, prompt_registry and prompts:read.

**Authentication:** `adminSession`

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Choices. | `application/json`: object |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | A flag is off (feature_disabled) | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `items` (array of object, required)
    - `team` (string, required)
    - `model` (string, required)
    - `updated_at` (string (date-time), required)
    - `updated_by` (string)
  - `all_teams` (boolean, required)
  - `manage_teams` (array of string, required)


## PUT /api/v1/admin/prompt-improve/{team}

`PUT /api/v1/admin/prompt-improve/{team}` · operation `setPromptImproveModel`

Chooses a team's Improve alias: an enabled chat alias that is not an automatic route. A global administrator, or an administrator of the team with prompt_scoped_write; prompts:manage and CSRF. Audited (prompt_improve.set).

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `team` | path | string, required, max length 128 |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `model` (string, required, max length 256)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | The choice. | `application/json`: object |
| `400` | Not an enabled chat alias (invalid_model) | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Not a global administrator or an administrator of the team (team_forbidden) | — |
| `404` | A flag is off, or the team does not exist | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `team` (string, required)
  - `model` (string, required)


## DELETE /api/v1/admin/prompt-improve/{team}

`DELETE /api/v1/admin/prompt-improve/{team}` · operation `deletePromptImproveModel`

Removes a team's choice, and with it Improve for that team. Same rights as the choice; audited (prompt_improve.delete).

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `team` | path | string, required, max length 128 |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Responses**

| Status | Description | Body |
|---|---|---|
| `204` | Removed. | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Not a global administrator or an administrator of the team (team_forbidden) | — |
| `404` | A flag is off, or the team has no choice to remove (not_found; nothing is audited) | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |


## GET /api/v1/admin/prompts/{id}/labels

`GET /api/v1/admin/prompts/{id}/labels` · operation `promptLabels`

Prompt labels (T186.013b). Requires prompt_labels and prompt_registry, prompts:read and a session that may read the prompt (a global administrator, or a member of the owning team with prompt_scoped_read). The labels of the prompt, each pointing at one revision, and whether this session may move them (can_deploy: the team's plan includes prompt_labels and, for a member, the current delegation lets the team publish the prompt). A prompt the session may not read answers 404 prompt_not_found.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Labels. | `application/json`: object |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | A flag is off (feature_disabled), or the prompt is not readable (prompt_not_found) | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `prompt_id` (string, required)
  - `team` (string, required)
  - `can_deploy` (boolean, required)
  - `labels` (array of [PromptLabel](/docs/api/schemas/p/#promptlabel), required, max items 20)


## PUT /api/v1/admin/prompts/{id}/labels/{label}

`PUT /api/v1/admin/prompts/{id}/labels/{label}` · operation `deployPromptLabel`

Deploy to (T186.013b). Requires prompt_labels, prompt_registry and prompt_management, prompts:manage and CSRF, and the right to publish the prompt: a global administrator, or a member of the owning team (prompt_scoped_write) whose current delegation lets the team publish it (403 prompt_action_forbidden otherwise); under plan entitlements the team's plan must include prompt_labels. Moves the label (or creates it) to a stored revision of the prompt, or to the revision another label points at (promoting staging to production), in one transaction with an audit row (prompt_label.deploy) and the prompt_label_deployed event (label, revision, previous revision, team, organization) for the alert channels and the prompts signal of the alert rules. A disabled revision, or one made on another YAML base, is refused (409). expected_revision (0: the label must be new) or expected_version guards against a move made meanwhile (409 label_moved). The same proof as a publication is made again in the transaction (the actor, the current delegation and license). Deploying a label to the revision it already has changes nothing and reports nothing. Deleting or reverting the prompt removes its labels, and a team member then needs the publish right as for a published prompt. At most 20 labels per prompt (409 label_capacity).

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `label` | path | string, required, pattern `^[a-z][a-z0-9_-]{0,31}$` |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `revision` (integer, min 1, max 100)
  - `from_label` (string, pattern `^[a-z][a-z0-9_-]{0,31}$`) — Copy the revision this other label points at; exactly one of revision and from_label
  - `expected_revision` (integer, min 0, max 100)
  - `expected_version` (integer, min 0) — The label's version the caller saw (0: new); unlike expected_revision it also catches a move away and back

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | The label after the move. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | No right to publish the prompt (prompt_action_forbidden), or the plan lacks prompt_labels (entitlement_forbidden) | — |
| `404` | A flag is off, the prompt is not readable, or the revision or from_label does not exist | — |
| `409` | label_moved, label_capacity, base_changed or prompt_unavailable | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `prompt_id` (string, required)
  - `team` (string, required)
  - `label` ([PromptLabel](/docs/api/schemas/p/#promptlabel), required)
  - `previous_revision` (integer, required, min 0, max 100) — 0 when the label is new


## DELETE /api/v1/admin/prompts/{id}/labels/{label}

`DELETE /api/v1/admin/prompts/{id}/labels/{label}` · operation `removePromptLabel`

Removes a label (same rights as Deploy to), audited (prompt_label.remove). Requests rendering by it then get 404. A label the prompt does not have is 404 label_not_found and writes nothing.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `label` | path | string, required, pattern `^[a-z][a-z0-9_-]{0,31}$` |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Responses**

| Status | Description | Body |
|---|---|---|
| `204` | Removed. | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | No right to publish the prompt | — |
| `404` | A flag is off, the prompt is not readable, or it has no such label | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |


## GET /api/v1/admin/prompt-tracking

`GET /api/v1/admin/prompt-tracking` · operation `promptTrackingSettings`

The effective prompt_tracking block (T186.013; YAML, read at startup) with where each value comes from, the headers an inference request names a prompt revision with, and the prompt events. Requires prompt_tracking or prompt_events, and config:read.

**Authentication:** `adminSession`

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Effective settings. | `application/json`: object |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | prompt_tracking and prompt_events are off | — |

Response `200` fields:

- `application/json`: object
  - `features` (object, required)
    - any other key: boolean
  - `prompt_tracking` ([PromptTrackingConfig](/docs/api/schemas/p/#prompttrackingconfig), required)
  - `sources` (object, required) — Where each value of prompt_tracking comes from
    - any other key: string
  - `headers` (object, required)
    - any other key: string
  - `events` (array of string, required)


## POST /api/v1/admin/prompts/{id}/publish

`POST /api/v1/admin/prompts/{id}/publish` · operation `promptsPublish`

Global administrator, prompt_management, active immutable owner and CSRF required. Selects an existing revision bound to the current YAML fingerprint; revision zero materializes and explicitly publishes a YAML base only when no PostgreSQL state exists. Publication changes resource version, not historical content. No provider calls. Scoped user/team_admin require explicit prompts:publish delegation, prompt_scoped_write and prompt_scoped_publish plus current custom/plan/license ceilings. They may only select an existing owned revision &gt;=1; revision0 remains global-admin-only. Scoped invalidation of an operator-enforced system_prompt reference is refused. An actual availability transition also advances the shared control version atomically; an unchanged revision does not.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: [PromptMutationGuard](/docs/api/schemas/p/#promptmutationguard) and object
  - All of (1): [PromptMutationGuard](/docs/api/schemas/p/#promptmutationguard)
  - All of (2): object
    - `revision` (integer, required, min 0, max 100)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Resource version, current_revision and published_revision, private/no-store | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature, prompt or revision unavailable | — |
| `409` | Version, fingerprint, inactive owner, disabled/deleted state or capacity conflict | — |
| `503` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |


## POST /api/v1/admin/prompts/{id}/render

`POST /api/v1/admin/prompts/{id}/render` · operation `promptsRender`

Global administrator, prompts:render (distinct from prompts:read), prompt_render, active owner, published version and CSRF required. Renders text locally in one pass; never invokes providers, tools, URLs, environment or template code. Values and rendered output are never persisted or logged. Unknown/missing/enum/bounds failures do not echo data. Four concurrent heavy operations per process, five-second storage timeout, raw output 128 KiB and rendered JSON 256 KiB limits.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: [PromptMutationGuard](/docs/api/schemas/p/#promptmutationguard) and object
  - All of (1): [PromptMutationGuard](/docs/api/schemas/p/#promptmutationguard)
  - All of (2): object
    - `variables` (object) — Values are validated by the selected published schema profile; flat_strings_v1 requires strings.
      - any other key: any

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Explicit authorized rendered text, private/no-store. Not a model inference response. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature or prompt unavailable | — |
| `409` | Version, base fingerprint, disabled/unpublished state or inactive owner conflict | — |
| `413` | Request JSON exceeds 256 KiB | — |
| `422` | String-only variables violate required, enum, text or output bounds | — |
| `503` | Storage unavailable or local heavy-operation capacity reached | — |

Response `200` fields:

- `application/json`: object
  - `id` (string, required)
  - `revision` (integer, required)
  - `content_hash` (string, required)
  - `messages` (array of [PromptMessage](/docs/api/schemas/p/#promptmessage), required, max items 32)


## Read the currently published prompt of the key team

`GET /v1/prompts/{id}` · operation `getPublishedPrompt`

Requires prompt_registry, prompt_api and bearer scope prompts:read. Typed publications additionally require prompt_json_schema and its applicable plan right. Team and organization feature plans are cumulative ceilings when enabled. Resolves one active same-team publication and matching current YAML fingerprint; never returns drafts, historical content, actor or audit metadata. Optional revision asserts the current publication, not a history selector. Private/no-store, metadata-only telemetry and no provider call.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |
| `revision` | query | integer, min 1, max 100 | Optional current published revision assertion; a different owned publication returns 409. Repeated or invalid query parameters are refused. |
| `label` | query | string, pattern `^[a-z][a-z0-9_-]{0,31}$` | prompt_labels (T186.013b): read the revision this label of the prompt points at, published or not (a draft too), instead of the publication; the answer names the label. Needs the feature (404 feature_disabled) and, under feature plans, the plan right prompt_labels; a label the prompt does not have is 404, an invalid name 400 invalid_label. With revision, the label's revision must be that one (409). |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Published immutable content; Cache-Control private, no-store | `application/json`: [PublishedPrompt](/docs/api/schemas/p/#publishedprompt) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled, missing/foreign/unpublished/disabled prompt, inactive owner or YAML fingerprint drift | — |
| `409` | Current published revision does not match the assertion | — |
| `503` | Storage unavailable; no content returned | — |
| `504` | Configured prompt lookup deadline exceeded | — |


## Render the key team's current publication without a provider call

`POST /v1/prompts/{id}/render` · operation `renderPublishedPrompt`

Requires prompt_registry, prompt_api, prompt_api_render and bearer scope prompts:render. Key team is never supplied by the caller. Authorization, publication and fingerprint checks share the selected storage snapshot. The authorized published profile selects flat string or bounded JSON Schema validation; typed publications additionally require prompt_json_schema and its plan right. Insertion is nonrecursive. No implicit inference, provider call, content logging, persistence or cache. Current revision assertion is optional. Private/no-store on all outcomes; console session permissions do not authorize this bearer route.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` |  |

**Request body** (required)

- `application/json`: object — Strict duplicate/unknown/case/null/UTF-8 handling. flat_strings_v1 requires string values (nonstring is400); json_schema_v1 validates structured values against the published input_schema (violations422). Typed trees are bounded to depth5,4096 nodes,64 items per array and8192 Unicode points per string, with safe round-trippable numeric values. Rendered text is at most128KiB and encoded messages256KiB; body256KiB.
  - `revision` (integer, min 1, max 100)
  - `label` (string, pattern `^[a-z][a-z0-9_-]{0,31}$`) — prompt_labels (T186.013b): render the revision this label points at, published or not; the answer names the label and its render token records it, so the request built from it records prompt_label. 404 when the feature is off or the prompt has no such label.
  - `variables` (object, required)
    - any other key: any

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Rendered immutable publication; Cache-Control private, no-store | `application/json`: [RenderedPublishedPrompt](/docs/api/schemas/r/#renderedpublishedprompt) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled or same-team publication unavailable, including YAML fingerprint drift | — |
| `409` | Current published revision does not match the assertion | — |
| `413` | Bounded request body exceeded | — |
| `422` | Variables or rendered output violate the selected published profile or output bounds | — |
| `503` | Storage or local render capacity unavailable | — |
| `504` | Configured prompt lookup deadline exceeded | — |

