Playground API
The playground API supports the Playground view of the SPA. All endpoints require an authenticated admin session and gateway-scoped access.
Issuing a playground token
POST /admin/v1/playground/token
Issues a short-lived gateway auth token for use by the Playground UI and by ordinary chat — both mint through this one route (the SPA's usePlayToken); there is no separate chat_enabled flag. The token is bound to the requested gateway, scoped to ["playground"], and expires 30 minutes after issuance (PLAYGROUND_TOKEN_TTL_S, raised from 10 minutes so a token that passes the app's pre-turn refresh check always outlives the longest legal turn). If a turn's request is nevertheless refused with 401 token_expired before any byte streamed (the token lapsed between that check and the request — a laptop that slept, a token rotated server-side), the chat app re-mints once through this route and replays the same turn; when the mint itself is refused because the browser session expired, it shows a typed "session expired" state in the conversation with a sign-in action rather than leaving the page mid-turn. See token_expired.
Not gated by
playground_enabled. Unlike the playground-only search route (POST /admin/v1/playground/search), which returns403 feature_disabledwhen the flag is off, this mint route is deliberately exempt from the tenant Playground kill-switch: gating it would break normal chat on aplayground_enabled=0tenant (403 feature_disabled). Minting requires only gateway-scoped access (require_gateway_access) plus the impersonation guard — neverplayground_enabled. The scope string["playground"]is legacy/unrecognized, so the minted token is an unrestricted gateway inference credential (not a chat-only token). Consequentlyplayground_enabled=0is not a lever to stop a tenant's self-service inference — use budget limits, trial expiry, or deprovisioning for that.
| Field | Type | Required |
|---|---|---|
gateway_id |
string | yes |
Status codes:
| Status | Condition |
|---|---|
201 |
Token minted (body below). |
400 {"error":"gateway_id required"} |
gateway_id absent, empty or not a string. |
401 / 403 |
Not signed in, no access to the gateway (require_gateway_access), the caller's department does not allow this gateway, or the session is impersonating a user (no token minting while viewing as a user — see Impersonation). |
404 {"error":"gateway not found"} |
The gateway does not exist. |
503 |
Transient database fault, no token stored (Retry-After is sent; retry). |
The 201 response is:
{
"token": "myra_<HEX64>",
"expires_at": "<ISO 8601>",
"tenant_slug": "<TENANT>",
"gateway_slug": "<GATEWAY>"
}
tenant_slug and gateway_slug are returned so the Playground UI can construct the inference URL. Calling the endpoint again deletes any expired playground tokens for the same gateway but leaves valid playground tokens in place; concurrent sessions are supported.
On the Auth Tokens card of the gateway page (Organisation › AI setup › Gateways, tab Auth tokens), these automatically minted session tokens (label playground, created by Chat, the Playground, agent test runs and the workflow copilot) are not listed in the token table. They are summarised in one line below the table (for example "3 session tokens") with a Show / Hide toggle, collapsed by default. Showing them lists the same rows, with Edit and Revoke. A token is grouped only when its label is exactly playground (case and whitespace must match) and it has an expiry set; any other token, including a playground-labelled one without an expiry, stays in the table. Session tokens normally expire on their own, but an administrator can extend an expiry. This is a display grouping only: the tokens, their expiry and the API are unchanged.
Searching the web (Playground) — deprecated
POST /admin/v1/playground/search?gateway_id=<ID> with the JSON body {"q": "<query>"}
Deprecated — both forms answer until 11 January 2027, with Deprecation / Sunset headers on every response. The Playground no longer calls this route: Claude panels with web search now use the same server-side, metered search as the chat and the other models (x-aig-web-search: 1 on the inference request).
Proxies a query to the gateway's configured web-search provider (web_search.provider: brave — US, default — or linkup — EU) on behalf of the gateway, using the same dispatch and error classification as live inference. The subscription key is read from the gateway's stored web_search.api_key configuration; if the gateway has no stored web_search.api_key, the response is 503 with an explanatory message. This endpoint deliberately reads the stored key, not the platform Linkup key that is injected at read time for every new production gateway (see inference): that shared platform key is spent only on the metered inference path, never through this unmetered admin search — so a gateway with no stored key correctly returns 503 here.
The gateway configuration is resolved with the tenant EU-residency floor applied, and the fail-closed EU gate runs first: if the gateway (or its tenant) enforces eu_region_routing and the configured provider is not EU-based (including the brave default), the response is 403 — the admin probe is never allowed to egress the query to a non-EU provider.
Parameters (the query travels in the body — never in the URL, because the web server writes request lines into its error log):
| Parameter | Where | Type | Description |
|---|---|---|---|
gateway_id |
query | string | Gateway whose web_search.api_key is used. Required (400 gateway_id required). |
q |
JSON body | string | Search query: non-empty, valid UTF-8, at most 1024 characters. Absent / empty → 400 q_required; malformed → 400 invalid_q; a non-object body → 400 malformed_body. |
Gateway access and the playground_enabled entitlement are checked before the body is read (an unauthorised caller gets its 403 even with a bad body).
Deprecated (older form): GET /admin/v1/playground/search?q=…&gateway_id=… answers the same way until 11 January 2027 with Deprecation / Sunset headers. See Search and lookup values travel in the request body.
The response is:
Up to five organic results are returned. A provider failure (quota, authentication, rate limit, network, decode) is answered with the classified upstream status (502 when none applies). Access also requires that the caller's department allows the gateway (the query leaves through that gateway's search provider); the gateway must exist (404 gateway not found).
Reading a playground trace
GET /admin/v1/playground/trace/<ID>
Returns the trace plus its ordered steps. The endpoint is also exposed at GET /admin/v1/traces/<ID>. Required permission: REQUEST_LOGS_VIEW (held by tenant_admin and platform admin; a tenant admin can delegate it through a custom role). The trace detail includes prompt and model-response content, so a caller without the permission (for example a member or viewer) gets 403, and the call needs an X-Read-Reason header (400 without it; the read is audited as request_log.content_read), or POST /admin/v1/traces/<ID>/read with a JSON body { "reason": "..." } (see Logs). A caller other than platform admin must additionally reach the tenant of the trace's gateway; otherwise the answer is 404 (see below). Platform admin can read any trace.
The response is:
{
"trace": { "id": "...", "gateway_id": "...", "...": "..." },
"steps": [
{ "name": "...", "started_at": ..., "ended_at": ..., "data": { ... } }
]
}
Each step's data field is JSON, decoded inline.
404 { "error": "not found" } when the trace does not exist (the same body as a trace on another tenant's gateway, so the answer never confirms that a trace id exists) (a trace on a gateway you cannot access is the same 404; the 403 above is the role gate); when the trace or its steps cannot be read the answer is 503 { "error": "temporarily unavailable; retry later" } (never steps: [] for a trace that has steps).