Skip to content

Tenant entitlements API

A tenant entitlement answers "what is this customer entitled to, and why" for both acquisition paths. The self-serve path derives add-ons from a Stripe subscription's price ids; an enterprise tenant has no subscription at all, so this table is where a sales/admin operator records its plan and add-ons — and, crucially, the per-customer instance values the catalog cannot hold (a plan describes a product; params_json holds a contract: {"seats":1500}).

One row per (tenant, catalog_slug); each row is a plan or an addon and references a product catalog slug. Exactly one plan row per tenant is enforced. These rows feed the one resolver that computes a tenant's effective entitlement:

effective(tenant) = plan_config[plan] floor        (the tier default)
                  ∪ active add-on grants            (from the product catalog)
                  ∪ the purchased add-on's grants   (self-serve: the add-on the subscription bills)
                  ∪ the tenant's own params_json    (per-customer override, highest precedence)

The user invitation, the restore of a deleted user and SCIM provisioning all read the resolved seat cap from this resolver. While a seat reduction is scheduled on the tenant's subscription (it takes effect at the end of the billing period), these seat-giving operations are already bounded by the scheduled, lower seat count — only when the current cap is finite; an uncapped tenant is never capped by a schedule. The read endpoint below shows the current cap. A tenant with no entitlement row behaves exactly as before (an enterprise tenant stays uncapped; a self-serve tenant keeps its plan_config cap) — there is no behaviour change until a row is written.

Seats of a Stripe-billed tenant

For a Stripe-billed (self-serve) tenant the plan row's seats is not an operator-owned value: it follows Stripe's live seat quantity. It is written when a subscription change is confirmed by the customer.subscription.updated items heal (webhooks) - an applied upgrade raises it, a landed scheduled downgrade lowers it, an unpaid upgrade leaves it - so a manual PUT that differs from Stripe is reverted on the next heal. Enterprise / manual plans are never converged. Each change is audited (tenant_entitlement, actor system).

Functional grants (grants)

Besides seats/budget, each row's catalog product may carry functional grants (grants_json, e.g. {"myra_hosted_models": true}). The resolver folds the grants of every non-expired row, regardless of source, plus the grants of the add-on a self-serve subscription bills (see Purchased add-on) — the read endpoint returns the union under effective.grants, and enforcement reads the very same fold. Grants fail closed: an unknown slug, a corrupt grant blob, or a malformed expires_at contributes nothing (never a permissive default); an absent row and a malformed row both deny.

The EU-Gov add-on (eu_gov) is the first such grant: it grants myra_hosted_models, which lets a self-serve tenant use Myra-hosted (non-commercial, provider-class myra) models. Enforcement is server-side in the model-routing allowlist path (a Myra-hosted model is refused for a self-serve tenant without the grant — eu_gov_model_not_allowed, fail closed; commercial providers are always allowed). Granting/revoking the eu_gov row re-resolves the tenant's gateways immediately (no cache-TTL wait). A row is the manual (enterprise/admin) acquisition path; a self-serve customer buys EU-Gov with the trial conversion, and that purchase is granted from the subscription, without a row (next section).

Purchased add-on

A self-serve workspace that bought the EU-Gov add-on (the second line of its trial-conversion checkout, or re-added by a reactivation) holds its grant through the subscription: the add-on mirror on the subscription row (written when the checkout completes and confirmed against Stripe by the items heal — see webhooks). The effective grant set is

grants(tenant) = the grants of the tenant_entitlement rows
               ∪ the catalog grants of the add-on the subscription bills, while the subscription SERVES

The subscription serves while its status is active (100) or in grace (50), or inactive (0) before its grace deadline; any other status, and a missing or malformed grace deadline on an inactive one, does not serve — so the purchased grant starts with the payment and ends with the service (a lapse revokes it without any write, a reactivation brings it back). The grant is derived, never stored: no eu_gov row is needed (or written) for a purchased add-on, and a manual row next to it changes nothing. Because the grant is read from the add-on's catalog row each time, a grants edit of that row (PUT /admin/v1/catalog) applies live to every subscriber. A failure to read the subscription (or the rows) denies the grants on the enforcement path (fail closed) and answers 503 on the admin read below — never a view that disagrees with what is enforced.

Trial-plan exemption. The 7-day free trial (self_serve_trial) is exempt from this gate: its plan (plan_config.models_json) entitles two Myra-hosted EU models (qwen3.8-27b, gemma-4-31b-it) by design, so a trial tenant may use them without the eu_gov add-on. The exemption is keyed on the exact server-stamped plan value and is bounded by the trial's own plan model list (it cannot reach models outside its entitlement); a paid self-serve tenant (self_serve_custom) without the add-on is still denied Myra-hosted providers on every path (offer, send, auto-route, degrade, cross-vendor failover, save-time pins). The exemption is not a grant: the trial does not "hold" eu_gov.

The paid Custom plan and EU-Gov (owner decision 2026-09-27). The Custom plan's model list is claude-haiku-4-5, claude-sonnet-5 (commercial) plus the Myra-hosted fleet qwen3.8-27b, gemma-4-31b-it, mistral-small-4 (migration 0327). The plan list is the union; the EU-Gov grant decides the Myra half — without it a Custom workspace sees and uses only the commercial models. EU-Gov is bought per seat, but all or none per workspace (every seat is an EU-Gov seat, or none is), so the grant is workspace-wide by construction. A trial that converts to Custom without EU-Gov loses its Myra models.

Stored pins that lose access. A model saved on an agent, a scheduled prompt task or as the tenant's Copilot document-AI model that the plan or the EU-Gov gate later denies (trial conversion, a revoked or lapsed grant, a plan change) no longer fails every run: the run uses the pinned gateway's Auto choice instead (only models the plan and grant permit; local-only when the project or agent area is local-only — no permitted model there → the run is refused as before, never moved to a cloud provider). Each substitution is audited (model_pin_substituted, at most one row per object per day on each gateway node; if the node's shared cache cannot coalesce, the row is still written — never dropped — so a day may then carry more than one) and recorded on the request row as meta.aig_substituted_from. An explicit per-request model (chat, /v1, the agent preview) is not substituted — it keeps its 403. A stored provider-qualified (pinned) model such as ionos/<id> is not substituted either: a pin never changes provider, so a run whose pinned model the plan or the EU-Gov gate denies keeps the 403 (plan_model_not_allowed / eu_gov_model_not_allowed) and writes no model_pin_substituted row. New saves of a denied model are refused: agents, projects (every change of default_model — a model-only pin, the shape the app saves, is judged against the workspace's plan and grant; a gateway + model pin additionally against that gateway) and scheduled tasks answer 400 with code: plan_model_not_allowed (not in the plan list) or eu_gov_model_not_allowed (Myra-hosted without the grant), judged on the retired-id successor the runs would carry. A project's pinned gateway + model that is denied starts new conversations on that gateway's Auto choice.

Platform infrastructure is exempt. The rule covers the models a customer chooses (chat and completions, agents, scheduled tasks, projects, conversations, /compact). Platform services that run on Myra-hosted models for every workspace are exempt (owner decision 2026-09-27): OCR and document extraction, image analysis (vision), embeddings (bge-m3) and reranking for knowledge search, the prompt-injection guard and the Llama Guard content-safety guardrail, text-to-speech normalisation and speech in/out, image generation and editing, and the platform default inner model of the agentic web fetch. A gateway's own agentic_fetch.model override is not exempt: on a self-serve workspace it must be in the plan (and Myra-hosted only with EU-Gov) — a gateway PATCH setting a non-permitted override is refused (400, same codes), and a stored non-permitted override runs on the platform default.

The SPA /me payload carries myra_hosted_models as the effective may-use-Myra decision (the raw add-on grant OR the trial-plan exemption), for display only — the picker hides Myra-hosted rows a send would refuse, and shows the trial's EU models — the client is never the authority. This is not "add-on purchased": a consumer that needs the raw grant reads it from effective.grants (below), not from /me.

Base URL: https://<your-gateway-host>/admin/v1

Every endpoint requires the platform admin role (permission PLANS_MANAGE); a lower role is 403, an unauthenticated caller 401. Access is re-gated server-side — the client is never the authorization boundary. Every write is audited (audit_log, entity tenant_entitlement, entity_id and tenant_id = the tenant id; the action create / update / delete with the before/after row — catalog slug, kind, params incl. seats — and the acting admin and time).

::: info SPA seat editor The tenant Edit pop-up's Seats & Budget section is the SPA's writer for an enterprise tenant's seat cap: it GETs this endpoint, merges the new seats into the existing plan row's params_json (preserving a budget_usd override), and PUTs it back. Because the endpoint is PLANS_MANAGE-gated (gate_class="platform"), a tenant admin — who sees the section read-only — cannot write it: a tenant-admin PUT/GET on their own tenant is refused 403 before the body is read, fail-closed (contract proof: agf2717-entitlements-authz.spec.ts). The read-only rendering in the SPA is UX only, not the boundary. :::

::: info Scope: the manual path only This API writes source='manual' rows. stripe_price_id is always NULL for a manual row, and a body that carries one is rejected. A self-serve purchase never writes a row at all — its add-on is granted from the subscription (Purchased add-on), so revoking a purchased add-on here is neither possible nor needed. A future source='stripe' row path requires widening the row's unique key to include source first (today it is (tenant_id, catalog_slug), so a stripe upsert would clobber a manual grant); these endpoints never write a stripe row and refuse to revoke one. :::

Read a tenant's entitlements

GET /admin/v1/tenants/{tenant_id}/entitlements

Returns the tenant's rows plus the resolved effective entitlement:

{
  "plan": "enterprise",
  "entitlements": [
    {
      "id": "…-uuid",
      "tenant_id": "t_123",
      "catalog_slug": "enterprise",
      "kind": "plan",
      "params": { "seats": 1500 },
      "source": "manual",
      "stripe_price_id": null,
      "granted_at": 1757800000,
      "expires_at": null,
      "granted_by": "u_admin"
    }
  ],
  "effective": { "seats": 1500, "grants": { "myra_hosted_models": true } }
}

effective.grants is the folded functional-grant set (see Functional grants) — the rows and a purchased add-on while the subscription serves, exactly the set enforcement uses; it is {} when the tenant holds no grant-bearing add-on. A purchased add-on appears here without a matching row in entitlements.

  • 404 { "error": "tenant not found" } if the tenant does not exist.
  • 503 { "error": "temporarily unavailable; retry later" } if the tenant, the entitlement rows or the tenant's subscription cannot be read (retry; never a partial answer, never a view that disagrees with enforcement; the cause is never appended).

Create or update an entitlement

PUT /admin/v1/tenants/{tenant_id}/entitlements

Upserts one source='manual' row, keyed by (tenant_id, catalog_slug). Body:

{
  "catalog_slug": "enterprise",
  "kind": "plan",
  "params_json": { "seats": 1500, "budget_usd": 5000 },
  "expires_at": 1893456000
}

Accepted shape

Field Required Rules
catalog_slug yes Non-empty string (surrounding whitespace is trimmed). Must exist in the product catalog and its catalog kind must match kind.
kind yes "plan" or "addon" (surrounding whitespace is trimmed).
params_json yes A JSON object whose only keys are the allowlist below. {} is valid (a plan assignment with no instance value).
params_json.seats no A JSON number, integer, 1..100000.
params_json.budget_usd no A JSON number >= 0 (finite). Stored and returned at full double precision (17 significant digits, integers up to 2^53-1), not rounded.
expires_at no A JSON integer number of unix seconds in the future, at most 100 years ahead, or null / absent (open-ended). Any string (including a digit string such as "1893456000"), a fraction, a boolean, an object or an array is refused 400 invalid_entitlement_expires_at.

Server-set, never taken from the body: source="manual", stripe_price_id=NULL, granted_by (the calling admin), granted_at (now), id (preserved on update, minted on create).

What is rejected (fail closed — nothing is persisted)

Response Cause
400 catalog_slug / kind missing or wrong type; kind not plan/addon.
400 Unknown catalog_slug.
400 kind does not match the catalog kind of that slug (e.g. an addon slug sent as a plan).
400 params_json absent, a JSON array, or a non-object scalar.
400 An unknown params_json key (only seats, budget_usd are allowed).
400 seats not a number, non-integer, or outside 1..100000; budget_usd not a number, negative, or +inf.
400 stripe_price_id present in the body with a value other than null (a manual row never carries one).
400 invalid_entitlement_expires_at expires_at non-integer, not in the future, or more than 100 years in the future.
400 A body that is not a JSON object (body required).
409 A plan PUT whose slug differs from the tenant's existing plan row (exactly one plan row per tenant).
409 The write would drop the tenant's effective seat cap below its current active-user count (seats_below_active_users).
409 standard_seats_locked — the tenant's plan is standard, the write changes its effective seat cap, and the platform setting paid_signup_enabled ("Offer paid upgrade at signup") is on (Standard seats are read-only then). A write that leaves the seat cap unchanged (a budget-only / add-on edit, the same seats) passes. Enterprise and every other plan are unaffected.
503 temporarily unavailable; retry later — a Standard seat-cap change while the "Offer paid upgrade at signup" setting cannot be read (store unavailable, malformed value); nothing persisted, retry. Never guessed open.
404 The tenant does not exist.
503 The product catalog is cold/unavailable (an unknown-slug verdict cannot be trusted, so the write is asked to retry rather than falsely rejected as 400).
503 The active-user count cannot be read (fail closed — never write when the count is unknown). Read only when the write lowers the effective seat cap.
503 The tenant, its existing entitlement rows or the plan-row conflict check cannot be read.
500 The write itself failed — { "error": "internal error", "request_id": "…" }; the database's own text is never returned.

A present but wrong value is rejected at the write boundary, never coerced — an absent field and a malformed field are different answers there. At the read boundary a tampered stored blob is re-validated and ignored, and the seat cap fails closed: for a self-serve tenant a malformed params_json falls back to the finite plan floor; for an enterprise/manual tenant (no plan floor) a row whose params_json cannot be read caps the tenant at the same finite fallback an unknown self-serve tier gets (the seat cap of the paid self-serve tier) — never uncapped. An absent override and a malformed one are different answers.

On success: 200 { "ok": true, "id": "…" }.

Seats can never drop below active users

Seats govern the tenant's headcount ceiling, so a write may never leave the tenant billed for — and capped at — fewer seats than it has active users (users may be fewer than seats, never the reverse). The server computes the effective seat cap that would result from this write (through the very same resolver the invite path enforces) and, when that cap would fall below the tenant's active-user count, refuses with 409 seats_below_active_users and persists nothing. This is a decrease control, not an absolute per-write floor: a tenant that is already over-seated (e.g. users added past the cap on a provisioning path) may still raise seats back toward its headcount or change an unrelated add-on — only a genuine lowering across the line is refused. The active-user count is resolved server-side; the client is never the authority. If the count cannot be read, the write fails closed (503) rather than proceed on an unknown headcount.

The accepted seats upper bound here is 100000 — the platform (admin) ceiling for a manually provisioned contract. The self-serve price calculator advertises a smaller cap (its own self-serve boundary); that lower figure is a deliberate subset of this authoritative range, not a second source of truth.

Audit. The upsert and its audit entry (tenant_entitlement, action create or update) commit in one transaction: both are stored or neither is. An identical re-PUT succeeds and writes exactly one audit entry. If the audit entry cannot be written, nothing is changed: the answer is 503 when nothing was written or the failure was transient (repeat the call), otherwise the sanitised 500 { "error": "internal error", "request_id": "…" }. The cause is logged, never returned. The tenant's entitlement cache is dropped whatever the outcome, so a failed write never leaves a stale answer behind.

Revoke an entitlement

DELETE /admin/v1/tenants/{tenant_id}/entitlements/{catalog_slug}

Removes a source='manual' row.

  • 404 { "error": "tenant not found" } if the tenant does not exist; 404 { "error": "no such entitlement" } if the tenant has no row for that slug.
  • 409 if the row is not source='manual' (for example source='stripe', owned by the subscription, not the admin) — checked before the seat rules below.
  • 409 standard_seats_locked (or 503, the standard retry answer) if the tenant is on standard, revoking the row changes its effective seat cap, and "Offer paid upgrade at signup" is on (or unreadable) — the same rule as the PUT.
  • 409 seats_below_active_users if revoking the row would drop the tenant's effective seat cap below its active-user count (e.g. deleting a seat-raising override the current headcount depends on). Deactivate users first, or raise seats on the surviving rows. Revoking an add-on that never carried seats is unaffected.
  • 503 if the tenant, its entitlement rows or the active-user count cannot be read (fail closed — never revoke on an unknown state).
  • 500 { "error": "internal error", "request_id": "…" } if the delete itself fails (the cause is logged, never returned). The delete and its audit entry (delete) commit in one transaction; when the audit entry cannot be written the row stays and the answer is 503 (nothing written / transient) or this 500.

On success: 200 { "ok": true }.

Plan-value validation on the tenant record

Writing tenant.plan (via POST /admin/v1/tenants or PATCH /admin/v1/tenants/{id}) is validated against the product-catalog plan slug set (the plan_value of each plan row, or the slug for a plan with no plan_value). The check is change-gated — an unrelated PATCH, or re-saving the current plan, is never rejected, so existing tenants stay editable. A present unknown plan value is 400; a cold catalog is 503 (retry), never a false 400.