# API reference — one origin, one namespace

Everything lives under `https://api.agentsky.dev/v1` with a Bearer token. Management is request/response; conversation is a 202 send plus one standing SSE stream. Machine-readable spec (generated from the same schemas the routes validate with): https://api.agentsky.dev/v1/openapi.json.

## Authentication

Every request sends `Authorization: Bearer ast_…`. Tokens are minted in Developer → API keys or by `sky auth login` — never by other tokens. Scopes are ordered `read ⊂ write ⊂ admin`; a token is personal (acts as you everywhere) or scoped to one universe. Pass `X-Universe: <slug>` to act inside a non-personal universe. A universe is the API's name for a workspace; `/workspaces/…` routes are aliases of `/universes/…`.

## Errors

Every non-2xx body is `{ "error": { "code", "message" } }`. Branch on `code`; `message` is for people and may change. Errors from the management routes also carry `request_id`, repeated in the `Request-Id` response header — quote it when you ask for support. The conversation plane (`/events`, `/stream`) does not add it yet.

| HTTP | code | When |
|------|------|------|
| 400 | `invalid_request` | malformed JSON / validation failure |
| 400 | `invalid_memory` | invalid memory operation or memory limit reached |
| 401 | `invalid_token` | missing, unknown, revoked, or expired token |
| 402 | `insufficient_credits` | the spend gate blocked the turn |
| 403 | `insufficient_scope` · `universe_mismatch` · `forbidden` | scope too low; X-Universe conflicts with a scoped token; agent has no API binding |
| 404 | `not_found` | unknown agent/universe (also masks unauthorized slugs) |
| 409 | `conflict` | version conflict |
| 403 | `personal_memory_only` | caller or universe is not eligible for personal memory |
| 409 | `memory_conflict` | memory changed; read the current version before writing |
| 400 | `not_downloadable` | `GET /files/{file_id}/content` on an upload — only session files download |
| 400 | `file_is_session_resource` | `DELETE /files/{file_id}` on a copy that backs a live session resource — delete the resource instead |
| 400 | `too_many_resources` | more than 500 resources or 5 repositories on one session |
| 400 | `egress_header_conflict` | two secrets, or two repository tokens, set one header on one host with different values |
| 413 | `file_too_large` | a single-request file upload over 32 MiB (use `/v1/files/uploads`; resumable uploads have no application file-size cap) |
| 422 | `invalid_spec` | valid JSON, invalid domain rules (e.g. llm not allowed for type) |
| 429 | `rate_limited` | 100,000 requests/min per token exceeded — honor Retry-After |

## Compatibility

Nothing is removed or changed under you in `/v1`. Any day we may add a route, an optional request field, a response field, a header, or **a new value of an enum-like field** — stream event types, `status`, `stop_reason` and error codes included. Ignore fields you do not know and give unknown enum values a default case. We never remove or rename a route, field or enum value, retype a field, make an optional field required, or change what an error code means. A deprecated operation stays served, is marked deprecated in the spec, and names its replacement.

## Retries

Creates that accept an `Idempotency-Key` header list it among their parameters: a repeat with the same key returns the first response instead of acting twice, and the same key with a different body is 409 `idempotency_conflict`. Some spends take the same guarantee as a body field (`request_id` on top-ups and wallet transfers).

## Billing

### GET /billing

Read credit balance, its split, card availability and latest activity (scope: read)

Returns the caller's credit balance, split into purchased and bonus credit, whether a card is on file, and their latest 20 payments and credits, newest first. No card details are returned, on purpose: the brand and last four digits stay on the Billing page. activity is null for a workspace key or a restricted credential, because it is the person's own.

Responses:

- `200` — OK
  - `balance_usd` (number, required)
  - `purchased_balance_usd` (number) — Credit the person paid for.
  - `bonus_balance_usd` (number) — Credit given to them rather than bought.
  - `card_on_file` (boolean, required)
  - `activity` (object[])
    - `id` (string, required)
    - `at` (string, required)
    - `description` (string, required)
    - `amount_usd` (number, required) — Positive for money in, negative for money out.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing' \
  -H "Authorization: Bearer ast_..."
```

### POST /billing/card-setup

Start saving a payment card (scope: write)

Returns a hosted card form URL to open in a browser. Saving the card does not charge it; auto top-up can charge it when a later session starts below the configured threshold. No request body is required.

Responses:

- `200` — OK
  - `url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/billing/card-setup \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/auto-topup

Read auto top-up settings (scope: read)

Whether the caller's saved card is charged when their balance falls under threshold_usd, and for how much credit. opted_out is true once the person turned it off, so a later top-up does not turn it back on. failure is the last charge that did not go through while it is on; paused when repeated failures stopped it.

Responses:

- `200` — OK
  - `enabled` (boolean, required)
  - `opted_out` (boolean, required)
  - `threshold_usd` (number, required)
  - `amount_usd` (number, required)
  - `card_on_file` (boolean, required)
  - `failure` (object, required)
    - `reason` (string)
    - `paused` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/auto-topup' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /billing/auto-topup

Change auto top-up settings (scope: write)

Omitted fields keep their value. threshold_usd is 5, 10 or 20; amount_usd is 10, 20, 50 or 100. Turning it on needs a saved card (402 no_payment_method — add one with POST /billing/card-setup) and agrees to the card processing fee each charge adds; turning it off is remembered. A workspace key or a restricted credential cannot change it.

Body (application/json):

- `enabled` (boolean)
- `threshold_usd` (enum<number>) — 5 · 10 · 20
- `amount_usd` (enum<number>) — 10 · 20 · 50 · 100

Responses:

- `200` — Saved
  - `enabled` (boolean, required)
  - `threshold_usd` (number, required)
  - `amount_usd` (number, required)
  - `failure` (object, required)
    - `reason` (string)
    - `paused` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/billing/auto-topup \
  -H "Authorization: Bearer ast_..."
```

### POST /billing/topups

Buy credit for your own balance: saved card, Alipay or WeChat Pay (scope: write)

Adds credit to the caller's own balance, as Billing › Add credits does. amount is 1000, 2000, 5000 or 10000 cents of credit; the charge adds the payment processing fee. payment_method card (the default) charges the saved card at once and answers 201 with the new balance; request_id makes a repeat of the same request charge once (200 instead of 201). Auto top-up is not changed. 409 card_required without a saved card (POST /billing/card-setup adds one), 402 card_declined. payment_method alipay or wechat_pay answers 202 with checkout_url, the payment page the person opens and pays (scan with Alipay or WeChat); nothing is charged until they do, the credit lands once the payment settles (read it with GET /billing), and a repeat with the same request_id returns the same page. 409 payment_method_unavailable when that method is not offered right now. 503 payments_unavailable where payments are not set up. A workspace key or a restricted credential cannot buy credit.

Body (application/json):

- `amount` (object, required)
  - `amount` (string, required) — Whole US cents
  - `currency` (enum<string>, required) — "USD"
- `request_id` (string, required) — max length 100
- `payment_method` (enum<string>) — card (default) charges the saved card; alipay and wechat_pay return a payment page the person pays. — "card" · "alipay" · "wechat_pay"

Responses:

- `201` — Bought
  - `charged` (boolean)
  - `balance` (object)
    - `amount` (string, required) — Whole US cents
    - `currency` (enum<string>, required) — "USD"
- `202` — Payment page opened for the person to pay
  - `charged` (enum<boolean>, required) — false
  - `payment_method` (enum<string>, required) — "alipay" · "wechat_pay"
  - `checkout_url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/billing/topups \
  -H "Authorization: Bearer ast_..."
```

### POST /billing/credit-invites/claim

Claim a credit invite for your own account (scope: write)

Redeems an operator's credit invite link (agentsky.dev/i/<code>) the way the invite page's Claim button does; code is the <code> part of the link. Not a workspace invitation: those are POST /invites/{token}. A gpt-pool invite activates private GPT pool API coverage and creates a restricted API key instead of funding general balance; access and remaining_usd describe that allowance. Gateway requests, responses and files are stored. 201 granted, or 200 already_claimed when this account redeemed the link before (nothing is funded twice). 404 not_found for an unknown code; 410 invite_expired, invite_disabled or invite_used; 403 invite_not_yours for a personal link issued to another address, 403 account_ineligible for an unverified or banned account. Rate-limited per account (429 rate_limited with Retry-After). A workspace key or a restricted credential cannot claim credit.

Body (application/json):

- `code` (string, required) — max length 200

Responses:

- `200` — Already claimed by this account
  - `status` (enum<string>, required) — "granted" · "already_claimed"
  - `amount_usd` (number, required)
  - `access` (enum<string>) — "gpt-pool"
  - `remaining_usd` (number)
- `201` — Granted
  - `status` (enum<string>, required) — "granted" · "already_claimed"
  - `amount_usd` (number, required)
  - `access` (enum<string>) — "gpt-pool"
  - `remaining_usd` (number)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/billing/credit-invites/claim \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/credit-invites/{code}

Read a credit invite link before claiming it (scope: read)

What the invite page shows for agentsky.dev/i/<code>; code is the <code> part of the link. state is active (amount_usd, remaining claims, expires_at, one_claim_per_account, and personal when the link was issued to one address), claimed (this account redeemed it; amount_usd is what it received), not_yours (a personal link issued to another address), or disabled, expired or exhausted. Only active and claimed carry an amount, and the address a personal link was issued to is never returned. 404 not_found for an unknown code. Rate-limited per account (429 rate_limited with Retry-After). A workspace key or a restricted credential cannot read credit invites. Redeem with POST /billing/credit-invites/claim.

Path parameters:

- `code` (string, required)

Responses:

- `200` — OK
  - `state` (enum<string>, required) — "active" · "claimed" · "not_yours" · "disabled" · "expired" · "exhausted"
  - `amount_usd` (number)
  - `access` (enum<string>) — "gpt-pool"
  - `remaining_usd` (number)
  - `remaining` (integer) — Claims left on the link.
  - `expires_at` (string)
  - `one_claim_per_account` (boolean)
  - `personal` (boolean) — The link was issued to one email address.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/credit-invites/code' \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/usage

Account-wide usage across sessions and API keys (scope: read)

What the caller spent over a range of UTC days, from both lanes that debit their balance: their sessions (model, capability, connector and runtime calls) and their developer API keys. totals.bySource splits the totals by lane; groups break them down by group_by. A group's key is null where the dimension does not apply to its lane, so the groups always sum to the totals. Per-session detail is GET /sessions/{id}/usage.

Query parameters:

- `from` (string) — First UTC day included, YYYY-MM-DD; defaults to 29 days before today
- `to` (string) — First UTC day excluded, YYYY-MM-DD; defaults to tomorrow. A range spans at most 366 days
- `source` (string) — Only sessions, or only developer API keys; both when omitted
- `api_key_id` (string) — Only this API key's usage
- `group_by` (string)

Responses:

- `200` — OK
  - `range` (object, required)
    - `from` (string)
    - `to` (string)
  - `groupBy` (enum<string>, required) — "day" · "kind" · "session" · "api_key"
  - `totals` (object, required)
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `cachedInputTokens` (integer)
    - `billedCostUsd` (number)
    - `bySource` (object)
      - `session` (object)
        - `calls` (integer)
        - `inputTokens` (integer)
        - `outputTokens` (integer)
        - `cachedInputTokens` (integer)
        - `billedCostUsd` (number)
      - `api_key` (object)
        - `calls` (integer)
        - `inputTokens` (integer)
        - `outputTokens` (integer)
        - `cachedInputTokens` (integer)
        - `billedCostUsd` (number)
  - `groups` (object[], required)
    - `key` (string)
    - `label` (string)
    - `source` (enum<string>) — "session" · "api_key"
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `cachedInputTokens` (integer)
    - `billedCostUsd` (number)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/usage' \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/usage/sessions

Spend per session, with who paid (scope: read)

Every session that cost the caller, newest first, and every session they started that a workspace's own balance paid for: the list Settings › Billing shows. userPaidUsd is what left their balance, platformAbsorbedUsd what the platform covered, paidByWorkspace the workspace that paid (userPaidUsd is then 0), and costFinalizing is true while the session's machine still runs, so its cost can still grow. Deleted sessions stay listed. It names sessions across all of the person's workspaces, so a workspace key or a restricted credential is 403.

Responses:

- `200` — OK
  - `sessions` (object[], required)
    - `sessionId` (string, required)
    - `playgroundId` (string) — Sessions with one id began in one Playground; Billing shows them as one row.
    - `name` (string, required) — The opening prompt, up to 240 characters, or the session's name.
    - `agentName` (string)
    - `deleted` (boolean, required)
    - `lastUsedAt` (string, required)
    - `billedCostUsd` (number, required)
    - `userPaidUsd` (number, required)
    - `platformAbsorbedUsd` (number, required)
    - `tokenCostUsd` (number)
    - `runtimeCostUsd` (number)
    - `capabilityCostUsd` (number)
    - `connectorCostUsd` (number)
    - `costFinalizing` (boolean, required)
    - `paidByWorkspace` (string) — The workspace whose balance paid; absent when the caller's own did.
    - `providers` (object[], required)
      - `provider` (string)
      - `providerName` (string)
      - `kind` (string)
      - `billedCostUsd` (number)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/usage/sessions' \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/usage/export

Download every usage record in a range as CSV or JSONL (scope: read)

One row per session call and one per API key, UTC day and kind, streamed. Columns: source, at, sessionId, sessionName, apiKeyId, apiKeyName, kind, model, provider, tool, calls, inputTokens, outputTokens, cachedInputTokens, cacheCreationTokens, listCostUsd, billedCostUsd, coveredBy (subscription when a connected plan paid), requestId. The same file Billing's export downloads.

Query parameters:

- `from` (string) — First UTC day included, YYYY-MM-DD; defaults to 29 days before today
- `to` (string) — First UTC day excluded, YYYY-MM-DD; defaults to tomorrow. A range spans at most 366 days
- `source` (string) — Only sessions, or only developer API keys; both when omitted
- `api_key_id` (string) — Only this API key's usage
- `format` (string)

Responses:

- `200` — The records
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/usage/export' \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/usage/requests

Per-request history of your developer API keys (scope: read)

One row per API gateway request the caller's developer API keys made in a range of UTC days, newest first, a page at a time: model, endpoint, tokens, list and billed cost, HTTP status and latency. Pass nextCursor back as cursor for the next page; it is null on the last page. Session usage is not included (source=session returns no rows). The same rows as Settings › API usage. 503 unavailable when the request log cannot be read; retry.

Query parameters:

- `from` (string) — First UTC day included, YYYY-MM-DD; defaults to 29 days before today
- `to` (string) — First UTC day excluded, YYYY-MM-DD; defaults to tomorrow. A range spans at most 366 days
- `api_key_id` (string) — Only this API key's requests
- `cursor` (string) — nextCursor from the previous page

Responses:

- `200` — OK
  - `rows` (object[], required)
    - `id` (string)
    - `requestId` (string)
    - `apiKeyId` (string)
    - `apiKeyName` (string)
    - `at` (string)
    - `model` (string)
    - `endpoint` (string)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `cachedInputTokens` (integer)
    - `cacheCreationTokens` (integer)
    - `totalTokens` (integer)
    - `listCostUsd` (number)
    - `billedCostUsd` (number)
    - `httpStatus` (integer)
    - `metered` (string)
    - `latencyMs` (integer)
  - `nextCursor` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/usage/requests' \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/coding-plan/enrollment

Whether the coding plan takes new members (scope: public)

open, full or closed. Needs no key.

Responses:

- `200` — OK
  - `enrollment` (enum<string>, required) — "open" · "full" · "closed"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/coding-plan/enrollment' \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/coding-plan

Read your coding plan (scope: read)

Whether a paid month of the coding plan covers now (every API gateway call is then billed at cost), its monthly credit, when the month ends, whether it renews, why the last charge failed, and whether new members can join (enrollment open, full or closed).

Responses:

- `200` — OK
  - `active` (boolean, required) — A paid month covers now
  - `monthly_credit_usd` (number, required)
  - `current_period_end` (string, required)
  - `renews` (boolean, required) — The plan charges again at current_period_end
  - `charge_failure` (string, required) — Why the last charge failed, worded for the cardholder
  - `enrollment` (enum<string>, required) — "open" · "full" · "closed"
  - `amounts_usd` (number[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/coding-plan' \
  -H "Authorization: Bearer ast_..."
```

### POST /billing/coding-plan

Join the coding plan, or change your monthly amount (scope: write)

Joining charges the caller's saved card amount_usd plus the card processing fee and adds amount_usd as purchased credit; the plan renews monthly on the same card. A current member's call changes the amount from the next renewal, charges nothing, and undoes a pending cancellation. request_id makes a repeat of the same join charge once. 409 card_required without a saved card (POST /billing/card-setup adds one), 402 card_declined, 403 enrollment_closed, 409 enrollment_full, 409 charge_in_progress, 503 payments_unavailable. A workspace key or a restricted credential cannot change the plan.

Body (application/json):

- `amount_usd` (enum<number>, required) — 10 · 40
- `request_id` (string, required) — max length 100

Responses:

- `200` — The plan after the change
  - `active` (boolean, required) — A paid month covers now
  - `monthly_credit_usd` (number, required)
  - `current_period_end` (string, required)
  - `renews` (boolean, required) — The plan charges again at current_period_end
  - `charge_failure` (string, required) — Why the last charge failed, worded for the cardholder
  - `enrollment` (enum<string>, required) — "open" · "full" · "closed"
  - `amounts_usd` (number[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/billing/coding-plan \
  -H "Authorization: Bearer ast_..."
```

### DELETE /billing/coding-plan

Stop your coding plan renewing (scope: write)

The plan does not charge again; the paid month and its credit stay. Join again with POST to undo it. A workspace key or a restricted credential cannot change the plan.

Responses:

- `200` — The plan after the change
  - `active` (boolean, required) — A paid month covers now
  - `monthly_credit_usd` (number, required)
  - `current_period_end` (string, required)
  - `renews` (boolean, required) — The plan charges again at current_period_end
  - `charge_failure` (string, required) — Why the last charge failed, worded for the cardholder
  - `enrollment` (enum<string>, required) — "open" · "full" · "closed"
  - `amounts_usd` (number[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/billing/coding-plan \
  -H "Authorization: Bearer ast_..."
```

### GET /billing/referral-links

Your customer discount links and what they earned (scope: read)

For an account on an eligible platform discount plan: the plan links are priced from (source_plan.multiplier is the lowest share of public price a customer can be given), the active SKUs with your own price for each, every link you created with its customer price, redemptions and status, and your earnings per referred customer. 403 not_eligible for any other account.

Responses:

- `200` — OK
  - `source_plan` (object, required)
    - `id` (string)
    - `name` (string)
    - `multiplier` (number)
  - `skus` (object[], required)
    - `id` (string)
    - `name` (string)
    - `kind` (string)
    - `source_multiplier_bps` (integer)
    - `second_list_usd` (number)
    - `source_second_usd_per_unit` (number)
  - `links` (object[], required)
    - `id` (string)
    - `url` (string)
    - `created_at` (string)
    - `customer_multiplier` (number) — Share of public price the customer pays
    - `custom_price_count` (integer) — SKUs priced differently from your own price
    - `prices` (object[])
      - `sku_id` (string)
      - `customer_multiplier_bps` (integer)
      - `customer_second_usd_per_unit` (string)
    - `audience_email` (string)
    - `email_status` (string)
    - `max_redemptions` (integer)
    - `redeemed_count` (integer)
    - `expires_at` (string)
    - `disabled_at` (string)
  - `earnings` (object[], required)
    - `enrollment_id` (string)
    - `amount_usd` (number)
    - `last_earned_at` (string)
    - `referred_user` (object)
      - `name` (string)
      - `email` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/billing/referral-links' \
  -H "Authorization: Bearer ast_..."
```

### POST /billing/referral-links

Create a customer discount link (scope: write)

Pass exactly one of customer_multiplier (one share of public price for every model, 0.01 to 100) or sku_prices (a multiplier, or for SECOND-only SKUs an exact second_usd_per_unit, per SKU). No price may be below your own (400 below_floor) or leave less than 15% over supplier cost on your route (400 below_margin, which names the lowest passing price); a SKU you leave at its default price is raised to that minimum. With audience_email the link is emailed to that customer and redeems once; email_status says whether the email was sent. max_redemptions defaults to 100 and expires_in_days to 30. 403 not_eligible without an eligible discount plan, 429 rate_limited after 20 emailed links in an hour, 503 unavailable while referral pricing is paused. A workspace key or a restricted credential cannot create links.

Body (application/json):

- `customer_multiplier` (number)
- `sku_prices` (object[])
  - `sku_id` (string, required)
  - `multiplier` (number)
  - `second_usd_per_unit` (number)
- `max_redemptions` (integer)
- `expires_in_days` (integer)
- `audience_email` (string)

Responses:

- `201` — Created
  - `url` (string, required)
  - `email_status` (enum<string>, required) — "sent" · "suppressed" · "uncertain" · null
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/billing/referral-links \
  -H "Authorization: Bearer ast_..."
```

### POST /billing/referral-links/{id}/disable

Disable one of your customer discount links (scope: write)

The link can no longer be redeemed; customers already enrolled keep their price. 404 not_found when the link is not yours or is already disabled.

Path parameters:

- `id` (string, required)

Responses:

- `200` — Disabled
  - `id` (string, required)
  - `disabled` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/billing/referral-links/sess_cmtb7q2j/disable \
  -H "Authorization: Bearer ast_..."
```

## Credit campaigns

### GET /credit-campaigns

List live and recent credit campaigns (scope: admin)

Responses:

- `200` — Campaign result
  - `campaigns` (string[], required)
- `400` — Invalid request
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Admin token scope and administrator allowlist membership required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown campaign
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Campaign migrations required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/credit-campaigns' \
  -H "Authorization: Bearer ast_..."
```

### POST /credit-campaigns

Issue a public credit link or personal email invitations (scope: admin)

Only allowlisted administrators can use these operations. Use one UUID requestId per campaign and reuse the identical body after timeouts. Personal emails are deduplicated and each gets a distinct, email-bound single-use code. Ordinary credits go immediately to existing verified, unbanned recipients. access: gpt-pool instead requires named recipients and an explicit verified-email claim: it creates private lifetime-capped GPT API coverage and a restricted key, not general wallet credit. The invitation discloses full gateway transit retention. sendEmail explicitly authorizes product email. Code creation is atomic; delivery/credit failures are per recipient. Retry the same request for retry_needed credit results; never change requestId just to retry. Email status sent means SES accepted, not inbox delivery. Sending/uncertain attempts are not automatically resent; use the returned personal link for manual delivery. Responses contain bearer codes: keep private. A different body with the same requestId returns 409.

Body (application/json):

- `requestId` (string, required) — pattern ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
- `amountUsd` (number, required)
- `expiresInDays` (integer, required)
- `note` (string, required) — max length 200
- `audience` (object, required)
  - option 1 (object)
    - `kind` ("anyone", required)
    - `slots` (integer, required)
  - option 2 (object)
    - `kind` ("recipients", required)
    - `emails` (string[], required) — pattern ^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$
- `sendEmail` (boolean) — default: false
- `access` ("gpt-pool")

Responses:

- `201` — Campaign result
  - `campaignId` (string, required)
  - `recipients` (object[], required)
    - `id` (string, required)
    - `email` (string | null, required)
    - `code` (string, required)
    - `url` (string, required)
    - `claim` (string, required)
    - `emailStatus` (string, required)
    - `notifiedAt` (string | null, required)
- `400` — Invalid request
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Admin token scope and administrator allowlist membership required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown campaign
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — requestId reused with different settings
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `415` — Content-Type must be application/json
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Campaign migrations required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/credit-campaigns \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"requestId":"40a9ae2a-4ea5-4a50-987e-d8b3c99c96f0","amountUsd":20,"expiresInDays":30,"note":"Launch invitations","audience":{"kind":"recipients","emails":["recipient@example.com"]},"sendEmail":true}'
```

### GET /credit-campaigns/{id}

Read claim, email and recipient usage results (scope: admin)

Returns grantedUsd, claimed, activeRecipients, agentUsageUsd and individual link states. Usage is agent/runtime ledger spend since first claim, excludes API gateway and is not attribution to the gifted credit pool.

Path parameters:

- `id` (string, required)

Responses:

- `200` — Campaign result
  - `campaignId` (string, required)
  - `note` (string, required)
  - `amountUsd` (number, required)
  - `maxRedemptions` (integer, required)
  - `claimed` (integer, required)
  - `grantedUsd` (number, required)
  - `activeRecipients` (integer, required)
  - `agentUsageUsd` (number, required)
  - `usageBasis` (string, required)
  - `links` (object[], required)
    - `id` (string, required)
    - `email` (string | null, required)
    - `access` (string | null, required)
    - `state` (enum<string>, required) — "active" · "disabled" · "expired" · "exhausted"
    - `claimed` (integer, required)
    - `emailStatus` (string, required)
    - `expiresAt` (string, required)
    - `notifiedAt` (string | null, required)
    - `url` (string | null, required)
- `400` — Invalid request
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Admin token scope and administrator allowlist membership required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown campaign
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Campaign migrations required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/credit-campaigns/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /credit-campaigns/{id}

Disable all unclaimed campaign codes (scope: admin)

Already granted credit stays in recipients' accounts.

Path parameters:

- `id` (string, required)

Responses:

- `200` — Campaign result
  - `disabled` (integer, required)
- `400` — Invalid request
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Admin token scope and administrator allowlist membership required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown campaign
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Campaign migrations required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/credit-campaigns/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

## Memory stores

### GET /memory_stores

List memory stores (scope: read)

Query parameters:

- `include_archived` (boolean)
- `after` (string)
- `limit` (integer)

Responses:

- `200` — List of memory stores
  - `memory_stores` (object[], required)
    - `id` (string, required) — memstore_…
    - `object` (enum<string>, required) — "memory_store"
    - `name` (string, required)
    - `description` (string, required)
    - `attach_by_default` (enum<string>, required) — "none" · "read_only"
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `archived_at` (string | null, required)
  - `has_more` (boolean, required)
  - `next_cursor` (string) — Opaque cursor; pass as `after` on the next request.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/memory_stores' \
  -H "Authorization: Bearer ast_..."
```

### POST /memory_stores

Create a memory store (scope: write)

Body (application/json):

- `name` (string, required) — max length 255
- `description` (string) — max length 4096
- `attach_by_default` (enum<string>) — "none" · "read_only"

Responses:

- `201` — Created memory store
  - `memory_store` (object, required)
    - `id` (string, required) — memstore_…
    - `object` (enum<string>, required) — "memory_store"
    - `name` (string, required)
    - `description` (string, required)
    - `attach_by_default` (enum<string>, required) — "none" · "read_only"
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `archived_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/memory_stores \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"name":"team-notes","description":"Shared team knowledge base"}'
```

### GET /memory_stores/{store_id}

Get a memory store (scope: read)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)

Responses:

- `200` — Memory store
  - `memory_store` (object, required)
    - `id` (string, required) — memstore_…
    - `object` (enum<string>, required) — "memory_store"
    - `name` (string, required)
    - `description` (string, required)
    - `attach_by_default` (enum<string>, required) — "none" · "read_only"
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `archived_at` (string | null, required)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x' \
  -H "Authorization: Bearer ast_..."
```

### POST /memory_stores/{store_id}

Update a memory store (scope: write)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)

Body (application/json):

- `name` (string) — max length 255
- `description` (string) — max length 4096
- `attach_by_default` (enum<string>) — "none" · "read_only"

Responses:

- `200` — Updated memory store
  - `memory_store` (object, required)
    - `id` (string, required) — memstore_…
    - `object` (enum<string>, required) — "memory_store"
    - `name` (string, required)
    - `description` (string, required)
    - `attach_by_default` (enum<string>, required) — "none" · "read_only"
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `archived_at` (string | null, required)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"name":"team-notes-v2","description":"Updated description"}'
```

### DELETE /memory_stores/{store_id}

Delete a memory store (scope: write)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)

Responses:

- `204` — Deleted
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x \
  -H "Authorization: Bearer ast_..."
```

### POST /memory_stores/{store_id}/archive

Archive a memory store (one-way, idempotent) (scope: write)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)

Responses:

- `200` — Archived memory store
  - `memory_store` (object, required)
    - `id` (string, required) — memstore_…
    - `object` (enum<string>, required) — "memory_store"
    - `name` (string, required)
    - `description` (string, required)
    - `attach_by_default` (enum<string>, required) — "none" · "read_only"
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `archived_at` (string | null, required)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/archive \
  -H "Authorization: Bearer ast_..."
```

### GET /memory_stores/{store_id}/memories

List memories in a store (scope: read)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)

Query parameters:

- `path_prefix` (string) — Must end with / (default: /)
- `depth` (integer)
- `after` (string)
- `limit` (integer)

Responses:

- `200` — List of memories
  - `memories` (object[], required)
    - option 1 (object) — Memory without content — returned in list responses.
      - `id` (string, required) — mem_…
      - `type` (enum<string>, required) — Discriminator for the memories list union. — "memory"
      - `object` (enum<string>, required) — "memory"
      - `memory_store_id` (string, required)
      - `path` (string, required) — Absolute path starting with /
      - `content_sha256` (string, required)
      - `content_bytes` (integer, required)
      - `created_at` (string, required)
      - `updated_at` (string, required)
    - option 2 (object)
      - `type` (enum<string>, required) — "memory_prefix"
      - `path` (string, required) — Common path prefix ending with /
  - `has_more` (boolean, required)
  - `next_cursor` (string) — Opaque cursor; pass as `after` on the next request.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/memories' \
  -H "Authorization: Bearer ast_..."
```

### POST /memory_stores/{store_id}/memories

Create a memory (scope: write)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)

Body (application/json):

- `path` (string, required) — Absolute path starting with /
- `content` (string) — max length 102400

Responses:

- `201` — Created memory
  - `memory` (object, required) — Memory with content — returned by single-get, create, and update responses.
    - `id` (string, required) — mem_…
    - `object` (enum<string>, required) — "memory"
    - `memory_store_id` (string, required)
    - `path` (string, required) — Absolute path starting with /
    - `content` (string, required)
    - `content_sha256` (string, required)
    - `content_bytes` (integer, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
  - `version_id` (string, required)
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/memories \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"path":"/notes/hello","content":"Hello, world"}'
```

### GET /memory_stores/{store_id}/memories/{memory_id}

Get a memory with content (scope: read)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)
- `memory_id` (string, required) — The memory id (mem_…)

Responses:

- `200` — Memory with content
  - `memory` (object, required) — Memory with content — returned by single-get, create, and update responses.
    - `id` (string, required) — mem_…
    - `object` (enum<string>, required) — "memory"
    - `memory_store_id` (string, required)
    - `path` (string, required) — Absolute path starting with /
    - `content` (string, required)
    - `content_sha256` (string, required)
    - `content_bytes` (integer, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/memories/mem_cmtc5q1y' \
  -H "Authorization: Bearer ast_..."
```

### POST /memory_stores/{store_id}/memories/{memory_id}

Update a memory (scope: write)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)
- `memory_id` (string, required) — The memory id (mem_…)

Body (application/json):

- `content` (string) — max length 102400
- `path` (string) — Rename the memory to this path
- `precondition` (object)
  - `type` (enum<string>, required) — "content_sha256"
  - `content_sha256` (string, required)

Responses:

- `200` — Updated memory
  - `memory` (object, required) — Memory with content — returned by single-get, create, and update responses.
    - `id` (string, required) — mem_…
    - `object` (enum<string>, required) — "memory"
    - `memory_store_id` (string, required)
    - `path` (string, required) — Absolute path starting with /
    - `content` (string, required)
    - `content_sha256` (string, required)
    - `content_bytes` (integer, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
  - `version_id` (string, required)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/memories/mem_cmtc5q1y \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"content":"Hello, world v2","precondition":{"type":"content_sha256","content_sha256":"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"}}'
```

### DELETE /memory_stores/{store_id}/memories/{memory_id}

Delete a memory (scope: write)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)
- `memory_id` (string, required) — The memory id (mem_…)

Responses:

- `204` — Deleted
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/memories/mem_cmtc5q1y \
  -H "Authorization: Bearer ast_..."
```

### GET /memory_stores/{store_id}/memory_versions

List memory versions for a store (scope: read)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)

Query parameters:

- `memory_id` (string) — Filter to a single memory
- `after` (string)
- `limit` (integer)

Responses:

- `200` — List of memory versions
  - `memory_versions` (object[], required)
    - `id` (string, required) — memver_…
    - `object` (enum<string>, required) — "memory_version"
    - `memory_store_id` (string, required)
    - `memory_id` (string, required)
    - `path` (string, required)
    - `content` (string | null, required) — null when redacted
    - `content_sha256` (string | null, required)
    - `operation` (enum<string>, required) — "create" · "update" · "delete"
    - `actor_type` (enum<string>, required) — "user" · "session"
    - `actor_id` (string, required)
    - `redacted_at` (string | null, required)
    - `created_at` (string, required)
  - `has_more` (boolean, required)
  - `next_cursor` (string) — Opaque cursor; pass as `after` on the next request.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/memory_versions' \
  -H "Authorization: Bearer ast_..."
```

### GET /memory_stores/{store_id}/memory_versions/{version_id}

Get a single memory version (scope: read)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)
- `version_id` (string, required) — The memory version id (memver_…)

Responses:

- `200` — Memory version
  - `memory_version` (object, required)
    - `id` (string, required) — memver_…
    - `object` (enum<string>, required) — "memory_version"
    - `memory_store_id` (string, required)
    - `memory_id` (string, required)
    - `path` (string, required)
    - `content` (string | null, required) — null when redacted
    - `content_sha256` (string | null, required)
    - `operation` (enum<string>, required) — "create" · "update" · "delete"
    - `actor_type` (enum<string>, required) — "user" · "session"
    - `actor_id` (string, required)
    - `redacted_at` (string | null, required)
    - `created_at` (string, required)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/memory_versions/memver_cmtc5q1z' \
  -H "Authorization: Bearer ast_..."
```

### POST /memory_stores/{store_id}/memory_versions/{version_id}/redact

Redact the content of a memory version (scope: write)

Path parameters:

- `store_id` (string, required) — The memory store id (memstore_…)
- `version_id` (string, required) — The memory version id (memver_…)

Responses:

- `200` — Redacted memory version
  - `memory_version` (object, required)
    - `id` (string, required) — memver_…
    - `object` (enum<string>, required) — "memory_version"
    - `memory_store_id` (string, required)
    - `memory_id` (string, required)
    - `path` (string, required)
    - `content` (string | null, required) — null when redacted
    - `content_sha256` (string | null, required)
    - `operation` (enum<string>, required) — "create" · "update" · "delete"
    - `actor_type` (enum<string>, required) — "user" · "session"
    - `actor_id` (string, required)
    - `redacted_at` (string | null, required)
    - `created_at` (string, required)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/memory_stores/memstore_cmtc5q1x/memory_versions/memver_cmtc5q1z/redact \
  -H "Authorization: Bearer ast_..."
```

### GET /workspace-context

What a session loads from the workspace's files (scope: read)

The workspace's context store, the files every session the caller starts loads (AGENTS.md, MEMORY.md, people/INDEX.md, projects/INDEX.md and the caller's own members/<handle>.md) with their sizes and limits, and the folders read on demand. What one session actually loaded is its `contextFiles`.

Responses:

- `200` — The workspace context
  - `workspace_context` (object, required) — The caller's workspace files as a session loads them. A session the caller starts loads the always_loaded files into its instructions (each cut at limit_chars, with a marker saying where to read the rest); everything else in the store is read on demand. Read and write the files themselves through /memory_stores/{store_id}/memories.
    - `object` (enum<string>, required) — "workspace_context"
    - `enabled` (boolean, required) — Whether this workspace keeps context files; where it does, the store is created the first time it is asked for
    - `memory_store_id` (string | null, required) — The workspace's store (memstore_…); null where it has none
    - `loads_by_default` (boolean, required) — Whether new sessions get the store (with write access) and load its always-loaded files
    - `mount_path` (string, required) — Where a session finds the store's files
    - `member_handle` (string | null, required) — The caller's page name under /members/
    - `upkeep_routine_id` (string | null, required) — The workspace's daily upkeep routine (rtn_…), which folds the daily notes into MEMORY.md and keeps each member's "How we work together"; pause or archive it to turn it off. Null where the workspace has none
    - `always_loaded` (object[], required)
      - `path` (string, required)
      - `purpose` (string, required)
      - `limit_chars` (integer, required) — Characters of the file a session loads at most
      - `exists` (boolean, required)
      - `memory_id` (string | null, required) — mem_…, when the file exists
      - `content_bytes` (integer | null, required)
    - `on_demand` (object[], required)
      - `path_prefix` (string, required)
      - `purpose` (string, required)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-context' \
  -H "Authorization: Bearer ast_..."
```

## Memory

### GET /memory

Read your personal cross-session memory (scope: read)

Requires read scope. Only unrestricted owner-facing credentials in the authenticated owner's personal universe are supported; restricted tokens, delegated callers, and team universes return 403.

Responses:

- `200` — Saved entries and the opaque version required for the next write.
  - `entries` (object[], required)
    - `index` (integer, required)
    - `text` (string, required)
  - `version` (string | null, required)
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — insufficient_scope or personal_memory_only: caller or universe is not eligible
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/memory' \
  -H "Authorization: Bearer ast_..."
```

### POST /memory

Save, edit, remove or clear a personal memory (scope: write)

Requires write scope and unrestricted owner-facing credentials in your personal universe. Read GET /memory first and copy its version exactly into expectedVersion, even when entries is empty. The sample uses null for a store before its first write; replace it with the returned version for an existing document. Stale writes return 409; reload and resolve the change instead of overwriting. Entries are limited to 2048 UTF-8 bytes and the complete recall context to 4000 characters. A state-changing clear advances the version; a no-op on an existing document retains it. Clear preserves allocated indexes.

Body (application/json):

- option 1 (object)
  - `op` ("save", required)
  - `text` (string, required) — max length 8192
  - `expectedVersion` (string | null, required) — max length 128
- option 2 (object)
  - `op` ("update", required)
  - `index` (integer, required)
  - `text` (string, required) — max length 8192
  - `expectedVersion` (string | null, required) — max length 128
- option 3 (object)
  - `op` ("remove", required)
  - `index` (integer, required)
  - `expectedVersion` (string | null, required) — max length 128
- option 4 (object)
  - `op` ("clear", required)
  - `expectedVersion` (string | null, required) — max length 128

Responses:

- `200` — Saved entries and the opaque version required for the next write.
  - `entries` (object[], required)
    - `index` (integer, required)
    - `text` (string, required)
  - `version` (string | null, required)
- `400` — invalid_memory: invalid operation or memory limit reached
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — insufficient_scope or personal_memory_only: caller or universe is not eligible
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — memory_conflict: reload before writing
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/memory \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"op":"save","text":"Use Celsius for temperatures.","expectedVersion":null}'
```

### GET /context/search

Search one platform source: memory, conversations, the trace library, memory notes, files, meeting notes, skills or agents (scope: read)

Searches one platform-owned source in the workspace your key is in. Restricted and delegated callers are refused. The consumer app's `/api/context/search` merges every source (including imports, artifacts and the Help Center) under the same grammar; use it to search everything at once. `q` is plain words (one case-insensitive substring, one hit per item), "an exact phrase" (case-sensitive, every matching line) or /a regex/ with optional i, s or u flags (every matching line). Nested repetition and backreferences are refused, and a pattern stops at a time budget with partial=true. Each hit carries `path` (such as `skills/review/SKILL.md`) and, for a match in the text, its 1-based `line`. Results are in stable source order, not a relevance ranking. Follow nextCursor until null and inspect partial/coverage before concluding no match exists. Memory entries have no per-entry timestamps, so their coverage reports that time filtering does not apply.

Query parameters:

- `q` (string, required)
- `scope` (string, required) — The source: traces is the current workspace's trace library (every member's uploaded local agent sessions); notes the workspace's memory-store notes; files and meetings its uploaded files (meetings is the Mac app's meeting notes); skills every file of its skills; agents each agent's name and prompt.
- `path` (string) — Keep only hits under this folder, such as skills/review/ or memory/sales/.
- `limit` (integer)
- `cursor` (string) — Source continuation returned by this query.
- `since` (string) — Inclusive lower time bound.
- `until` (string) — Exclusive upper time bound; must follow since.

Responses:

- `200` — A bounded source page, with continuation and coverage.
  - `hits` (object[], required)
    - `hit` (object, required)
      - `source` (enum<string>, required) — "memory" · "notes" · "sessions" · "imports" · "traces" · "artifacts" · "files" · "meetings" · "skills" · "agents" · "docs"
      - `id` (string, required)
      - `title` (string, required)
      - `snippet` (string, required)
      - `occurredAt` (string)
      - `path` (string) — max length 2048
      - `line` (integer)
      - `ref` (object, required)
        - option 1 (object)
          - `kind` ("memory", required)
          - `index` (integer, required)
          - `version` (string | null, required)
        - option 2 (object)
          - `kind` ("session_message", required)
          - `sessionId` (string, required) — max length 200
          - `messageId` (string, required) — max length 200
        - option 3 (object)
          - `kind` ("import_event", required)
          - `traceId` (string, required) — max length 200
          - `seq` (integer, required)
        - option 4 (object)
          - `kind` ("artifact", required)
          - `artifactId` (string, required) — max length 200
          - `version` (integer, required)
        - option 5 (object)
          - `kind` ("trace_message", required)
          - `traceId` (string, required) — max length 200
          - `seq` (integer, required)
        - option 6 (object)
          - `kind` ("memory_note", required)
          - `storeId` (string, required) — max length 200
          - `memoryId` (string, required) — max length 200
        - option 7 (object)
          - `kind` ("file", required)
          - `fileId` (string, required) — max length 200
        - option 8 (object)
          - `kind` ("skill_file", required)
          - `skillId` (string, required) — max length 200
          - `revisionId` (string, required) — max length 200
          - `path` (string, required) — max length 1024
        - option 9 (object)
          - `kind` ("agent", required)
          - `agentId` (string, required) — max length 200
        - option 10 (object)
          - `kind` ("doc", required)
          - `slug` (string, required) — max length 200
      - `citation` (string)
      - `external_input` (true)
    - `cursor` (string, required) — max length 4096
  - `nextCursor` (string | null, required) — max length 4096
  - `coverage` (string, required)
  - `partial` (boolean)
- `400` — Invalid query, source reference, cursor or text offset
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — The caller lacks personal-context authority or read scope
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/context/search?q=concise&scope=memory' \
  -H "Authorization: Bearer ast_..."
```

### GET /context/read

Read the source behind a search hit (scope: read)

Rechecks ownership, workspace and deletion. Accepts memory, session_message, trace_message, memory_note, file, skill_file and agent references from search; a file that is not text reads as text null. Memory returns the current entry and flags version changes; it does not preserve old versions. Message reads return bounded text and adjacent references for surrounding context. Use nextOffset for a long main message; follow adjacent refs to continue reading. All text together is bounded to 20,000 characters per page.

Query parameters:

- `ref` (string, required) — URL-encoded JSON source reference copied from a search hit.
- `offset` (integer)

Responses:

- `200` — Current reference, text, nextOffset, truncated, updated, adjacent references and coverage.
  - `ref` (object)
  - `text` (string)
  - `nextOffset` (integer | null)
  - `truncated` (boolean)
  - `updated` (boolean)
  - `coverage` (string)
  - `adjacent` (object[])
    - `ref` (object)
    - `text` (string)
    - `truncated` (boolean)
- `400` — Invalid query, source reference, cursor or text offset
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — The caller lacks personal-context authority or read scope
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Source unavailable or not owned by this caller
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Memory changed while paging; read again from offset zero
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/context/read?ref=%7B%22kind%22%3A%22memory%22%2C%22index%22%3A0%2C%22version%22%3Anull%7D' \
  -H "Authorization: Bearer ast_..."
```

## Events

### GET /events

The work graph log: everything that happened in a task, a session or your own work, in time order (scope: read)

With `task` or `session`, the workspace log's events for it plus your own; with neither, your private log only. The log never shows anything you cannot already open. `object=<type>:<id>` returns every event that touched that object — `sha256:<hex>` traces a file's exact bytes back to the session that produced them, across every thread of the work. Follow next_cursor until null.

Query parameters:

- `task` (string) — A task (its root session id, sess_…)
- `session` (string) — One session
- `object` (string) — <type>:<id>, e.g. sha256:<hex>, artifact:<id>, chat_message:<id>
- `kind` (string)
- `from` (string) — Inclusive
- `to` (string) — Exclusive
- `cursor` (string)
- `limit` (integer)

Responses:

- `200` — A page of events
  - `data` (object[])
    - `id` (string) — evt_…, time-ordered
    - `log` (enum<string>) — The caller's private log, or the workspace's shared log — "person" · "workspace"
    - `kind` (string) — Dotted event type, e.g. session.message, taskfile.version_created, artifact.revised, result.obtained
    - `occurred_at` (string)
    - `recorded_at` (string)
    - `clock_source` (enum<string>) — "server" · "device" · "platform"
    - `skew_ms` (integer | null)
    - `actor` (object) — {kind: person|agent|teammate|guest|external|system, user_id?, session_id?, platform_user?}
    - `surface` (string) — web, mac, api, pod, channel:<platform>, connector:<app>…
    - `source` (object)
      - `system` (string)
      - `kind` (string)
      - `version` (string | null)
    - `objects` (object[]) — Every object the event touched: sha256 of file contents, documents, sessions, messages
      - `type` (string)
      - `id` (string)
      - `role` (string)
    - `payload` (object | null)
    - `payload_sha256` (string | null) — Set when the payload was large and is read through /events/{id}/body?part=payload
    - `payload_removed_at` (string | null)
    - `provenance` (object | null)
    - `correlation` (object) — Explicit links: task_id, session_id, thread, calendar event, PR…
    - `task_id` (string | null)
    - `session_id` (string | null)
  - `next_cursor` (string | null)
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/events' \
  -H "Authorization: Bearer ast_..."
```

### POST /events

Write events from any program into the work graph log (scope: write)

Appends up to 500 events in the same envelope GET /events returns, from an agent running elsewhere, a script or your own app. Each event's idempotency_key is unique per log: pushing it again answers status duplicate with the existing id and writes nothing. log person (default) is your private log; workspace is your workspace's shared log. task_id or session_id must be one you can open. bodies are kept whole, whatever their size: text or base64 inline, or file_id of a file uploaded first through POST /files/uploads for large ones; credentials in text bodies are masked before storage. source.system names your program; the platform's own systems are refused (400 reserved_source). The whole batch is checked before anything is written.

Body (application/json):

- `events` (object[], required)
  - `idempotency_key` (string, required) — pattern ^[A-Za-z0-9._:@/-]{1,200}$
  - `log` (enum<string>) — "person" · "workspace" — default: "person"
  - `kind` (string, required) — Dotted lowercase type, e.g. tool.call, slack.message
  - `occurred_at` (string)
  - `clock_source` (enum<string>) — "device" · "platform" — default: "device"
  - `actor` (object)
    - `kind` (enum<string>) — "person" · "agent" · "teammate" · "guest" · "external" · "system"
    - `platform_user` (object)
    - `label` (string)
  - `surface` (string) — default: "api"
  - `source` (object, required)
    - `system` (string, required)
    - `kind` (string, required)
    - `version` (string)
  - `objects` (object[])
    - `type` (string, required)
    - `id` (string, required)
    - `role` (string)
  - `payload` (object)
  - `correlation` (map<string, string>)
  - `task_id` (string)
  - `session_id` (string)
  - `bodies` (object[])
    - `role` (string) — default: "response"
    - `media_type` (string)
    - `text` (string)
    - `base64` (string)
    - `file_id` (string)
    - `complete` (boolean)

Responses:

- `200` — One result per event, in order
  - `data` (object[])
    - `idempotency_key` (string)
    - `status` (enum<string>) — "created" · "duplicate"
    - `id` (string)
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/events \
  -H "Authorization: Bearer ast_..."
```

### GET /digests

Short summaries of your own recorded work, per local day or hour (scope: read)

A digest is the short memory an agent reads before searching the raw log: what you worked on, where (app, repository, site, conversation), decisions, outputs (pull requests, commits, files, messages, meetings) and the tasks involved, for one hour or one local day. Newest window first; only the latest revision of each window (a window is rewritten when late uploads change its records). Every activity cites event_ids that GET /events/{id} opens, and each raw query lists the window's original records through GET /events. Your private log only; the raw records are never shortened or removed.

Query parameters:

- `period` (string)
- `from` (string) — Inclusive earliest window start
- `to` (string) — Exclusive
- `limit` (integer) — Windows to return (default 7 days or 24 hours)

Responses:

- `200` — The digests
  - `data` (object[])
    - `id` (string)
    - `period` (enum<string>) — "day" · "hour"
    - `window` (object)
      - `key` (string)
      - `from` (string)
      - `to` (string)
      - `time_zone` (string)
    - `title` (string)
    - `summary` (string | null)
    - `activities` (object[])
      - `title` (string)
      - `where` (string)
      - `what` (string)
      - `decisions` (string[])
      - `outputs` (string[])
      - `event_ids` (string[])
      - `raw` (object)
    - `outputs` (object[])
    - `tasks` (object[])
    - `sources` (object[])
    - `stats` (object)
  - `how_to_read` (string)
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/digests' \
  -H "Authorization: Bearer ast_..."
```

### GET /timeline

One day of your own work timeline: stretches of work, pauses and digests (scope: read)

Built from what your Mac recorded: each stretch is work in one app or time away, with the apps, documents and sites in it, and `raw` is the `GET /events` range holding its original records. `summaries` are the digests written for that day, when digests run for you. Records inside a pause are left out. Only your own key reaches this: every other credential is refused.

Query parameters:

- `date` (string) — The local day, YYYY-MM-DD. Default: today in `tz`.
- `tz` (string) — IANA time zone the day is counted in, such as Asia/Shanghai

Responses:

- `200` — The day
  - `date` (string)
  - `time_zone` (string)
  - `paused` (object | null) — The pause in force now, whichever day was read
  - `pauses` (object[]) — Paused stretches overlapping the day
    - `start_at` (string)
    - `end_at` (string | null)
    - `until` (string | null)
  - `last_recorded_at` (string | null) — When the day's latest record reached the platform
  - `stretches` (object[])
    - `kind` (enum<string>) — "work" · "away"
    - `start_at` (string)
    - `end_at` (string)
    - `title` (string)
    - `minutes` (integer)
    - `apps` (string[])
    - `documents` (string[])
    - `sites` (string[])
    - `counts` (object)
      - `actions` (integer)
      - `screens` (integer)
      - `file_saves` (integer)
      - `commits` (integer)
    - `raw` (object)
      - `from` (string)
      - `to` (string)
  - `summaries` (object) — Digests, in the shape `GET /digests` answers
    - `day` (object | null)
    - `hours` (object[])
  - `how_to_read` (string)
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/timeline' \
  -H "Authorization: Bearer ast_..."
```

### GET /timeline/pause

Whether your work timeline is paused (scope: read)

Responses:

- `200` — The pause in force, or null
  - `paused` (object | null)
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/timeline/pause' \
  -H "Authorization: Bearer ast_..."
```

### PUT /timeline/pause

Pause your work timeline on every device (scope: write)

Your Macs stop recording within about a minute of hearing this, and until you resume the platform stores nothing they send (423 `timeline_paused`). Calling it again while paused moves `until`. A Mac that is offline stops once it reconnects; whatever it recorded in between never enters your work log.

Body (application/json):

- `until` (string | null) — When to resume by itself. Omitted or null: stays paused until you resume.

Responses:

- `200` — The pause in force
  - `paused` (object | null)
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/timeline/pause \
  -H "Authorization: Bearer ast_..."
```

### DELETE /timeline/pause

Resume your work timeline on every device (scope: write)

Responses:

- `200` — Resumed; resuming when nothing is paused changes nothing
  - `paused` (object | null)
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/timeline/pause \
  -H "Authorization: Bearer ast_..."
```

### GET /events/{id}

One work graph event (scope: read)

Path parameters:

- `id` (string, required)

Responses:

- `200` — The event
  - `id` (string) — evt_…, time-ordered
  - `log` (enum<string>) — The caller's private log, or the workspace's shared log — "person" · "workspace"
  - `kind` (string) — Dotted event type, e.g. session.message, taskfile.version_created, artifact.revised, result.obtained
  - `occurred_at` (string)
  - `recorded_at` (string)
  - `clock_source` (enum<string>) — "server" · "device" · "platform"
  - `skew_ms` (integer | null)
  - `actor` (object) — {kind: person|agent|teammate|guest|external|system, user_id?, session_id?, platform_user?}
  - `surface` (string) — web, mac, api, pod, channel:<platform>, connector:<app>…
  - `source` (object)
    - `system` (string)
    - `kind` (string)
    - `version` (string | null)
  - `objects` (object[]) — Every object the event touched: sha256 of file contents, documents, sessions, messages
    - `type` (string)
    - `id` (string)
    - `role` (string)
  - `payload` (object | null)
  - `payload_sha256` (string | null) — Set when the payload was large and is read through /events/{id}/body?part=payload
  - `payload_removed_at` (string | null)
  - `provenance` (object | null)
  - `correlation` (object) — Explicit links: task_id, session_id, thread, calendar event, PR…
  - `task_id` (string | null)
  - `session_id` (string | null)
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/events/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### GET /events/{id}/body

An event's stored body, whole: a connector reply, a context result, a request, or a large payload (scope: read)

Bodies are stored whole, whatever their size; `x-body-complete: false` means only that the source itself ended early. `x-body-redacted: true` means credentials were masked before storage.

Path parameters:

- `id` (string, required)

Query parameters:

- `part` (string) — A body role: response, request, payload (a large event payload), or a role the writer named
- `as` (string) — text answers the extracted text when the body has one

Responses:

- `200` — The bytes, with x-content-sha256
- `400` — Invalid filter, time or cursor
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown, not visible to the caller, or the work graph is off for this workspace
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `410` — The content was deleted
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — The work graph is not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/events/sess_cmtb7q2j/body' \
  -H "Authorization: Bearer ast_..."
```

## Identity

### GET /navigation-profile

Read the caller's role and spendable balance in this workspace (scope: read)

What the app shell shows in the resolved workspace (X-Universe). role is the account's role. credit_balance_usd, balance_text and spendable_usd belong to the wallet the caller may see: the workspace's when it has one and they own or administer it, otherwise their own. paying_spendable_usd is what admits a new chat here: what the paying wallet can spend, null when it has credit this person may not see the amount of, 0 when it has none. sky says whether the Sky home is on, gateway_referral whether they can issue customer referral links, language the language they chose (null when they never chose).

Responses:

- `200` — OK
  - `role` (enum<string>, required) — "USER" · "DEVELOPER"
  - `sky` (boolean, required)
  - `balance_text` (string, required) — The balance as the shell writes it, such as $12.50.
  - `credit_balance_usd` (number, required)
  - `spendable_usd` (number, required)
  - `paying_spendable_usd` (number, required)
  - `gateway_referral` (boolean, required)
  - `language` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/navigation-profile' \
  -H "Authorization: Bearer ast_..."
```

### GET /whoami

Caller identity, resolved universe, effective scopes (scope: read)

Responses:

- `200` — OK
  - `user` (object, required)
    - `id` (string)
    - `email` (string)
    - `name` (string | null)
  - `universe` (object, required)
    - `slug` (string)
    - `name` (string)
    - `isPersonal` (boolean)
  - `scopes` (enum<string>[], required) — "read" · "write" · "admin"
  - `auth` (enum<string>, required) — "token" · "session"
  - `account_access` (boolean) — Whether this credential represents the whole account rather than a workspace, app, task, system client or restricted purpose. Scopes still apply.
  - `credential_universe` (string | null) — The workspace this credential is fixed to, or null.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/whoami' \
  -H "Authorization: Bearer ast_..."
```

### POST /account/deletion

Request deletion of your own account (scope: admin)

Uses the same support queue as Settings. Requires an unrestricted personal admin key not fixed to a workspace; workspace keys, delegated credentials and support views are refused. Pass confirm DELETE. The idempotent receipt means the request is recorded, not completed deletion. Support completes deletion within 30 days; it cannot be undone. Does not clear browser sessions or revoke the calling key at request time.

Body (application/json):

- `confirm` ("DELETE", required)

Responses:

- `200` — OK
  - `requestedAt` (string, required)
  - `email` (string | null, required)
  - `emailed` (boolean, required)
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/account/deletion \
  -H "Authorization: Bearer ast_..."
```

## Gateway capability choices

### GET /gateway/capabilities

Deprecated: use GET /plugins?view=discover&source=tool. Deprecated: use GET /plugins?view=discover&source=tool. Deprecated: use GET /plugins?view=discover&source=tool. Read gateway capability choices (scope: read)

Deprecated: use `GET /plugins?view=discover&source=tool`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins?view=discover&source=tool`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins?view=discover&source=tool`. Still served exactly as before; every answer carries a `Deprecation` header. Reads the same account-priced gateway choices as the console picker. Each capability names available priced session-compatible endpoints and their public catalog links. This read grants nothing and does not expose operator configuration or credentials. Catalog outages return 503, not an empty available set.

Responses:

- `200` — OK
  - `capabilities` (object[], required)
    - `id` (string, required)
    - `available` (boolean, required)
    - `details` (object[], required)
      - `name` (string)
      - `href` (string)
      - `price` (string)
- `401` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/gateway/capabilities' \
  -H "Authorization: Bearer ast_..."
```

## Gateway prices and trying an item

### GET /gateway/prices

Read the Market's price lists

The Market's Models and Tools price lists as the web draws them, read from the gateway with the caller's own key, so the prices are the ones their plan pays. Models are newest first, text models with input and output per 1M tokens, media models at their own meter. `available` is false, with empty lists, when the catalog could not be read.

Responses:

- `200` — OK
  - `available` (boolean, required)
  - `models` (object[], required)
    - `id` (string)
    - `name` (string)
    - `owner` (string)
    - `meta` (string)
    - `discount` (string)
    - `description` (string)
    - `categories` (string[])
    - `input` (string)
    - `output` (string)
    - `list` (object) — The official rates a discounted text model is compared with: `{input, output, inputDiscounted, outputDiscounted}`.
    - `from` (boolean)
    - `price` (string)
    - `use` (object) — The agent a text model starts on: `{agentType, llm}`.
    - `capability` (string)
  - `modelTabs` (object[], required)
    - `id` (string)
    - `label` (string)
  - `tools` (object[], required)
    - `id` (string)
    - `name` (string)
    - `provider` (string)
    - `description` (string)
    - `function` (string)
    - `price` (string)
    - `capability` (string)
  - `toolTabs` (object[], required)
    - `id` (string)
    - `label` (string)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/gateway/prices' \
  -H "Authorization: Bearer ast_..."
```

### GET /gateway/discounts

Read your Gateway discounts

The caller's prices against the standard ones, as `/gateway/discounts` compares them: each discounted model or tool, largest discount first, with its percent, label and prices. `listPricing` and `listPricePerUnit` are the reference prices. `available` is false, with no discounts, when either catalog could not be read; an empty list with `available: true` means the plan has no discount.

Responses:

- `200` — OK
  - `available` (boolean, required)
  - `upToPercent` (number, required)
  - `discounts` (object[], required)
    - `id` (string, required)
    - `name` (string, required)
    - `owner` (string)
    - `description` (string)
    - `categories` (string[])
    - `href` (string)
    - `discountPercent` (number, required)
    - `discountLabel` (string, required)
    - `pricing` (any)
    - `listPricing` (object)
    - `pricingTiers` (object[])
    - `unit` (string)
    - `pricePerUnit` (string)
    - `listPricePerUnit` (string)
    - `pricingRoutes` (object[])
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/gateway/discounts' \
  -H "Authorization: Bearer ast_..."
```

### GET /gateway/try

Preview trying a catalog item

What `POST /gateway/try` would send for this item and what it can cost, the note the Try button shows. Spends nothing.

Query parameters:

- `kind` (string, required)
- `id` (string, required) — Catalog id, such as `openai/gpt-6`.

Responses:

- `200` — OK
  - `kind` (string)
  - `id` (string)
  - `request` (object)
    - `path` (string)
    - `body` (object)
  - `costNote` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/gateway/try?kind=kind&id=sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### POST /gateway/try

Try a catalog item

Runs a catalog item's own sample request, as its page's Try button does. **This spends money**: the call is billed to the caller's balance like any gateway call. The request is rebuilt from the catalog entry and the caller names only which entry. It goes out under the caller's own key, so the gateway's scope check, rate limit and balance gate apply unchanged: an out-of-credit or rate-limited refusal keeps the gateway's status under code `gateway_refused`, with its answer in `error.body`. `runId` is set for a tool still working; read it with `GET /gateway/try/{run_id}`. A tool run honours `Idempotency-Key`, so reuse one on retry. 504 means the gateway did not answer in time and the request may still have run and been billed.

Body (application/json):

- `kind` (enum<string>, required) — "model" · "tool"
- `id` (string, required)

Responses:

- `200` — OK
  - `status` (integer, required) — The gateway's own status.
  - `body` (string, required) — The gateway's answer, formatted and cut at 8,000 characters.
  - `costUsd` (number, required) — What the call cost, when the gateway reports it.
  - `ms` (integer, required)
  - `runId` (string, required) — Set while a tool run is still working.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `402` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `429` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `502` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `504` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/gateway/try \
  -H "Authorization: Bearer ast_..."
```

### GET /gateway/try/{run_id}

Read a tried tool's run

Reads a tool run `POST /gateway/try` started, under the caller's own key. `id` is the catalog id it was started from. Reading costs nothing.

Path parameters:

- `run_id` (string, required)

Query parameters:

- `id` (string, required) — Catalog id the run was started from.

Responses:

- `200` — OK
  - `status` (integer, required) — The gateway's own status.
  - `body` (string, required) — The gateway's answer, formatted and cut at 8,000 characters.
  - `costUsd` (number, required) — What the call cost, when the gateway reports it.
  - `ms` (integer, required)
  - `runId` (string, required) — Set while a tool run is still working.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `502` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/gateway/try/run_id?id=sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

## Universes

### GET /universes

List universes (scope: read)

With include=connections, each universe also carries sharing, connections[] and, while sharing is on, can_connect: what GET /universes/{slug}/connections answers for it, for every workspace in one call.

Query parameters:

- `include` (string) — connections: add each workspace's shared connections

Responses:

- `200` — OK
  - `universes` (object[], required)
    - `slug` (string)
    - `name` (string)
    - `isPersonal` (boolean) — The workspace is its owner's default workspace
    - `isDefault` (boolean) — The workspace is the caller's own default workspace
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes' \
  -H "Authorization: Bearer ast_..."
```

### POST /universes

Create a universe (scope: write, personal tokens only)

Any credential of the person may create one, whichever workspace the request selects with X-Universe. A key limited to one team workspace (a workspace-scoped token, a workspace key or an app credential) is 403 forbidden.

Body (application/json):

- `slug` (string, required) — max length 40 — pattern ^[a-z0-9][a-z0-9-]*[a-z0-9]$
- `name` (string) — max length 80

Responses:

- `201` — Created
  - `universe` (object, required)
    - `slug` (string)
    - `name` (string)
    - `isPersonal` (boolean) — The workspace is its owner's default workspace
    - `isDefault` (boolean) — The workspace is the caller's own default workspace
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"slug":"acme","name":"Acme"}'
```

### GET /universes/{slug}

Universe detail (scope: read)

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `universe` (object, required)
    - `slug` (string)
    - `name` (string)
    - `isPersonal` (boolean) — The workspace is its owner's default workspace
    - `isDefault` (boolean) — The workspace is the caller's own default workspace
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /universes/{slug}

Rename a workspace or enable Google Limited Use (scope: write, owner)

Owner only. Pass a name to rename as Settings › General does; the slug stays unchanged. Alternatively pass google_limited_use: true to permanently enable Google-data processor and export restrictions for this workspace; false is refused. A credential locked to another workspace is 403 universe_mismatch; a member who is not the owner is 403 forbidden.

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- option 1 (object)
  - `name` (string, required) — max length 100
- option 2 (object)
  - `google_limited_use` (enum<boolean>, required) — true

Responses:

- `200` — OK
  - `universe` (object)
    - `slug` (string)
    - `name` (string)
    - `isPersonal` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/universes/acme \
  -H "Authorization: Bearer ast_..."
```

### DELETE /universes/{slug}

Permanently delete a workspace and everything in it (scope: write, owner)

Owner only, with a personal ast_ API key (a workspace key, a workspace-scoped token or an app credential is 403). Everyone else loses access at once; every session is stopped and its pod destroyed; agent fees held on its tasks are settled; the purchased credit in its wallet goes to the owner; apps the workspace connected are disconnected; then its sessions and transcripts, agents, artifacts, task files, files, memory, routines, channels, webhooks, keys, vaults, skills, environments, traces, members and invitations are removed. Money records (ledger, bills, receipts) are kept. A default workspace cannot be deleted (409 default_workspace), nor one with an agent live in the catalog (409 live_listing), a public environment (409 public_environment) or a published product (409 published_product). 503 pod_teardown_failed when a pod would not stop: nothing else was removed, and repeating the call finishes the delete. Read GET /universes/{slug}/deletion first to show what will go.

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `deleted` (object, required)
    - `slug` (string, required)
    - `sessions_stopped` (integer, required) — Pods that were running and were destroyed
    - `wallet_returned_micros` (integer, required) — Purchased credit moved from the workspace wallet to the owner, in USD micros
    - `session_ids` (string[], required) — Every session the workspace held, all now deleted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/universes/acme \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/deletion

What deleting the workspace would remove, and whether it can be deleted (scope: read, owner)

When new deletions are temporarily unavailable, can_delete is false with a not_enabled blocker. An existing exact deletion request remains recoverable; other workspace blockers still apply.

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `workspace` (object, required)
    - `slug` (string)
    - `name` (string)
    - `created_at` (string)
  - `can_delete` (boolean, required)
  - `blockers` (object[], required)
    - `code` (enum<string>) — "default_workspace" · "live_listing" · "public_environment" · "published_product" · "not_enabled"
    - `message` (string)
  - `removes` (map<string, integer>, required) — Counts by kind: sessions, running_sessions, agents, artifacts, files, memory_stores, routines, channels, webhooks, api_keys, vaults, skills, environments, connections, traces, members (besides the owner), invites (pending)
  - `wallet` (object, required) — Present when the workspace wallet holds purchased credit
    - `balance_micros` (integer)
    - `returns_to` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/deletion' \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/deletion/requests/{requestId}

Read the exact accepted workspace deletion proof (scope: write, owner)

Internal callback of the existing workspace deletion coordinator, not another delete action. Requires the actual current workspace owner with unrestricted personal write authority or the exact first-party agent-use-web credential, and the immutable accepted request UUID/actor/workspace incarnation. A key fixed to a workspace, team/app/task/restricted credential or foreign owner is refused. The dedicated fixed-origin workspace transport may carry only the runtime session-token cookie and reauthenticates the actual owner; bearer presence never falls back to cookies. Read-only pages expose the measured sessions and canonical artifact/reclamation facts needed by source begin/finish, not a content or editing grant. Existing exact requests remain readable/recoverable with LEGACY_ARTIFACT_ADOPTION off. A missing, superseded or purged intent does not create or revive one. after_revision requires target_id, which must belong to this deletion's measured scope. Every cursor is an exact internal id, at most 200 characters.

Path parameters:

- `slug` (string, required) — Exact workspace slug or persisted universe id
- `requestId` (string, required) — The existing canonical Universe.deletionIntent request UUID

Query parameters:

- `after_session` (string)
- `after_artifact` (string)
- `target_id` (string) — One exact artifact in this workspace deletion for its bounded reclamation proof
- `after_revision` (string)

Responses:

- `200` — Exact accepted deletion proof; private, no-store
  - `purpose` ("workspace_delete", required)
  - `version` (1, required)
  - `request_id` (string, required)
  - `actor_user_id` (string, required)
  - `universe_id` (string, required)
  - `universe_slug` (string, required)
  - `universe_created_at` (string, required)
  - `phase` (enum<string>, required) — "preparing" · "fenced" · "reclaiming"
  - `source_fence_digest` (string) — pattern ^[a-f0-9]{64}$
  - `progress` (object)
    - `source_finished_digest` (string, required) — pattern ^[a-f0-9]{64}$
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required) — "agent-use-web" · null
  - `session_ids` (string[], required) — At most 50 measured sessions, with their internal and public ids
  - `next_session` (string | null, required)
  - `canonical_targets` (object[], required)
    - `target_id` (string, required)
    - `source_id` (string, required)
    - `source_epoch` (integer, required)
    - `owner_user_id` (string, required)
    - `adoption_state` (string, required)
    - `bytes_reclaimed` (boolean, required)
    - `reclamation_request_id` (string)
  - `next_artifact` (string | null, required)
  - `reclamation` (object)
    - `target_id` (string, required)
    - `request_id` (string, required)
    - `source_id` (string, required)
    - `source_epoch` (integer, required)
    - `bytes_complete` (boolean, required)
    - `next` (string | null, required)
    - `entries` (object[], required)
      - `request_id` (string, required)
      - `source_epoch` (integer, required)
      - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
      - `raw_size_bytes` (integer, required)
      - `media_type` (string, required)
      - `site` (boolean, required)
      - `version` (integer | null, required)
      - `canonical_revision_id` (string, required)
      - `generations_reclaimed` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/deletion/requests/requestId' \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/members

People in the workspace and, for owners and admins, waiting invitations (scope: read)

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `role` (enum<string>, required) — "owner" · "admin" · "member"
  - `members` (object[], required)
    - `user_id` (string)
    - `email` (string)
    - `name` (string)
    - `avatar_url` (string)
    - `role` (enum<string>) — "owner" · "admin" · "member"
    - `joined_at` (string)
  - `invites` (object[], required)
    - `id` (string)
    - `email` (string)
    - `role` (enum<string>) — "admin" · "member"
    - `invited_by` (string)
    - `expires_at` (string)
    - `created_at` (string)
  - `limit_requests` (object[]) — Members' tasks that wait for a higher monthly limit, oldest first
    - `id` (string)
    - `session_id` (string)
    - `title` (string)
    - `member` (object)
      - `user_id` (string)
      - `name` (string)
      - `email` (string)
    - `raise_to` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
    - `held` (integer) — Messages the task holds and will run when the limit is raised
    - `created_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/members' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /universes/{slug}/members/{userId}

Make someone an admin or a member (scope: write, owner)

Path parameters:

- `slug` (string, required) — The universe slug
- `userId` (string, required)

Body (application/json):

- `role` (enum<string>, required) — "admin" · "member"

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/universes/acme/members/cmtb3u5r7k2p9x01s6q8n4w2 \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"role":"admin"}'
```

### DELETE /universes/{slug}/members/{userId}

Remove a non-owner from the workspace, or leave it (scope: write)

The owner removes anyone but themselves. Anyone else may name only themselves (their id, or me), which is how a person leaves; naming someone else is 403, and the owner cannot leave (400). Ends membership access, stops sharing every connection the person shared with the workspace, and closes pending and accepted invitation links. Accounts and threads remain; workspace-visible threads owned by the removed person become read-only for remaining members.

Path parameters:

- `slug` (string, required) — The universe slug
- `userId` (string, required)

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/universes/acme/members/cmtb3u5r7k2p9x01s6q8n4w2 \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/agents

The agents this workspace chose from the catalog (scope: read)

The catalog is the same for everyone; this is what the workspace installed from it, enabled or not, with the model members start each agent with by default. agent is the listing as the catalog serves it now, null once it has left the catalog. Installing gates nothing: a policy rule forbids an agent, and starting a session still validates the model it is given.

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `role` (enum<string>, required) — "owner" · "admin" · "member"
  - `installs` (object[], required)
    - `handle` (string, required) — The catalog handle without its @
    - `enabled` (boolean, required)
    - `default_model` (string, required) — The model members start this agent with unless they pick another; null = the agent's own default
    - `installed_by` (object, required)
      - `user_id` (string, required)
      - `name` (string)
      - `email` (string)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `agent` (object, required) — The listing as the catalog serves it to this workspace now; null once it has left the catalog
      - `handle` (string, required) — Globally unique and stable: lower-case letters, digits and underscores. What a person types after "/".
      - `kind` (enum<string>, required) — A platform engine, or an agent a person listed — "engine" · "agent"
      - `engine_type` (string | null, required) — The agent type to create an agent with, for an engine listing
      - `agent_id` (string | null, required) — The agent one of the caller's own workspace listings stands for; null for an engine and for another person's agent
      - `visibility` (enum<string>, required) — public for everyone: an engine, or another person's agent that was reviewed and approved. workspace for the caller's own listing, whether or not it is also public. — "public" · "workspace"
      - `seller` (object | null, required) — Who made a public agent that is not a platform engine, by the name they chose. Null for an engine and for the caller's own listing.
      - `name` (string, required)
      - `tagline` (string, required) — One line, at most 140 characters
      - `description` (string, required)
      - `does` (string[], required) — What it does. Empty when not yet written; never guessed.
      - `does_not` (string[], required) — What it does not do. Empty when not yet written.
      - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
      - `examples` (string[], required) — Example tasks
      - `requirements` (object, required) — What the agent needs, stated rather than hidden. `mcp_servers` says whether it can use MCP servers; `website` is the engine's own site. `hosted_by_seller: { host }` is present when the agent runs on its maker's own server instead of a sandbox: what a person sends it, and the files of the task, go to that host, and a person's first task with it waits for them to agree (a task request).
      - `pricing` (object, required) — `{ mode: "usage" }`: the model and tool usage the task incurs, with no agent fee. `{ mode: "per_task", fee: { amount, currency } }`: usage, plus a flat fee the agent's maker asks for each task; `amount` is whole US cents as a string. Starting such an agent asks the person to confirm the price the first time (a task request of kind `spend`), holds the fee on their credit when the task starts and takes it when the task gives its first result.
      - `stats` (object, required) — Counts from real use, recounted hourly; never estimated. `uses`: sessions started on the agent. `comparisons` and `wins`: decided side-by-side comparisons the agent took part in, and the ones a person picked it in. `completed_yes` and `completed_no`: people who said a task on this agent did the job, and people who said it did not (`PUT /tasks/{id}/completion_answer`).
        - `uses` (integer, required)
        - `comparisons` (integer, required)
        - `wins` (integer, required)
        - `completed_yes` (integer, required)
        - `completed_no` (integer, required)
        - `usage` (object | null) — What one task typically consumes: medians over the agent's sessions of the last 30 days that metered model usage. Null until at least 10 such sessions exist.
      - `conformance` (object | null, required) — The verdicts of the listing's latest finished conformance run; for another person's agent, of the run it was submitted with. Null when it has never finished one.
      - `created_at` (string, required)
      - `installed` (boolean) — Whether the caller's workspace installed this agent from the catalog and left it enabled. Only on a read made for a workspace.
      - `default_model` (string | null) — The model the caller's workspace starts this agent with by default; null when it set none. Only with installed.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/agents' \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/agents/{handle}

One agent the workspace chose from the catalog (scope: read)

Path parameters:

- `slug` (string, required) — The universe slug
- `handle` (string, required) — The catalog handle, with or without its @

Responses:

- `200` — OK
  - `install` (object, required)
    - `handle` (string, required) — The catalog handle without its @
    - `enabled` (boolean, required)
    - `default_model` (string, required) — The model members start this agent with unless they pick another; null = the agent's own default
    - `installed_by` (object, required)
      - `user_id` (string, required)
      - `name` (string)
      - `email` (string)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `agent` (object, required) — The listing as the catalog serves it to this workspace now; null once it has left the catalog
      - `handle` (string, required) — Globally unique and stable: lower-case letters, digits and underscores. What a person types after "/".
      - `kind` (enum<string>, required) — A platform engine, or an agent a person listed — "engine" · "agent"
      - `engine_type` (string | null, required) — The agent type to create an agent with, for an engine listing
      - `agent_id` (string | null, required) — The agent one of the caller's own workspace listings stands for; null for an engine and for another person's agent
      - `visibility` (enum<string>, required) — public for everyone: an engine, or another person's agent that was reviewed and approved. workspace for the caller's own listing, whether or not it is also public. — "public" · "workspace"
      - `seller` (object | null, required) — Who made a public agent that is not a platform engine, by the name they chose. Null for an engine and for the caller's own listing.
      - `name` (string, required)
      - `tagline` (string, required) — One line, at most 140 characters
      - `description` (string, required)
      - `does` (string[], required) — What it does. Empty when not yet written; never guessed.
      - `does_not` (string[], required) — What it does not do. Empty when not yet written.
      - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
      - `examples` (string[], required) — Example tasks
      - `requirements` (object, required) — What the agent needs, stated rather than hidden. `mcp_servers` says whether it can use MCP servers; `website` is the engine's own site. `hosted_by_seller: { host }` is present when the agent runs on its maker's own server instead of a sandbox: what a person sends it, and the files of the task, go to that host, and a person's first task with it waits for them to agree (a task request).
      - `pricing` (object, required) — `{ mode: "usage" }`: the model and tool usage the task incurs, with no agent fee. `{ mode: "per_task", fee: { amount, currency } }`: usage, plus a flat fee the agent's maker asks for each task; `amount` is whole US cents as a string. Starting such an agent asks the person to confirm the price the first time (a task request of kind `spend`), holds the fee on their credit when the task starts and takes it when the task gives its first result.
      - `stats` (object, required) — Counts from real use, recounted hourly; never estimated. `uses`: sessions started on the agent. `comparisons` and `wins`: decided side-by-side comparisons the agent took part in, and the ones a person picked it in. `completed_yes` and `completed_no`: people who said a task on this agent did the job, and people who said it did not (`PUT /tasks/{id}/completion_answer`).
        - `uses` (integer, required)
        - `comparisons` (integer, required)
        - `wins` (integer, required)
        - `completed_yes` (integer, required)
        - `completed_no` (integer, required)
        - `usage` (object | null) — What one task typically consumes: medians over the agent's sessions of the last 30 days that metered model usage. Null until at least 10 such sessions exist.
      - `conformance` (object | null, required) — The verdicts of the listing's latest finished conformance run; for another person's agent, of the run it was submitted with. Null when it has never finished one.
      - `created_at` (string, required)
      - `installed` (boolean) — Whether the caller's workspace installed this agent from the catalog and left it enabled. Only on a read made for a workspace.
      - `default_model` (string | null) — The model the caller's workspace starts this agent with by default; null when it set none. Only with installed.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/agents/handle' \
  -H "Authorization: Bearer ast_..."
```

### PUT /universes/{slug}/agents/{handle}

Install an agent from the catalog, or change its default model or enabled state (scope: write, owner or admin)

Idempotent on the handle: the first call installs (201), later calls update (200). The handle must be one the catalog serves to this workspace (404 otherwise). default_model is checked against the agent's engine the way starting a session checks it; null clears it so the agent's own default applies again.

Path parameters:

- `slug` (string, required) — The universe slug
- `handle` (string, required) — The catalog handle, with or without its @

Body (application/json):

- `enabled` (boolean)
- `default_model` (string | null) — max length 200

Responses:

- `200` — Updated
  - `install` (object, required)
    - `handle` (string, required) — The catalog handle without its @
    - `enabled` (boolean, required)
    - `default_model` (string, required) — The model members start this agent with unless they pick another; null = the agent's own default
    - `installed_by` (object, required)
      - `user_id` (string, required)
      - `name` (string)
      - `email` (string)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `agent` (object, required) — The listing as the catalog serves it to this workspace now; null once it has left the catalog
      - `handle` (string, required) — Globally unique and stable: lower-case letters, digits and underscores. What a person types after "/".
      - `kind` (enum<string>, required) — A platform engine, or an agent a person listed — "engine" · "agent"
      - `engine_type` (string | null, required) — The agent type to create an agent with, for an engine listing
      - `agent_id` (string | null, required) — The agent one of the caller's own workspace listings stands for; null for an engine and for another person's agent
      - `visibility` (enum<string>, required) — public for everyone: an engine, or another person's agent that was reviewed and approved. workspace for the caller's own listing, whether or not it is also public. — "public" · "workspace"
      - `seller` (object | null, required) — Who made a public agent that is not a platform engine, by the name they chose. Null for an engine and for the caller's own listing.
      - `name` (string, required)
      - `tagline` (string, required) — One line, at most 140 characters
      - `description` (string, required)
      - `does` (string[], required) — What it does. Empty when not yet written; never guessed.
      - `does_not` (string[], required) — What it does not do. Empty when not yet written.
      - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
      - `examples` (string[], required) — Example tasks
      - `requirements` (object, required) — What the agent needs, stated rather than hidden. `mcp_servers` says whether it can use MCP servers; `website` is the engine's own site. `hosted_by_seller: { host }` is present when the agent runs on its maker's own server instead of a sandbox: what a person sends it, and the files of the task, go to that host, and a person's first task with it waits for them to agree (a task request).
      - `pricing` (object, required) — `{ mode: "usage" }`: the model and tool usage the task incurs, with no agent fee. `{ mode: "per_task", fee: { amount, currency } }`: usage, plus a flat fee the agent's maker asks for each task; `amount` is whole US cents as a string. Starting such an agent asks the person to confirm the price the first time (a task request of kind `spend`), holds the fee on their credit when the task starts and takes it when the task gives its first result.
      - `stats` (object, required) — Counts from real use, recounted hourly; never estimated. `uses`: sessions started on the agent. `comparisons` and `wins`: decided side-by-side comparisons the agent took part in, and the ones a person picked it in. `completed_yes` and `completed_no`: people who said a task on this agent did the job, and people who said it did not (`PUT /tasks/{id}/completion_answer`).
        - `uses` (integer, required)
        - `comparisons` (integer, required)
        - `wins` (integer, required)
        - `completed_yes` (integer, required)
        - `completed_no` (integer, required)
        - `usage` (object | null) — What one task typically consumes: medians over the agent's sessions of the last 30 days that metered model usage. Null until at least 10 such sessions exist.
      - `conformance` (object | null, required) — The verdicts of the listing's latest finished conformance run; for another person's agent, of the run it was submitted with. Null when it has never finished one.
      - `created_at` (string, required)
      - `installed` (boolean) — Whether the caller's workspace installed this agent from the catalog and left it enabled. Only on a read made for a workspace.
      - `default_model` (string | null) — The model the caller's workspace starts this agent with by default; null when it set none. Only with installed.
- `201` — Installed
  - `install` (object, required)
    - `handle` (string, required) — The catalog handle without its @
    - `enabled` (boolean, required)
    - `default_model` (string, required) — The model members start this agent with unless they pick another; null = the agent's own default
    - `installed_by` (object, required)
      - `user_id` (string, required)
      - `name` (string)
      - `email` (string)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `agent` (object, required) — The listing as the catalog serves it to this workspace now; null once it has left the catalog
      - `handle` (string, required) — Globally unique and stable: lower-case letters, digits and underscores. What a person types after "/".
      - `kind` (enum<string>, required) — A platform engine, or an agent a person listed — "engine" · "agent"
      - `engine_type` (string | null, required) — The agent type to create an agent with, for an engine listing
      - `agent_id` (string | null, required) — The agent one of the caller's own workspace listings stands for; null for an engine and for another person's agent
      - `visibility` (enum<string>, required) — public for everyone: an engine, or another person's agent that was reviewed and approved. workspace for the caller's own listing, whether or not it is also public. — "public" · "workspace"
      - `seller` (object | null, required) — Who made a public agent that is not a platform engine, by the name they chose. Null for an engine and for the caller's own listing.
      - `name` (string, required)
      - `tagline` (string, required) — One line, at most 140 characters
      - `description` (string, required)
      - `does` (string[], required) — What it does. Empty when not yet written; never guessed.
      - `does_not` (string[], required) — What it does not do. Empty when not yet written.
      - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
      - `examples` (string[], required) — Example tasks
      - `requirements` (object, required) — What the agent needs, stated rather than hidden. `mcp_servers` says whether it can use MCP servers; `website` is the engine's own site. `hosted_by_seller: { host }` is present when the agent runs on its maker's own server instead of a sandbox: what a person sends it, and the files of the task, go to that host, and a person's first task with it waits for them to agree (a task request).
      - `pricing` (object, required) — `{ mode: "usage" }`: the model and tool usage the task incurs, with no agent fee. `{ mode: "per_task", fee: { amount, currency } }`: usage, plus a flat fee the agent's maker asks for each task; `amount` is whole US cents as a string. Starting such an agent asks the person to confirm the price the first time (a task request of kind `spend`), holds the fee on their credit when the task starts and takes it when the task gives its first result.
      - `stats` (object, required) — Counts from real use, recounted hourly; never estimated. `uses`: sessions started on the agent. `comparisons` and `wins`: decided side-by-side comparisons the agent took part in, and the ones a person picked it in. `completed_yes` and `completed_no`: people who said a task on this agent did the job, and people who said it did not (`PUT /tasks/{id}/completion_answer`).
        - `uses` (integer, required)
        - `comparisons` (integer, required)
        - `wins` (integer, required)
        - `completed_yes` (integer, required)
        - `completed_no` (integer, required)
        - `usage` (object | null) — What one task typically consumes: medians over the agent's sessions of the last 30 days that metered model usage. Null until at least 10 such sessions exist.
      - `conformance` (object | null, required) — The verdicts of the listing's latest finished conformance run; for another person's agent, of the run it was submitted with. Null when it has never finished one.
      - `created_at` (string, required)
      - `installed` (boolean) — Whether the caller's workspace installed this agent from the catalog and left it enabled. Only on a read made for a workspace.
      - `default_model` (string | null) — The model the caller's workspace starts this agent with by default; null when it set none. Only with installed.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/universes/acme/agents/handle \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"enabled":true,"default_model":"claude-sonnet-5"}'
```

### DELETE /universes/{slug}/agents/{handle}

Remove an agent from the workspace's choices (scope: write, owner or admin)

Removes the install and its default model. Sessions already running with the agent are untouched, and members can still start it by handle: use a policy rule to forbid it.

Path parameters:

- `slug` (string, required) — The universe slug
- `handle` (string, required) — The catalog handle, with or without its @

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/universes/acme/agents/handle \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/invites

Add people to the workspace by email (scope: write, owner or admin)

Up to 50 emails per call; the workspace may hold at most 200 pending invitations in total. To invite more than 50 people, send multiple calls. Set send_email to true to send invitation mail and include per-email delivery results. sent means provider acceptance; unavailable leaves a usable link to share. No email is sent and no delivery field is returned by default. The response carries one link token per new invitation (shown only here; links are /join/{token} on the consumer app). Each person joins through the link, or the next time they use AgentSky signed in with that verified email; an invitation lasts 30 days.

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- `emails` (string[], required)
- `send_email` (boolean) — default: false
- `role` (enum<string>) — "admin" · "member" — default: "member"

Responses:

- `201` — Created
  - `invites` (object[])
  - `links` (object[])
    - `email` (string)
    - `token` (string)
  - `delivery` (object[])
    - `email` (string)
    - `status` (enum<string>) — "sent" · "unavailable"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/invites \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"emails":["teammate@acme.com"],"role":"member","send_email":true}'
```

### DELETE /universes/{slug}/invites/{inviteId}

Withdraw an invitation that has not been taken up (scope: write, owner or admin)

Path parameters:

- `slug` (string, required) — The universe slug
- `inviteId` (string, required)

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/universes/acme/invites/cmtb4i7v2n6q8z01s6k3m5p1 \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/wallet

A workspace's own wallet: balance, each member's spending this month, limits, members waiting for a higher limit (scope: read, owner or admin)

Available in every workspace, including the owner's default workspace with no other members. 404 where workspace wallets are not switched on for the workspace, 403 for a plain member.

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `wallet` (object | null, required) — Null until the workspace is given a wallet. Where every workspace has a wallet, a person's default workspace reads its owner's own balance here (holder owner) and other workspaces get theirs with their first session or funding
  - `month_start` (string, required) — The first instant (UTC) of the month the spending below is counted from
  - `members` (object[], required)
    - `user_id` (string)
    - `email` (string)
    - `name` (string)
    - `role` (enum<string>) — "owner" · "admin" · "member"
    - `spent` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
    - `monthly_limit` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
  - `funding` (object[], required) — The latest additions to the wallet, newest first
    - `id` (string)
    - `amount` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
    - `added_by` (string)
    - `created_at` (string)
  - `limit_requests` (object[], required) — Members' tasks that wait for a higher monthly limit, oldest first
    - `id` (string)
    - `session_id` (string)
    - `title` (string)
    - `member` (object)
      - `user_id` (string)
      - `name` (string)
      - `email` (string)
    - `raise_to` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
    - `held` (integer) — Messages the task holds and will run when the limit is raised
    - `created_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/wallet' \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/wallet

Give the workspace a wallet of its own (scope: write, owner or admin)

Available in every workspace, even with only its owner. From then on a new session a member starts in the workspace is paid from this wallet unless its request names payer personal, and is refused with 402 workspace_wallet_empty while the wallet holds nothing. Sessions that already exist keep the payer recorded for them. Repeating the call returns the wallet that exists.

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `201` — Created
  - `wallet` (object | null, required) — Null until the workspace is given a wallet. Where every workspace has a wallet, a person's default workspace reads its owner's own balance here (holder owner) and other workspaces get theirs with their first session or funding
  - `month_start` (string, required) — The first instant (UTC) of the month the spending below is counted from
  - `members` (object[], required)
    - `user_id` (string)
    - `email` (string)
    - `name` (string)
    - `role` (enum<string>) — "owner" · "admin" · "member"
    - `spent` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
    - `monthly_limit` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
  - `funding` (object[], required) — The latest additions to the wallet, newest first
    - `id` (string)
    - `amount` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
    - `added_by` (string)
    - `created_at` (string)
  - `limit_requests` (object[], required) — Members' tasks that wait for a higher monthly limit, oldest first
    - `id` (string)
    - `session_id` (string)
    - `title` (string)
    - `member` (object)
      - `user_id` (string)
      - `name` (string)
      - `email` (string)
    - `raise_to` (object)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
    - `held` (integer) — Messages the task holds and will run when the limit is raised
    - `created_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/wallet \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/wallet/transfers

Move some of your own purchased credit into the workspace wallet (scope: write, owner or admin)

All or nothing. Only credit the caller bought moves; free credit stays. 402 insufficient_purchased_credit when the caller holds less purchased credit than the amount, 409 workspace_wallet_missing before the wallet exists. request_id makes a repeat of the same request land once (200 instead of 201); the same id with another amount is 409 idempotency_conflict.

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- `amount` (object, required)
  - `amount` (string, required) — Whole US cents
  - `currency` (enum<string>, required) — "USD"
- `request_id` (string, required) — max length 100

Responses:

- `201` — Moved
  - `transferred` (boolean)
  - `balance` (object)
    - `amount` (string, required) — Whole US cents
    - `currency` (enum<string>, required) — "USD"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/wallet/transfers \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/wallet/topups

Buy credit for the workspace wallet with your own saved card (scope: write, owner or admin)

Charges the caller's own saved card the credit plus the card processing fee and adds the credit to the workspace wallet. The caller's own balance, card and auto top-up are not changed. amount is 1000, 2000, 5000 or 10000 cents. request_id makes a repeat of the same request charge once (200 instead of 201). 409 card_required when the caller has no saved card (add one to your own account first), 402 card_declined, 409 workspace_wallet_missing before the wallet exists, 503 payments_unavailable where card payments are not set up. A workspace key or a restricted credential cannot buy credit.

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- `amount` (object, required)
  - `amount` (string, required) — Whole US cents
  - `currency` (enum<string>, required) — "USD"
- `request_id` (string, required) — max length 100
- `payment_method` (enum<string>) — card (default) charges the saved card; alipay and wechat_pay return a payment page the person pays. — "card" · "alipay" · "wechat_pay"

Responses:

- `201` — Bought
  - `charged` (boolean)
  - `balance` (object)
    - `amount` (string, required) — Whole US cents
    - `currency` (enum<string>, required) — "USD"
- `202` — Payment page opened for the person to pay
  - `charged` (enum<boolean>, required) — false
  - `payment_method` (enum<string>, required) — "alipay" · "wechat_pay"
  - `checkout_url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/wallet/topups \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/wallet/limit-requests/{requestId}

Answer a member's request for a higher monthly limit (scope: write, owner or admin)

A member who reaches their monthly limit is not only refused: the task they started or wrote to waits, holding what it was given, and a request is raised (limit_requests on the wallet, and a spend request on the task). raise sets the member's limit to the amount the request offered and sends on what every waiting task of theirs was holding; decline closes this request and drops what its task held. 404 when the request is not open.

Path parameters:

- `slug` (string, required) — The universe slug
- `requestId` (string, required)

Body (application/json):

- `answer` (enum<string>, required) — "raise" · "decline"

Responses:

- `200` — OK
  - `ok` (boolean)
  - `message_id` (string) — The first message sent on to a waiting task, when one was
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/wallet/limit-requests/requestId \
  -H "Authorization: Bearer ast_..."
```

### PUT /universes/{slug}/wallet/limits/{userId}

Set or clear a member's monthly limit on workspace wallet spending (scope: write, owner or admin)

The limit counts workspace-wallet charges attributed to that member in the calendar month (UTC): the admitted sender of each turn or consumption, including helpers. Historical charges without a recorded sender and work outside an active turn count against the session starter. At the limit a message to a session the workspace pays for, a helper, a handoff and a fork are refused with 402 member_limit_reached, and a new session is created waiting; other members are not affected. monthly_limit null removes the limit. When the new limit lets the member spend again their waiting tasks continue by themselves: resumed counts the messages that were sent on.

Path parameters:

- `slug` (string, required) — The universe slug
- `userId` (string, required)

Body (application/json):

- `monthly_limit` (object, required)
  - `amount` (string, required) — Whole US cents
  - `currency` (enum<string>, required) — "USD"

Responses:

- `200` — OK
  - `ok` (boolean)
  - `resumed` (integer)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/universes/acme/wallet/limits/cmtb3u5r7k2p9x01s6q8n4w2 \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/connections

Deprecated: use GET /universes?include=connections. Connected apps people share with the workspace, and the ones it owns (scope: read)

Deprecated: use `GET /universes?include=connections`. Still served exactly as before; every answer carries a `Deprecation` header. sharing says whether members can share connected apps with this workspace; while it is on, can_connect says whether the caller may connect an app for the workspace itself, and a connection the workspace owns carries workspace_owned. A person's default workspace takes shared connections only once someone besides its owner is in it. Agents in the workspace's sessions can call through a shared connection whoever started the session; nobody but the person who shared it holds its sign-in.

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `sharing` (boolean, required) — Whether members can share connected apps with this workspace.
  - `can_connect` (boolean) — While sharing is on: whether the caller may connect an app for the workspace itself.
  - `connections` (object[], required)
    - `connection_id` (string)
    - `app` (string)
    - `app_name` (string)
    - `label` (string)
    - `when_to_use` (string) — Optional owner-provided account selection guidance.
    - `shared_by` (object)
      - `user_id` (string)
      - `name` (string)
    - `shared_at` (string)
    - `mine` (boolean) — True when the caller is the person who shared it.
    - `workspace_owned` (boolean) — Present and true when the workspace itself owns the connection.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/connections' \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/connections

Share one of your own connections with the workspace, or start connecting an app for it (scope: write)

With connection_id: only a connection of the caller's can be shared; answers 201 with the workspace's connections. With app, success_url and error_url (owner or admin): starts connecting an app for the workspace itself and answers 200 with the address to open in a browser; record the result with POST /universes/{slug}/connections/complete. A connection made this way belongs to the workspace, not to the person who made it, and stays when they leave.

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- `connection_id` (string)
- `app` (string)
- `success_url` (string)
- `error_url` (string)

Responses:

- `200` — Started
  - `url` (string)
- `201` — Created
  - `sharing` (boolean, required) — Whether members can share connected apps with this workspace.
  - `can_connect` (boolean) — While sharing is on: whether the caller may connect an app for the workspace itself.
  - `connections` (object[], required)
    - `connection_id` (string)
    - `app` (string)
    - `app_name` (string)
    - `label` (string)
    - `when_to_use` (string) — Optional owner-provided account selection guidance.
    - `shared_by` (object)
      - `user_id` (string)
      - `name` (string)
    - `shared_at` (string)
    - `mine` (boolean) — True when the caller is the person who shared it.
    - `workspace_owned` (boolean) — Present and true when the workspace itself owns the connection.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/connections \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/connections/complete

Record an app connected for the workspace itself (scope: write, owner or admin)

The account is checked against the workspace's own accounts at the provider; without account_id its newest one for the app is used. From then on agents in every session of the workspace can call through it. 404 when the workspace has no such account.

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- `app` (string, required)
- `account_id` (string)

Responses:

- `201` — Created
  - `sharing` (boolean, required) — Whether members can share connected apps with this workspace.
  - `can_connect` (boolean) — While sharing is on: whether the caller may connect an app for the workspace itself.
  - `connections` (object[], required)
    - `connection_id` (string)
    - `app` (string)
    - `app_name` (string)
    - `label` (string)
    - `when_to_use` (string) — Optional owner-provided account selection guidance.
    - `shared_by` (object)
      - `user_id` (string)
      - `name` (string)
    - `shared_at` (string)
    - `mine` (boolean) — True when the caller is the person who shared it.
    - `workspace_owned` (boolean) — Present and true when the workspace itself owns the connection.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/connections/complete \
  -H "Authorization: Bearer ast_..."
```

### DELETE /universes/{slug}/connections/{connectionId}

Deprecated: use DELETE /plugins/app:{app}/share?workspace={slug}&connection_id={connectionId}. Stop sharing a connection with the workspace (scope: write, the sharer, owner or admin)

Deprecated: use `DELETE /plugins/app:{app}/share?workspace={slug}&connection_id={connectionId}`. Still served exactly as before; every answer carries a `Deprecation` header. Agents lose it at once. A connection the workspace owns itself is disconnected for good, by an owner or admin only.

Path parameters:

- `slug` (string, required) — The universe slug
- `connectionId` (string, required)

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/universes/acme/connections/connectionId \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/keys

Keys that belong to the workspace (scope: read, owner or admin)

A workspace key belongs to the workspace, not to the person who made it, and keeps working after they leave. It acts through the workspace owner's account, whose wallet pays for the sessions it starts, and reaches only the workspace's agents, sessions, files, skills and environments. The listing never carries a secret.

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `keys` (object[], required)
    - `id` (string, required)
    - `name` (string, required)
    - `prefix` (string, required) — The start of the secret, to tell one key from another.
    - `scopes` (enum<string>[], required) — "read" · "write" · "admin"
    - `created_by` (object, required)
      - `user_id` (string)
      - `name` (string)
    - `created_at` (string, required)
    - `last_used_at` (string)
    - `expires_at` (string)
    - `revoked_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/keys' \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/keys

Make a workspace key (scope: admin, owner or admin)

The secret is returned only in this response. The key carries no more scope than the credential that makes it.

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- `name` (string, required) — max length 80
- `scopes` (enum<string>[], required) — "read" · "write" · "admin"
- `restriction` (enum<string>) — `signing`: the key reaches only the MCP server and `whoami`, sees only the signing tools, reads only the signing requests it made, and the signer is told the key's name. Give one to each customer or agent. — "signing"
- `expires_at` (string)

Responses:

- `201` — Created
  - `key` (object, required)
    - `id` (string, required)
    - `name` (string, required)
    - `prefix` (string, required) — The start of the secret, to tell one key from another.
    - `scopes` (enum<string>[], required) — "read" · "write" · "admin"
    - `created_by` (object, required)
      - `user_id` (string)
      - `name` (string)
    - `created_at` (string, required)
    - `last_used_at` (string)
    - `expires_at` (string)
    - `revoked_at` (string)
  - `secret` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/keys \
  -H "Authorization: Bearer ast_..."
```

### DELETE /universes/{slug}/keys/{keyId}

Revoke a workspace key (scope: admin, owner or admin)

Path parameters:

- `slug` (string, required) — The universe slug
- `keyId` (string, required)

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/universes/acme/keys/keyId \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/hooks

Get workspace shared hooks (scope: read)

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `hooks` (any[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/hooks' \
  -H "Authorization: Bearer ast_..."
```

### PUT /universes/{slug}/hooks

Replace workspace shared hooks (owner only) (scope: write)

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- `hooks` (any[], required)

Responses:

- `200` — OK
  - `hooks` (any[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/universes/acme/hooks \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"hooks":[{"event":"pre_tool_use","matcher":"Bash","command":"./.agentsky/check-command.sh","timeout_s":30}]}'
```

### GET /universes/{slug}/policies

List workspace policy rules (scope: read)

Path parameters:

- `slug` (string, required) — The universe slug

Responses:

- `200` — OK
  - `rules` (object[])
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/policies' \
  -H "Authorization: Bearer ast_..."
```

### POST /universes/{slug}/policies

Create a workspace policy rule (owner only) (scope: write)

A rule {name, kind: "CAPABILITY", config: {"platform.orchestration": "deny"}} stops every session of the workspace from bringing in other agents as helpers (403 hiring_disabled to the agent; helpers it already has can still be listed, collected and stopped), and sessions created afterwards are not told how to hire. Disable or delete the rule to turn hiring back on.

Path parameters:

- `slug` (string, required) — The universe slug

Body (application/json):

- option 1 (object)
  - `name` (string, required) — max length 128
  - `enabled` (boolean) — default: true
  - `position` (integer) — default: 0
  - `kind` ("TOOL_CALL", required)
  - `config` (object, required)
    - `action` (enum<string>, required) — "allow" · "ask" · "deny"
    - `matcher` (string) — max length 255
    - `commandPatterns` (string[]) — max length 500
- option 2 (object)
  - `name` (string, required) — max length 128
  - `enabled` (boolean) — default: true
  - `position` (integer) — default: 0
  - `kind` ("SPEND_CAP", required)
  - `config` (object, required)
    - `warnUsdMicros` (integer | null)
    - `hardCapUsdMicros` (integer, required)
- option 3 (object)
  - `name` (string, required) — max length 128
  - `enabled` (boolean) — default: true
  - `position` (integer) — default: 0
  - `kind` ("CALL_COUNT", required)
  - `config` (object, required)
    - `limitPerSession` (integer, required)
- option 4 (object)
  - `name` (string, required) — max length 128
  - `enabled` (boolean) — default: true
  - `position` (integer) — default: 0
  - `kind` ("CAPABILITY", required)
  - `config` (map<string, enum<string>>, required) — "allow" · "ask" · "deny"

Responses:

- `201` — Created
  - `rule` (object)
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/universes/acme/policies \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"name":"Block destructive shell commands","kind":"TOOL_CALL","config":{"action":"deny","matcher":"Bash","commandPatterns":["rm -rf *"]}}'
```

### GET /universes/{slug}/policies/{ruleId}

Get a workspace policy rule (scope: read)

Path parameters:

- `slug` (string, required) — The universe slug
- `ruleId` (string, required) — The policy rule id

Responses:

- `200` — OK
  - `rule` (object)
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/policies/cmtb5p0l3r8w2k01s6x7n9q4' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /universes/{slug}/policies/{ruleId}

Update a workspace policy rule (owner only) (scope: write)

Path parameters:

- `slug` (string, required) — The universe slug
- `ruleId` (string, required) — The policy rule id

Body (application/json):

- `name` (string) — max length 128
- `enabled` (boolean)
- `position` (integer)
- `config` (object | map<string, enum<string>>)
  - option 1 (object)
    - `action` (enum<string>, required) — "allow" · "ask" · "deny"
    - `matcher` (string) — max length 255
    - `commandPatterns` (string[]) — max length 500
  - option 2 (object)
    - `warnUsdMicros` (integer | null)
    - `hardCapUsdMicros` (integer, required)
  - option 3 (object)
    - `limitPerSession` (integer, required)
  - option 4 (map<string, enum<string>>) — "allow" · "ask" · "deny"

Responses:

- `200` — OK
  - `rule` (object)
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/universes/acme/policies/cmtb5p0l3r8w2k01s6x7n9q4 \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"enabled":false}'
```

### DELETE /universes/{slug}/policies/{ruleId}

Delete a workspace policy rule (owner only) (scope: write)

Path parameters:

- `slug` (string, required) — The universe slug
- `ruleId` (string, required) — The policy rule id

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/universes/acme/policies/cmtb5p0l3r8w2k01s6x7n9q4 \
  -H "Authorization: Bearer ast_..."
```

### GET /universes/{slug}/pod-provider

Read the elected BYO provider and whether a credential is registered (scope: admin)

Returns the workspace's elected BYO pod provider name, its optional label, and `has_credential: true`. 404 when BYO_POD_PROVIDER is not enabled for this workspace, no provider is elected, or no credential row exists. 503 `not_migrated` before the credential table exists.

Path parameters:

- `slug` (string, required) — The workspace slug.

Responses:

- `200` — OK
  - `provider` (enum<string>) — The elected provider. — "e2b" · "sandbox-oss" · "daytona"
  - `label` (string | null) — The admin-supplied label for this credential.
  - `has_credential` (boolean) — Always true when the response is present.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/universes/acme/pod-provider' \
  -H "Authorization: Bearer ast_..."
```

### PUT /universes/{slug}/pod-provider

Register a BYO provider credential for the workspace (scope: admin)

Stores the encrypted provider credential and elects the provider for the workspace. The credential is write-only and never returned by any API. Setting a new credential replaces the old one. 404 when BYO_POD_PROVIDER is not enabled for this workspace. 503 `not_migrated` before the credential table exists.

Path parameters:

- `slug` (string, required) — The workspace slug.

Body (application/json):

- `provider` (enum<string>, required) — The provider to elect. — "e2b" · "sandbox-oss" · "daytona"
- `credential` (string, required) — The provider API key (write-only; never returned). — max length 10000
- `label` (string) — Optional human-readable label. — max length 128

Responses:

- `200` — Credential stored and provider elected.
  - `provider` (enum<string>) — The elected provider. — "e2b" · "sandbox-oss" · "daytona"
  - `label` (string | null) — The admin-supplied label for this credential.
  - `has_credential` (boolean) — Always true when the response is present.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/universes/acme/pod-provider \
  -H "Authorization: Bearer ast_..."
```

### DELETE /universes/{slug}/pod-provider

Remove the BYO provider credential and clear the election (scope: admin)

Deletes the credential row and clears Universe.podProvider. Future sessions use the platform's provider. 404 when BYO_POD_PROVIDER is not enabled for this workspace. 503 `not_migrated` before the credential table exists.

Path parameters:

- `slug` (string, required) — The workspace slug.

Responses:

- `200` — Credential removed.
  - `deleted` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/universes/acme/pod-provider \
  -H "Authorization: Bearer ast_..."
```

## Products and Runs

### POST /runs

Run a product (scope: write)

String input is a shortcut. Agent objects preserve one user message and optional system message. Direct Agent Runs prepare a Session with platform billing; an existing Session retains its payer and billing settings. Non-streaming waits up to ten seconds. SSE begins with the durable Run identity. Disconnect never cancels execution. A catalog handle (`@handle`) runs that agent as one turn of a new session of it, charged as that session is: `addons` may set `model`, within the agent's engine, and `instructions`, files added after the agent's own, and nothing else; a `user.message` sent to the Run (POST /runs/{id}/events) is the next turn of that session and a Run of its own. When a Run of a handle ends, each webhook endpoint of the workspace subscribed to `run.completed`, `run.interrupted`, `run.failed` or `run.blocked` receives that event once, signed like every other webhook. A handle whose agent has not passed its checks is refused with `listing_not_checked` or `listing_checks_failed`.

Body (application/json):

- `product` (string, required) — max length 240
- `input` (any, required)
- `addons` (map<string, any>)
- `session_id` (string)
- `stream` (boolean)
- `metadata` (map<string, any>)

Responses:

- `200` — Durable Run identity, status, output and references to authoritative billing.
  - `run` (object)
    - `id` (string, required)
    - `product` (string | null, required)
    - `session_id` (string | null, required)
    - `status` (enum<string>, required) — "queued" · "running" · "waiting_input" · "stopping" · "completed" · "interrupted" · "failed" · "blocked" · "reconciling"
    - `output` (any, required)
    - `output_available` (boolean)
    - `usage` (any, required)
    - `billing` (any, required)
    - `error` (any, required)
    - `artifact` (object)
      - `id` (string, required)
      - `mediaType` (string, required)
      - `url` (string, required)
    - `source` (object)
      - `goal_id` (string)
      - `iteration` (integer)
      - `routine_run_id` (string)
      - `routine_id` (string)
    - `created_at` (string, required)
    - `completed_at` (string | null, required)
- `202` — Durable Run identity, status, output and references to authoritative billing.
  - `run` (object)
    - `id` (string, required)
    - `product` (string | null, required)
    - `session_id` (string | null, required)
    - `status` (enum<string>, required) — "queued" · "running" · "waiting_input" · "stopping" · "completed" · "interrupted" · "failed" · "blocked" · "reconciling"
    - `output` (any, required)
    - `output_available` (boolean)
    - `usage` (any, required)
    - `billing` (any, required)
    - `error` (any, required)
    - `artifact` (object)
      - `id` (string, required)
      - `mediaType` (string, required)
      - `url` (string, required)
    - `source` (object)
      - `goal_id` (string)
      - `iteration` (integer)
      - `routine_run_id` (string)
      - `routine_id` (string)
    - `created_at` (string, required)
    - `completed_at` (string | null, required)
- `409` — Session busy or conflicting idempotency key
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — The product cannot be run: a listed agent that has not passed its checks, or an override that is not allowed
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/runs \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"product":"@claude_code","input":"Summarize the repository."}'
```

### GET /runs/{id}

Read a Run (scope: read)

Path parameters:

- `id` (string, required)

Responses:

- `200` — Durable Run identity, status, output and references to authoritative billing.
  - `run` (object)
    - `id` (string, required)
    - `product` (string | null, required)
    - `session_id` (string | null, required)
    - `status` (enum<string>, required) — "queued" · "running" · "waiting_input" · "stopping" · "completed" · "interrupted" · "failed" · "blocked" · "reconciling"
    - `output` (any, required)
    - `output_available` (boolean)
    - `usage` (any, required)
    - `billing` (any, required)
    - `error` (any, required)
    - `artifact` (object)
      - `id` (string, required)
      - `mediaType` (string, required)
      - `url` (string, required)
    - `source` (object)
      - `goal_id` (string)
      - `iteration` (integer)
      - `routine_run_id` (string)
      - `routine_id` (string)
    - `created_at` (string, required)
    - `completed_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/runs/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### GET /runs/{id}/events

Read durable Run events, or observe with Accept: text/event-stream (scope: read)

A Run of a catalog handle reports `run.running`, each `agent.message` with its text, and how it ended.

Path parameters:

- `id` (string, required)

Query parameters:

- `cursor` (string)

Responses:

- `200` — Opaque Run cursor, separate from the Session transcript cursor
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/runs/sess_cmtb7q2j/events' \
  -H "Authorization: Bearer ast_..."
```

### POST /runs/{id}/events

Target steering or an interrupt to this Run (scope: write)

For a Run of a catalog handle, one `user.message` starts the next turn of the Run's session as a new Run and is answered with `{ run_id, status }` naming that new Run (also in `Location`); it follows the idempotency rules of starting a Run, and is refused with 409 `session_busy` while a turn of the session is still going and 409 `session_archived` once the session has ended. One `user.interrupt` stops this Run's turn and is answered with `{ run_id, status }` for this Run; a Run that has already ended is answered with the status it ended in. A system message is not accepted.

Path parameters:

- `id` (string, required)

Body (application/json):

- `events` (object[], required)
  - type: "user.message" (object)
    - `type` ("user.message", required)
    - `content` (object[], required)
      - type: "text" (object)
        - `type` ("text", required)
        - `text` (string, required)
      - type: "image" (object)
        - `type` ("image", required)
        - `source` (object, required)
          - type: "base64" (object)
            - `type` ("base64", required)
            - `media_type` (string, required)
            - `data` (string, required)
          - type: "url" (object)
            - `type` ("url", required)
            - `url` (string, required)
          - type: "file" (object)
            - `type` ("file", required)
            - `file_id` (string, required)
      - type: "document" (object)
        - `type` ("document", required)
        - `source` (object, required)
          - type: "base64" (object)
            - `type` ("base64", required)
            - `media_type` (string, required)
            - `data` (string, required)
          - type: "text" (object)
            - `type` ("text", required)
            - `media_type` ("text/plain") — default: "text/plain"
            - `data` (string, required)
          - type: "url" (object)
            - `type` ("url", required)
            - `url` (string, required)
          - type: "file" (object)
            - `type` ("file", required)
            - `file_id` (string, required)
        - `title` (string | null)
        - `context` (string | null)
    - `interaction_mode` (enum<string> | null) — "plan" · "build"
  - type: "system.message" (object)
    - `type` ("system.message", required)
    - `content` (object[], required)
      - `type` ("text", required)
      - `text` (string, required)
  - type: "user.interrupt" (object)
    - `type` ("user.interrupt", required)

Responses:

- `202` — Control admitted; runtime confirmation is separate
- `409` — Run is terminal or input conflicts
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/runs/sess_cmtb7q2j/events \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"events":[{"type":"user.interrupt"}]}'
```

## Agents

### GET /agents

List agents in the resolved universe (scope: read)

Responses:

- `200` — OK
  - `agents` (object[], required)
    - `id` (string) — The agent id (agent_…) — the only address
    - `name` (string)
    - `displayName` (string)
    - `agentType` (string) — Engine — hermes · claude_code · codex · openclaw · pi · dsh · kimi_code · opencode · jev, or any ACP harness (the full vocabulary is the enum on CreateAgent)
    - `llm` (string)
    - `harnessVersion` (string | null) — The engine CLI version this agent's sessions run; PATCH to move to the platform's current version
    - `reasoningEffort` (string | null) — Harness-native reasoning effort; null = model-compatible fallback for constrained models, otherwise harness default. Applies from the next provision/restart. Allowed values depend on agentType — agoragentic_acp: not supported; amp_acp: not supported; auggie: not supported; autohand: not supported; cline: not supported; codebuddy_code: not supported; cortex_code: not supported; corust_agent: not supported; crow_cli: not supported; cursor: not supported; deepagents: not supported; devin: not supported; dimcode: not supported; dirac: not supported; factory_droid: not supported; fast_agent: not supported; gemini: not supported; github_copilot_cli: not supported; glm_acp_agent: not supported; antigravity_acp: not supported; goose: not supported; grok_build: not supported; harn: not supported; junie: not supported; kilo: not supported; kimchi: not supported; minimax_code: not supported; minion_code: not supported; mistral_vibe: not supported; nova: not supported; poolside: not supported; qoder: not supported; qwen_code: not supported; sigit: not supported; stakpak: not supported; vtcode: not supported; code_assistant: not supported; docker_cagent: not supported; kiro: not supported; muse_code: not supported; openhands: not supported; hermes: none/minimal/low/medium/high/xhigh/max/ultra; claude_code: low/medium/high/xhigh/max; codex: none/minimal/low/medium/high/xhigh/max; openclaw: not supported; jev: not supported; pi: off/minimal/low/medium/high/xhigh/max; dsh: not supported; kimi_code: not supported; opencode: none/minimal/low/medium/high/xhigh/max; workspace_acp: not supported; models: claude-fable-5-1: low/medium/high/xhigh/max; claude-fable-5: low/medium/high/xhigh/max; claude-opus-5-5: low/medium/high/xhigh/max; claude-opus-5: low/medium/high/xhigh/max; claude-opus-4-8: low/medium/high/xhigh/max; claude-sonnet-5-5: low/medium/high/xhigh/max; claude-sonnet-5: low/medium/high/xhigh/max; claude-sonnet-4-6: low/medium/high/max; claude-haiku-5-5: low/medium/high/xhigh/max; claude-haiku-4-5: not supported; gpt-6.1-sol: low/medium/high/xhigh/max; gpt-6-astra: low/medium/high/xhigh/max; gpt-6-sol: none/low/medium/high/xhigh/max; gpt-6-luna: none/low/medium/high/xhigh/max; gpt-5.6-sol: none/low/medium/high/xhigh/max; gpt-5.6-terra: none/low/medium/high/xhigh/max; gpt-5.6-luna: none/low/medium/high/xhigh/max; gpt-5.5: none/low/medium/high/xhigh; gpt-4.1: not supported; deepseek-v4-pro: low/high/max; deepseek-flash: low/high/max; kimi-k3.1-pro: low/high/max; kimi-k3: low/high/max; kimi-k2.7-code: not supported; minimax-m3: not supported; muse-spark-1.1: minimal/low/medium/high/xhigh; muse-spark-1.2: minimal/low/medium/high/xhigh; muse-spark-1.3: minimal/low/medium/high/xhigh/max; minimax-m3.1-flash: low/medium/high/xhigh/max; gemini-4-argon: low/medium/high; gemini-3.5-flash-lite: low/medium/high; gemini-3.8-flash: low/medium/high; gemini-3.5-flash: low/medium/high; glm-5.3: low/high/max; glm-5.3-flash: low/high/max; grok-4.6: low/medium/high; grok-4.7: low/medium/high/xhigh — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra" · null
    - `capabilities` (enum<string>[]) — The built-in capabilities this agent is granted — the exact set its sessions may execute (enforced; empty = none). Ids are listed at /docs/capabilities. — "embedding.openai" · "embedding.voyage" · "rerank.voyage" · "ocr.mistral" · "exa.search" · "exa.contents" · "tinyfish.fetch" · "tinyfish.browser" · "tinyfish.agent" · "dataforseo.serp" · "dataforseo.ai-keywords" · "dataforseo.llm-responses" · "dataforseo.app-info" · "dataforseo.app-search" · "dataforseo.backlinks" · "dataforseo.business-reviews" · "dataforseo.business-pinterest" · "dataforseo.content-analysis" · "dataforseo.technologies" · "dataforseo.keyword-data" · "dataforseo.labs" · "dataforseo.amazon" · "dataforseo.onpage" · "gptimage.generate" · "rembg.remove-background" · "seedance.generate" · "mm.i2v" · "wan.t2v" · "wan.i2v" · "happyhorse.t2v" · "minimax.h3" · "fish-audio.transcribe" · "code-review" · "exa.answer" · "googlemap.geocode" · "googlemap.places" · "agentmail.list-inboxes" · "tinyfish.search" · "tinyfish.profile-list" · "meta.transcribe" · "minimax.tts" · "elevenlabs.sound" · "elevenlabs.tts" · "elevenlabs.music" · "zai.transcribe" · "openai.transcribe" · "fish-audio.tts" · "google.image" · "openai.image-2.5" · "wan.image" · "logo.lookup" · "openmeteo.weather" · "frankfurter.fx" · "dictionary.define" · "openlibrary.search" · "googledns.resolve" · "qrserver.create" · "recall.meeting-record" · "social-boost.catalog"
    - `version` (integer) — Bumped on every update; see expectedVersion
    - `archived` (boolean)
    - `sessionCount` (integer)
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/agents' \
  -H "Authorization: Bearer ast_..."
```

### POST /agents

Create an agent (scope: write)

An agent is a reusable configuration — engine, prompt, capabilities, secrets. Every field is optional: an empty body creates the default pi agent with no built-in capabilities (capabilities are explicit opt-in; unknown ids → 400). The response's `id` (agent_…) is the agent's only address. One agent can run many sessions; creating the agent provisions nothing — session creation provisions the pod by default (POST /v1/sessions supports deferred provisioning). Optional Idempotency-Key safely replays the original 201 response within the same user and universe; changing the body with the same key returns 409 idempotency_conflict. Keys do not expire.

Body (application/json):

- `name` (string) — Prompt label only — not an address. An agent is addressed by the `id` in the response (agent_…); names are free and need not be unique — max length 60
- `description` (string) — max length 500
- `agentType` (enum<string>) — "hermes" · "claude_code" · "codex" · "openclaw" · "pi" · "dsh" · "kimi_code" · "opencode" · "jev" · "agoragentic_acp" · "amp_acp" · "auggie" · "autohand" · "cline" · "codebuddy_code" · "cortex_code" · "corust_agent" · "crow_cli" · "cursor" · "deepagents" · "devin" · "dimcode" · "dirac" · "factory_droid" · "fast_agent" · "gemini" · "github_copilot_cli" · "glm_acp_agent" · "antigravity_acp" · "goose" · "grok_build" · "harn" · "junie" · "kilo" · "kimchi" · "minimax_code" · "minion_code" · "mistral_vibe" · "nova" · "poolside" · "qoder" · "qwen_code" · "sigit" · "stakpak" · "vtcode" · "code_assistant" · "docker_cagent" · "kiro" · "openhands" · "muse_code" · "workspace_acp"
- `llm` (string)
- `reasoningEffort` (enum<string>) — Harness/model-compatible reasoning effort; omitted = model-compatible fallback for constrained models, otherwise harness default. Explicit values must fit both agentType and llm — agoragentic_acp: not supported; amp_acp: not supported; auggie: not supported; autohand: not supported; cline: not supported; codebuddy_code: not supported; cortex_code: not supported; corust_agent: not supported; crow_cli: not supported; cursor: not supported; deepagents: not supported; devin: not supported; dimcode: not supported; dirac: not supported; factory_droid: not supported; fast_agent: not supported; gemini: not supported; github_copilot_cli: not supported; glm_acp_agent: not supported; antigravity_acp: not supported; goose: not supported; grok_build: not supported; harn: not supported; junie: not supported; kilo: not supported; kimchi: not supported; minimax_code: not supported; minion_code: not supported; mistral_vibe: not supported; nova: not supported; poolside: not supported; qoder: not supported; qwen_code: not supported; sigit: not supported; stakpak: not supported; vtcode: not supported; code_assistant: not supported; docker_cagent: not supported; kiro: not supported; muse_code: not supported; openhands: not supported; hermes: none/minimal/low/medium/high/xhigh/max/ultra; claude_code: low/medium/high/xhigh/max; codex: none/minimal/low/medium/high/xhigh/max; openclaw: not supported; jev: not supported; pi: off/minimal/low/medium/high/xhigh/max; dsh: not supported; kimi_code: not supported; opencode: none/minimal/low/medium/high/xhigh/max; workspace_acp: not supported; models: claude-fable-5-1: low/medium/high/xhigh/max; claude-fable-5: low/medium/high/xhigh/max; claude-opus-5-5: low/medium/high/xhigh/max; claude-opus-5: low/medium/high/xhigh/max; claude-opus-4-8: low/medium/high/xhigh/max; claude-sonnet-5-5: low/medium/high/xhigh/max; claude-sonnet-5: low/medium/high/xhigh/max; claude-sonnet-4-6: low/medium/high/max; claude-haiku-5-5: low/medium/high/xhigh/max; claude-haiku-4-5: not supported; gpt-6.1-sol: low/medium/high/xhigh/max; gpt-6-astra: low/medium/high/xhigh/max; gpt-6-sol: none/low/medium/high/xhigh/max; gpt-6-luna: none/low/medium/high/xhigh/max; gpt-5.6-sol: none/low/medium/high/xhigh/max; gpt-5.6-terra: none/low/medium/high/xhigh/max; gpt-5.6-luna: none/low/medium/high/xhigh/max; gpt-5.5: none/low/medium/high/xhigh; gpt-4.1: not supported; deepseek-v4-pro: low/high/max; deepseek-flash: low/high/max; kimi-k3.1-pro: low/high/max; kimi-k3: low/high/max; kimi-k2.7-code: not supported; minimax-m3: not supported; muse-spark-1.1: minimal/low/medium/high/xhigh; muse-spark-1.2: minimal/low/medium/high/xhigh; muse-spark-1.3: minimal/low/medium/high/xhigh/max; minimax-m3.1-flash: low/medium/high/xhigh/max; gemini-4-argon: low/medium/high; gemini-3.5-flash-lite: low/medium/high; gemini-3.8-flash: low/medium/high; gemini-3.5-flash: low/medium/high; glm-5.3: low/high/max; glm-5.3-flash: low/high/max; grok-4.6: low/medium/high; grok-4.7: low/medium/high/xhigh — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra"
- `prompt` (string) — max length 100000
- `displayName` (string) — What the agent is called in the console and in channels; omitted = an auto-generated asteroid name — max length 60
- `capabilities` (enum<string>[]) — "embedding.openai" · "embedding.voyage" · "rerank.voyage" · "ocr.mistral" · "exa.search" · "exa.contents" · "tinyfish.fetch" · "tinyfish.browser" · "tinyfish.agent" · "dataforseo.serp" · "dataforseo.ai-keywords" · "dataforseo.llm-responses" · "dataforseo.app-info" · "dataforseo.app-search" · "dataforseo.backlinks" · "dataforseo.business-reviews" · "dataforseo.business-pinterest" · "dataforseo.content-analysis" · "dataforseo.technologies" · "dataforseo.keyword-data" · "dataforseo.labs" · "dataforseo.amazon" · "dataforseo.onpage" · "gptimage.generate" · "rembg.remove-background" · "seedance.generate" · "mm.i2v" · "wan.t2v" · "wan.i2v" · "happyhorse.t2v" · "minimax.h3" · "fish-audio.transcribe" · "code-review" · "exa.answer" · "googlemap.geocode" · "googlemap.places" · "agentmail.list-inboxes" · "tinyfish.search" · "tinyfish.profile-list" · "meta.transcribe" · "minimax.tts" · "elevenlabs.sound" · "elevenlabs.tts" · "elevenlabs.music" · "zai.transcribe" · "openai.transcribe" · "fish-audio.tts" · "google.image" · "openai.image-2.5" · "wan.image" · "logo.lookup" · "openmeteo.weather" · "frankfurter.fx" · "dictionary.define" · "openlibrary.search" · "googledns.resolve" · "qrserver.create" · "recall.meeting-record" · "social-boost.catalog"
- `instructions` (object[])
  - `name` (string, required) — pattern .*\.md$
  - `content` (string) — default: ""
- `skills` (object[]) — RFC-0073 skill attachments: store references ({type:'skill', skillId, version?: 'latest'|skr_…}) and GitHub shortcuts ({type:'github', url, ref?, tokenSecretRef?}). Max 20.
  - type: "skill" (object)
    - `type` ("skill", required)
    - `skillId` (string, required)
    - `version` (string) — default: "latest"
  - type: "github" (object)
    - `type` ("github", required)
    - `url` (string, required)
    - `ref` (string) — Branch or commit SHA; default branch when omitted.
    - `tokenSecretRef` (string) — Agent secret key holding a clone token for private repos.
- `mcpServers` (object[]) — Remote streamable-HTTP MCP servers this agent connects to.
  - `type` ("url") — default: "url"
  - `name` (string, required) — max length 255
  - `url` (string, required)
  - `tools` (object)
    - `include` (string[]) — default: []
    - `exclude` (string[]) — default: []
- `hooks` (object[]) — Shell commands run in the session's pod at lifecycle events ({event, command, matcher?, timeout_s?}). Every harness accepts every event; a hook can stop a prompt or a tool call only on a harness whose own hook system fires that event. Max 20.
  - `event` (enum<string>, required) — "pre_session_start" · "session_start" · "user_prompt_submit" · "pre_tool_use" · "post_tool_use" · "stop" · "session_end"
  - `command` (string, required) — max length 4000
  - `matcher` (string) — max length 255
  - `timeout_s` (integer)
- `customData` (object[])
  - `id` (string, required)
  - `name` (string, required) — pattern ^[a-z0-9_]+$
  - `kind` (enum<string>, required) — "spreadsheet" · "doc" · "private_api" · "other"
  - `scope` (enum<string>) — "creator" · "user" — default: "creator"
  - `description` (string)
  - `uri` (string)
  - `config` (map<string, string>) — default: {}
- `metadata` (map<string, any>)
- `environmentId` (string) — The workspace environment this agent is built for: a session boots in it when its create names no `environment_id` (ahead of the workspace default), and a create naming an environment that neither is it nor extends it is 409 `environment_mismatch`. Omitted = no link.
- `browserProfile` (enum<string> | string) — The browser this agent's sessions open with when they name none: mine, fresh or user:<user id>. Applies to sessions created afterwards — "mine" · "fresh" · "workspace" · "private"
- `vaultId` (string) — A workspace vault every session of this agent carries: after the vaults the session create names, ahead of the workspace default. Omitted = no agent vault.
- `capabilityPolicies` (map<string, enum<string>>) — "always_allow" · "always_ask" · "auto"
- `nativeToolPolicy` (enum<string>) — Owner-only permission for native pod tools; omitted defaults to always_allow. Supported by Claude Code and Codex after native approval rollout. — "always_allow" · "always_ask"
- `hiringPolicy` (enum<string>) — Whether this agent's sessions may bring in other agents as helpers; omitted defaults to allow. deny makes the agent work alone. — "allow" · "deny"
- `harness` (string) — workspace_acp only: the public id (hrn_…) of the workspace harness to pin. Required when agentType is workspace_acp.
- `handle` (string) — Workspace-scoped @handle. Lower-case, 2–40 chars: [a-z0-9_]. Unique within a workspace. Reserves the address handle@agents.agentsky.dev, returned as `email`; that domain does not receive mail yet. — pattern ^[a-z0-9_]{2,40}$
- `channel_settings` (object) — Channel persona settings for Slack/Lark.
  - `invitable` (boolean, required)
  - `description` (string) — max length 500
- `runtime` (object) — BYO-code runtime config. {kind:'endpoint',protocol:'a2a'|'acp'|'mcp',url} or {kind:'image',image}.
  - option 1 (object)
    - `kind` ("endpoint", required)
    - `protocol` (enum<string>, required) — "a2a" · "acp" · "mcp"
    - `url` (string, required)
  - option 2 (object)
    - `kind` ("image", required)
    - `image` (string, required)

Responses:

- `201` — Created
  - `agent` (object, required) — Everything in the list item, plus configuration state.
    - `id` (string) — The agent id (agent_…) — the only address
    - `name` (string)
    - `displayName` (string)
    - `agentType` (string)
    - `llm` (string)
    - `harnessVersion` (string | null)
    - `reasoningEffort` (string | null) — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra" · null
    - `version` (integer)
    - `archived` (boolean)
    - `sessionCount` (integer)
    - `createdAt` (string)
    - `description` (string | null)
    - `prompt` (string | null) — The user prompt layer
    - `promptVersion` (integer | null)
    - `capabilities` (enum<string>[]) — The built-in capabilities this agent is granted — the exact set its sessions may execute (enforced; empty = none). Ids are listed at /docs/capabilities. — "embedding.openai" · "embedding.voyage" · "rerank.voyage" · "ocr.mistral" · "exa.search" · "exa.contents" · "tinyfish.fetch" · "tinyfish.browser" · "tinyfish.agent" · "dataforseo.serp" · "dataforseo.ai-keywords" · "dataforseo.llm-responses" · "dataforseo.app-info" · "dataforseo.app-search" · "dataforseo.backlinks" · "dataforseo.business-reviews" · "dataforseo.business-pinterest" · "dataforseo.content-analysis" · "dataforseo.technologies" · "dataforseo.keyword-data" · "dataforseo.labs" · "dataforseo.amazon" · "dataforseo.onpage" · "gptimage.generate" · "rembg.remove-background" · "seedance.generate" · "mm.i2v" · "wan.t2v" · "wan.i2v" · "happyhorse.t2v" · "minimax.h3" · "fish-audio.transcribe" · "code-review" · "exa.answer" · "googlemap.geocode" · "googlemap.places" · "agentmail.list-inboxes" · "tinyfish.search" · "tinyfish.profile-list" · "meta.transcribe" · "minimax.tts" · "elevenlabs.sound" · "elevenlabs.tts" · "elevenlabs.music" · "zai.transcribe" · "openai.transcribe" · "fish-audio.tts" · "google.image" · "openai.image-2.5" · "wan.image" · "logo.lookup" · "openmeteo.weather" · "frankfurter.fx" · "dictionary.define" · "openlibrary.search" · "googledns.resolve" · "qrserver.create" · "recall.meeting-record" · "social-boost.catalog"
    - `capabilityPolicies` (map<string, enum<string>>) — Per-capability permission policy map; omitted when no entries exist. always_allow: invoke without user confirmation. always_ask: prompt the session owner before every invocation. auto: reserved for future policy evaluation; currently prompts the session owner like always_ask. — "always_allow" · "always_ask" · "auto"
    - `nativeToolPolicy` (enum<string>) — Native pod-tool permission, independent of capabilities. Returned on create and detail responses; omitted legacy settings mean always_allow. Only the agent owner can change it, while sessions are idle. — "always_allow" · "always_ask"
    - `hiringPolicy` (enum<string>) — Whether this agent's sessions may bring in other agents as helpers. allow unless set to deny. Returned on create and detail responses. — "allow" · "deny"
    - `mcpServers` (object[]) — Declared remote MCP server references, including tool filters; runtime authentication fields are never returned
      - `type` ("url") — default: "url"
      - `name` (string, required) — max length 255
      - `url` (string, required)
      - `tools` (object)
        - `include` (string[]) — default: []
        - `exclude` (string[]) — default: []
    - `hooks` (object[]) — Shell commands run in the session's pod at lifecycle events
      - `event` (enum<string>, required) — "pre_session_start" · "session_start" · "user_prompt_submit" · "pre_tool_use" · "post_tool_use" · "stop" · "session_end"
      - `command` (string, required) — max length 4000
      - `matcher` (string) — max length 255
      - `timeout_s` (integer)
    - `metadata` (object) — Your key-merged client metadata
    - `environmentId` (string | null) — The environment sessions of this agent boot in when their create names none; ahead of the workspace default
    - `vaultId` (string | null) — The vault every session of this agent carries, after the vaults its create names and ahead of the workspace default
    - `defaultSessionId` (string | null) — The session conversation verbs target when addressed by agent id
    - `universe` (string) — Resolved universe slug
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/agents \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"displayName":"Research Agent","agentType":"hermes","llm":"deepseek-v4-pro","capabilities":["exa.search"]}'
```

Example response (201 Created):

```json
{
  "agent": {
    "id": "agent_cmtb2f0a8m9k7x51q4ez6r0d",
    "name": "Research Agent",
    "displayName": "Research Agent",
    "agentType": "hermes",
    "llm": "deepseek-v4-pro",
    "version": 1,
    "capabilities": [
      "exa.search"
    ],
    "defaultSessionId": null,
    "universe": "acme"
  }
}
```

### GET /agents/{id}

Agent detail (scope: read)

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Responses:

- `200` — OK
  - `agent` (object, required) — Everything in the list item, plus configuration state.
    - `id` (string) — The agent id (agent_…) — the only address
    - `name` (string)
    - `displayName` (string)
    - `agentType` (string)
    - `llm` (string)
    - `harnessVersion` (string | null)
    - `reasoningEffort` (string | null) — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra" · null
    - `version` (integer)
    - `archived` (boolean)
    - `sessionCount` (integer)
    - `createdAt` (string)
    - `description` (string | null)
    - `prompt` (string | null) — The user prompt layer
    - `promptVersion` (integer | null)
    - `capabilities` (enum<string>[]) — The built-in capabilities this agent is granted — the exact set its sessions may execute (enforced; empty = none). Ids are listed at /docs/capabilities. — "embedding.openai" · "embedding.voyage" · "rerank.voyage" · "ocr.mistral" · "exa.search" · "exa.contents" · "tinyfish.fetch" · "tinyfish.browser" · "tinyfish.agent" · "dataforseo.serp" · "dataforseo.ai-keywords" · "dataforseo.llm-responses" · "dataforseo.app-info" · "dataforseo.app-search" · "dataforseo.backlinks" · "dataforseo.business-reviews" · "dataforseo.business-pinterest" · "dataforseo.content-analysis" · "dataforseo.technologies" · "dataforseo.keyword-data" · "dataforseo.labs" · "dataforseo.amazon" · "dataforseo.onpage" · "gptimage.generate" · "rembg.remove-background" · "seedance.generate" · "mm.i2v" · "wan.t2v" · "wan.i2v" · "happyhorse.t2v" · "minimax.h3" · "fish-audio.transcribe" · "code-review" · "exa.answer" · "googlemap.geocode" · "googlemap.places" · "agentmail.list-inboxes" · "tinyfish.search" · "tinyfish.profile-list" · "meta.transcribe" · "minimax.tts" · "elevenlabs.sound" · "elevenlabs.tts" · "elevenlabs.music" · "zai.transcribe" · "openai.transcribe" · "fish-audio.tts" · "google.image" · "openai.image-2.5" · "wan.image" · "logo.lookup" · "openmeteo.weather" · "frankfurter.fx" · "dictionary.define" · "openlibrary.search" · "googledns.resolve" · "qrserver.create" · "recall.meeting-record" · "social-boost.catalog"
    - `capabilityPolicies` (map<string, enum<string>>) — Per-capability permission policy map; omitted when no entries exist. always_allow: invoke without user confirmation. always_ask: prompt the session owner before every invocation. auto: reserved for future policy evaluation; currently prompts the session owner like always_ask. — "always_allow" · "always_ask" · "auto"
    - `nativeToolPolicy` (enum<string>) — Native pod-tool permission, independent of capabilities. Returned on create and detail responses; omitted legacy settings mean always_allow. Only the agent owner can change it, while sessions are idle. — "always_allow" · "always_ask"
    - `hiringPolicy` (enum<string>) — Whether this agent's sessions may bring in other agents as helpers. allow unless set to deny. Returned on create and detail responses. — "allow" · "deny"
    - `mcpServers` (object[]) — Declared remote MCP server references, including tool filters; runtime authentication fields are never returned
      - `type` ("url") — default: "url"
      - `name` (string, required) — max length 255
      - `url` (string, required)
      - `tools` (object)
        - `include` (string[]) — default: []
        - `exclude` (string[]) — default: []
    - `hooks` (object[]) — Shell commands run in the session's pod at lifecycle events
      - `event` (enum<string>, required) — "pre_session_start" · "session_start" · "user_prompt_submit" · "pre_tool_use" · "post_tool_use" · "stop" · "session_end"
      - `command` (string, required) — max length 4000
      - `matcher` (string) — max length 255
      - `timeout_s` (integer)
    - `metadata` (object) — Your key-merged client metadata
    - `environmentId` (string | null) — The environment sessions of this agent boot in when their create names none; ahead of the workspace default
    - `vaultId` (string | null) — The vault every session of this agent carries, after the vaults its create names and ahead of the workspace default
    - `defaultSessionId` (string | null) — The session conversation verbs target when addressed by agent id
    - `universe` (string) — Resolved universe slug
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /agents/{id}

Update displayName / capabilities / metadata (scope: write)

Omitted fields preserved; capabilities replaced whole (explicit [] revokes all; effective on the next capability call, no restart); metadata key-merged (null deletes a key); optional expectedVersion → 409 version_conflict on mismatch.

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Body (application/json):

- `displayName` (string) — max length 60
- `agentType` (enum<string>) — Moves the agent to another engine, checked as a new agent's would be. Sessions keep the engine they started on; new sessions use this one. Not for workspace-harness or image agents. — "hermes" · "claude_code" · "codex" · "openclaw" · "pi" · "dsh" · "kimi_code" · "opencode" · "jev" · "agoragentic_acp" · "amp_acp" · "auggie" · "autohand" · "cline" · "codebuddy_code" · "cortex_code" · "corust_agent" · "crow_cli" · "cursor" · "deepagents" · "devin" · "dimcode" · "dirac" · "factory_droid" · "fast_agent" · "gemini" · "github_copilot_cli" · "glm_acp_agent" · "antigravity_acp" · "goose" · "grok_build" · "harn" · "junie" · "kilo" · "kimchi" · "minimax_code" · "minion_code" · "mistral_vibe" · "nova" · "poolside" · "qoder" · "qwen_code" · "sigit" · "stakpak" · "vtcode" · "code_assistant" · "docker_cagent" · "kiro" · "openhands" · "muse_code" · "workspace_acp"
- `llm` (string) — The model new sessions run; must be selectable on the agent's (next) agentType. Omitted with a new agentType = that engine's default model. A reasoning effort the new pair does not support is cleared.
- `capabilities` (enum<string>[]) — "embedding.openai" · "embedding.voyage" · "rerank.voyage" · "ocr.mistral" · "exa.search" · "exa.contents" · "tinyfish.fetch" · "tinyfish.browser" · "tinyfish.agent" · "dataforseo.serp" · "dataforseo.ai-keywords" · "dataforseo.llm-responses" · "dataforseo.app-info" · "dataforseo.app-search" · "dataforseo.backlinks" · "dataforseo.business-reviews" · "dataforseo.business-pinterest" · "dataforseo.content-analysis" · "dataforseo.technologies" · "dataforseo.keyword-data" · "dataforseo.labs" · "dataforseo.amazon" · "dataforseo.onpage" · "gptimage.generate" · "rembg.remove-background" · "seedance.generate" · "mm.i2v" · "wan.t2v" · "wan.i2v" · "happyhorse.t2v" · "minimax.h3" · "fish-audio.transcribe" · "code-review" · "exa.answer" · "googlemap.geocode" · "googlemap.places" · "agentmail.list-inboxes" · "tinyfish.search" · "tinyfish.profile-list" · "meta.transcribe" · "minimax.tts" · "elevenlabs.sound" · "elevenlabs.tts" · "elevenlabs.music" · "zai.transcribe" · "openai.transcribe" · "fish-audio.tts" · "google.image" · "openai.image-2.5" · "wan.image" · "logo.lookup" · "openmeteo.weather" · "frankfurter.fx" · "dictionary.define" · "openlibrary.search" · "googledns.resolve" · "qrserver.create" · "recall.meeting-record" · "social-boost.catalog"
- `metadata` (map<string, any>)
- `environmentId` (string | null) — The environment sessions of this agent boot in when they name none; null clears, omitted preserves. Applies to sessions created afterwards.
- `browserProfile` (enum<string> | string | null) — The browser this agent's sessions open with when they name none: mine, fresh or user:<user id>; null clears back to mine. Applies to sessions created afterwards
- `pluginsOff` (string[]) — Plugin ids switched off for this agent (app:gmail, tool:exa.web, chat:slack, bundle:<name>, skill:<id>, mcp:<id>); replaces the whole list, [] clears, omitted preserves. Tools, apps and chat apps stop at once in every chat of the agent; skills and MCP servers from the next provision. PUT /plugins/{id}/off switches one. — max length 220
- `vaultId` (string | null) — The vault every session of this agent carries; null clears, omitted preserves. Applies to sessions created afterwards.
- `capabilityPolicies` (map<string, enum<string>>) — "always_allow" · "always_ask" · "auto"
- `nativeToolPolicy` (enum<string>) — Owner-only permission for native pod tools. Omitted preserves; changing permission requires idle sessions. There is no session override. — "always_allow" · "always_ask"
- `hiringPolicy` (enum<string>) — Whether this agent's sessions may bring in other agents as helpers. Omitted preserves. deny refuses the next helper a session tries to start; sessions created afterwards are not told how to hire. — "allow" · "deny"
- `harnessVersion` (string)
- `reasoningEffort` (enum<string> | null) — Harness-native reasoning effort; null clears the pin and applies model-compatible normalization. Applies from the next provision/restart. Allowed values depend on agentType — agoragentic_acp: not supported; amp_acp: not supported; auggie: not supported; autohand: not supported; cline: not supported; codebuddy_code: not supported; cortex_code: not supported; corust_agent: not supported; crow_cli: not supported; cursor: not supported; deepagents: not supported; devin: not supported; dimcode: not supported; dirac: not supported; factory_droid: not supported; fast_agent: not supported; gemini: not supported; github_copilot_cli: not supported; glm_acp_agent: not supported; antigravity_acp: not supported; goose: not supported; grok_build: not supported; harn: not supported; junie: not supported; kilo: not supported; kimchi: not supported; minimax_code: not supported; minion_code: not supported; mistral_vibe: not supported; nova: not supported; poolside: not supported; qoder: not supported; qwen_code: not supported; sigit: not supported; stakpak: not supported; vtcode: not supported; code_assistant: not supported; docker_cagent: not supported; kiro: not supported; muse_code: not supported; openhands: not supported; hermes: none/minimal/low/medium/high/xhigh/max/ultra; claude_code: low/medium/high/xhigh/max; codex: none/minimal/low/medium/high/xhigh/max; openclaw: not supported; jev: not supported; pi: off/minimal/low/medium/high/xhigh/max; dsh: not supported; kimi_code: not supported; opencode: none/minimal/low/medium/high/xhigh/max; workspace_acp: not supported; models: claude-fable-5-1: low/medium/high/xhigh/max; claude-fable-5: low/medium/high/xhigh/max; claude-opus-5-5: low/medium/high/xhigh/max; claude-opus-5: low/medium/high/xhigh/max; claude-opus-4-8: low/medium/high/xhigh/max; claude-sonnet-5-5: low/medium/high/xhigh/max; claude-sonnet-5: low/medium/high/xhigh/max; claude-sonnet-4-6: low/medium/high/max; claude-haiku-5-5: low/medium/high/xhigh/max; claude-haiku-4-5: not supported; gpt-6.1-sol: low/medium/high/xhigh/max; gpt-6-astra: low/medium/high/xhigh/max; gpt-6-sol: none/low/medium/high/xhigh/max; gpt-6-luna: none/low/medium/high/xhigh/max; gpt-5.6-sol: none/low/medium/high/xhigh/max; gpt-5.6-terra: none/low/medium/high/xhigh/max; gpt-5.6-luna: none/low/medium/high/xhigh/max; gpt-5.5: none/low/medium/high/xhigh; gpt-4.1: not supported; deepseek-v4-pro: low/high/max; deepseek-flash: low/high/max; kimi-k3.1-pro: low/high/max; kimi-k3: low/high/max; kimi-k2.7-code: not supported; minimax-m3: not supported; muse-spark-1.1: minimal/low/medium/high/xhigh; muse-spark-1.2: minimal/low/medium/high/xhigh; muse-spark-1.3: minimal/low/medium/high/xhigh/max; minimax-m3.1-flash: low/medium/high/xhigh/max; gemini-4-argon: low/medium/high; gemini-3.5-flash-lite: low/medium/high; gemini-3.8-flash: low/medium/high; gemini-3.5-flash: low/medium/high; glm-5.3: low/high/max; glm-5.3-flash: low/high/max; grok-4.6: low/medium/high; grok-4.7: low/medium/high/xhigh — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra"
- `skills` (object[]) — Replaces the whole skills array; omitted preserves. Applies from the next provision.
  - type: "skill" (object)
    - `type` ("skill", required)
    - `skillId` (string, required)
    - `version` (string) — default: "latest"
  - type: "github" (object)
    - `type` ("github", required)
    - `url` (string, required)
    - `ref` (string) — Branch or commit SHA; default branch when omitted.
    - `tokenSecretRef` (string) — Agent secret key holding a clone token for private repos.
- `mcpServers` (object[]) — Replaces the whole MCP server list; omitted preserves. Applies from the next provision.
  - `type` ("url") — default: "url"
  - `name` (string, required) — max length 255
  - `url` (string, required)
  - `tools` (object)
    - `include` (string[]) — default: []
    - `exclude` (string[]) — default: []
- `hooks` (object[]) — Replaces the whole hook list; omitted preserves. Applies from the next provision.
  - `event` (enum<string>, required) — "pre_session_start" · "session_start" · "user_prompt_submit" · "pre_tool_use" · "post_tool_use" · "stop" · "session_end"
  - `command` (string, required) — max length 4000
  - `matcher` (string) — max length 255
  - `timeout_s` (integer)
- `handle` (string | null) — Workspace-scoped @handle for Slack/Lark mentions. Lower-case, 2–40 chars: [a-z0-9_]. Unique within a workspace; null clears. — pattern ^[a-z0-9_]{2,40}$
- `channel_settings` (object | null) — Channel persona settings for Slack/Lark. null resets to defaults (invitable: true, no description).
  - `invitable` (boolean, required)
  - `description` (string) — max length 500
- `runtime` (object | null) — BYO-code runtime config. {kind:'endpoint',protocol:'a2a'|'acp'|'mcp',url} or {kind:'image',image}. null clears (agent runs in the standard sandbox).
  - option 1 (object)
    - `kind` ("endpoint", required)
    - `protocol` (enum<string>, required) — "a2a" · "acp" · "mcp"
    - `url` (string, required)
  - option 2 (object)
    - `kind` ("image", required)
    - `image` (string, required)
- `expectedVersion` (integer)

Responses:

- `200` — OK
  - `agent` (object, required) — Everything in the list item, plus configuration state.
    - `id` (string) — The agent id (agent_…) — the only address
    - `name` (string)
    - `displayName` (string)
    - `agentType` (string)
    - `llm` (string)
    - `harnessVersion` (string | null)
    - `reasoningEffort` (string | null) — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra" · null
    - `version` (integer)
    - `archived` (boolean)
    - `sessionCount` (integer)
    - `createdAt` (string)
    - `description` (string | null)
    - `prompt` (string | null) — The user prompt layer
    - `promptVersion` (integer | null)
    - `capabilities` (enum<string>[]) — The built-in capabilities this agent is granted — the exact set its sessions may execute (enforced; empty = none). Ids are listed at /docs/capabilities. — "embedding.openai" · "embedding.voyage" · "rerank.voyage" · "ocr.mistral" · "exa.search" · "exa.contents" · "tinyfish.fetch" · "tinyfish.browser" · "tinyfish.agent" · "dataforseo.serp" · "dataforseo.ai-keywords" · "dataforseo.llm-responses" · "dataforseo.app-info" · "dataforseo.app-search" · "dataforseo.backlinks" · "dataforseo.business-reviews" · "dataforseo.business-pinterest" · "dataforseo.content-analysis" · "dataforseo.technologies" · "dataforseo.keyword-data" · "dataforseo.labs" · "dataforseo.amazon" · "dataforseo.onpage" · "gptimage.generate" · "rembg.remove-background" · "seedance.generate" · "mm.i2v" · "wan.t2v" · "wan.i2v" · "happyhorse.t2v" · "minimax.h3" · "fish-audio.transcribe" · "code-review" · "exa.answer" · "googlemap.geocode" · "googlemap.places" · "agentmail.list-inboxes" · "tinyfish.search" · "tinyfish.profile-list" · "meta.transcribe" · "minimax.tts" · "elevenlabs.sound" · "elevenlabs.tts" · "elevenlabs.music" · "zai.transcribe" · "openai.transcribe" · "fish-audio.tts" · "google.image" · "openai.image-2.5" · "wan.image" · "logo.lookup" · "openmeteo.weather" · "frankfurter.fx" · "dictionary.define" · "openlibrary.search" · "googledns.resolve" · "qrserver.create" · "recall.meeting-record" · "social-boost.catalog"
    - `capabilityPolicies` (map<string, enum<string>>) — Per-capability permission policy map; omitted when no entries exist. always_allow: invoke without user confirmation. always_ask: prompt the session owner before every invocation. auto: reserved for future policy evaluation; currently prompts the session owner like always_ask. — "always_allow" · "always_ask" · "auto"
    - `nativeToolPolicy` (enum<string>) — Native pod-tool permission, independent of capabilities. Returned on create and detail responses; omitted legacy settings mean always_allow. Only the agent owner can change it, while sessions are idle. — "always_allow" · "always_ask"
    - `hiringPolicy` (enum<string>) — Whether this agent's sessions may bring in other agents as helpers. allow unless set to deny. Returned on create and detail responses. — "allow" · "deny"
    - `mcpServers` (object[]) — Declared remote MCP server references, including tool filters; runtime authentication fields are never returned
      - `type` ("url") — default: "url"
      - `name` (string, required) — max length 255
      - `url` (string, required)
      - `tools` (object)
        - `include` (string[]) — default: []
        - `exclude` (string[]) — default: []
    - `hooks` (object[]) — Shell commands run in the session's pod at lifecycle events
      - `event` (enum<string>, required) — "pre_session_start" · "session_start" · "user_prompt_submit" · "pre_tool_use" · "post_tool_use" · "stop" · "session_end"
      - `command` (string, required) — max length 4000
      - `matcher` (string) — max length 255
      - `timeout_s` (integer)
    - `metadata` (object) — Your key-merged client metadata
    - `environmentId` (string | null) — The environment sessions of this agent boot in when their create names none; ahead of the workspace default
    - `vaultId` (string | null) — The vault every session of this agent carries, after the vaults its create names and ahead of the workspace default
    - `defaultSessionId` (string | null) — The session conversation verbs target when addressed by agent id
    - `universe` (string) — Resolved universe slug
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"displayName":"Research Agent","expectedVersion":1}'
```

### DELETE /agents/{id}

Delete the agent — only with zero live sessions (409 agent_has_sessions) (scope: admin)

An agent that never had a session is deleted (outcome deleted). One whose sessions were all deleted is archived instead (outcome archived), so their history keeps naming it: it stays readable, is listed with archived: true, and starts no new sessions — the same state POST /agents/{id}/archive leaves.

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Responses:

- `200` — OK
  - `ok` (enum<boolean>, required) — true
  - `outcome` (enum<string>, required) — "deleted" · "archived"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d \
  -H "Authorization: Bearer ast_..."
```

### POST /agents/{id}/archive

Archive the agent — read-only, sessions keep running, new sessions rejected (scope: admin)

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Responses:

- `200` — OK
  - `agent` (object, required) — Everything in the list item, plus configuration state.
    - `id` (string) — The agent id (agent_…) — the only address
    - `name` (string)
    - `displayName` (string)
    - `agentType` (string)
    - `llm` (string)
    - `harnessVersion` (string | null)
    - `reasoningEffort` (string | null) — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra" · null
    - `version` (integer)
    - `archived` (boolean)
    - `sessionCount` (integer)
    - `createdAt` (string)
    - `description` (string | null)
    - `prompt` (string | null) — The user prompt layer
    - `promptVersion` (integer | null)
    - `capabilities` (enum<string>[]) — The built-in capabilities this agent is granted — the exact set its sessions may execute (enforced; empty = none). Ids are listed at /docs/capabilities. — "embedding.openai" · "embedding.voyage" · "rerank.voyage" · "ocr.mistral" · "exa.search" · "exa.contents" · "tinyfish.fetch" · "tinyfish.browser" · "tinyfish.agent" · "dataforseo.serp" · "dataforseo.ai-keywords" · "dataforseo.llm-responses" · "dataforseo.app-info" · "dataforseo.app-search" · "dataforseo.backlinks" · "dataforseo.business-reviews" · "dataforseo.business-pinterest" · "dataforseo.content-analysis" · "dataforseo.technologies" · "dataforseo.keyword-data" · "dataforseo.labs" · "dataforseo.amazon" · "dataforseo.onpage" · "gptimage.generate" · "rembg.remove-background" · "seedance.generate" · "mm.i2v" · "wan.t2v" · "wan.i2v" · "happyhorse.t2v" · "minimax.h3" · "fish-audio.transcribe" · "code-review" · "exa.answer" · "googlemap.geocode" · "googlemap.places" · "agentmail.list-inboxes" · "tinyfish.search" · "tinyfish.profile-list" · "meta.transcribe" · "minimax.tts" · "elevenlabs.sound" · "elevenlabs.tts" · "elevenlabs.music" · "zai.transcribe" · "openai.transcribe" · "fish-audio.tts" · "google.image" · "openai.image-2.5" · "wan.image" · "logo.lookup" · "openmeteo.weather" · "frankfurter.fx" · "dictionary.define" · "openlibrary.search" · "googledns.resolve" · "qrserver.create" · "recall.meeting-record" · "social-boost.catalog"
    - `capabilityPolicies` (map<string, enum<string>>) — Per-capability permission policy map; omitted when no entries exist. always_allow: invoke without user confirmation. always_ask: prompt the session owner before every invocation. auto: reserved for future policy evaluation; currently prompts the session owner like always_ask. — "always_allow" · "always_ask" · "auto"
    - `nativeToolPolicy` (enum<string>) — Native pod-tool permission, independent of capabilities. Returned on create and detail responses; omitted legacy settings mean always_allow. Only the agent owner can change it, while sessions are idle. — "always_allow" · "always_ask"
    - `hiringPolicy` (enum<string>) — Whether this agent's sessions may bring in other agents as helpers. allow unless set to deny. Returned on create and detail responses. — "allow" · "deny"
    - `mcpServers` (object[]) — Declared remote MCP server references, including tool filters; runtime authentication fields are never returned
      - `type` ("url") — default: "url"
      - `name` (string, required) — max length 255
      - `url` (string, required)
      - `tools` (object)
        - `include` (string[]) — default: []
        - `exclude` (string[]) — default: []
    - `hooks` (object[]) — Shell commands run in the session's pod at lifecycle events
      - `event` (enum<string>, required) — "pre_session_start" · "session_start" · "user_prompt_submit" · "pre_tool_use" · "post_tool_use" · "stop" · "session_end"
      - `command` (string, required) — max length 4000
      - `matcher` (string) — max length 255
      - `timeout_s` (integer)
    - `metadata` (object) — Your key-merged client metadata
    - `environmentId` (string | null) — The environment sessions of this agent boot in when their create names none; ahead of the workspace default
    - `vaultId` (string | null) — The vault every session of this agent carries, after the vaults its create names and ahead of the workspace default
    - `defaultSessionId` (string | null) — The session conversation verbs target when addressed by agent id
    - `universe` (string) — Resolved universe slug
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/archive \
  -H "Authorization: Bearer ast_..."
```

### PUT /agents/{id}/prompt

Save the user prompt layer; applies to sessions started after the save (scope: write)

Pass expectedVersion from the agent promptVersion to reject a stale save with 409 version_conflict. Null expects no saved prompt. Omit for legacy unconditional saves.

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Body (application/json):

- `prompt` (string, required) — max length 100000
- `expectedVersion` (integer | null)

Responses:

- `200` — OK
  - `version` (integer)
  - `unchanged` (boolean) — Content identical to the active version
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/prompt \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"prompt":"You are a meticulous research agent…"}'
```

### GET /agents/{id}/prompt/versions

Prompt version history (scope: read)

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Responses:

- `200` — OK
  - `versions` (object[], required)
    - `version` (integer)
    - `note` (string | null)
    - `createdAt` (string)
    - `active` (boolean)
    - `content` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/prompt/versions' \
  -H "Authorization: Bearer ast_..."
```

### GET /agents/{id}/secrets

Declared secret keys + set/unset — never values (scope: read)

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Responses:

- `200` — OK
  - `secrets` (object[], required)
    - `key` (string)
    - `description` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/secrets' \
  -H "Authorization: Bearer ast_..."
```

### PUT /agents/{id}/secrets/{key}

Set a declared secret's value (write-only) (scope: write)

Path parameters:

- `id` (string, required) — The agent id (agent_…)
- `key` (string, required)

Body (application/json):

- `value` (string, required) — max length 10000
- `description` (string) — max length 500

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/secrets/NOTION_TOKEN \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"value":"secret_…"}'
```

### DELETE /agents/{id}/secrets/{key}

Unset a secret (scope: write)

Path parameters:

- `id` (string, required) — The agent id (agent_…)
- `key` (string, required)

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/secrets/NOTION_TOKEN \
  -H "Authorization: Bearer ast_..."
```

### POST /agents/{id}/invite

Invite the agent into a team chat: with conversation_id it joins that conversation's roster (RFC-0151); without, returns the Slack install URL (scope: write)

404 and 409 are the channel service's own answers, with its code; 503 when it cannot be reached; 424, with its code, for any other refusal.

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Body (application/json):

- `conversation_id` (string) — Channel conversation id, e.g. slack:C0123:1712345678.000100

Responses:

- `200` — OK
  - `session_id` (string)
  - `agent_ref` (string)
  - `agent_type` (string)
  - `install_url` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/invite \
  -H "Authorization: Bearer ast_..."
```

### PUT /agents/{id}/avatar

Upload a custom PNG/JPEG avatar for the agent (≤ 1 MB) (scope: write)

Accepts `multipart/form-data` with a `file` field, or raw bytes with `Content-Type: image/png | image/jpeg`. Replaces any previously uploaded avatar; the engine-mark / sky-avatar fallback is only shown when no custom upload exists. 413 payload_too_large past 1 MiB.

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Responses:

- `200` — OK
  - `avatar_url` (string, required) — Absolute URL for the PNG avatar — cache-able for 5 minutes.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/avatar \
  -H "Authorization: Bearer ast_..."
```

### DELETE /agents/{id}/avatar

Remove the custom avatar and revert to the engine-mark / sky-avatar fallback (scope: write)

Path parameters:

- `id` (string, required) — The agent id (agent_…)

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/agents/agent_cmtb2f0a8m9k7x51q4ez6r0d/avatar \
  -H "Authorization: Bearer ast_..."
```

### GET /agents/{ref}/avatar.png

PNG avatar for an agent — public, no auth required

Returns the agent's avatar as a square PNG. Resolution order: 1. owner-uploaded image; 2. engine brand mark; 3. deterministic sky avatar. `ref` is the agent id (`agent_…`), an engine type string (e.g. `codex`), or a catalog handle. Optional `?size=N` (default 64, max 512).

Path parameters:

- `ref` (string, required) — agent id, engine type, or catalog handle

Query parameters:

- `size` (integer) — Output side length in pixels (square)

Responses:

- `200` — PNG image
- `404` — Unknown ref
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/agents/ref/avatar.png' \
  -H "Authorization: Bearer ast_..."
```

## Skills

### GET /skills

Deprecated: use GET /plugins?view=yours&source=skill. List skills in the resolved universe (scope: read)

Deprecated: use `GET /plugins?view=yours&source=skill`. Still served exactly as before; every answer carries a `Deprecation` header.

Query parameters:

- `cursor` (string)
- `limit` (integer)

Responses:

- `200` — OK
  - `skills` (object[], required)
    - `id` (string, required)
    - `displayName` (string, required)
    - `latestRevisionId` (string | null, required) — What `latest` references resolve to.
    - `attachByDefault` (boolean, required) — Whether every new session in the workspace starts with this skill's latest revision.
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
  - `nextCursor` (string | null)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/skills' \
  -H "Authorization: Bearer ast_..."
```

### POST /skills

Deprecated: use POST /plugins (multipart, as before). Create a skill (uploads revision 1) (scope: write)

Deprecated: use `POST /plugins (multipart, as before)`. Still served exactly as before; every answer carries a `Deprecation` header. A skill is a universe-scoped, immutably-revisioned file bundle agents load on demand (RFC-0073). Attach it to agents via the `skills` array on create/patch.

Responses:

- `201` — Created
  - `skill` (object, required)
    - `id` (string, required)
    - `displayName` (string, required)
    - `latestRevisionId` (string | null, required) — What `latest` references resolve to.
    - `attachByDefault` (boolean, required) — Whether every new session in the workspace starts with this skill's latest revision.
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
  - `revision` (object, required)
    - `id` (string, required)
    - `skillId` (string, required)
    - `name` (string, required) — Frontmatter name — the skill's identity name.
    - `description` (string, required)
    - `files` (object[], required)
      - `path` (string, required)
      - `size` (integer, required)
      - `sha256` (string, required)
      - `executable` (boolean, required)
    - `createdAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/skills \
  -H "Authorization: Bearer ast_..."
```

### GET /skills/lookup

Find a skill across the layers (scope: read)

By name or words, in order: the caller's own, this workspace, the platform, then Market. It never reads the caller's other workspaces. Answers 403 `not_enabled` where layers are off.

Query parameters:

- `q` (string, required)

Responses:

- `200` — OK
  - `matches` (object[], required)
    - `layer` (enum<string>, required) — "personal" · "workspace" · "platform" · "market"
    - `name` (string, required)
    - `description` (string, required)
    - `skill_id` (string)
    - `revision_id` (string)
    - `market_id` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/skills/lookup?q=q' \
  -H "Authorization: Bearer ast_..."
```

### GET /skills/personal

The caller's own skills (scope: read)

Skills that belong to the caller and follow them to every workspace, including their changes to shared skills.

Responses:

- `200` — OK
  - `skills` (object[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/skills/personal' \
  -H "Authorization: Bearer ast_..."
```

### POST /skills/personal

Save a way of working as the caller's own skill (scope: write)

Takes a complete SKILL.md. The same name adds a version. Rules on permissions, spending, compliance or sending outside the workspace answer 422 `sensitive_change`.

Body (application/json):

- `skill_md` (string, required) — max length 100000

Responses:

- `200` — OK
  - `skill` (object, required)
    - `id` (string, required)
    - `displayName` (string, required)
    - `latestRevisionId` (string | null, required) — What `latest` references resolve to.
    - `attachByDefault` (boolean, required) — Whether every new session in the workspace starts with this skill's latest revision.
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/skills/personal \
  -H "Authorization: Bearer ast_..."
```

### POST /skills/{skillId}/overlay

Change a skill for the caller alone (scope: write)

Adds text after the skill for the caller's own sessions. The skill's updates keep arriving. Text touching permissions, spending, compliance or sending outside the workspace answers 422 `sensitive_change`.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)

Body (application/json):

- `text` (string, required) — max length 20000

Responses:

- `200` — OK
  - `overlay` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/skills/skillId/overlay \
  -H "Authorization: Bearer ast_..."
```

### POST /skills/{skillId}/promote

Add your own skill to this workspace (scope: write)

Copies the caller's skill into this workspace as an ordinary skill. A name already there answers 409 `name_taken`.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)

Responses:

- `200` — OK
  - `skill` (object, required)
    - `id` (string, required)
    - `displayName` (string, required)
    - `latestRevisionId` (string | null, required) — What `latest` references resolve to.
    - `attachByDefault` (boolean, required) — Whether every new session in the workspace starts with this skill's latest revision.
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/skills/skillId/promote \
  -H "Authorization: Bearer ast_..."
```

### POST /skills/{skillId}/restore

Bring a retired skill back (scope: write)

Retired skills keep every version. New sessions get a restored skill again. A skill that is not retired is returned unchanged.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)

Responses:

- `200` — OK
  - `skill` (object, required)
    - `id` (string, required)
    - `displayName` (string, required)
    - `latestRevisionId` (string | null, required) — What `latest` references resolve to.
    - `attachByDefault` (boolean, required) — Whether every new session in the workspace starts with this skill's latest revision.
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/skills/skillId/restore \
  -H "Authorization: Bearer ast_..."
```

### GET /skills/usage

Skill use, lookups and misses in the resolved universe (scope: read)

Per skill name, since `since` (default 30 days): `views` and `misses` count the times an agent asked for a workspace skill by name (`actl skill get`), found or not; `uses` counts sessions whose agent really read the skill. `uses` stays 0 in a workspace where recording is not on.

Query parameters:

- `since` (string)

Responses:

- `200` — OK
  - `skills` (object[], required)
    - `name` (string, required)
    - `views` (integer, required)
    - `misses` (integer, required)
    - `uses` (integer, required)
    - `lastSeen` (string, required)
  - `topMissed` (object[], required)
    - `name` (string, required)
    - `misses` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/skills/usage' \
  -H "Authorization: Bearer ast_..."
```

### GET /skills/{skillId}

Deprecated: use GET /plugins/skill:{skillId}. Skill detail (scope: read)

Deprecated: use `GET /plugins/skill:{skillId}`. Still served exactly as before; every answer carries a `Deprecation` header.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)

Responses:

- `200` — OK
  - `skill` (object, required)
    - `id` (string, required)
    - `displayName` (string, required)
    - `latestRevisionId` (string | null, required) — What `latest` references resolve to.
    - `attachByDefault` (boolean, required) — Whether every new session in the workspace starts with this skill's latest revision.
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/skills/skillId' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /skills/{skillId}

Make a skill always available, or stop (scope: write)

With `attachByDefault: true`, every session created in the workspace from then on is provisioned with the skill's latest revision, unless the session is created with `defaults: "none"`. Sessions of agents that cannot take skills start without it.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)

Body (application/json):

- `attachByDefault` (boolean, required)

Responses:

- `200` — OK
  - `skill` (object, required)
    - `id` (string, required)
    - `displayName` (string, required)
    - `latestRevisionId` (string | null, required) — What `latest` references resolve to.
    - `attachByDefault` (boolean, required) — Whether every new session in the workspace starts with this skill's latest revision.
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/skills/skillId \
  -H "Authorization: Bearer ast_..."
```

### DELETE /skills/{skillId}

Deprecated: use DELETE /plugins/skill:{skillId}. Delete a skill and all its revisions (scope: write)

Deprecated: use `DELETE /plugins/skill:{skillId}`. Still served exactly as before; every answer carries a `Deprecation` header. 409 skill_in_use while any agent references the skill.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/skills/skillId \
  -H "Authorization: Bearer ast_..."
```

### GET /skills/{skillId}/revisions

Deprecated: use GET /plugins/skill:{skillId}/revisions. List a skill's revisions, newest first (scope: read)

Deprecated: use `GET /plugins/skill:{skillId}/revisions`. Still served exactly as before; every answer carries a `Deprecation` header.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)

Responses:

- `200` — OK
  - `revisions` (object[], required)
    - `id` (string, required)
    - `skillId` (string, required)
    - `name` (string, required) — Frontmatter name — the skill's identity name.
    - `description` (string, required)
    - `files` (object[], required)
      - `path` (string, required)
      - `size` (integer, required)
      - `sha256` (string, required)
      - `executable` (boolean, required)
    - `createdAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/skills/skillId/revisions' \
  -H "Authorization: Bearer ast_..."
```

### POST /skills/{skillId}/revisions

Deprecated: use POST /plugins/skill:{skillId}/revisions. Create a revision — a complete snapshot (scope: write)

Deprecated: use `POST /plugins/skill:{skillId}/revisions`. Still served exactly as before; every answer carries a `Deprecation` header. Omitted files are not carried over. The new SKILL.md name must match the skill's name (400 name_mismatch).

Responses:

- `201` — Created
  - `revision` (object, required)
    - `id` (string, required)
    - `skillId` (string, required)
    - `name` (string, required) — Frontmatter name — the skill's identity name.
    - `description` (string, required)
    - `files` (object[], required)
      - `path` (string, required)
      - `size` (integer, required)
      - `sha256` (string, required)
      - `executable` (boolean, required)
    - `createdAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/skills/skillId/revisions \
  -H "Authorization: Bearer ast_..."
```

### GET /skills/{skillId}/revisions/{revisionId}

Deprecated: use GET /plugins/skill:{skillId}/revisions/{revisionId}. Skill revision detail (metadata + file manifest) (scope: read)

Deprecated: use `GET /plugins/skill:{skillId}/revisions/{revisionId}`. Still served exactly as before; every answer carries a `Deprecation` header.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)
- `revisionId` (string, required) — The skill revision id (skr_…)

Responses:

- `200` — OK
  - `revision` (object, required)
    - `id` (string, required)
    - `skillId` (string, required)
    - `name` (string, required) — Frontmatter name — the skill's identity name.
    - `description` (string, required)
    - `files` (object[], required)
      - `path` (string, required)
      - `size` (integer, required)
      - `sha256` (string, required)
      - `executable` (boolean, required)
    - `createdAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/skills/skillId/revisions/revisionId' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /skills/{skillId}/revisions/{revisionId}

Deprecated: use DELETE /plugins/skill:{skillId}/revisions/{revisionId}. Delete one revision (scope: write)

Deprecated: use `DELETE /plugins/skill:{skillId}/revisions/{revisionId}`. Still served exactly as before; every answer carries a `Deprecation` header. 400 last_revision for a skill's only revision; 409 revision_in_use while pinned by an agent; deleting the latest repoints latestRevisionId.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)
- `revisionId` (string, required) — The skill revision id (skr_…)

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/skills/skillId/revisions/revisionId \
  -H "Authorization: Bearer ast_..."
```

### GET /skills/{skillId}/revisions/{revisionId}/content

Deprecated: use GET /plugins/skill:{skillId}/revisions/{revisionId}/content. Read a UTF-8 skill file (scope: read)

Deprecated: use `GET /plugins/skill:{skillId}/revisions/{revisionId}/content`. Still served exactly as before; every answer carries a `Deprecation` header. Reads only a file in the authorized immutable revision. Default JSON text mode returns 415 for binary files. raw=1 returns the original bytes as an attachment, including binaries. Absent files return 404. Responses are not cached.

Path parameters:

- `skillId` (string, required) — The skill id (skill_…)
- `revisionId` (string, required) — The skill revision id (skr_…)

Query parameters:

- `path` (string, required) — Exact relative file path, such as SKILL.md
- `raw` (string) — Return original file bytes as an attachment instead of the default JSON text response.

Responses:

- `200` — OK
  - `path` (string, required)
  - `content` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/skills/skillId/revisions/revisionId/content?path=report.md' \
  -H "Authorization: Bearer ast_..."
```

## Capabilities overview

### GET /capabilities

Deprecated: use GET /plugins?view=yours. Everything your agents can use, in one list (scope: read)

Deprecated: use `GET /plugins?view=yours`. Still served exactly as before; every answer carries a `Deprecation` header. Connected apps (yours, shared with the workspace, and the workspace's services), tools from the workspace's default environment and the gateway, plugins and their MCP servers, vault MCP servers and secrets, browser logins, what your Macs lend (folders, browser, screen, apps and files) and your plans — each with where it works (cloud, mac, both), who shared it, its status (on, connected, needs_signin, needs_permission, off) and what it costs (free, credits, plan, provider). Read-only: `manage` names the existing routes that change each one. A part that cannot be read is listed in `unavailable` and the rest still answer. A workspace key sees the workspace's parts; Macs and your own browser need the person's own key.

Responses:

- `200` — OK
  - `data` (object[], required)
    - `kind` (enum<string>, required) — "connector" · "tool" · "plugin" · "mcp_server" · "vault" · "browser" · "mac" · "plan"
    - `id` (string, required) — Stable within its kind: a connection id, a tool group id, a plugin name, a vault secret id, `<machine>:<reach>` for a Mac.
    - `name` (string, required)
    - `detail` (string | null, required) — One more fact: the account, the address, the variable names, what a Mac lends now.
    - `where` (enum<string>, required) — "cloud" · "mac" · "both"
    - `shared_by` (object, required)
      - `type` (enum<string>, required) — "me" · "workspace" · "member"
      - `name` (string) — The member, when type is member
    - `status` (enum<string>, required) — "on" · "connected" · "needs_signin" · "needs_permission" · "off"
    - `cost` (enum<string>, required) — free, credits from the balance, the person's own plan, or external provider pricing — "free" · "credits" · "plan" · "provider"
    - `manage` (enum<string>, required) — The existing page and API group that change it — "connectors" · "tools" · "plugins" · "vaults" · "browser-logins" · "mac" · "plans"
    - `machine` (object) — On a mac capability: the Mac that lends it
      - `id` (string)
      - `name` (string)
      - `online` (boolean)
  - `unavailable` (object[], required) — Parts that could not be read right now, so a missing kind is not mistaken for none.
    - `kind` (string, required)
    - `message` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/capabilities' \
  -H "Authorization: Bearer ast_..."
```

## Plugins

### GET /plugins

Everything agents can use, as one Plugin list; or the installed plugin bundles (scope: read)

With `view`, one list of Plugins over every source: connected apps (yours, shared with the workspace, the workspace's services), gateway tools (priced from the gateway's endpoint directory), chat apps, plugin bundles, standalone skills, custom MCP servers (vault secrets with a server address and servers agents declare), browser logins and the Mac app's plugins. `yours` is what is added, off or waiting on the person (those first); `discover` is what can still be added, without anything `yours` lists (with `source`, that source's whole catalog, added ones marked), paged through the connector catalog with `cursor` (a cursor from other filters is 400 invalid_cursor). `view=yours&source=skill` with `limit`, `cursor` or `bundled` answers the workspace's skills one page at a time, newest first, and a failed read fails the request instead of being named in `unavailable`. A source that cannot be read is named in `unavailable` and the rest still answer. A workspace key lists only what the workspace holds; a person's own apps, chat apps and Macs need the person's own key. One product is one plugin: an app and a chat app (or a tool) of the same product are listed once, under the product's first id with the others as `aliases`, `needs_you` when any part needs the person, else `added` when any part is added; `source=` lists that source alone, unmerged, by each plugin's own id. Without `view` this answers the installed plugin bundles exactly as before: each bundle's name and the workspace skills named plugin:<plugin>/<part> it installed.

Query parameters:

- `view` (string) — Omit for the installed plugin bundles
- `q` (string) — Search name, line and provider
- `use` (string)
- `cursor` (string) — discover, or yours with source=skill: a page's `next_cursor`
- `limit` (integer) — yours with source=skill: skills per page, 50 when left out. 400 invalid_request anywhere else
- `bundled` (string) — yours with source=skill: also the skills a plugin bundle installed, which that list otherwise leaves to their bundle. 400 invalid_request anywhere else
- `source` (string) — Only this source's plugins
- `agent_id` (string) — yours only: what this agent can use. A plugin switched off for it reads `off`, and `layers.agent` is its list
- `session_id` (string) — yours only: what this chat can use (its agent's switches and its own). `off_for.session` and `layers.session` say what the chat switched off
- `include` (string) — With `view`, a comma-separated list of connector rows to answer beside the list, each exactly as its store reads it: `connections` (your own connected accounts as `connections`, and the credit you earned by connecting as `credit`), `granted` (connections other people granted to this credential, which POST /plugins/{id}/call may call through), `shared` (every connection you share with a workspace, with the calls agents made through it) and `services` (the workspace's installed services). 400 invalid_request for another name.

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins' \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins

Install a plugin bundle, add a custom MCP server, or upload a skill (scope: write)

multipart/form-data uploads a skill exactly as POST /skills did (one zip or individual files, SKILL.md at the root): its first revision, answered as {skill, revision}. 424 source_unreachable or source_unreadable when GitHub refuses the source, cannot be reached, or its archive cannot be read. source is github:owner/repo[/path][@ref] or a github.com URL to a folder in Claude Code's plugin format (.claude-plugin/plugin.json, skills/, commands/, .mcp.json). skills/<name>/ become workspace skills as they are and commands/<name>.md become skills whose SKILL.md is the command's prompt, all attached to every new session. Installing again updates in place: kept parts get a new revision, dropped parts are deleted (or switched off when a session holds them). Sub-agents, hooks and local MCP servers are listed under skipped. connectors lists each .mcp.json server, the AgentSky connector app it maps to, whether the caller has that connection, and the link to connect it.

Body (application/json):

- option 1 (object)
  - `source` (string, required)
  - `mcp_tokens` (map<string, string>) — Bearer tokens for the plugin's remote MCP servers, by server name. Write-only; stored sealed.
- option 2 (object) — Add a custom MCP server: with `token`, a static_bearer secret in the workspace's default vault, or over the token it already has; with `agent_id`, the server on that agent. At least one. The server is called first: a token it refuses is 422 mcp_token_rejected and nothing is saved. A retry after any failure is safe. Answers PluginAddAnswer (201), `status: needs_you` with `next.steps` while no session can use it (no agent declares it, or it wants a token), and `result.check` with what the server said (ok, needs_token, unverified, unreachable).
  - `mcp_url` (string, required) — https to a public host
  - `name` (string) — What people call it. Defaults to the host's name. — max length 64
  - `note` (string) — What it is for, shown on its card — max length 500
  - `token` (string) — Write-only
  - `agent_id` (string)
  - `skip_check` (boolean) — Save a token the server refuses

Responses:

- `201` — Installed; a multipart upload answers {skill, revision}: the new skill:<id> plugin and its first revision
  - `plugin` (object)
    - `name` (string)
    - `version` (string | null)
    - `description` (string)
    - `source` (string)
  - `skills` (object[])
    - `id` (string, required)
    - `displayName` (string, required)
    - `latestRevisionId` (string | null, required) — What `latest` references resolve to.
    - `attachByDefault` (boolean, required) — Whether every new session in the workspace starts with this skill's latest revision.
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
  - `connectors` (object[])
    - `server` (string)
    - `app` (string | null)
    - `transport` (enum<string>) — "remote" · "local"
    - `connected` (boolean)
    - `connect_url` (string | null)
  - `skipped` (object[])
    - `part` (string)
    - `reason` (string)
  - `removed` (object[])
    - `part` (string)
    - `result` (enum<string>) — "deleted" · "switched_off"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins \
  -H "Authorization: Bearer ast_..."
```

### GET /plugins/{name}

One plugin by id (scope: read)

`name` is a Plugin id (app:gmail, tool:exa.web, chat:slack, bundle:review-kit, skill:skl_…, mcp:<sha8>, mac:meetings, browser:mine); a bare name is a plugin bundle's (the same as bundle:<name>). Read through the same sources as GET /plugins?view=…; an app nobody connected is looked up in the connector catalog. Any id of a merged product (chat:slack, app:slack, tool:code-review) answers the product under its first id (app:slack_v2, app:github). `unavailable` names this plugin's sources when they could not be read. Once the workspace has the plugin, `used_by` names the agents that use it: every saved agent that has not switched it off (`all` is true when none has; a Mac feature or browser login is used by every agent, one the workspace switched off by none). A bundle's `name` is its marketplace display name, or its name in title case. 404 not_found when no source knows the id.

Path parameters:

- `name` (string, required)

Query parameters:

- `agent_id` (string) — Read it as this agent sees it
- `session_id` (string) — Read it as this chat sees it

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins/name' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /plugins/{name}

Update a plugin or an owned account’s usage guidance (scope: write)

For mcp:<id>, send {name?, note?, token?, skip_check?}: the name and note people see (an agent's tools keep the name the server was added under; note null clears), and a token that replaces the saved one in place, so running sessions take it without a restart. The server is called with a new token first: 422 mcp_token_rejected keeps the old one unless skip_check. 409 oauth_server when it signs in with OAuth. For app:<slug>, send {connection_id, when_to_use} to save optional owner-only account guidance (500 characters, null clears). The account must belong to this person and exact app; labels, permissions and grants stay unchanged. For a bundle, send {enabled}, or {rollback_revision, expected_revision} to restore saved content using the last-read active_revision. A stale expected_revision is 409 revision_conflict, an unknown or foreign version is 404 not_found. Credentials are retained only for the same source, server name and exact URL. A rollback creates a new active_revision and preserves the enabled state. Off: its skills stop attaching to new sessions and plugin sessions refuse to start. A plugin a workspace admin blocked cannot be switched on (403 plugin_blocked).

Path parameters:

- `name` (string, required)

Body (application/json):

- option 1 (object)
  - `enabled` (boolean, required)
- option 2 (object)
  - `rollback_revision` (string, required)
  - `expected_revision` (string | null, required)
- option 3 (object)
  - `connection_id` (string, required)
  - `when_to_use` (string, required) — max length 500
- option 4 (object) — A custom MCP server. At least one of name, note and token.
  - `name` (string) — max length 64
  - `note` (string) — max length 500
  - `token` (string) — Write-only
  - `skip_check` (boolean)

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/plugins/name \
  -H "Authorization: Bearer ast_..."
```

### DELETE /plugins/{name}

Remove a plugin or disconnect it (scope: write)

A bare name removes that installed plugin bundle exactly as before (deprecated: the answer carries a `Deprecation` header; use bundle:<name>): its skills are deleted, and a skill a session still holds is switched off (no longer attached to new sessions) instead. A Plugin id runs the source's own removal, and never deletes a connection a plugin uses: app:<slug> disconnects your connection of that app only with disconnect=true (`connection_id` when you have several, else 409 connection_required naming them; a workspace key is 403 person_required), chat:<platform> disconnects your chat-app connection, tool:<id> switches it off in the workspace's default environment, bundle:<name> uninstalls it (the apps it used stay connected), skill:<id> deletes it (409 skill_in_use while attached), mcp:<id> takes the server off every agent that declares it and deletes its saved tokens, name and note, so it is gone everywhere it was listed (more than one agent needs all_agents=true, else 409 agents_required naming them; agent_id takes it off that agent only and keeps the rest; running sessions keep it until their next start; archived agents are left alone; 502 remove_incomplete changes no token and a retry finishes). Mac features and browser logins are 422 not_switchable. A merged product's first id (app:slack_v2) also disconnects its chat-app connections and switches its tool off, answering `result: {removed, kept}`; the person's app connection is kept unless disconnect=true. Each alias (chat:slack) removes only itself, as before. To stop one agent or chat using a plugin, use PUT /plugins/{id}/off.

Path parameters:

- `name` (string, required)

Query parameters:

- `connection_id` (string) — Which of your connections, for an app or a chat app
- `disconnect` (string) — app:<slug> only: disconnect that account at the provider. Without it, 409 disconnect_required: the person may use it elsewhere
- `agent_id` (string) — mcp:<id> only: the one agent that stops using the server
- `all_agents` (string) — mcp:<id> only: remove it from every agent that uses it

Responses:

- `200` — Removed
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/plugins/name \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins/{name}/complete

Record a completed app authorization (scope: write)

Canonical version of POST /connectors/connections/complete; uses the same completion writer. Person only, app:<slug> only, explicit account_id required so the caller never binds guidance to a guessed newest account. Verifies account ownership at the provider and returns the exact persisted connection_id for subsequent PATCH usage guidance. account_source selects the native or provider registry. No notes are carried in OAuth state. Reconnecting preserves guidance.

Path parameters:

- `name` (string, required)

Body (application/json):

- `account_id` (string, required) — max length 200
- `account_source` (enum<string>) — "pipedream" · "google_native"

Responses:

- `200` — Recorded
  - `connection` (object)
    - `connection_id` (string)
    - `app` (string)
    - `app_name` (string)
    - `label` (string)
    - `credit_grant` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins/name/complete \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins/{name}/add

Add a plugin, or connect an app (scope: write)

Runs the source's own add: tool:<id> is switched on in the workspace's default environment; skill:<id> attaches to every new session; bundle:<name> is switched back on, or installed from `source` or the marketplace that lists it; app:<slug> starts connecting (without `success_url` and `error_url` the browser returns to a page that records the connection for the caller and needs no signed-in browser) and answers `next.url`, the address the person opens to sign in; with `task_id` and `request_id` instead, `next.url` is the once-only connect link of that task's connect_app request, as POST /connectors/links (404 when the task has no such open request, 403 request_not_yours, 422 wrong_app when it asks for another app); chat:<platform> starts the chat-app connect (`agent_id` or `session_id` chooses who answers, `app` a registered app) and answers the pairing page as `next.url`; mac:<id> and browser:<scope> answer `next.steps`, and mac:meetings with `agent_id` adds its follow-up routine for that agent, paused (one already there is left as it is). A merged product's first id connects its app and names its chat app's pairing in `next.steps`; a bundle names one app per category it still needs. When a person must finish, the answer is 202 with status needs_you; otherwise 200 added. 403 plugin_blocked when an admin blocked it; 403 person_required for apps and chat apps under a workspace key; 503 platform_unavailable for a chat app that cannot be connected yet. A custom MCP server is added with POST /plugins {mcp_url}.

Path parameters:

- `name` (string, required)

Body (application/json):

- `success_url` (string)
- `error_url` (string)
- `return_to` (enum<string>) — An app, without `success_url`: the return page opens the AgentSky Mac app when the person finishes. — "mac"
- `source` (string)
- `connection_id` (string) — App only: reconnect this existing connection owned by the caller, preserving its grants and shares. Cannot be combined with task_id/request_id. — max length 200
- `mcp_tokens` (map<string, string>)
- `agent_id` (string)
- `session_id` (string)
- `label` (string)
- `app` (string)
- `task_id` (string) — app only, with request_id: the task whose connect_app request this answers
- `request_id` (string) — app only, with task_id: answers next.url, a link the person the request is addressed to opens once, within fifteen minutes, without signing in

Responses:

- `200` — Added
  - `plugin_id` (string, required)
  - `status` (enum<string>, required) — "added" · "needs_you"
  - `next` (object) — What a person must finish, one step per part
    - `url` (string)
    - `steps` (string[])
  - `result` (any, required) — What the source's own function answered
- `202` — A person must finish: open next.url or follow next.steps
  - `plugin_id` (string, required)
  - `status` (enum<string>, required) — "added" · "needs_you"
  - `next` (object) — What a person must finish, one step per part
    - `url` (string)
    - `steps` (string[])
  - `result` (any, required) — What the source's own function answered
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins/name/add \
  -H "Authorization: Bearer ast_..."
```

### PUT /plugins/{name}/off

Switch a plugin off or back on for one agent or one chat (scope: write)

Exactly one of `agent_id` (the agent's list, AgentSpec pluginsOff, written as PATCH /agents/{id} pluginsOff) or `session_id` (the chat's own list). Available to a chat = added to the workspace − off for its agent − off for the chat. Tools, connected apps and chat apps stop at once (a call answers 403 plugin_off, whose message names the id to switch back on as `(plugin_off: <id>)`); skills and MCP servers from the chat's next start. `off: false` takes the plugin out of that list; with `session_id`, when the chat's agent has it off, it is also put on the chat's `plugins_on`, so that chat alone uses it (switching it off for the chat takes it out again). It never adds what the workspace has not added. A tool is named by its group (tool:exa.web) or one capability (tool:exa.search). A merged product's first id switches every id of it (app:slack_v2 also writes app:slack, app:slack_bot and chat:slack); an alias switches only itself. Mac features and browser logins are 422 not_switchable.

Path parameters:

- `name` (string, required)

Body (application/json):

- `agent_id` (string)
- `session_id` (string)
- `off` (boolean, required)

Responses:

- `200` — OK
  - `plugin_id` (string, required)
  - `off` (boolean, required)
  - `agent_id` (string)
  - `session_id` (string)
  - `plugins_off` (string[], required) — That agent's or chat's whole list after the switch
  - `plugins_on` (string[]) — With session_id: what this chat uses although its agent has it off
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/plugins/name/off \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins/{name}/request

Ask a person for what a plugin needs in one chat (scope: write)

For one chat (`session_id`), the chat's owner is asked with one question card: to switch the plugin back on when it is off for the chat's agent or the chat (`need: off`), to add it to the workspace (`not_added`), or to sign in to an app (`sign_in`). `status: question` carries `call_id`; a repeat call is idempotent. `status: decided` carries `decision`, and `next` is what a person must still finish after an Add. `status: available` asks nobody. Skills and MCP servers switched back on arrive from the chat's next start. A plugin a workspace admin blocked is 403 plugin_blocked and nobody is asked; Mac features and browser logins are 422 not_requestable.

Path parameters:

- `name` (string, required)

Body (application/json):

- `session_id` (string, required)

Responses:

- `200` — OK
  - `plugin_id` (string, required)
  - `need` (enum<string>, required) — "off" · "not_added" · "sign_in"
  - `status` (enum<string>, required) — "available" · "question" · "decided"
  - `call_id` (string)
  - `decision` (enum<string>) — "allow_once" · "allow_always" · "deny"
  - `next` (object)
    - `url` (string)
    - `steps` (string[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins/name/request \
  -H "Authorization: Bearer ast_..."
```

### GET /plugins/{name}/share

Where your connections of an app are shared (scope: read)

app:<slug> only (422 not_shareable otherwise). One row per connection of that app that is yours: each workspace it is shared with and the calls agents made there, as GET /shared-connections, and each API-key grant with its calls, as GET /connectors/connections/{id}/grants. `connection_id` narrows it to one (404 when it is not yours). A workspace key is 403 person_required.

Path parameters:

- `name` (string, required)

Query parameters:

- `connection_id` (string)

Responses:

- `200` — OK
  - `plugin_id` (string, required)
  - `connections` (object[], required)
    - `connection_id` (string, required)
    - `label` (string, required)
    - `workspaces` (object[], required)
      - `workspace` (object)
      - `shared_at` (string)
      - `use_count` (integer)
      - `uses` (object[])
    - `api_keys` (object[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins/name/share' \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins/{name}/share

Share an app connection with a workspace, or grant it to API keys (scope: write)

app:<slug> only (422 not_shareable otherwise). Without `api_key`, your connection of that app is shared with `workspace`'s sessions, as POST /universes/{slug}/connections. With `api_key` (a key id of the request's workspace, which `workspace` must name), that key may call through it with POST /plugins/{id}/call, as POST /connectors/connections/{id}/grants; `all_api_keys: true` instead lets every key of that workspace. `connection_id` when you have several. A workspace key is 403 person_required.

Path parameters:

- `name` (string, required)

Body (application/json):

- `workspace` (string, required)
- `api_key` (string)
- `all_api_keys` (boolean)
- `connection_id` (string)

Responses:

- `201` — Shared
  - `plugin_id` (string)
  - `shared` (enum<string>) — "workspace" · "api_key" · "all_api_keys"
  - `workspace` (string)
  - `connection_id` (string)
  - `grant` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins/name/share \
  -H "Authorization: Bearer ast_..."
```

### DELETE /plugins/{name}/share

Stop sharing an app connection with a workspace, or take back one API key's grant (scope: write)

app:<slug> only (422 not_shareable otherwise); the same fields as sharing, in the query. Without `api_key`, `workspace`'s sessions lose your connection of that app at once, as DELETE /universes/{slug}/connections/{id}. With `api_key` (a key id of the request's workspace, which `workspace` must name), that key can no longer call through it, as DELETE /connectors/connections/{id}/grants; `all_api_keys=true` takes back the grant to every key of that workspace. The connection itself stays connected. `connection_id` when you have several (else 409 connection_required); a workspace owner or admin may name another member's connection shared with `workspace`. 404 when it was not shared there. A workspace key is 403 person_required.

Path parameters:

- `name` (string, required)

Query parameters:

- `workspace` (string, required) — The workspace slug it is shared with
- `api_key` (string) — The API key id it was granted to, instead of the whole workspace
- `all_api_keys` (boolean) — true: the grant to every API key of the workspace
- `connection_id` (string) — Which connection of that app

Responses:

- `200` — No longer shared
  - `plugin_id` (string, required)
  - `unshared` (enum<string>, required) — "workspace" · "api_key" · "all_api_keys"
  - `workspace` (string)
  - `api_key` (string)
  - `connection_id` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/plugins/name/share \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins/{name}/call

Call an app's API through a connection granted to this API key (scope: write)

For a service holding an API key: app:<slug> only (422 not_callable otherwise). Calls `url` (https only, 400 https_required) through the caller's own connection with an unrestricted personal key, or an explicit grant to this key or workspace (POST /plugins/{id}/share {workspace, api_key | all_api_keys}), exactly as POST /connectors/proxy: the workspace's tool-call rules decide first (403 capability_denied; 503 policy_unavailable), and a 2xx books one connector call to the key's account (native GitHub calls are free). `connection_id` names the connection when several of that app are granted (else 409 connection_required); 404 not_granted when none is. A browser session or a task pass is 403 key_required. Answers the third party's {status, ok, body}; 502 proxy_error when it could not be called.

Path parameters:

- `name` (string, required)

Body (application/json):

- `url` (string, required)
- `method` (string)
- `headers` (map<string, string>)
- `body` (string)
- `connection_id` (string)

Responses:

- `200` — The third party's answer
  - `status` (integer, required)
  - `ok` (boolean, required)
  - `body` (any)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins/name/call \
  -H "Authorization: Bearer ast_..."
```

### PUT /plugins/{name}/answer

Choose which agent answers a chat app (scope: write)

chat:<platform>, or a merged product whose chat app it is (app:slack_v2); 422 not_a_chat_app otherwise. `agent_id` binds the agent's default chat (409 no_default_session when it has none), or `session_id` a chat. Forwarded to the channel service's PUT /channels/connections/{id}/binding with your own credential; `connection_id` names the chat-app connection when you have several.

Path parameters:

- `name` (string, required)

Body (application/json):

- `agent_id` (string)
- `session_id` (string)
- `connection_id` (string)

Responses:

- `200` — OK
  - `plugin_id` (string)
  - `connection_id` (string)
  - `session_id` (string)
  - `result` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/plugins/name/answer \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins/{name}/sessions

Start a plugin session (scope: write)

RFC-0155 §3. The session starts with only the plugin's skills (not the workspace's default skills) and its remote MCP servers, and its calls to connected apps are limited to the apps the plugin declared: any other app is refused (capability_denied, reason plugin_scope). agent defaults to the workspace's Sky. Answers the created session.

Path parameters:

- `name` (string, required)

Body (application/json):

- `message` (string, required)
- `agent` (string)
- `title` (string)

Responses:

- `201` — Created
  - `id` (string) — sess_… identifier
  - `agentId` (string | null) — The agent id (agent_…)
  - `title` (string | null)
  - `updatedAt` (string) — When the session last changed.
  - `status` (enum<string>) — provisioning = the sandbox is booting or installing the environment's packages (a turn sent meanwhile waits for it); running = a turn is in flight; terminated = archived or the last runtime was destroyed. Use archived for the durable archive receipt — "provisioning" · "idle" · "running" · "terminated"
  - `provisioningStage` (string | null) — Which part of its boot the session's computer is in, as the platform observed it: creating_computer until the sandbox provider reports the computer exists, then starting_agent until the agent in it answers. A provider that does not report the computer's creation stays at creating_computer. Null once the computer is up and whenever it is not booting. — "creating_computer" · "starting_agent" · null
  - `archived` (boolean) — True only after this Session's archive mark was durably written; false for an active Session whose runtime was destroyed
  - `agentType` (string)
  - `llm` (string) — The model this session runs on (PATCH to change; the agent's model is unchanged)
  - `harnessVersion` (string) — Harness release the session runs: the one its serving pod booted, the restored checkpoint's for a native-fork handoff, the agent's pin for ACP harnesses, otherwise the current release
  - `reasoningEffort` (string | null) — The model-compatible effort resolved from the session pin, then agent pin. Constrained models use an allowed fallback; no-setting models return null. Unpinned unconstrained models return null for the harness default.
  - `subscriptionApiFallback` (boolean) — Paid API continuation once no subscription account can run the task, preserving the same supported explicit model and wallet/budget gates. On unless set to false
  - `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription — "platform" · "account"
  - `idleTimeoutSeconds` (integer | null) — Seconds the session's machine stays awake after a turn ends before it is paused; null = the platform default of 60. Set it when people use apps on the session's exposed ports after the agent finishes
  - `browserProfile` (string) — Resolved browser: the session's choice, then the agent's default, then mine. mine is the browser of the person whose turn it is; fresh is signed out; user:<user id> is the sites that person shared with whoever runs the turn. Applied before the next browser turn when browser profiles are enabled.
  - `browserLoginsSavedAt` (string | null) — Most recent browser login save-back time, or null when this session has not saved changed logins.
  - `routineId` (string | null) — The routine whose run started this session, or null for any other session
  - `ownerId` (string) — The member who owns this session, as user_id in GET /universes/{slug}/members
  - `default` (boolean) — Is this the agent's default session
  - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
    - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
    - `workspace` (object) — The paying workspace; only with type workspace
      - `slug` (string)
      - `name` (string)
  - `metadata` (object)
  - `budget` (object | null) — Hard spend cap, or null when the session has none. A reached budget pauses the session (402 budget_reached on new work) until the cap is raised above consumed_cost or removed — removal is one-way.
  - `parentSessionId` (string | null) — The session this one came from: a helper names the session that hired it, a handoff child names the session it continued; null for a root. Every session a task's root produced, with its role, is GET /tasks/{id}?by=session on any member's id.
  - `parentRelation` (string | null) — How this session relates to parentSessionId: `helper` was hired by it (actl hire or the orchestration API), `handoff` continued its conversation on another agent; null for a root. — "helper" · "handoff" · null
  - `resources` (object[]) — The files, GitHub repositories, and read-only memory stores mounted into the session, oldest first
    - option 1 (object)
      - `type` (enum<string>, required) — "file"
      - `id` (string, required) — sesrsc_…
      - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
      - `mount_path` (string, required) — Absolute, under /workspace
      - `created_at` (string, required)
      - `updated_at` (string, required)
    - option 2 (object)
      - `type` (enum<string>, required) — "github_repository"
      - `id` (string, required) — sesrsc_…
      - `url` (string, required) — https://github.com/{owner}/{repo}
      - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
      - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
        - `type` (enum<string>) — "branch" · "commit"
        - `name` (string)
        - `sha` (string)
      - `created_at` (string, required)
      - `updated_at` (string, required)
    - option 3 (object)
      - `type` (enum<string>, required) — "memory_store"
      - `id` (string, required) — smsr_…
      - `memory_store_id` (string, required) — memstore_…
      - `mount_path` (string, required) — Absolute, under /mnt/memory
      - `access` (enum<string>, required) — "read_only" · "read_write"
      - `instructions` (string) — Optional per-session guidance
      - `created_at` (string, required)
      - `updated_at` (string, required)
  - `workspaceDefaults` (object | null) — What the session started with because its workspace made it a default; everything else it carries was named at creation. Null when it took nothing.
  - `contextFiles` (object | null) — The workspace files the session loaded into its instructions when its sandbox was last provisioned (GET /workspace-context describes the set); null before that and for a session without its workspace's store. Every other file in the store is read on demand.
  - `continuedOnMac` (object) — Present when the owner moved this session to their own computer. Without `claimedAt` no computer has taken it yet, and a new turn here releases the move. With `claimedAt` the session refuses turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`.
    - `handoffId` (string, required)
    - `at` (string, required)
    - `machine` (string)
    - `claimedAt` (string)
  - `localControl` (object) — Present on a synced chat that runs on the caller's own Mac. `state` is `running`, `waiting_for_you` (a command waits for an answer), `idle`, or `unknown` while the Mac is offline, so a run is never shown as running from an offline Mac. `controllable` is the Mac's side only: each device or key still needs its own pairing (`POST /desktop/machines/{id}/controllers`), checked on every stop and answer. When false, `reason` is `mac_offline`, `phone_control_off` (turned off on the Mac), `terminal_session` (started in Terminal; read-only here) or `older_mac_app` (no Mac has reported its chats).
    - `mac` (object | null, required)
    - `state` (enum<string>, required) — "running" · "waiting_for_you" · "idle" · "unknown"
    - `controllable` (boolean, required)
    - `reason` (enum<string>) — "mac_offline" · "phone_control_off" · "terminal_session" · "older_mac_app"
    - `limit` (object) — The plan limit this chat's last run on the Mac reported: the same state the Mac shows above the composer. Absent until a run reports one and while the Mac is offline.
      - `level` (enum<string>, required) — "ok" · "warn" · "critical"
      - `window` (string | null, required)
      - `utilization` (number | null, required)
      - `resetsAt` (string | null, required)
    - `pressure` (object) — This Mac's disk, memory and battery as it last reported them. Absent while the Mac is offline.
      - `disk` (object)
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `freeBytes` (integer | null, required)
      - `memory` (object)
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
      - `battery` (object)
        - `percent` (number, required)
        - `charging` (boolean, required)
  - `hostedBySeller` (object) — Present only when the session runs on its agent's maker's own server instead of a sandbox: what is sent to the session goes to this host. `agentType` and `llm` then name a stand-in that never runs.
    - `host` (string, required)
  - `attachments` (object[]) — Everything the session started with: its environment, vaults, mounted files and memory stores, and the workspace's always-available skills. The skills of the session's agent are on the agent and are not repeated here.
    - `type` (enum<string>, required) — "environment" · "vault" · "file" · "skill" · "memory_store"
    - `id` (string, required) — The id of the environment, vault, file, skill or memory store
    - `mountPath` (string | null, required) — Where a file or memory store is mounted; null for the other types
    - `source` (enum<string>, required) — default = the workspace supplied it; explicit = it was named when the session was created. A memory store on a session created before 2026-10-06 reads as explicit — "default" · "explicit"
  - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins/name/sessions \
  -H "Authorization: Bearer ast_..."
```

### PUT /plugins/{name}/policy

Set a plugin's workspace policy (scope: write, owner or admin)

For a bare name or bundle:<name>: recommended, default (installs it now, from source or the plugin's recorded source), blocked (cannot be installed or switched on; an installed one is switched off), or null to clear, exactly as before. Any other Plugin id is recorded under that id: blocked refuses adding it (403 plugin_blocked) and takes a tool or a skill out of the workspace now; default adds a tool or a skill now (422 policy_unsupported for other kinds); recommended is recorded.

Path parameters:

- `name` (string, required)

Body (application/json):

- `policy` (string | null, required) — "recommended" · "default" · "blocked" · null
- `source` (string)

Responses:

- `200` — OK
  - `name` (string)
  - `policy` (string | null)
  - `source` (string | null)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/plugins/name/policy \
  -H "Authorization: Bearer ast_..."
```

### GET /plugins/marketplaces

Plugins the workspace's marketplaces list (scope: read)

Each Claude Code marketplace (.claude-plugin/marketplace.json) the workspace added, or AgentSky's defaults when it added none, with each plugin's install source, workspace policy and whether it is installed.

Responses:

- `200` — OK
  - `marketplaces` (object[])
    - `source` (string)
    - `name` (string)
    - `workspace` (boolean)
    - `error` (string)
    - `plugins` (object[])
      - `name` (string)
      - `display_name` (string | null) — The manifest's displayName
      - `description` (string)
      - `version` (string | null)
      - `category` (string | null)
      - `source` (string | null)
      - `policy` (string | null)
      - `installed` (boolean)
      - `enabled` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins/marketplaces' \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins/marketplaces

Add a marketplace (scope: write, owner or admin)

404 not_a_marketplace when the source has no .claude-plugin/marketplace.json; 424 source_unreachable when GitHub refuses it or cannot be reached.

Body (application/json):

- `source` (string, required)

Responses:

- `201` — Added
  - `source` (string)
  - `name` (string)
  - `plugins` (object[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins/marketplaces \
  -H "Authorization: Bearer ast_..."
```

### DELETE /plugins/marketplaces

Remove a marketplace (scope: write, owner or admin)

Query parameters:

- `source` (string, required)

Responses:

- `200` — Removed
  - `source` (string)
  - `removed` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/plugins/marketplaces \
  -H "Authorization: Bearer ast_..."
```

### GET /plugins/{name}/export

Export a plugin as a Codex package (scope: read)

One plugin, by the id GET /plugins shows, as a package. `format=claude` (or `grok`, the same folder) writes a Claude Code plugin folder that Grok installs as written: `.claude-plugin/plugin.json`, `skills/<name>/` and `.mcp.json` with each server `{type: http, url}`; an API-key server sends its key as a bearer token read from the `<SERVER>_API_KEY` environment variable (`AGENTSKY_API_KEY` for AgentSky's own), which both expand when they start it. `format=codex` writes a Codex portable plugin package: root `plugin.json` (with `extensions["com.openai"].interface`), `skills/<name>/` and root `mcp.json` (Agent Plugins 1.0.0: each server `{type: streamable-http, url}`) for the servers that need no key or sign in with OAuth. A server that signs in with an API key, which a plugin cannot carry, is named instead in an `api-key-setup` onboarding skill that adds it with `codex mcp add … --bearer-token-env-var`. No token is ever written. A bundle keeps its skills (its commands were installed as skills) and remote MCP servers; a skill is one plugin; a custom MCP server is a plugin with that server. Apps, tools, chat apps, Mac features and browser logins export the AgentSky plugin, AgentSky's own MCP server (API key) and help server, because Codex reaches them only through it. Write each file to `path` under one folder (base64 when `encoding` is base64, made executable when `executable`). 400 invalid_request without `format=codex|claude|grok`; 404 not_found for a bundle or MCP server the workspace has not added; 409 skill_empty for a skill with no saved version.

Path parameters:

- `name` (string, required) — Plugin id, e.g. bundle:review-kit, skill:skl_…, mcp:1a2b3c4d, app:gmail

Query parameters:

- `format` (string, required)

Responses:

- `200` — The package
  - `format` (enum<string>, required) — "codex" · "claude" · "grok"
  - `plugin_id` (string, required)
  - `name` (string, required) — The package's kebab-case name
  - `files` (object[], required) — Every file of an exported package or marketplace, by its path from the root
    - `path` (string, required)
    - `encoding` (enum<string>, required) — "utf-8" · "base64"
    - `content` (string, required)
    - `executable` (boolean) — Present and true for a file to make executable
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins/name/export?format=format' \
  -H "Authorization: Bearer ast_..."
```

### GET /plugins/marketplace.json

The workspace's plugins as a marketplace for Codex, Claude Code or Grok (scope: read)

`format=claude` or `grok` (the same folder): `.claude-plugin/marketplace.json` and Grok's `.grok-plugin/marketplace.json` and `plugin-index.json`, every package as GET /plugins/{id}/export?format=claude writes it under `plugins/<name>/`; add it with `claude plugin marketplace add <folder>` or `grok plugin marketplace add <folder>` (name the folder after `name`: Grok names a folder's marketplace after it). `sky setup plugins` writes it and installs every plugin in each agent on the computer. `format=codex`: a Codex marketplace root, `.agents/plugins/marketplace.json` listing each plugin with a local source (`./plugins/<name>`, policy AVAILABLE / ON_INSTALL) and every plugin's package under `plugins/<name>/`, as GET /plugins/{id}/export writes it. It holds the AgentSky plugin, every switched-on, unblocked bundle, every skill attached to new chats (not a bundle's) and every custom MCP server; `skipped` names what was left out and why. Write the files under one folder and run `codex plugin marketplace add <folder>`. 400 invalid_request without `format=codex|claude|grok`; 413 export_too_large past 64 MB.

Query parameters:

- `format` (string, required)

Responses:

- `200` — The marketplace
  - `format` (enum<string>, required) — "codex" · "claude" · "grok"
  - `name` (string, required) — The marketplace's name, agentsky-<workspace>
  - `files` (object[], required) — Every file of an exported package or marketplace, by its path from the root
    - `path` (string, required)
    - `encoding` (enum<string>, required) — "utf-8" · "base64"
    - `content` (string, required)
    - `executable` (boolean) — Present and true for a file to make executable
  - `plugins` (object[], required)
    - `plugin_id` (string)
    - `name` (string)
  - `skipped` (object[], required)
    - `plugin_id` (string)
    - `reason` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins/marketplace.json?format=format' \
  -H "Authorization: Bearer ast_..."
```

### GET /plugins/{name}/revisions

A plugin's saved versions, newest first (scope: read)

For skill:<id>, returns skill revisions. For bundle:<name>, returns active_revision and saved content versions. Old installations have no saved versions until upgraded. Credentials are never returned.

Path parameters:

- `name` (string, required) — skill:<id>

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins/name/revisions' \
  -H "Authorization: Bearer ast_..."
```

### POST /plugins/{name}/revisions

Save a new version of a skill plugin — a complete snapshot (scope: write)

Omitted files are not carried over. The new SKILL.md name must match the skill's name (400 name_mismatch).

Path parameters:

- `name` (string, required) — skill:<id>

Responses:

- `201` — Created
  - `revision` (object, required)
    - `id` (string, required)
    - `skillId` (string, required)
    - `name` (string, required) — Frontmatter name — the skill's identity name.
    - `description` (string, required)
    - `files` (object[], required)
      - `path` (string, required)
      - `size` (integer, required)
      - `sha256` (string, required)
      - `executable` (boolean, required)
    - `createdAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/plugins/name/revisions \
  -H "Authorization: Bearer ast_..."
```

### GET /plugins/{name}/revisions/{revisionId}

One version of a skill plugin (metadata + file manifest) (scope: read)

Path parameters:

- `name` (string, required) — skill:<id>
- `revisionId` (string, required) — The skill revision id (skr_…)

Responses:

- `200` — OK
  - `revision` (object, required)
    - `id` (string, required)
    - `skillId` (string, required)
    - `name` (string, required) — Frontmatter name — the skill's identity name.
    - `description` (string, required)
    - `files` (object[], required)
      - `path` (string, required)
      - `size` (integer, required)
      - `sha256` (string, required)
      - `executable` (boolean, required)
    - `createdAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins/name/revisions/revisionId' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /plugins/{name}/revisions/{revisionId}

Delete one version of a skill plugin (scope: write)

400 last_revision for a skill's only revision; 409 revision_in_use while pinned by an agent; deleting the latest repoints latestRevisionId.

Path parameters:

- `name` (string, required) — skill:<id>
- `revisionId` (string, required) — The skill revision id (skr_…)

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/plugins/name/revisions/revisionId \
  -H "Authorization: Bearer ast_..."
```

### GET /plugins/{name}/revisions/{revisionId}/content

Read one file of a skill plugin's version (scope: read)

Reads only a file in that immutable version. Default JSON text mode returns 415 for binary files; raw=1 returns the original bytes as an attachment. Absent files return 404. Responses are not cached.

Path parameters:

- `name` (string, required) — skill:<id>
- `revisionId` (string, required) — The skill revision id (skr_…)

Query parameters:

- `path` (string, required) — Exact relative file path, such as SKILL.md
- `raw` (string)

Responses:

- `200` — OK
  - `path` (string, required)
  - `content` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/plugins/name/revisions/revisionId/content?path=report.md' \
  -H "Authorization: Bearer ast_..."
```

## Reflection

### GET /reflection_proposals

Proposed skill and lesson changes from post-task reflection (scope: read)

After a workspace-visible session ends, a reviewer may propose a skill patch, a new skill, or a `/lessons/` note. Nothing changes until a workspace owner or admin approves. Newest first, at most 100.

Query parameters:

- `status` (string)

Responses:

- `200` — OK
  - `reflection_proposals` (object[], required)
    - `id` (string)
    - `object` (enum<string>) — "reflection_proposal"
    - `session_id` (string)
    - `kind` (enum<string>) — "patch_skill" · "create_skill" · "save_lesson"
    - `target_skill_id` (string | null)
    - `target_store_id` (string | null)
    - `path` (string | null)
    - `payload` (object)
    - `evidence` (object[])
    - `status` (enum<string>) — "pending" · "approved" · "rejected" · "superseded" · "applied" · "rolled_back"
    - `decided_by` (string | null)
    - `decided_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/reflection_proposals' \
  -H "Authorization: Bearer ast_..."
```

### POST /reflection_proposals/{id}/approve

Approve a proposal: write it through the skill store or memory store (scope: write, owner or admin)

A target that changed since the proposal was made answers 409 `stale_target` and marks the proposal superseded.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `reflection_proposal` (object)
    - `id` (string)
    - `object` (enum<string>) — "reflection_proposal"
    - `session_id` (string)
    - `kind` (enum<string>) — "patch_skill" · "create_skill" · "save_lesson"
    - `target_skill_id` (string | null)
    - `target_store_id` (string | null)
    - `path` (string | null)
    - `payload` (object)
    - `evidence` (object[])
    - `status` (enum<string>) — "pending" · "approved" · "rejected" · "superseded" · "applied" · "rolled_back"
    - `decided_by` (string | null)
    - `decided_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/reflection_proposals/sess_cmtb7q2j/approve \
  -H "Authorization: Bearer ast_..."
```

### POST /reflection_proposals/{id}/rollback

Undo an automatic skill change (scope: write)

Restores the version before the change, as a new revision. Open to the person it came from, the workspace's owner or an admin. Undoing twice changes nothing. A later revision of the skill answers 409 `stale_target`; a change that was not applied by itself answers 409 `not_applied`.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `reflection_proposal` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/reflection_proposals/sess_cmtb7q2j/rollback \
  -H "Authorization: Bearer ast_..."
```

### POST /reflection_proposals/{id}/reject

Reject a proposal; nothing is written (scope: write, owner or admin)

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `reflection_proposal` (object)
    - `id` (string)
    - `object` (enum<string>) — "reflection_proposal"
    - `session_id` (string)
    - `kind` (enum<string>) — "patch_skill" · "create_skill" · "save_lesson"
    - `target_skill_id` (string | null)
    - `target_store_id` (string | null)
    - `path` (string | null)
    - `payload` (object)
    - `evidence` (object[])
    - `status` (enum<string>) — "pending" · "approved" · "rejected" · "superseded" · "applied" · "rolled_back"
    - `decided_by` (string | null)
    - `decided_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/reflection_proposals/sess_cmtb7q2j/reject \
  -H "Authorization: Bearer ast_..."
```

## Routing

### GET /routing_policy

The workspace's routing policy (scope: read)

The current version: `mode` (`off`, `observe`, `act`), `owners` and `channels`. Answers 403 `not_enabled` where routing is off. Version 0 means none has been saved.

Responses:

- `200` — OK
  - `version` (integer, required)
  - `sha256` (string | null)
  - `document` (object, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routing_policy' \
  -H "Authorization: Bearer ast_..."
```

### PUT /routing_policy

Save a new version of the routing policy (scope: write, owner or admin)

The body is the whole document. The same rules write no new version. `mode: act` answers 409 `act_not_available` until `act` is on for the workspace. A change never cancels live work.

Body (application/json):

- `mode` (enum<string>) — "off" · "observe" · "act"
- `owners` (object[])
- `channels` (object[])

Responses:

- `200` — OK
  - `version` (integer, required)
  - `sha256` (string | null)
  - `document` (object, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/routing_policy \
  -H "Authorization: Bearer ast_..."
```

### POST /routing_policy/resolve

Ask who a request goes to (scope: read)

In order: `named` (`user:<id>` or `agent:<id>`), the owner of `area`, its cover, then `accountable`. The workspace's owner, an admin and the creator are never defaults. With nobody left, `recipient` is null and `missing` says what coverage is absent. While the policy watches or acts, the decision is recorded.

Body (application/json):

- `named` (string)
- `area` (string)
- `accountable` (string)

Responses:

- `200` — OK
  - `recipient` (string | null)
  - `basis` (enum<string>) — "named" · "documented_owner" · "cover" · "accountable" · "unavailable"
  - `rule` (string | null)
  - `missing` (string)
  - `policy_version` (integer)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/routing_policy/resolve \
  -H "Authorization: Bearer ast_..."
```

### GET /routing_decisions

Recent routing decisions (scope: read)

Newest first, at most 100, each with the rule and policy version it relied on. `would_route` is what the policy would have done while only watching.

Query parameters:

- `disposition` (string)

Responses:

- `200` — OK
  - `decisions` (object[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routing_decisions' \
  -H "Authorization: Bearer ast_..."
```

## Files

### GET /files

List files — your universe's uploads, or one session's files (scope: read)

Without `scope_id`, the universe's uploads. `scope_id=sess_…` lists that session's files: the copies minted from message content, channel attachments, and agent-stored files. `ids[]` (≤100) returns exactly those files in one page and cannot be combined with page/limit.

Query parameters:

- `limit` (integer)
- `page` (string) — A next_page cursor
- `ids[]` (array)
- `scope_id` (string) — sess_…
- `expiring` (boolean) — false leaves out files with an expiry, which are mostly archives the system uploaded for a session.

Responses:

- `200` — OK
  - `data` (object[], required) — Newest first
    - `type` (enum<string>, required) — "file"
    - `id` (string, required) — file_…
    - `created_at` (string, required)
    - `filename` (string, required)
    - `mime_type` (string, required)
    - `size_bytes` (integer, required)
    - `downloadable` (boolean, required) — true for image uploads (readable within the workspace) and for the per-session copies minted when a file rides a message; false for other uploads (write-once)
    - `attach_by_default` (boolean, required) — Whether every new session in the workspace starts with a read-only copy under /workspace/shared/
    - `expires_at` (string | null, required)
    - `canonical` (object) — Optional reference for a currently readable canonical execution-generated meeting file. Ordinary uploads and older unprojected Recall files omit it. This is a discovery reference, not a permission grant: read GET /artifacts/{artifact_id} for current can_discuss and other authoritative controls before using existing private history/comments/policy/delete operations. Generated content remains read-only; no public sharing is implied.
      - `artifact_id` (string, required)
      - `origin` ("execution", required)
      - `version` (integer, required)
  - `next_page` (string | null, required) — Pass back as ?page= for the next page
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/files' \
  -H "Authorization: Bearer ast_..."
```

Example response (200 OK):

```json
{
  "data": [
    {
      "type": "file",
      "id": "file_cmtb9x4p",
      "created_at": "2026-09-10T18:00:00.000Z",
      "filename": "design.pdf",
      "mime_type": "application/pdf",
      "size_bytes": 102400,
      "downloadable": false,
      "expires_at": null
    }
  ],
  "next_page": null
}
```

### POST /files

Upload a file — universe-scoped; images are readable back, other uploads are write-once (scope: write)

multipart/form-data with a `file` part and an optional `expires_in_seconds` (3600–7776000). 32 MiB per file (413 file_too_large); upload larger files through POST /files/uploads. Reference the returned id from a message as `{"type":"image","source":{"type":"file","file_id":"file_…"}}` or a `document` block.

Responses:

- `200` — OK
  - `type` (enum<string>, required) — "file"
  - `id` (string, required) — file_…
  - `created_at` (string, required)
  - `filename` (string, required)
  - `mime_type` (string, required)
  - `size_bytes` (integer, required)
  - `downloadable` (boolean, required) — true for image uploads (readable within the workspace) and for the per-session copies minted when a file rides a message; false for other uploads (write-once)
  - `attach_by_default` (boolean, required) — Whether every new session in the workspace starts with a read-only copy under /workspace/shared/
  - `expires_at` (string | null, required)
  - `canonical` (object) — Optional reference for a currently readable canonical execution-generated meeting file. Ordinary uploads and older unprojected Recall files omit it. This is a discovery reference, not a permission grant: read GET /artifacts/{artifact_id} for current can_discuss and other authoritative controls before using existing private history/comments/policy/delete operations. Generated content remains read-only; no public sharing is implied.
    - `artifact_id` (string, required)
    - `origin` ("execution", required)
    - `version` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/files \
  -H "Authorization: Bearer ast_..." \
  -F "file=@report.pdf"
```

Example response (200 OK):

```json
{
  "type": "file",
  "id": "file_cmtb9x4p",
  "created_at": "2026-09-10T18:00:00.000Z",
  "filename": "design.pdf",
  "mime_type": "application/pdf",
  "size_bytes": 102400,
  "downloadable": false,
  "expires_at": null
}
```

### GET /files/usage

Storage your workspace's uploads take (scope: read)

Counts the universe's uploads and sums their bytes. There is no storage cap (`storage_limit_bytes` is null) or application file-size cap; `max_file_bytes` is the exact integer byte-count boundary of the JSON protocol.

Responses:

- `200` — OK
  - `type` (enum<string>, required) — "files_usage"
  - `file_count` (integer, required) — The workspace's uploads, expired and deleted ones left out
  - `size_bytes` (integer, required) — The bytes those uploads take
  - `max_file_bytes` (integer, required) — Largest exact integer byte count in the JSON protocol (9007199254740991); no application file-size cap
  - `storage_limit_bytes` (null, required) — Always null: a workspace has no storage cap
  - `storage` (object, required) — How the workspace's stored files are billed. Storage billing measures every distinct stored file in the workspace, its sessions' files included, once a day.
    - `billed_bytes` (integer, required) — Distinct stored bytes the meter measures for the workspace
    - `price_usd_per_gib_month` (number, required) — What a GiB stored for a month costs once charged
    - `monthly_estimate_usd` (number, required) — What the current bytes would cost for a month
    - `billing` (enum<string>, required) — off: storage is not billed for this workspace; free: inside its free month; charged: billed daily — "off" · "free" · "charged"
    - `free_until` (string | null, required) — When the free month ends; null while billing is off
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/files/usage' \
  -H "Authorization: Bearer ast_..."
```

### POST /files/uploads

Start a resumable upload with no application file-size cap (scope: write)

JSON `{filename, size_bytes, mime_type?, expires_in_seconds?}` (expires_in_seconds 3600–7776000; omitted, the file never expires). Send the bytes to `upload_url` as `PUT` requests carrying `Content-Range: bytes <first>-<last>/<size_bytes>`, `chunk_size` bytes at a time: each answers 308 with `Range: bytes=0-<last received>` until the final chunk answers 200. After a dropped connection, `PUT` with no body and `Content-Range: bytes */<size_bytes>` answers the same 308 or 200, and the upload continues from the byte after the `Range`. The session lasts a week. There is no application file-size cap; size_bytes must be a positive exact integer no greater than 9007199254740991. Chunks are 64 MiB for direct storage uploads and at most 16 MiB through the app; follow the returned chunk_size.

Body (application/json):

- `filename` (string, required) — max length 255
- `size_bytes` (integer, required)
- `mime_type` (string)
- `expires_in_seconds` (integer)

Responses:

- `200` — OK
  - `type` (enum<string>, required) — "file_upload"
  - `id` (string, required) — fupl_…; pass to /files/uploads/{upload_id}/complete
  - `upload_url` (string, required) — Where the bytes go, in Content-Range chunks. Needs no credentials: the URL is the capability, so keep it private.
  - `chunk_size` (integer, required) — The chunk size to send; every chunk but the last must be exactly this long
  - `size_bytes` (integer, required)
  - `filename` (string, required)
  - `mime_type` (string, required)
  - `expires_at` (string, required) — When the upload session lapses; start a new one after
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/files/uploads \
  -H "Authorization: Bearer ast_..."
```

### POST /files/uploads/{upload_id}/complete

Finish a resumable upload into a file (scope: write)

Once every byte is in, answers the File; retrying answers the same File. 409 upload_incomplete while bytes are missing; 410 upload_expired once the session has lapsed. Large files can take a while to complete: allow a few minutes.

Path parameters:

- `upload_id` (string, required) — The upload id (fupl_…)

Responses:

- `200` — OK
  - `type` (enum<string>, required) — "file"
  - `id` (string, required) — file_…
  - `created_at` (string, required)
  - `filename` (string, required)
  - `mime_type` (string, required)
  - `size_bytes` (integer, required)
  - `downloadable` (boolean, required) — true for image uploads (readable within the workspace) and for the per-session copies minted when a file rides a message; false for other uploads (write-once)
  - `attach_by_default` (boolean, required) — Whether every new session in the workspace starts with a read-only copy under /workspace/shared/
  - `expires_at` (string | null, required)
  - `canonical` (object) — Optional reference for a currently readable canonical execution-generated meeting file. Ordinary uploads and older unprojected Recall files omit it. This is a discovery reference, not a permission grant: read GET /artifacts/{artifact_id} for current can_discuss and other authoritative controls before using existing private history/comments/policy/delete operations. Generated content remains read-only; no public sharing is implied.
    - `artifact_id` (string, required)
    - `origin` ("execution", required)
    - `version` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/files/uploads/upload_id/complete \
  -H "Authorization: Bearer ast_..."
```

### GET /files/{file_id}

File metadata (scope: read)

Path parameters:

- `file_id` (string, required) — The file id (file_…)

Responses:

- `200` — OK
  - `type` (enum<string>, required) — "file"
  - `id` (string, required) — file_…
  - `created_at` (string, required)
  - `filename` (string, required)
  - `mime_type` (string, required)
  - `size_bytes` (integer, required)
  - `downloadable` (boolean, required) — true for image uploads (readable within the workspace) and for the per-session copies minted when a file rides a message; false for other uploads (write-once)
  - `attach_by_default` (boolean, required) — Whether every new session in the workspace starts with a read-only copy under /workspace/shared/
  - `expires_at` (string | null, required)
  - `canonical` (object) — Optional reference for a currently readable canonical execution-generated meeting file. Ordinary uploads and older unprojected Recall files omit it. This is a discovery reference, not a permission grant: read GET /artifacts/{artifact_id} for current can_discuss and other authoritative controls before using existing private history/comments/policy/delete operations. Generated content remains read-only; no public sharing is implied.
    - `artifact_id` (string, required)
    - `origin` ("execution", required)
    - `version` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/files/file_cmtb9x4p' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /files/{file_id}

Make an upload always available, or stop (scope: write)

With `attach_by_default: true`, every session created in the workspace from then on starts with a read-only copy at `/workspace/shared/<filename>`, unless the session is created with `defaults: "none"`. Only a workspace upload that does not expire can carry the flag (400 otherwise). A file whose name is already taken in a session, or that would take the set past 64 MiB or 50 files, is skipped for that session; the session still starts.

Path parameters:

- `file_id` (string, required) — The file id (file_…)

Body (application/json):

- `attach_by_default` (boolean, required)

Responses:

- `200` — OK
  - `type` (enum<string>, required) — "file"
  - `id` (string, required) — file_…
  - `created_at` (string, required)
  - `filename` (string, required)
  - `mime_type` (string, required)
  - `size_bytes` (integer, required)
  - `downloadable` (boolean, required) — true for image uploads (readable within the workspace) and for the per-session copies minted when a file rides a message; false for other uploads (write-once)
  - `attach_by_default` (boolean, required) — Whether every new session in the workspace starts with a read-only copy under /workspace/shared/
  - `expires_at` (string | null, required)
  - `canonical` (object) — Optional reference for a currently readable canonical execution-generated meeting file. Ordinary uploads and older unprojected Recall files omit it. This is a discovery reference, not a permission grant: read GET /artifacts/{artifact_id} for current can_discuss and other authoritative controls before using existing private history/comments/policy/delete operations. Generated content remains read-only; no public sharing is implied.
    - `artifact_id` (string, required)
    - `origin` ("execution", required)
    - `version` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/files/file_cmtb9x4p \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"attach_by_default":true}'
```

### DELETE /files/{file_id}

Delete a file (scope: write)

Soft delete: the file stops resolving everywhere; sessions that already received a copy keep it.

Path parameters:

- `file_id` (string, required) — The file id (file_…)

Responses:

- `200` — OK
  - `type` (enum<string>, required) — "file_deleted"
  - `id` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/files/file_cmtb9x4p \
  -H "Authorization: Bearer ast_..."
```

Example response (200 OK):

```json
{
  "type": "file_deleted",
  "id": "file_cmtb9x4p"
}
```

### GET /files/{file_id}/content

Download a file's bytes (scope: read)

Only `downloadable` files (an image upload, readable within the workspace, and every session-scoped file: message copies, channel attachments, agent outputs); other uploads answer 400 not_downloadable. 404 once the file has expired. A file over 32 MiB answers 302 to a short-lived storage URL that serves the bytes and its own byte ranges. Otherwise a single `Range: bytes=…` answers 206 with that span, so an interrupted download resumes; `ETag` is the file's SHA-256, and an `If-Range` naming any other validator answers the whole file.

Path parameters:

- `file_id` (string, required) — The file id (file_…)

Responses:

- `200` — The bytes, with content-type, content-disposition, Accept-Ranges and ETag
- `206` — The requested span, with Content-Range
- `302` — A file over 32 MiB: Location is a short-lived storage URL that serves its bytes
- `416` — The range starts past the end of the file; Content-Range names its size
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/files/file_cmtb9x4p/content' \
  -H "Authorization: Bearer ast_..."
```

## Environments

### GET /environments

List the universe's environments, oldest first (scope: read)

Responses:

- `200` — OK
  - `environments` (object[], required)
    - `id` (string, required) — env_…
    - `name` (string, required)
    - `config` (object, required) — `packages` are installed into the image at build time — an environment is built when it is created and rebuilt when its config changes, so a session starting from it pays no install cost. `networking` is the egress policy its sessions run under; `limited` needs `allow_package_managers` when packages are declared, or the install could never succeed.
      - `type` ("cloud") — default: "cloud"
      - `packages` (object)
        - `apt` (string[]) — default: [] — max length 512
        - `pip` (string[]) — default: [] — max length 512
        - `npm` (string[]) — default: [] — max length 512
      - `networking` (object)
        - type: "unrestricted" (object)
          - `type` ("unrestricted", required)
        - type: "limited" (object)
          - `type` ("limited", required)
          - `allowed_hosts` (string[]) — default: [] — max length 253 — pattern ^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$
          - `allow_mcp_servers` (boolean) — default: false
          - `allow_package_managers` (boolean) — default: false
    - `is_default` (boolean, required) — Whether a new session that names no environment uses this one. At most one per workspace; setting it on one clears it on the others.
    - `extends` (string | null, required) — The env_… id of the parent environment this one extends, or null. Immutable after create. Child packages, tools.disabled and networking compose on the parent's at write time.
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/environments' \
  -H "Authorization: Bearer ast_..."
```

### POST /environments

Create an environment (scope: write)

The image build starts immediately; the environment is usable as `environment_id` on POST /sessions as soon as it exists, and a session created against a still-building environment waits for the build. Supplying `extends` (an `env_…` id in the same workspace) composes packages, tools.disabled and networking from the parent at write time and records the lineage. `extends` is immutable after create; chain depth is capped at 16.

Body (application/json):

- `name` (string, required) — max length 128
- `config` (object) — default: {"type":"cloud"}
  - `type` ("cloud") — default: "cloud"
  - `packages` (object)
    - `apt` (string[]) — default: [] — max length 512
    - `pip` (string[]) — default: [] — max length 512
    - `npm` (string[]) — default: [] — max length 512
  - `networking` (object)
    - type: "unrestricted" (object)
      - `type` ("unrestricted", required)
    - type: "limited" (object)
      - `type` ("limited", required)
      - `allowed_hosts` (string[]) — default: [] — max length 253 — pattern ^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$
      - `allow_mcp_servers` (boolean) — default: false
      - `allow_package_managers` (boolean) — default: false
- `extends` (string)

Responses:

- `201` — Created
  - `environment` (object, required)
    - `id` (string, required) — env_…
    - `name` (string, required)
    - `config` (object, required) — `packages` are installed into the image at build time — an environment is built when it is created and rebuilt when its config changes, so a session starting from it pays no install cost. `networking` is the egress policy its sessions run under; `limited` needs `allow_package_managers` when packages are declared, or the install could never succeed.
      - `type` ("cloud") — default: "cloud"
      - `packages` (object)
        - `apt` (string[]) — default: [] — max length 512
        - `pip` (string[]) — default: [] — max length 512
        - `npm` (string[]) — default: [] — max length 512
      - `networking` (object)
        - type: "unrestricted" (object)
          - `type` ("unrestricted", required)
        - type: "limited" (object)
          - `type` ("limited", required)
          - `allowed_hosts` (string[]) — default: [] — max length 253 — pattern ^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$
          - `allow_mcp_servers` (boolean) — default: false
          - `allow_package_managers` (boolean) — default: false
    - `is_default` (boolean, required) — Whether a new session that names no environment uses this one. At most one per workspace; setting it on one clears it on the others.
    - `extends` (string | null, required) — The env_… id of the parent environment this one extends, or null. Immutable after create. Child packages, tools.disabled and networking compose on the parent's at write time.
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/environments \
  -H "Authorization: Bearer ast_..."
```

### GET /environments/{id}

One environment (scope: read)

Path parameters:

- `id` (string, required) — The environment id (env_…)

Responses:

- `200` — OK
  - `environment` (object, required)
    - `id` (string, required) — env_…
    - `name` (string, required)
    - `config` (object, required) — `packages` are installed into the image at build time — an environment is built when it is created and rebuilt when its config changes, so a session starting from it pays no install cost. `networking` is the egress policy its sessions run under; `limited` needs `allow_package_managers` when packages are declared, or the install could never succeed.
      - `type` ("cloud") — default: "cloud"
      - `packages` (object)
        - `apt` (string[]) — default: [] — max length 512
        - `pip` (string[]) — default: [] — max length 512
        - `npm` (string[]) — default: [] — max length 512
      - `networking` (object)
        - type: "unrestricted" (object)
          - `type` ("unrestricted", required)
        - type: "limited" (object)
          - `type` ("limited", required)
          - `allowed_hosts` (string[]) — default: [] — max length 253 — pattern ^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$
          - `allow_mcp_servers` (boolean) — default: false
          - `allow_package_managers` (boolean) — default: false
    - `is_default` (boolean, required) — Whether a new session that names no environment uses this one. At most one per workspace; setting it on one clears it on the others.
    - `extends` (string | null, required) — The env_… id of the parent environment this one extends, or null. Immutable after create. Child packages, tools.disabled and networking compose on the parent's at write time.
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/environments/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /environments/{id}

Rename an environment or change its config (scope: write)

Omitted fields are left as they are. A changed `config` rebuilds the image; sessions already running keep the image they started on.

Path parameters:

- `id` (string, required) — The environment id (env_…)

Body (application/json):

- `name` (string) — max length 128
- `config` (object)
  - `type` ("cloud") — default: "cloud"
  - `packages` (object)
    - `apt` (string[]) — default: [] — max length 512
    - `pip` (string[]) — default: [] — max length 512
    - `npm` (string[]) — default: [] — max length 512
  - `networking` (object)
    - type: "unrestricted" (object)
      - `type` ("unrestricted", required)
    - type: "limited" (object)
      - `type` ("limited", required)
      - `allowed_hosts` (string[]) — default: [] — max length 253 — pattern ^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$
      - `allow_mcp_servers` (boolean) — default: false
      - `allow_package_managers` (boolean) — default: false

Responses:

- `200` — OK
  - `environment` (object, required)
    - `id` (string, required) — env_…
    - `name` (string, required)
    - `config` (object, required) — `packages` are installed into the image at build time — an environment is built when it is created and rebuilt when its config changes, so a session starting from it pays no install cost. `networking` is the egress policy its sessions run under; `limited` needs `allow_package_managers` when packages are declared, or the install could never succeed.
      - `type` ("cloud") — default: "cloud"
      - `packages` (object)
        - `apt` (string[]) — default: [] — max length 512
        - `pip` (string[]) — default: [] — max length 512
        - `npm` (string[]) — default: [] — max length 512
      - `networking` (object)
        - type: "unrestricted" (object)
          - `type` ("unrestricted", required)
        - type: "limited" (object)
          - `type` ("limited", required)
          - `allowed_hosts` (string[]) — default: [] — max length 253 — pattern ^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$
          - `allow_mcp_servers` (boolean) — default: false
          - `allow_package_managers` (boolean) — default: false
    - `is_default` (boolean, required) — Whether a new session that names no environment uses this one. At most one per workspace; setting it on one clears it on the others.
    - `extends` (string | null, required) — The env_… id of the parent environment this one extends, or null. Immutable after create. Child packages, tools.disabled and networking compose on the parent's at write time.
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/environments/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### DELETE /environments/{id}

Delete an environment (scope: write)

Path parameters:

- `id` (string, required) — The environment id (env_…)

Responses:

- `204` — Deleted — no body
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/environments/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### PUT /environments/{id}/listing

Publish one of your own environments as a listing (scope: write)

Creates or replaces the listing for this environment on the shelf, visible to the caller's workspace until a submission of it is approved. The environment must belong to the caller's workspace. A public listing's handle cannot change (409 `listing_public`). Answers 404 when the shelf is not enabled for this workspace or the environment is not found. Answers 503 `not_migrated` until the shelf migration is applied.

Path parameters:

- `id` (string, required) — The environment id (env_…)

Body (application/json):

- `handle` (string, required) — 2 to 40 lower-case letters, digits or underscores; unique across environment listings
- `name` (string, required) — max length 128
- `tagline` (string) — max length 140
- `description` (string) — max length 4000
- `categories` (enum<string>[]) — Defaults to general — "websites" · "content" · "video" · "code" · "research" · "general"

Responses:

- `200` — OK
  - `listing` (object, required)
    - `id` (string, required) — The listing id (lst_…)
    - `handle` (string, required) — Globally unique within environment listings; lower-case letters, digits and underscores
    - `name` (string, required)
    - `tagline` (string, required) — One line, at most 140 characters
    - `description` (string, required)
    - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
    - `packages` (object | null, required) — The listed environment's package configuration, or null when it has none
    - `tools` (object | null, required) — The listed environment's tool policy, or null when it has none
    - `networking` (object | null, required) — The listed environment's networking configuration, or null when it has none
    - `installs` (integer, required) — How many workspaces have installed this listing
    - `seller` (object | null, required) — Who published it to other workspaces, by the name they chose; null while it is visible only to its own workspace
    - `visibility` (enum<string>, required) — workspace = visible only to the owning workspace; public = approved, and visible to every workspace the shelf is open to. Other workspaces read and install the approved version; the owner's later edits wait for a new approval — "workspace" · "public"
    - `conformance` (object | null, required) — The smoke run the approved version passed; null for a listing that is not public
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/environments/sess_cmtb7q2j/listing \
  -H "Authorization: Bearer ast_..."
```

### DELETE /environments/{id}/listing

Remove the listing for one of your own environments (scope: write)

Delists the environment, withdrawing a waiting submission and ending a public one; the environment itself and any installed copies in other workspaces are not touched. Answers 404 when the shelf is not enabled, the environment is not found, or it has no listing. Answers 503 `not_migrated` until the shelf migration is applied.

Path parameters:

- `id` (string, required) — The environment id (env_…)

Responses:

- `204` — Delisted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/environments/sess_cmtb7q2j/listing \
  -H "Authorization: Bearer ast_..."
```

### GET /environments/{id}/listing/submission

Where your environment's listing stands with the public shelf (scope: read)

What is missing before it can be submitted, the latest submission and its smoke run, and the approved version other workspaces see. Answers 404 when the shelf is not enabled for this workspace or the environment has no listing.

Path parameters:

- `id` (string, required) — The environment id (env_…)

Responses:

- `200` — OK
  - `missing` (string[], required) — What still has to be true before it can be submitted, in words; empty when it can
  - `submission` (object | null, required) — The latest submission; null when it has never been submitted
  - `published` (object | null, required) — The approved version other workspaces read and install; null when it is not public
  - `taken_down` (object | null, required) — Set when a reviewer took the public listing down and nothing has been approved since
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/environments/sess_cmtb7q2j/listing/submission' \
  -H "Authorization: Bearer ast_..."
```

### POST /environments/{id}/listing/submission

Submit your environment's listing for the public shelf (scope: write)

Stores the listing and the environment as they are now and starts a smoke run, paid from your wallet: the platform's default engine starts a session on the environment, checks that every listed package is installed, and the session is deleted. A failed run sends the submission back with the failed checks as the reason; a passed one waits for a reviewer, whose approval makes the listing public. Answers 422 `not_submittable` naming what is missing, 409 `already_in_review` while an earlier submission is waiting, 404 when the shelf is not enabled for this workspace or the environment has no listing.

Path parameters:

- `id` (string, required) — The environment id (env_…)

Body (application/json):

- `seller_name` (string, required) — The name the shelf shows as the maker: 2 to 60 characters, not an email address

Responses:

- `201` — Submitted
  - `missing` (string[], required) — What still has to be true before it can be submitted, in words; empty when it can
  - `submission` (object | null, required) — The latest submission; null when it has never been submitted
  - `published` (object | null, required) — The approved version other workspaces read and install; null when it is not public
  - `taken_down` (object | null, required) — Set when a reviewer took the public listing down and nothing has been approved since
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/environments/sess_cmtb7q2j/listing/submission \
  -H "Authorization: Bearer ast_..."
```

### DELETE /environments/{id}/listing/submission

Withdraw your environment's waiting submission (scope: write)

Answers 404 when nothing is waiting for review.

Path parameters:

- `id` (string, required) — The environment id (env_…)

Responses:

- `200` — OK
  - `missing` (string[], required) — What still has to be true before it can be submitted, in words; empty when it can
  - `submission` (object | null, required) — The latest submission; null when it has never been submitted
  - `published` (object | null, required) — The approved version other workspaces read and install; null when it is not public
  - `taken_down` (object | null, required) — Set when a reviewer took the public listing down and nothing has been approved since
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/environments/sess_cmtb7q2j/listing/submission \
  -H "Authorization: Bearer ast_..."
```

### DELETE /environments/{id}/listing/publication

Stop serving your environment's listing to other workspaces (scope: write)

The listing stays visible to your workspace and copies already installed are not touched. Answers 404 when it is not public, or when the shelf is not enabled for this workspace.

Path parameters:

- `id` (string, required) — The environment id (env_…)

Responses:

- `200` — OK
  - `missing` (string[], required) — What still has to be true before it can be submitted, in words; empty when it can
  - `submission` (object | null, required) — The latest submission; null when it has never been submitted
  - `published` (object | null, required) — The approved version other workspaces read and install; null when it is not public
  - `taken_down` (object | null, required) — Set when a reviewer took the public listing down and nothing has been approved since
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/environments/sess_cmtb7q2j/listing/publication \
  -H "Authorization: Bearer ast_..."
```

## Vaults

### GET /vaults

List the universe's vaults, oldest first (scope: read)

Responses:

- `200` — OK
  - `vaults` (object[], required)
    - `type` (enum<string>, required) — "vault"
    - `id` (string, required) — vlt_…
    - `display_name` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/vaults' \
  -H "Authorization: Bearer ast_..."
```

### POST /vaults

Create a vault (scope: write)

Pass its id in `vault_ids` on POST /sessions to grant a session its secrets.

Body (application/json):

- `display_name` (string, required) — max length 128

Responses:

- `201` — Created
  - `vault` (object, required)
    - `type` (enum<string>, required) — "vault"
    - `id` (string, required) — vlt_…
    - `display_name` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/vaults \
  -H "Authorization: Bearer ast_..."
```

### GET /vaults/{id}

One vault (scope: read)

Path parameters:

- `id` (string, required) — The vault id (vlt_…)

Responses:

- `200` — OK
  - `vault` (object, required)
    - `type` (enum<string>, required) — "vault"
    - `id` (string, required) — vlt_…
    - `display_name` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/vaults/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /vaults/{id}

Delete a vault and every secret in it (scope: write)

The revocation is pushed to the pods of any sessions the vault was attached to — they lose the credentials without restarting.

Path parameters:

- `id` (string, required) — The vault id (vlt_…)

Responses:

- `204` — Deleted — no body
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/vaults/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /vaults/{id}/secrets

List a vault's secrets (scope: read)

Path parameters:

- `id` (string, required) — The vault id (vlt_…)

Responses:

- `200` — OK
  - `secrets` (object[], required)
    - `type` (enum<string>, required) — "vault_secret"
    - `id` (string, required) — vsec_…
    - `display_name` (string, required)
    - `auth_type` (enum<string>, required) — "static_bearer" · "mcp_oauth" · "environment_variable"
    - `mcp_server_url` (string)
    - `secret_name` (string) — The environment variable the pod sees
    - `allowed_hosts` (string[]) — The sites the credential may be sent to, present on every environment_variable secret and on any other that names sites. An empty list disables credential injection. Omit this field on update to keep the current sites; send [] to clear them.
    - `header` (string, required) — The header the credential is sent in; null when it is sent only in the body.
    - `template` (string, required) — What goes in that header, with {secret} where the value lands, such as `Bearer {secret}`. Never the value itself.
    - `body_only` (boolean, required) — The credential is sent in the request body and in no header.
    - `status` (string, required)
    - `expires_at` (string)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/vaults/sess_cmtb7q2j/secrets' \
  -H "Authorization: Bearer ast_..."
```

### POST /vaults/{id}/secrets

Add a secret to a vault (scope: write)

`auth.type` picks the kind: static_bearer and mcp_oauth authenticate an MCP server at `mcp_server_url`; environment_variable exposes `secret_name` to the pod. The value is encrypted at rest and never returned.

Path parameters:

- `id` (string, required) — The vault id (vlt_…)

Body (application/json):

- `display_name` (string, required) — max length 128
- `auth` (object, required)
  - type: "static_bearer" (object)
    - `type` ("static_bearer", required)
    - `mcp_server_url` (string, required) — https, public host
    - `token` (string, required)
  - type: "mcp_oauth" (object)
    - `type` ("mcp_oauth", required)
    - `mcp_server_url` (string, required) — https, public host
    - `access_token` (string, required)
    - `scope` (string)
    - `expires_at` (string)
    - `refresh` (object)
      - `token_endpoint` (string, required)
      - `client_id` (string, required)
      - `client_secret` (string)
      - `refresh_token` (string, required)
      - `token_endpoint_auth` (enum<string>) — "none" · "client_secret_basic" · "client_secret_post" — default: "none"
  - type: "environment_variable" (object)
    - `type` ("environment_variable", required)
    - `secret_name` (string, required) — A valid environment variable name — max length 128
    - `value` (string, required)
    - `allowed_hosts` (string[]) — default: []
    - `injection_location` (object) — default: {"header":true,"body":false}
      - `header` (boolean)
      - `body` (boolean)
      - `header_name` (string)
      - `value_template` (string) — max length 256

Responses:

- `201` — Created
  - `secret` (object, required) — Metadata only — the secret value is never returned after it is written. `secret_name` is set for environment_variable secrets, `mcp_server_url` for the two MCP kinds.
    - `type` (enum<string>, required) — "vault_secret"
    - `id` (string, required) — vsec_…
    - `display_name` (string, required)
    - `auth_type` (enum<string>, required) — "static_bearer" · "mcp_oauth" · "environment_variable"
    - `mcp_server_url` (string)
    - `secret_name` (string) — The environment variable the pod sees
    - `allowed_hosts` (string[]) — The sites the credential may be sent to, present on every environment_variable secret and on any other that names sites. An empty list disables credential injection. Omit this field on update to keep the current sites; send [] to clear them.
    - `header` (string, required) — The header the credential is sent in; null when it is sent only in the body.
    - `template` (string, required) — What goes in that header, with {secret} where the value lands, such as `Bearer {secret}`. Never the value itself.
    - `body_only` (boolean, required) — The credential is sent in the request body and in no header.
    - `status` (string, required)
    - `expires_at` (string)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/vaults/sess_cmtb7q2j/secrets \
  -H "Authorization: Bearer ast_..."
```

### POST /vaults/{id}/secrets/move

Move the secrets of other vaults into this one (scope: write)

Moves every secret of the `from` vaults of the same workspace into this vault and answers what happened to each, by name; a value is never returned. A secret is copied and confirmed stored before its source copy is touched, and the source copy is removed only when no session that is not archived still uses that vault without this one (`source` says which). A name this vault already holds with another value is a `clash` and is left alone unless it is listed in `replace`. A secret past this vault's limit, or one that could not be applied together with this vault's secrets, is `blocked` with a `reason`. Calling again moves nothing twice: what is already here answers `already`. With `dry_run` nothing is written and the outcomes are what a real call would do.

Path parameters:

- `id` (string, required) — The vault id (vlt_…)

Body (application/json):

- `from` (string[], required) — The vaults to move out of (vlt_…) — max length 128
- `replace` (object[]) — Clashing names to overwrite in this vault with the named source's secret
  - `from` (string, required) — max length 128
  - `name` (string, required) — max length 256
- `dry_run` (boolean)

Responses:

- `200` — OK
  - `dry_run` (boolean, required)
  - `secrets` (object[], required)
    - `from` (string, required) — The vault it was in (vlt_…)
    - `name` (string, required) — The environment variable name, or the display name of an MCP secret
    - `auth_type` (enum<string>, required) — "static_bearer" · "mcp_oauth" · "environment_variable"
    - `outcome` (enum<string>, required) — "moved" · "already" · "clash" · "blocked"
    - `source` (enum<string>, required) — Whether the copy in the source vault was removed — "removed" · "kept"
    - `reason` (string) — Why a secret is blocked, e.g. limit_reached or egress_header_conflict
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/vaults/sess_cmtb7q2j/secrets/move \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"from":["vlt_cmtb7q2j"],"dry_run":true}'
```

### PATCH /vaults/{id}/secrets/{secretId}

Rotate or re-scope a secret in place (scope: write)

The secret keeps its id and its placeholder, so attached pods need no restart — the recompiled policy is pushed to them. Fields not sent are left as they are; `injection_location` merges per field.

Path parameters:

- `id` (string, required) — The vault id (vlt_…)
- `secretId` (string, required) — The secret id (vsec_…)

Body (application/json):

- `display_name` (string) — max length 128
- `value` (string)
- `token` (string)
- `allowed_hosts` (string[]) — Omit to keep the current sites; send a list to replace them, or [] to stop credential injection.
- `injection_location` (object)
  - `header` (boolean)
  - `body` (boolean)
  - `header_name` (string)
  - `value_template` (string) — max length 256

Responses:

- `200` — OK
  - `secret` (object, required) — Metadata only — the secret value is never returned after it is written. `secret_name` is set for environment_variable secrets, `mcp_server_url` for the two MCP kinds.
    - `type` (enum<string>, required) — "vault_secret"
    - `id` (string, required) — vsec_…
    - `display_name` (string, required)
    - `auth_type` (enum<string>, required) — "static_bearer" · "mcp_oauth" · "environment_variable"
    - `mcp_server_url` (string)
    - `secret_name` (string) — The environment variable the pod sees
    - `allowed_hosts` (string[]) — The sites the credential may be sent to, present on every environment_variable secret and on any other that names sites. An empty list disables credential injection. Omit this field on update to keep the current sites; send [] to clear them.
    - `header` (string, required) — The header the credential is sent in; null when it is sent only in the body.
    - `template` (string, required) — What goes in that header, with {secret} where the value lands, such as `Bearer {secret}`. Never the value itself.
    - `body_only` (boolean, required) — The credential is sent in the request body and in no header.
    - `status` (string, required)
    - `expires_at` (string)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/vaults/sess_cmtb7q2j/secrets/secretId \
  -H "Authorization: Bearer ast_..."
```

### DELETE /vaults/{id}/secrets/{secretId}

Delete a secret (scope: write)

Path parameters:

- `id` (string, required) — The vault id (vlt_…)
- `secretId` (string, required) — The secret id (vsec_…)

Responses:

- `204` — Deleted — no body
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/vaults/sess_cmtb7q2j/secrets/secretId \
  -H "Authorization: Bearer ast_..."
```

### POST /vaults/{id}/secrets/{secretId}/validate

Exercise an mcp_oauth grant and report whether it still works (scope: write)

Path parameters:

- `id` (string, required) — The vault id (vlt_…)
- `secretId` (string, required) — The secret id (vsec_…)

Responses:

- `200` — OK
  - `result` (enum<string>, required) — "valid" · "invalid" · "unknown"
  - `detail` (string)
  - `secret` (object, required) — Metadata only — the secret value is never returned after it is written. `secret_name` is set for environment_variable secrets, `mcp_server_url` for the two MCP kinds.
    - `type` (enum<string>, required) — "vault_secret"
    - `id` (string, required) — vsec_…
    - `display_name` (string, required)
    - `auth_type` (enum<string>, required) — "static_bearer" · "mcp_oauth" · "environment_variable"
    - `mcp_server_url` (string)
    - `secret_name` (string) — The environment variable the pod sees
    - `allowed_hosts` (string[]) — The sites the credential may be sent to, present on every environment_variable secret and on any other that names sites. An empty list disables credential injection. Omit this field on update to keep the current sites; send [] to clear them.
    - `header` (string, required) — The header the credential is sent in; null when it is sent only in the body.
    - `template` (string, required) — What goes in that header, with {secret} where the value lands, such as `Bearer {secret}`. Never the value itself.
    - `body_only` (boolean, required) — The credential is sent in the request body and in no header.
    - `status` (string, required)
    - `expires_at` (string)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/vaults/sess_cmtb7q2j/secrets/secretId/validate \
  -H "Authorization: Bearer ast_..."
```

### GET /workspace-secrets/move

Preview moving earlier conversations' secrets into the workspace vault

What moving the secrets the caller saved in earlier conversations into their workspace's vault would do, by name only: each name and whether it moves, or clashes with a secret the workspace already holds under that name. Nothing moves by reading it. 404 when the workspace vault is not available.

Responses:

- `200` — OK
  - `secrets` (object[])
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-secrets/move' \
  -H "Authorization: Bearer ast_..."
```

### POST /workspace-secrets/move

Move earlier conversations' secrets into the workspace vault

Moves them, as the Mac's Vaults page does. A secret whose name the workspace already uses is left alone unless `replace` names it (`{vault, name}`). Answers names and outcomes only, never values.

Body (application/json):

- `replace` (object[])
  - `vault` (string, required)
  - `name` (string, required)

Responses:

- `200` — OK
  - `secrets` (object[])
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/workspace-secrets/move \
  -H "Authorization: Bearer ast_..."
```

## Browser profiles

### GET /browser_profiles

Your browser and the browsers shared with you (scope: read)

Your browser is yours in every workspace: sessions whose turn you send open signed in to its sites and save new sign-ins back to it. A browser someone shared with you here lists only the sites they shared. A workspace key gets what is shared with the whole workspace. Cookies are never returned.

Responses:

- `200` — OK
  - `data` (object[], required)
    - `scope` (enum<string>, required) — mine: your browser. shared: someone's browser shared with you here, with only the sites they shared. workspace (a workspace key): what is shared with the whole workspace — "mine" · "shared" · "workspace"
    - `revision` (integer, required) — Changes whenever the browser, or for workspace what is shared, changes
    - `owner` (object) — Whose browser it is, for shared
      - `id` (string)
      - `email` (string | null)
      - `name` (string | null)
    - `sites` (object[], required)
      - `site` (string, required)
      - `site_id` (string) — Stable reference for removal with by=id, on your own browser's sites. Present when new removals are enabled, and always present for incomplete removals.
      - `status` (enum<string>, required) — needs_signin: sign in again. removing: cleanup is incomplete; retry Remove using site_id. The site cannot be used or imported while removal is pending. — "ready" · "needs_signin" · "removing"
      - `signed_in_by` (object | null, required)
      - `signed_in_at` (string, required)
      - `last_used_at` (string | null, required)
      - `shareable` (boolean) — false for a Google login: it stays in its owner's own sessions and is never shared, so a share never includes it.
    - `shares` (object[]) — For mine: whom you shared it with in this workspace
      - `id` (string, required)
      - `grantee` (object, required) — Who may use it: everyone in this workspace, or one member
        - `type` (enum<string>, required) — "workspace" · "member"
        - `user` (object)
          - `id` (string)
          - `email` (string | null)
          - `name` (string | null)
      - `sites` (array | null, required) — The shared sites; null means every site, including ones signed in later
      - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/browser_profiles' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /browser_profiles/{scope}/sites/{site}

Sign your browser out of a site (scope: write)

Signs the site out of running sessions that use your browser, yours and the ones it is shared into. Only the browser's owner can. Cleanup failure retains the listed site as removing, so it can be retried after a refresh. New removals return 503 during the compatibility rollout; existing removing sites remain retryable.

Path parameters:

- `scope` (string, required) — mine: your browser
- `site` (string, required) — The site domain, or its listed site_id when by=id

Query parameters:

- `by` (string) — Use the listed site_id to address a specific saved site, including legacy names that cannot be used in a URL. The identifier must belong to this scope.

Responses:

- `204` — Removed — no body
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/browser_profiles/scope/sites/site \
  -H "Authorization: Bearer ast_..."
```

### POST /browser_profiles/{scope}/shares

Share your browser in this workspace (scope: write)

With one member or everyone here, for every site or only some. Sharing again with the same grantee replaces its sites. Their agents use the sites from their next turn and never see the stored state; new sign-ins in their turns are saved to their own browser.

Path parameters:

- `scope` (string, required) — mine: your browser

Body (application/json):

- `grantee` (enum<string> | object, required) — workspace for everyone here, or { user_id } for one member
  - option 1 (enum<string>) — "workspace"
  - option 2 (object)
    - `user_id` (string, required)
- `sites` (array | null) — Only these sites; omitted or null shares every site

Responses:

- `200` — Shared
  - `share` (object, required)
    - `id` (string, required)
    - `grantee` (object, required) — Who may use it: everyone in this workspace, or one member
      - `type` (enum<string>, required) — "workspace" · "member"
      - `user` (object)
        - `id` (string)
        - `email` (string | null)
        - `name` (string | null)
    - `sites` (array | null, required) — The shared sites; null means every site, including ones signed in later
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/browser_profiles/scope/shares \
  -H "Authorization: Bearer ast_..."
```

### DELETE /browser_profiles/{scope}/shares/{share}

Stop sharing your browser (scope: write)

The grantee's sessions lose it from their next turn.

Path parameters:

- `scope` (string, required) — mine: your browser
- `share` (string, required) — The share's id from the list

Responses:

- `204` — Stopped — no body
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/browser_profiles/scope/shares/share \
  -H "Authorization: Bearer ast_..."
```

### GET /browser_profiles/{scope}/export

What is shared with the whole workspace, with its state, for a registered service runtime (scope: read)

Cookies and localStorage of every ready site shared with the whole workspace, the counterpart of delivery into a session pod, for the one machine registered to hold them outside the pods (BROWSER_PROFILE_SERVICE_RUNTIMES, by workspace and workspace key). Any other caller gets 403. A site shared with one member is never exported.

Path parameters:

- `scope` (string, required) — mine (your browser; private and, for a person, workspace are accepted as mine) or workspace (a workspace key: what is shared with the whole workspace)

Responses:

- `200` — OK
  - `scope` (enum<string>, required) — "workspace"
  - `runtime` (string, required) — The registered runtime's name
  - `revision` (integer, required) — Changes whenever what is shared changes; poll the list route and pull again when it does
  - `sites` (string[], required)
  - `state` (object, required) — Playwright storage state: cookies and per-origin localStorage
    - `cookies` (object[])
    - `origins` (object[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/browser_profiles/scope/export' \
  -H "Authorization: Bearer ast_..."
```

### POST /browser_profiles/{scope}/imports

Bring sites signed in elsewhere into your browser (scope: write)

Merges per site like a session's save: new and changed cookies win, nothing is deleted. Used by AgentSky for Mac and `sky login import`. Only a workspace key registered as that workspace's service runtime may use the workspace scope; it writes into the workspace's service browser, never into a person's browser, and never changes a share. Any other workspace key gets 403. Cookie domains are normalized as hostnames (including international and internal hosts); malformed domains return 400. An import cannot restore a site whose removal is incomplete.

Path parameters:

- `scope` (string, required) — mine (your browser; private and, for a person, workspace are accepted as mine) or workspace (a workspace key: what is shared with the whole workspace)

Body (application/json):

- `session_id` (string) — Optionally restore into this session owned by the caller in this workspace. No runtime is started. The delivery receipt distinguishes saved state from a verified restore in the current runtime.
- `state` (object, required) — Playwright storage state: cookies (name, value, domain, path, expires, httpOnly, secure, sameSite) and per-origin localStorage
  - `cookies` (object[], required)
  - `origins` (object[])

Responses:

- `200` — Merged
  - `sites` (string[])
  - `delivery` (object)
    - `session_id` (string)
    - `profile_id` (string)
    - `revision` (integer)
    - `ready` (boolean)
    - `pod_id` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/browser_profiles/scope/imports \
  -H "Authorization: Bearer ast_..."
```

## Worker pools

### GET /worker-pools

List worker pools in the workspace (scope: read)

Responses:

- `200` — OK
  - `worker_pools` (object[], required)
    - `id` (string, required) — wpool_…
    - `name` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/worker-pools' \
  -H "Authorization: Bearer ast_..."
```

### POST /worker-pools

Create a worker pool (scope: write)

Returns the pool and a one-time `wpt_…` bearer token the worker machine passes to `GET /worker-pools/{id}/connect`. Store it securely — it is never shown again; call POST /worker-pools/{id}/tokens to rotate.

Body (application/json):

- `name` (string, required) — max length 128

Responses:

- `201` — Created
  - `worker_pool` (object, required)
    - `id` (string, required) — wpool_…
    - `name` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
  - `token` (string, required) — A wpt_… bearer token the worker machine passes to the connect endpoint. Shown only once — rotate it from /worker-pools/{id}/tokens if lost.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/worker-pools \
  -H "Authorization: Bearer ast_..."
```

### GET /worker-pools/{id}

One worker pool (scope: read)

Path parameters:

- `id` (string, required) — The worker pool id (wpool_…)

Responses:

- `200` — OK
  - `id` (string, required) — wpool_…
  - `name` (string, required)
  - `created_at` (string, required)
  - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/worker-pools/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /worker-pools/{id}

Delete a worker pool (scope: write)

Disconnects every worker currently connected to the pool.

Path parameters:

- `id` (string, required) — The worker pool id (wpool_…)

Responses:

- `204` — Deleted — no body
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/worker-pools/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### POST /worker-pools/{id}/tokens

Rotate the pool's connect token (scope: write)

Issues a new `wpt_…` token and immediately invalidates the previous one. Workers currently connected keep their session; they will need the new token on reconnect.

Path parameters:

- `id` (string, required) — The worker pool id (wpool_…)

Responses:

- `201` — Created
  - `token` (string, required) — The new wpt_… token. The previous token is immediately invalidated.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/worker-pools/sess_cmtb7q2j/tokens \
  -H "Authorization: Bearer ast_..."
```

### GET /worker-pools/{id}/workers

List workers connected to a pool (scope: read)

Path parameters:

- `id` (string, required) — The worker pool id (wpool_…)

Responses:

- `200` — OK
  - `workers` (object[], required)
    - `id` (string, required) — wrk_…
    - `pool_id` (string, required) — wpool_…
    - `label` (string, required) — Human-readable label the worker sent at connect time.
    - `image_digest` (string)
    - `status` (enum<string>, required) — `connected` — idle and ready; `busy` — running a session; `offline` — disconnected. — "connected" · "busy" · "offline"
    - `last_seen_at` (string | null)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/worker-pools/sess_cmtb7q2j/workers' \
  -H "Authorization: Bearer ast_..."
```

### GET /worker-pools/{id}/connect

Open a worker's control WebSocket (scope: worker)

Workers upgrade this HTTP connection to a WebSocket using `Upgrade: websocket`. Pass the `wpt_…` bearer token in the `Authorization` header. Served by chat-proxy, not asteroids.

Path parameters:

- `id` (string, required) — The worker pool id (wpool_…)

Responses:

- `101` — Switching Protocols — WebSocket upgrade accepted
- `401` — Missing or invalid wpt_… token
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/worker-pools/sess_cmtb7q2j/connect' \
  -H "Authorization: Bearer ast_..."
```

## Sessions

### GET /sessions

List sessions, newest first, one page at a time; ?agent= filters to one spec (scope: read)

Answers at most `limit` sessions (default 100, max 500) and `next_cursor` for the rest; null on the last page. A limit that is not an integer from 1 to 500, or a cursor that is not valid, is 400 invalid_request.

Query parameters:

- `agent` (string) — The agent id (agent_…)
- `limit` (integer)
- `cursor` (string) — next_cursor from the previous page
- `session_id[]` (array) — Only these sessions. One that was deleted, or that the caller cannot list, is left out of the answer.

Responses:

- `200` — OK
  - `sessions` (object[], required)
    - `id` (string) — sess_… identifier
    - `agentId` (string | null) — The agent id (agent_…)
    - `title` (string | null)
    - `updatedAt` (string) — When the session last changed.
    - `status` (enum<string>) — provisioning = the sandbox is booting or installing the environment's packages (a turn sent meanwhile waits for it); running = a turn is in flight; terminated = archived or the last runtime was destroyed. Use archived for the durable archive receipt — "provisioning" · "idle" · "running" · "terminated"
    - `provisioningStage` (string | null) — Which part of its boot the session's computer is in, as the platform observed it: creating_computer until the sandbox provider reports the computer exists, then starting_agent until the agent in it answers. A provider that does not report the computer's creation stays at creating_computer. Null once the computer is up and whenever it is not booting. — "creating_computer" · "starting_agent" · null
    - `archived` (boolean) — True only after this Session's archive mark was durably written; false for an active Session whose runtime was destroyed
    - `agentType` (string)
    - `llm` (string) — The model this session runs on (PATCH to change; the agent's model is unchanged)
    - `harnessVersion` (string) — Harness release the session runs: the one its serving pod booted, the restored checkpoint's for a native-fork handoff, the agent's pin for ACP harnesses, otherwise the current release
    - `reasoningEffort` (string | null) — The model-compatible effort resolved from the session pin, then agent pin. Constrained models use an allowed fallback; no-setting models return null. Unpinned unconstrained models return null for the harness default.
    - `subscriptionApiFallback` (boolean) — Paid API continuation once no subscription account can run the task, preserving the same supported explicit model and wallet/budget gates. On unless set to false
    - `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription — "platform" · "account"
    - `idleTimeoutSeconds` (integer | null) — Seconds the session's machine stays awake after a turn ends before it is paused; null = the platform default of 60. Set it when people use apps on the session's exposed ports after the agent finishes
    - `browserProfile` (string) — Resolved browser: the session's choice, then the agent's default, then mine. mine is the browser of the person whose turn it is; fresh is signed out; user:<user id> is the sites that person shared with whoever runs the turn. Applied before the next browser turn when browser profiles are enabled.
    - `browserLoginsSavedAt` (string | null) — Most recent browser login save-back time, or null when this session has not saved changed logins.
    - `routineId` (string | null) — The routine whose run started this session, or null for any other session
    - `ownerId` (string) — The member who owns this session, as user_id in GET /universes/{slug}/members
    - `default` (boolean) — Is this the agent's default session
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `metadata` (object)
    - `budget` (object | null) — Hard spend cap, or null when the session has none. A reached budget pauses the session (402 budget_reached on new work) until the cap is raised above consumed_cost or removed — removal is one-way.
    - `parentSessionId` (string | null) — The session this one came from: a helper names the session that hired it, a handoff child names the session it continued; null for a root. Every session a task's root produced, with its role, is GET /tasks/{id}?by=session on any member's id.
    - `parentRelation` (string | null) — How this session relates to parentSessionId: `helper` was hired by it (actl hire or the orchestration API), `handoff` continued its conversation on another agent; null for a root. — "helper" · "handoff" · null
    - `resources` (object[]) — The files, GitHub repositories, and read-only memory stores mounted into the session, oldest first
      - option 1 (object)
        - `type` (enum<string>, required) — "file"
        - `id` (string, required) — sesrsc_…
        - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
        - `mount_path` (string, required) — Absolute, under /workspace
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 2 (object)
        - `type` (enum<string>, required) — "github_repository"
        - `id` (string, required) — sesrsc_…
        - `url` (string, required) — https://github.com/{owner}/{repo}
        - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
        - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
          - `type` (enum<string>) — "branch" · "commit"
          - `name` (string)
          - `sha` (string)
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 3 (object)
        - `type` (enum<string>, required) — "memory_store"
        - `id` (string, required) — smsr_…
        - `memory_store_id` (string, required) — memstore_…
        - `mount_path` (string, required) — Absolute, under /mnt/memory
        - `access` (enum<string>, required) — "read_only" · "read_write"
        - `instructions` (string) — Optional per-session guidance
        - `created_at` (string, required)
        - `updated_at` (string, required)
    - `workspaceDefaults` (object | null) — What the session started with because its workspace made it a default; everything else it carries was named at creation. Null when it took nothing.
    - `contextFiles` (object | null) — The workspace files the session loaded into its instructions when its sandbox was last provisioned (GET /workspace-context describes the set); null before that and for a session without its workspace's store. Every other file in the store is read on demand.
    - `continuedOnMac` (object) — Present when the owner moved this session to their own computer. Without `claimedAt` no computer has taken it yet, and a new turn here releases the move. With `claimedAt` the session refuses turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`.
      - `handoffId` (string, required)
      - `at` (string, required)
      - `machine` (string)
      - `claimedAt` (string)
    - `localControl` (object) — Present on a synced chat that runs on the caller's own Mac. `state` is `running`, `waiting_for_you` (a command waits for an answer), `idle`, or `unknown` while the Mac is offline, so a run is never shown as running from an offline Mac. `controllable` is the Mac's side only: each device or key still needs its own pairing (`POST /desktop/machines/{id}/controllers`), checked on every stop and answer. When false, `reason` is `mac_offline`, `phone_control_off` (turned off on the Mac), `terminal_session` (started in Terminal; read-only here) or `older_mac_app` (no Mac has reported its chats).
      - `mac` (object | null, required)
      - `state` (enum<string>, required) — "running" · "waiting_for_you" · "idle" · "unknown"
      - `controllable` (boolean, required)
      - `reason` (enum<string>) — "mac_offline" · "phone_control_off" · "terminal_session" · "older_mac_app"
      - `limit` (object) — The plan limit this chat's last run on the Mac reported: the same state the Mac shows above the composer. Absent until a run reports one and while the Mac is offline.
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `window` (string | null, required)
        - `utilization` (number | null, required)
        - `resetsAt` (string | null, required)
      - `pressure` (object) — This Mac's disk, memory and battery as it last reported them. Absent while the Mac is offline.
        - `disk` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
          - `freeBytes` (integer | null, required)
        - `memory` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `battery` (object)
          - `percent` (number, required)
          - `charging` (boolean, required)
    - `hostedBySeller` (object) — Present only when the session runs on its agent's maker's own server instead of a sandbox: what is sent to the session goes to this host. `agentType` and `llm` then name a stand-in that never runs.
      - `host` (string, required)
    - `attachments` (object[]) — Everything the session started with: its environment, vaults, mounted files and memory stores, and the workspace's always-available skills. The skills of the session's agent are on the agent and are not repeated here.
      - `type` (enum<string>, required) — "environment" · "vault" · "file" · "skill" · "memory_store"
      - `id` (string, required) — The id of the environment, vault, file, skill or memory store
      - `mountPath` (string | null, required) — Where a file or memory store is mounted; null for the other types
      - `source` (enum<string>, required) — default = the workspace supplied it; explicit = it was named when the session was created. A memory store on a session created before 2026-10-06 reads as explicit — "default" · "explicit"
    - `createdAt` (string) — ISO 8601
  - `next_cursor` (string) — Pass back as ?cursor= for the next page; null on the last page
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions

Create a session — starts provisioning by default; optionally defer until the first turn (scope: write)

Optional llm and reasoningEffort override the agent's defaults for this session before billing selection or provisioning. A model must be current for the agent's harness; omitted or null reasoningEffort inherits the agent's setting normalized for the target model. Explicit effort must fit both harness and target model. A non-empty initial_events list (user.message only, all-or-nothing) starts the first turn in the same call and provisions in either mode. Without initial events, provision: "deferred" skips the boot: the session reads idle with no pod and costs nothing until its first turn — for a session that waits on a gate or a schedule. Machine shape (vcpus/memoryMb) is per-session.

Body (application/json):

- `agent` (string, required) — An agent id, or "@handle" for an agent from the catalog (GET /catalog/agents). A handle that names a platform engine uses the workspace's agent for that engine, created on first use.
- `llm` (string) — Model for this session (a current model for the agent's harness). Omitted = the agent's model
- `reasoningEffort` (enum<string> | null) — Reasoning effort for this session; omitted or null inherits the agent's setting normalized for the target model. Explicit values must fit both harness and target model - agoragentic_acp: not supported; amp_acp: not supported; auggie: not supported; autohand: not supported; cline: not supported; codebuddy_code: not supported; cortex_code: not supported; corust_agent: not supported; crow_cli: not supported; cursor: not supported; deepagents: not supported; devin: not supported; dimcode: not supported; dirac: not supported; factory_droid: not supported; fast_agent: not supported; gemini: not supported; github_copilot_cli: not supported; glm_acp_agent: not supported; antigravity_acp: not supported; goose: not supported; grok_build: not supported; harn: not supported; junie: not supported; kilo: not supported; kimchi: not supported; minimax_code: not supported; minion_code: not supported; mistral_vibe: not supported; nova: not supported; poolside: not supported; qoder: not supported; qwen_code: not supported; sigit: not supported; stakpak: not supported; vtcode: not supported; code_assistant: not supported; docker_cagent: not supported; kiro: not supported; muse_code: not supported; openhands: not supported; hermes: none/minimal/low/medium/high/xhigh/max/ultra; claude_code: low/medium/high/xhigh/max; codex: none/minimal/low/medium/high/xhigh/max; openclaw: not supported; jev: not supported; pi: off/minimal/low/medium/high/xhigh/max; dsh: not supported; kimi_code: not supported; opencode: none/minimal/low/medium/high/xhigh/max; workspace_acp: not supported; models: claude-fable-5-1: low/medium/high/xhigh/max; claude-fable-5: low/medium/high/xhigh/max; claude-opus-5-5: low/medium/high/xhigh/max; claude-opus-5: low/medium/high/xhigh/max; claude-opus-4-8: low/medium/high/xhigh/max; claude-sonnet-5-5: low/medium/high/xhigh/max; claude-sonnet-5: low/medium/high/xhigh/max; claude-sonnet-4-6: low/medium/high/max; claude-haiku-5-5: low/medium/high/xhigh/max; claude-haiku-4-5: not supported; gpt-6.1-sol: low/medium/high/xhigh/max; gpt-6-astra: low/medium/high/xhigh/max; gpt-6-sol: none/low/medium/high/xhigh/max; gpt-6-luna: none/low/medium/high/xhigh/max; gpt-5.6-sol: none/low/medium/high/xhigh/max; gpt-5.6-terra: none/low/medium/high/xhigh/max; gpt-5.6-luna: none/low/medium/high/xhigh/max; gpt-5.5: none/low/medium/high/xhigh; gpt-4.1: not supported; deepseek-v4-pro: low/high/max; deepseek-flash: low/high/max; kimi-k3.1-pro: low/high/max; kimi-k3: low/high/max; kimi-k2.7-code: not supported; minimax-m3: not supported; muse-spark-1.1: minimal/low/medium/high/xhigh; muse-spark-1.2: minimal/low/medium/high/xhigh; muse-spark-1.3: minimal/low/medium/high/xhigh/max; minimax-m3.1-flash: low/medium/high/xhigh/max; gemini-4-argon: low/medium/high; gemini-3.5-flash-lite: low/medium/high; gemini-3.8-flash: low/medium/high; gemini-3.5-flash: low/medium/high; glm-5.3: low/high/max; glm-5.3-flash: low/high/max; grok-4.6: low/medium/high; grok-4.7: low/medium/high/xhigh — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra"
- `title` (string) — max length 120
- `metadata` (map<string, any>) — Client metadata. At creation, tracePreservationRequired: true pins a durable requirement for final trace upload before runtime destruction; later metadata edits do not revoke it.
- `idleTimeoutSeconds` (integer) — Seconds this session's machine stays awake after a turn ends before it is paused (60-86400; omitted = the platform default of 60). A paused machine wakes on the next message; apps the agent serves on exposed ports are unreachable while it is paused, so set this to how long people keep using them after the agent finishes
- `browserProfile` (enum<string> | string) — Which saved browser the agent's browser opens with: mine (the browser of the person whose turn it is; new sign-ins are saved there), fresh (nothing loaded or saved) or user:<user id> (the sites that person shared with whoever runs the turn; used, never saved). workspace and private are accepted as mine. Omitted = the agent's default, then mine. Only harnesses with a persistent browser use it — "mine" · "fresh" · "workspace" · "private"
- `instructions` (object[])
  - `name` (string, required) — pattern .*\.md$
  - `content` (string) — default: ""
- `mcp_servers` (object[]) — Per-session MCP server overlay (RFC-0149 §3): up to 20 streamable-HTTP servers layered over the agent spec's declared servers at provision time. Names must not collide with the spec or with each other (→ 409), URLs must be HTTPS (→ 422), total spec + overlay ≤ 20 (→ 422). authorization_token is write-only.
  - `name` (string, required) — max length 255
  - `url` (string, required) — HTTPS URL of a streamable-HTTP MCP server.
  - `authorization_token` (string) — Bearer token for the server. Write-only: stored encrypted, stamped as Authorization: Bearer at provision, never returned in reads.
  - `tools` (object)
    - `include` (string[])
    - `exclude` (string[])
- `initial_events` (object[])
  - `type` ("user.message", required)
  - `content` (object[], required)
    - type: "text" (object)
      - `type` ("text", required)
      - `text` (string, required)
    - type: "image" (object)
      - `type` ("image", required)
      - `source` (object, required)
        - type: "base64" (object)
          - `type` ("base64", required)
          - `media_type` (string, required)
          - `data` (string, required)
        - type: "url" (object)
          - `type` ("url", required)
          - `url` (string, required)
        - type: "file" (object)
          - `type` ("file", required)
          - `file_id` (string, required)
    - type: "document" (object)
      - `type` ("document", required)
      - `source` (object, required)
        - type: "base64" (object)
          - `type` ("base64", required)
          - `media_type` (string, required)
          - `data` (string, required)
        - type: "text" (object)
          - `type` ("text", required)
          - `media_type` ("text/plain") — default: "text/plain"
          - `data` (string, required)
        - type: "url" (object)
          - `type` ("url", required)
          - `url` (string, required)
        - type: "file" (object)
          - `type` ("file", required)
          - `file_id` (string, required)
      - `title` (string | null)
      - `context` (string | null)
  - `interaction_mode` (enum<string> | null) — "plan" · "build"
- `provision` (enum<string>) — eager (default) boots the sandbox as soon as the row exists; deferred leaves the session idle with no pod until its first turn, so a session waiting on a gate or a schedule costs nothing while it waits. Ignored when initial_events start the first turn — "eager" · "deferred"
- `environment_id` (string)
- `vault_ids` (string[])
- `vcpus` (integer)
- `memoryMb` (integer)
- `subscriptionApiFallback` (boolean) — After every subscription account is exhausted, continue on the same model using the paid platform API; wallet and session budget still apply
- `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription. Omitted = auto-apply (a connected subscription with "use for new agents" powers eligible compositions) — "platform" · "account"
- `budget` (object) — Hard spend cap for this session. Attachable only at create; changeable or removable later via PATCH (removal is one-way)
  - `type` ("limit", required)
  - `max_list_cost` (object, required)
    - `amount` (string, required) — Whole US cents as an integer decimal string, e.g. "125" for $1.25 — max length 15
    - `currency` ("USD", required)
- `payer` (enum<string>) — Which balance pays for the session, in a team workspace that has a wallet of its own: "workspace" (the default there) or "personal", the caller's own. Decided once, here, and shown as `payer` on the session and its task. "workspace" where the workspace has no wallet is refused with 409 workspace_wallet_unavailable. — "personal" · "workspace"
- `defaults` (enum<string>) — Whether the session also starts with its workspace's defaults: the default environment when none is named, the default vault when it holds a secret, the team memory stores that attach by default, and the always-available files and skills. "none" attaches only what this request names. Omitted means "workspace". — "workspace" · "none"
- `resources` (object[]) — Files, GitHub repositories, and team Memory Stores attached before the first turn (max 100 create-time resources; max 8 memory stores). `{type:"file", file_id, mount_path?}` copies an upload read-only to `/workspace<mount_path>` (default `/workspace/<file_id>`); `{type:"github_repository", url, authorization_token?, checkout?: {type:"branch", name} | {type:"commit", sha}, mount_path?}` clones `https://github.com/{owner}/{repo}` to `/workspace<mount_path>` (default `/workspace/<repo>`); the token never enters the sandbox. `{type:"memory_store", memory_store_id, access:"read_only"|"read_write", mount_path?, instructions?}` attaches a creation-time snapshot under `/mnt/memory/` (default `/mnt/memory/<memory_store_id>`; 8 MiB total per Session). `read_write` explicitly grants the session-scoped Agent API permission to update this store; the mounted snapshot remains read-only.
  - type: "file" (object)
    - `type` ("file", required)
    - `file_id` (string, required) — max length 128
    - `mount_path` (string | null) — max length 4096
  - type: "github_repository" (object)
    - `type` ("github_repository", required)
    - `url` (string, required) — max length 2048
    - `authorization_token` (string) — max length 1024
    - `checkout` (object | null)
      - type: "branch" (object)
        - `type` ("branch", required)
        - `name` (string, required) — max length 255
      - type: "commit" (object)
        - `type` ("commit", required)
        - `sha` (string, required) — max length 64
    - `mount_path` (string | null) — max length 4096
  - type: "memory_store" (object)
    - `type` ("memory_store", required)
    - `memory_store_id` (string, required) — max length 255
    - `access` (enum<string>, required) — "read_only" · "read_write"
    - `instructions` (string) — max length 4096
    - `mount_path` (string | null) — max length 4096
- `local_mirror` (object) — Mark this session as a local mirror running on the user's Mac. No sandbox is provisioned; no billing gate is applied. Messages are ingested via PUT /v1/sessions/{id}/mirror. Idempotent: a second create with the same harness+source_session_id returns the existing session.
  - `harness` (enum<string>, required) — "claude_code" · "codex"
  - `source_session_id` (string, required) — max length 200
  - `parent_source_session_id` (string) — Native parent conversation id, supplied with parent_harness. Sync the parent first under the same actor, workspace and recorded machine; an existing parent binding cannot be changed. — max length 200
  - `parent_harness` (enum<string>) — Harness of parent_source_session_id; both parent fields must be supplied together. — "claude_code" · "codex"
  - `origin` (enum<string>, required) — "app" · "terminal" · "import"
  - `folder` (string) — max length 200
  - `machine` (string) — max length 200

Responses:

- `201` — Created
  - `session` (object, required)
    - `id` (string) — sess_… identifier
    - `agentId` (string | null) — The agent id (agent_…)
    - `title` (string | null)
    - `updatedAt` (string) — When the session last changed.
    - `status` (enum<string>) — provisioning = the sandbox is booting or installing the environment's packages (a turn sent meanwhile waits for it); running = a turn is in flight; terminated = archived or the last runtime was destroyed. Use archived for the durable archive receipt — "provisioning" · "idle" · "running" · "terminated"
    - `provisioningStage` (string | null) — Which part of its boot the session's computer is in, as the platform observed it: creating_computer until the sandbox provider reports the computer exists, then starting_agent until the agent in it answers. A provider that does not report the computer's creation stays at creating_computer. Null once the computer is up and whenever it is not booting. — "creating_computer" · "starting_agent" · null
    - `archived` (boolean) — True only after this Session's archive mark was durably written; false for an active Session whose runtime was destroyed
    - `agentType` (string)
    - `llm` (string) — The model this session runs on (PATCH to change; the agent's model is unchanged)
    - `harnessVersion` (string) — Harness release the session runs: the one its serving pod booted, the restored checkpoint's for a native-fork handoff, the agent's pin for ACP harnesses, otherwise the current release
    - `reasoningEffort` (string | null) — The model-compatible effort resolved from the session pin, then agent pin. Constrained models use an allowed fallback; no-setting models return null. Unpinned unconstrained models return null for the harness default.
    - `subscriptionApiFallback` (boolean) — Paid API continuation once no subscription account can run the task, preserving the same supported explicit model and wallet/budget gates. On unless set to false
    - `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription — "platform" · "account"
    - `idleTimeoutSeconds` (integer | null) — Seconds the session's machine stays awake after a turn ends before it is paused; null = the platform default of 60. Set it when people use apps on the session's exposed ports after the agent finishes
    - `browserProfile` (string) — Resolved browser: the session's choice, then the agent's default, then mine. mine is the browser of the person whose turn it is; fresh is signed out; user:<user id> is the sites that person shared with whoever runs the turn. Applied before the next browser turn when browser profiles are enabled.
    - `browserLoginsSavedAt` (string | null) — Most recent browser login save-back time, or null when this session has not saved changed logins.
    - `routineId` (string | null) — The routine whose run started this session, or null for any other session
    - `ownerId` (string) — The member who owns this session, as user_id in GET /universes/{slug}/members
    - `default` (boolean) — Is this the agent's default session
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `metadata` (object)
    - `budget` (object | null) — Hard spend cap, or null when the session has none. A reached budget pauses the session (402 budget_reached on new work) until the cap is raised above consumed_cost or removed — removal is one-way.
    - `parentSessionId` (string | null) — The session this one came from: a helper names the session that hired it, a handoff child names the session it continued; null for a root. Every session a task's root produced, with its role, is GET /tasks/{id}?by=session on any member's id.
    - `parentRelation` (string | null) — How this session relates to parentSessionId: `helper` was hired by it (actl hire or the orchestration API), `handoff` continued its conversation on another agent; null for a root. — "helper" · "handoff" · null
    - `resources` (object[]) — The files, GitHub repositories, and read-only memory stores mounted into the session, oldest first
      - option 1 (object)
        - `type` (enum<string>, required) — "file"
        - `id` (string, required) — sesrsc_…
        - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
        - `mount_path` (string, required) — Absolute, under /workspace
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 2 (object)
        - `type` (enum<string>, required) — "github_repository"
        - `id` (string, required) — sesrsc_…
        - `url` (string, required) — https://github.com/{owner}/{repo}
        - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
        - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
          - `type` (enum<string>) — "branch" · "commit"
          - `name` (string)
          - `sha` (string)
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 3 (object)
        - `type` (enum<string>, required) — "memory_store"
        - `id` (string, required) — smsr_…
        - `memory_store_id` (string, required) — memstore_…
        - `mount_path` (string, required) — Absolute, under /mnt/memory
        - `access` (enum<string>, required) — "read_only" · "read_write"
        - `instructions` (string) — Optional per-session guidance
        - `created_at` (string, required)
        - `updated_at` (string, required)
    - `workspaceDefaults` (object | null) — What the session started with because its workspace made it a default; everything else it carries was named at creation. Null when it took nothing.
    - `contextFiles` (object | null) — The workspace files the session loaded into its instructions when its sandbox was last provisioned (GET /workspace-context describes the set); null before that and for a session without its workspace's store. Every other file in the store is read on demand.
    - `continuedOnMac` (object) — Present when the owner moved this session to their own computer. Without `claimedAt` no computer has taken it yet, and a new turn here releases the move. With `claimedAt` the session refuses turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`.
      - `handoffId` (string, required)
      - `at` (string, required)
      - `machine` (string)
      - `claimedAt` (string)
    - `localControl` (object) — Present on a synced chat that runs on the caller's own Mac. `state` is `running`, `waiting_for_you` (a command waits for an answer), `idle`, or `unknown` while the Mac is offline, so a run is never shown as running from an offline Mac. `controllable` is the Mac's side only: each device or key still needs its own pairing (`POST /desktop/machines/{id}/controllers`), checked on every stop and answer. When false, `reason` is `mac_offline`, `phone_control_off` (turned off on the Mac), `terminal_session` (started in Terminal; read-only here) or `older_mac_app` (no Mac has reported its chats).
      - `mac` (object | null, required)
      - `state` (enum<string>, required) — "running" · "waiting_for_you" · "idle" · "unknown"
      - `controllable` (boolean, required)
      - `reason` (enum<string>) — "mac_offline" · "phone_control_off" · "terminal_session" · "older_mac_app"
      - `limit` (object) — The plan limit this chat's last run on the Mac reported: the same state the Mac shows above the composer. Absent until a run reports one and while the Mac is offline.
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `window` (string | null, required)
        - `utilization` (number | null, required)
        - `resetsAt` (string | null, required)
      - `pressure` (object) — This Mac's disk, memory and battery as it last reported them. Absent while the Mac is offline.
        - `disk` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
          - `freeBytes` (integer | null, required)
        - `memory` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `battery` (object)
          - `percent` (number, required)
          - `charging` (boolean, required)
    - `hostedBySeller` (object) — Present only when the session runs on its agent's maker's own server instead of a sandbox: what is sent to the session goes to this host. `agentType` and `llm` then name a stand-in that never runs.
      - `host` (string, required)
    - `attachments` (object[]) — Everything the session started with: its environment, vaults, mounted files and memory stores, and the workspace's always-available skills. The skills of the session's agent are on the agent and are not repeated here.
      - `type` (enum<string>, required) — "environment" · "vault" · "file" · "skill" · "memory_store"
      - `id` (string, required) — The id of the environment, vault, file, skill or memory store
      - `mountPath` (string | null, required) — Where a file or memory store is mounted; null for the other types
      - `source` (enum<string>, required) — default = the workspace supplied it; explicit = it was named when the session was created. A memory store on a session created before 2026-10-06 reads as explicit — "default" · "explicit"
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"agent":"agent_cmtb2f0a8m9k7x51q4ez6r0d","llm":"deepseek-flash","reasoningEffort":"high","title":"Signups digest","resources":[{"type":"file","file_id":"file_cmtb9x4p","mount_path":"/data/signups.csv"},{"type":"github_repository","url":"https://github.com/acme/growth","checkout":{"type":"branch","name":"main"}},{"type":"memory_store","memory_store_id":"memstore_cmtb9x4p","access":"read_only"}],"initial_events":[{"type":"user.message","content":[{"type":"text","text":"Summarize the signups from today"}]}]}'
```

Example response (201 Created):

```json
{
  "session": {
    "id": "sess-8c41f0…",
    "agent": "research-agent",
    "status": "idle",
    "default": true
  }
}
```

### GET /sessions/{id}

Session detail — status is provisioning (sandbox booting or installing packages) | idle | running | terminated (scope: read)

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `session` (object, required)
    - `id` (string) — sess_… identifier
    - `agentId` (string | null) — The agent id (agent_…)
    - `title` (string | null)
    - `updatedAt` (string) — When the session last changed.
    - `status` (enum<string>) — provisioning = the sandbox is booting or installing the environment's packages (a turn sent meanwhile waits for it); running = a turn is in flight; terminated = archived or the last runtime was destroyed. Use archived for the durable archive receipt — "provisioning" · "idle" · "running" · "terminated"
    - `provisioningStage` (string | null) — Which part of its boot the session's computer is in, as the platform observed it: creating_computer until the sandbox provider reports the computer exists, then starting_agent until the agent in it answers. A provider that does not report the computer's creation stays at creating_computer. Null once the computer is up and whenever it is not booting. — "creating_computer" · "starting_agent" · null
    - `archived` (boolean) — True only after this Session's archive mark was durably written; false for an active Session whose runtime was destroyed
    - `agentType` (string)
    - `llm` (string) — The model this session runs on (PATCH to change; the agent's model is unchanged)
    - `harnessVersion` (string) — Harness release the session runs: the one its serving pod booted, the restored checkpoint's for a native-fork handoff, the agent's pin for ACP harnesses, otherwise the current release
    - `reasoningEffort` (string | null) — The model-compatible effort resolved from the session pin, then agent pin. Constrained models use an allowed fallback; no-setting models return null. Unpinned unconstrained models return null for the harness default.
    - `subscriptionApiFallback` (boolean) — Paid API continuation once no subscription account can run the task, preserving the same supported explicit model and wallet/budget gates. On unless set to false
    - `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription — "platform" · "account"
    - `idleTimeoutSeconds` (integer | null) — Seconds the session's machine stays awake after a turn ends before it is paused; null = the platform default of 60. Set it when people use apps on the session's exposed ports after the agent finishes
    - `browserProfile` (string) — Resolved browser: the session's choice, then the agent's default, then mine. mine is the browser of the person whose turn it is; fresh is signed out; user:<user id> is the sites that person shared with whoever runs the turn. Applied before the next browser turn when browser profiles are enabled.
    - `browserLoginsSavedAt` (string | null) — Most recent browser login save-back time, or null when this session has not saved changed logins.
    - `routineId` (string | null) — The routine whose run started this session, or null for any other session
    - `ownerId` (string) — The member who owns this session, as user_id in GET /universes/{slug}/members
    - `default` (boolean) — Is this the agent's default session
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `metadata` (object)
    - `budget` (object | null) — Hard spend cap, or null when the session has none. A reached budget pauses the session (402 budget_reached on new work) until the cap is raised above consumed_cost or removed — removal is one-way.
    - `parentSessionId` (string | null) — The session this one came from: a helper names the session that hired it, a handoff child names the session it continued; null for a root. Every session a task's root produced, with its role, is GET /tasks/{id}?by=session on any member's id.
    - `parentRelation` (string | null) — How this session relates to parentSessionId: `helper` was hired by it (actl hire or the orchestration API), `handoff` continued its conversation on another agent; null for a root. — "helper" · "handoff" · null
    - `resources` (object[]) — The files, GitHub repositories, and read-only memory stores mounted into the session, oldest first
      - option 1 (object)
        - `type` (enum<string>, required) — "file"
        - `id` (string, required) — sesrsc_…
        - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
        - `mount_path` (string, required) — Absolute, under /workspace
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 2 (object)
        - `type` (enum<string>, required) — "github_repository"
        - `id` (string, required) — sesrsc_…
        - `url` (string, required) — https://github.com/{owner}/{repo}
        - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
        - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
          - `type` (enum<string>) — "branch" · "commit"
          - `name` (string)
          - `sha` (string)
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 3 (object)
        - `type` (enum<string>, required) — "memory_store"
        - `id` (string, required) — smsr_…
        - `memory_store_id` (string, required) — memstore_…
        - `mount_path` (string, required) — Absolute, under /mnt/memory
        - `access` (enum<string>, required) — "read_only" · "read_write"
        - `instructions` (string) — Optional per-session guidance
        - `created_at` (string, required)
        - `updated_at` (string, required)
    - `workspaceDefaults` (object | null) — What the session started with because its workspace made it a default; everything else it carries was named at creation. Null when it took nothing.
    - `contextFiles` (object | null) — The workspace files the session loaded into its instructions when its sandbox was last provisioned (GET /workspace-context describes the set); null before that and for a session without its workspace's store. Every other file in the store is read on demand.
    - `continuedOnMac` (object) — Present when the owner moved this session to their own computer. Without `claimedAt` no computer has taken it yet, and a new turn here releases the move. With `claimedAt` the session refuses turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`.
      - `handoffId` (string, required)
      - `at` (string, required)
      - `machine` (string)
      - `claimedAt` (string)
    - `localControl` (object) — Present on a synced chat that runs on the caller's own Mac. `state` is `running`, `waiting_for_you` (a command waits for an answer), `idle`, or `unknown` while the Mac is offline, so a run is never shown as running from an offline Mac. `controllable` is the Mac's side only: each device or key still needs its own pairing (`POST /desktop/machines/{id}/controllers`), checked on every stop and answer. When false, `reason` is `mac_offline`, `phone_control_off` (turned off on the Mac), `terminal_session` (started in Terminal; read-only here) or `older_mac_app` (no Mac has reported its chats).
      - `mac` (object | null, required)
      - `state` (enum<string>, required) — "running" · "waiting_for_you" · "idle" · "unknown"
      - `controllable` (boolean, required)
      - `reason` (enum<string>) — "mac_offline" · "phone_control_off" · "terminal_session" · "older_mac_app"
      - `limit` (object) — The plan limit this chat's last run on the Mac reported: the same state the Mac shows above the composer. Absent until a run reports one and while the Mac is offline.
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `window` (string | null, required)
        - `utilization` (number | null, required)
        - `resetsAt` (string | null, required)
      - `pressure` (object) — This Mac's disk, memory and battery as it last reported them. Absent while the Mac is offline.
        - `disk` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
          - `freeBytes` (integer | null, required)
        - `memory` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `battery` (object)
          - `percent` (number, required)
          - `charging` (boolean, required)
    - `hostedBySeller` (object) — Present only when the session runs on its agent's maker's own server instead of a sandbox: what is sent to the session goes to this host. `agentType` and `llm` then name a stand-in that never runs.
      - `host` (string, required)
    - `attachments` (object[]) — Everything the session started with: its environment, vaults, mounted files and memory stores, and the workspace's always-available skills. The skills of the session's agent are on the agent and are not repeated here.
      - `type` (enum<string>, required) — "environment" · "vault" · "file" · "skill" · "memory_store"
      - `id` (string, required) — The id of the environment, vault, file, skill or memory store
      - `mountPath` (string | null, required) — Where a file or memory store is mounted; null for the other types
      - `source` (enum<string>, required) — default = the workspace supplied it; explicit = it was named when the session was created. A memory store on a session created before 2026-10-06 reads as explicit — "default" · "explicit"
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /sessions/{id}

Update title / metadata / model / reasoning effort / billing / budget (scope: write)

llm and reasoningEffort are session settings: they change this session only, never the agent or its other sessions. The model must fit the harness; explicit effort must fit both harness and target model. Inherited effort is normalized for that model. An idle session restarts its engine in place; a running session finishes its turn and applies the change at the next turn (the response is 200 either way). A parked session applies it at its next wake.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `mcp_servers_mode` (enum<string>) — How mcp_servers changes the session overlay; default replace. Append preserves other servers and credentials. Duplicate names are refused except renewal of an owned, revoked browser/screen reach with a live reach of the same kind in the same Task. — "replace" · "append"
- `title` (string | null) — max length 120
- `metadata` (map<string, any>)
- `idleTimeoutSeconds` (integer | null) — Seconds this session's machine stays awake after a turn ends before it is paused (60-86400; omitted = the platform default of 60). A paused machine wakes on the next message; apps the agent serves on exposed ports are unreachable while it is paused, so set this to how long people keep using them after the agent finishes; null clears back to the platform default. Applies from the next time the session goes idle
- `browserProfile` (enum<string> | string | null) — Which saved browser the agent's browser opens with: mine (the browser of the person whose turn it is; new sign-ins are saved there), fresh (nothing loaded or saved) or user:<user id> (the sites that person shared with whoever runs the turn; used, never saved). workspace and private are accepted as mine. Omitted = the agent's default, then mine. Only harnesses with a persistent browser use it; null clears back to the agent's default. Applies from the next turn
- `llm` (string) — Switch this session's model (a current model for its harness; the agent's model is unchanged). Applies from the next turn
- `reasoningEffort` (enum<string> | null) — Session-level reasoning effort; null clears to the agent's setting normalized for the target model. Applies from the next turn. Explicit values must fit both harness and target model — agoragentic_acp: not supported; amp_acp: not supported; auggie: not supported; autohand: not supported; cline: not supported; codebuddy_code: not supported; cortex_code: not supported; corust_agent: not supported; crow_cli: not supported; cursor: not supported; deepagents: not supported; devin: not supported; dimcode: not supported; dirac: not supported; factory_droid: not supported; fast_agent: not supported; gemini: not supported; github_copilot_cli: not supported; glm_acp_agent: not supported; antigravity_acp: not supported; goose: not supported; grok_build: not supported; harn: not supported; junie: not supported; kilo: not supported; kimchi: not supported; minimax_code: not supported; minion_code: not supported; mistral_vibe: not supported; nova: not supported; poolside: not supported; qoder: not supported; qwen_code: not supported; sigit: not supported; stakpak: not supported; vtcode: not supported; code_assistant: not supported; docker_cagent: not supported; kiro: not supported; muse_code: not supported; openhands: not supported; hermes: none/minimal/low/medium/high/xhigh/max/ultra; claude_code: low/medium/high/xhigh/max; codex: none/minimal/low/medium/high/xhigh/max; openclaw: not supported; jev: not supported; pi: off/minimal/low/medium/high/xhigh/max; dsh: not supported; kimi_code: not supported; opencode: none/minimal/low/medium/high/xhigh/max; workspace_acp: not supported; models: claude-fable-5-1: low/medium/high/xhigh/max; claude-fable-5: low/medium/high/xhigh/max; claude-opus-5-5: low/medium/high/xhigh/max; claude-opus-5: low/medium/high/xhigh/max; claude-opus-4-8: low/medium/high/xhigh/max; claude-sonnet-5-5: low/medium/high/xhigh/max; claude-sonnet-5: low/medium/high/xhigh/max; claude-sonnet-4-6: low/medium/high/max; claude-haiku-5-5: low/medium/high/xhigh/max; claude-haiku-4-5: not supported; gpt-6.1-sol: low/medium/high/xhigh/max; gpt-6-astra: low/medium/high/xhigh/max; gpt-6-sol: none/low/medium/high/xhigh/max; gpt-6-luna: none/low/medium/high/xhigh/max; gpt-5.6-sol: none/low/medium/high/xhigh/max; gpt-5.6-terra: none/low/medium/high/xhigh/max; gpt-5.6-luna: none/low/medium/high/xhigh/max; gpt-5.5: none/low/medium/high/xhigh; gpt-4.1: not supported; deepseek-v4-pro: low/high/max; deepseek-flash: low/high/max; kimi-k3.1-pro: low/high/max; kimi-k3: low/high/max; kimi-k2.7-code: not supported; minimax-m3: not supported; muse-spark-1.1: minimal/low/medium/high/xhigh; muse-spark-1.2: minimal/low/medium/high/xhigh; muse-spark-1.3: minimal/low/medium/high/xhigh/max; minimax-m3.1-flash: low/medium/high/xhigh/max; gemini-4-argon: low/medium/high; gemini-3.5-flash-lite: low/medium/high; gemini-3.8-flash: low/medium/high; gemini-3.5-flash: low/medium/high; glm-5.3: low/high/max; glm-5.3-flash: low/high/max; grok-4.6: low/medium/high; grok-4.7: low/medium/high/xhigh — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra"
- `subscriptionApiFallback` (boolean) — After every subscription account is exhausted, continue on the same model using the paid platform API; wallet and session budget still apply
- `modelBilling` (enum<string>) — Who pays for model calls; switching restarts the agent's engine in place — "platform" · "account"
- `budget` (object | null) — Change the spend cap (must be strictly above consumed cost) or null to remove it — removal is one-way
  - `type` ("limit", required)
  - `max_list_cost` (object, required)
    - `amount` (string, required) — Whole US cents as an integer decimal string, e.g. "125" for $1.25 — max length 15
    - `currency` ("USD", required)
- `mcp_servers` (object[]) — Change the session's MCP server overlay. Default replaces the entire overlay; mcp_servers_mode append preserves other servers and credentials atomically. It permits replacing an owned revoked browser/screen reach only with a live reach of the same kind bound to the same Task; other duplicate names are refused; omit mcp_servers to leave unchanged. Same rules as at create (HTTPS, no spec-name collisions, ≤ 20 total). Takes effect at the next provision.
  - `name` (string, required) — max length 255
  - `url` (string, required) — HTTPS URL of a streamable-HTTP MCP server.
  - `authorization_token` (string) — Bearer token for the server. Write-only: stored encrypted, stamped as Authorization: Bearer at provision, never returned in reads.
  - `tools` (object)
    - `include` (string[])
    - `exclude` (string[])

Responses:

- `200` — OK
  - `session` (object, required)
    - `id` (string) — sess_… identifier
    - `agentId` (string | null) — The agent id (agent_…)
    - `title` (string | null)
    - `updatedAt` (string) — When the session last changed.
    - `status` (enum<string>) — provisioning = the sandbox is booting or installing the environment's packages (a turn sent meanwhile waits for it); running = a turn is in flight; terminated = archived or the last runtime was destroyed. Use archived for the durable archive receipt — "provisioning" · "idle" · "running" · "terminated"
    - `provisioningStage` (string | null) — Which part of its boot the session's computer is in, as the platform observed it: creating_computer until the sandbox provider reports the computer exists, then starting_agent until the agent in it answers. A provider that does not report the computer's creation stays at creating_computer. Null once the computer is up and whenever it is not booting. — "creating_computer" · "starting_agent" · null
    - `archived` (boolean) — True only after this Session's archive mark was durably written; false for an active Session whose runtime was destroyed
    - `agentType` (string)
    - `llm` (string) — The model this session runs on (PATCH to change; the agent's model is unchanged)
    - `harnessVersion` (string) — Harness release the session runs: the one its serving pod booted, the restored checkpoint's for a native-fork handoff, the agent's pin for ACP harnesses, otherwise the current release
    - `reasoningEffort` (string | null) — The model-compatible effort resolved from the session pin, then agent pin. Constrained models use an allowed fallback; no-setting models return null. Unpinned unconstrained models return null for the harness default.
    - `subscriptionApiFallback` (boolean) — Paid API continuation once no subscription account can run the task, preserving the same supported explicit model and wallet/budget gates. On unless set to false
    - `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription — "platform" · "account"
    - `idleTimeoutSeconds` (integer | null) — Seconds the session's machine stays awake after a turn ends before it is paused; null = the platform default of 60. Set it when people use apps on the session's exposed ports after the agent finishes
    - `browserProfile` (string) — Resolved browser: the session's choice, then the agent's default, then mine. mine is the browser of the person whose turn it is; fresh is signed out; user:<user id> is the sites that person shared with whoever runs the turn. Applied before the next browser turn when browser profiles are enabled.
    - `browserLoginsSavedAt` (string | null) — Most recent browser login save-back time, or null when this session has not saved changed logins.
    - `routineId` (string | null) — The routine whose run started this session, or null for any other session
    - `ownerId` (string) — The member who owns this session, as user_id in GET /universes/{slug}/members
    - `default` (boolean) — Is this the agent's default session
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `metadata` (object)
    - `budget` (object | null) — Hard spend cap, or null when the session has none. A reached budget pauses the session (402 budget_reached on new work) until the cap is raised above consumed_cost or removed — removal is one-way.
    - `parentSessionId` (string | null) — The session this one came from: a helper names the session that hired it, a handoff child names the session it continued; null for a root. Every session a task's root produced, with its role, is GET /tasks/{id}?by=session on any member's id.
    - `parentRelation` (string | null) — How this session relates to parentSessionId: `helper` was hired by it (actl hire or the orchestration API), `handoff` continued its conversation on another agent; null for a root. — "helper" · "handoff" · null
    - `resources` (object[]) — The files, GitHub repositories, and read-only memory stores mounted into the session, oldest first
      - option 1 (object)
        - `type` (enum<string>, required) — "file"
        - `id` (string, required) — sesrsc_…
        - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
        - `mount_path` (string, required) — Absolute, under /workspace
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 2 (object)
        - `type` (enum<string>, required) — "github_repository"
        - `id` (string, required) — sesrsc_…
        - `url` (string, required) — https://github.com/{owner}/{repo}
        - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
        - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
          - `type` (enum<string>) — "branch" · "commit"
          - `name` (string)
          - `sha` (string)
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 3 (object)
        - `type` (enum<string>, required) — "memory_store"
        - `id` (string, required) — smsr_…
        - `memory_store_id` (string, required) — memstore_…
        - `mount_path` (string, required) — Absolute, under /mnt/memory
        - `access` (enum<string>, required) — "read_only" · "read_write"
        - `instructions` (string) — Optional per-session guidance
        - `created_at` (string, required)
        - `updated_at` (string, required)
    - `workspaceDefaults` (object | null) — What the session started with because its workspace made it a default; everything else it carries was named at creation. Null when it took nothing.
    - `contextFiles` (object | null) — The workspace files the session loaded into its instructions when its sandbox was last provisioned (GET /workspace-context describes the set); null before that and for a session without its workspace's store. Every other file in the store is read on demand.
    - `continuedOnMac` (object) — Present when the owner moved this session to their own computer. Without `claimedAt` no computer has taken it yet, and a new turn here releases the move. With `claimedAt` the session refuses turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`.
      - `handoffId` (string, required)
      - `at` (string, required)
      - `machine` (string)
      - `claimedAt` (string)
    - `localControl` (object) — Present on a synced chat that runs on the caller's own Mac. `state` is `running`, `waiting_for_you` (a command waits for an answer), `idle`, or `unknown` while the Mac is offline, so a run is never shown as running from an offline Mac. `controllable` is the Mac's side only: each device or key still needs its own pairing (`POST /desktop/machines/{id}/controllers`), checked on every stop and answer. When false, `reason` is `mac_offline`, `phone_control_off` (turned off on the Mac), `terminal_session` (started in Terminal; read-only here) or `older_mac_app` (no Mac has reported its chats).
      - `mac` (object | null, required)
      - `state` (enum<string>, required) — "running" · "waiting_for_you" · "idle" · "unknown"
      - `controllable` (boolean, required)
      - `reason` (enum<string>) — "mac_offline" · "phone_control_off" · "terminal_session" · "older_mac_app"
      - `limit` (object) — The plan limit this chat's last run on the Mac reported: the same state the Mac shows above the composer. Absent until a run reports one and while the Mac is offline.
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `window` (string | null, required)
        - `utilization` (number | null, required)
        - `resetsAt` (string | null, required)
      - `pressure` (object) — This Mac's disk, memory and battery as it last reported them. Absent while the Mac is offline.
        - `disk` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
          - `freeBytes` (integer | null, required)
        - `memory` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `battery` (object)
          - `percent` (number, required)
          - `charging` (boolean, required)
    - `hostedBySeller` (object) — Present only when the session runs on its agent's maker's own server instead of a sandbox: what is sent to the session goes to this host. `agentType` and `llm` then name a stand-in that never runs.
      - `host` (string, required)
    - `attachments` (object[]) — Everything the session started with: its environment, vaults, mounted files and memory stores, and the workspace's always-available skills. The skills of the session's agent are on the agent and are not repeated here.
      - `type` (enum<string>, required) — "environment" · "vault" · "file" · "skill" · "memory_store"
      - `id` (string, required) — The id of the environment, vault, file, skill or memory store
      - `mountPath` (string | null, required) — Where a file or memory store is mounted; null for the other types
      - `source` (enum<string>, required) — default = the workspace supplied it; explicit = it was named when the session was created. A memory store on a session created before 2026-10-06 reads as explicit — "default" · "explicit"
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"title":"Signups digest","metadata":{"team":"growth"},"llm":"claude-sonnet-5","reasoningEffort":"high"}'
```

### DELETE /sessions/{id}

Retire a Session and tear down its runtime (scope: write)

Marks the Session deleted and removes operational bindings; durable transcripts and accounting records are retained. GET Session answers 404 afterward. Active execution must stop before cleanup. Works on idle and archived Sessions.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/access

Who may use the session, and what you are to it (scope: read)

Members of the session's workspace may read and prompt a workspace session; a private session is the owner's alone. People whose verified email is listed may read its message history from any workspace. Viewer emails are returned to the owner only.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `session_id` (string, required)
  - `title` (string, required)
  - `agent_type` (string, required)
  - `llm` (string, required)
  - `visibility` (enum<string>, required) — "workspace" · "private"
  - `access` (enum<string>, required) — "owner" · "member" · "viewer"
  - `owner` (object, required)
    - `id` (string)
    - `name` (string)
    - `email` (string)
  - `workspace` (object, required)
    - `slug` (string)
    - `name` (string)
    - `personal` (boolean)
  - `viewers` (object[], required)
    - `email` (string)
    - `added_at` (string)
    - `notification` (enum<string>) — Whether this person was emailed when they were added; null for someone added before those emails existed — "sent" · "not_sent"
  - `logins_shared` (object) — Whether everyone who may send turns here uses the owner's saved browser logins. Null for a read-only viewer.
    - `enabled` (boolean)
    - `sites` (string[]) — The sites it covers; null is every site except Google
    - `since` (string) — When it began or was last narrowed
    - `suspended` (enum<string>) — Why it is not applied right now: prompt_link while anyone with the session's link can send messages — "prompt_link" · "unavailable"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/access' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /sessions/{id}/access

Make the session private or workspace-visible, edit its viewers, and share the owner's logins with it (scope: write, owner)

Each address newly added to `add_viewers` is told once per session, by the `shared` notification (email, and push for someone with an account). A failed email never fails the change: that viewer answers `notification: "not_sent"`, and the owner sends them the link. One person's shares email at most 50 new addresses a day. `logins_shared` lets everyone who may send turns here act with the owner's saved browser logins: the same browser and computer stay across their turns, Google logins never go, and nothing is saved back. Only the owner may set it, themselves or with their own key: 403 `owner_required` for anyone else, a workspace key or an agent's task pass. 409 `invalid_scope` while the session starts signed out, uses someone else's browser, runs on a Mac or has a link that can send messages. Turning it on restarts a computer that holds the owner's whole browser; narrowing or turning it off restarts one that holds the grant, at once, even during a turn, so nothing of it remains. 503 `unavailable` means that restart has not happened yet: send the same change again.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `visibility` (enum<string>) — "workspace" · "private"
- `add_viewers` (string[])
- `browser_visible` (boolean) — Explicitly grant current browser pixels to add_viewers. Does not grant input, runtime start, or credentials. Omission never expands existing grants. — default: false
- `remove_viewers` (string[])
- `logins_shared` (object)
  - `enabled` (boolean, required)
  - `sites` (string[]) — Limit it to these domains. Omitted: every site except Google, including new sign-ins

Responses:

- `200` — OK
  - `session_id` (string, required)
  - `title` (string, required)
  - `agent_type` (string, required)
  - `llm` (string, required)
  - `visibility` (enum<string>, required) — "workspace" · "private"
  - `access` (enum<string>, required) — "owner" · "member" · "viewer"
  - `owner` (object, required)
    - `id` (string)
    - `name` (string)
    - `email` (string)
  - `workspace` (object, required)
    - `slug` (string)
    - `name` (string)
    - `personal` (boolean)
  - `viewers` (object[], required)
    - `email` (string)
    - `added_at` (string)
    - `notification` (enum<string>) — Whether this person was emailed when they were added; null for someone added before those emails existed — "sent" · "not_sent"
  - `logins_shared` (object) — Whether everyone who may send turns here uses the owner's saved browser logins. Null for a read-only viewer.
    - `enabled` (boolean)
    - `sites` (string[]) — The sites it covers; null is every site except Google
    - `since` (string) — When it began or was last narrowed
    - `suspended` (enum<string>) — Why it is not applied right now: prompt_link while anyone with the session's link can send messages — "prompt_link" · "unavailable"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/access \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"visibility":"private","add_viewers":["reviewer@acme.com"],"logins_shared":{"enabled":true,"sites":["linkedin.com"]}}'
```

### GET /shared-sessions

Sessions other people shared with you to read, newest first (scope: read)

Viewing is a person's access, so a credential limited to one workspace lists none. A limit that is not an integer from 1 to 100, or a cursor that is not valid, is 400 invalid_request.

Query parameters:

- `limit` (integer)
- `cursor` (string) — next_cursor from the previous page

Responses:

- `200` — OK
  - `sessions` (object[], required)
    - `id` (string)
    - `title` (string)
    - `agent_type` (string)
    - `owner` (object)
      - `name` (string)
      - `email` (string)
    - `workspace` (object)
      - `name` (string)
    - `shared_at` (string)
    - `unread` (boolean) — Not opened since it was shared
  - `next_cursor` (string, required) — Pass back as ?cursor= for the next page; null on the last page
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/shared-sessions' \
  -H "Authorization: Bearer ast_..."
```

### POST /shared-sessions/{id}/seen

Mark a session shared with you as opened, so it stops reading as unread (scope: write)

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `seen_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/shared-sessions/sess_cmtb7q2j/seen \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/share

The session's share link, or {"token": null} when sharing is off (owner only) (scope: read)

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `token` (string, required)
  - `access` (enum<string>) — "prompt" · "view"
  - `shareUrl` (string)
  - `browser_visible` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/share' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/share

Turn sharing on and get the share link — idempotent; {"access": "view"} asks for a view-only link; {"rotate": true} replaces it (scope: write)

A guest link (access prompt, the default) has a shareUrl that opens the session's guest page for anyone holding it, with no account; turns sent through it bill the session's owner. A view-only link (access view) is read only. Anyone holding its token reads the conversation's text at GET /links/{token}/events; browser_visible explicitly adds browser observation for signed-in holders. A session has one link; asking for the other access level replaces it with a new token, so the old URL dies. Rotating keeps the level and kills the old URL immediately; rotate cannot be combined with access.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `rotate` (boolean) — default: false
- `browser_visible` (boolean) — Explicitly include the same live browser, observation only. Changing this scope rotates the token. Historical links and omitted fields do not gain browser access. Cannot combine with rotate. — default: false
- `access` (enum<string>) — "prompt" · "view" — default: "prompt"

Responses:

- `200` — OK
  - `token` (string, required)
  - `access` (enum<string>) — "prompt" · "view"
  - `shareUrl` (string)
  - `browser_visible` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/share \
  -H "Authorization: Bearer ast_..."
```

### DELETE /sessions/{id}/share

Turn sharing off — the link stops working immediately (scope: write)

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/share \
  -H "Authorization: Bearer ast_..."
```

### GET /links/{token}/events

Read the conversation a share link opens, as any signed-in caller holding the link

Answers the session as its reader sees it and one page of people's turns and the agent's replies, text only (no attachments, tool calls, system messages or marks), oldest first, with the same opaque cursor as /sessions/{id}/events. Works for view-only and guest links. Unknown, rotated, disabled and deleted links all answer 404 not_found; reads are rate-limited per token (429 rate_limited with Retry-After). Needs a token with read scope from any workspace; the link is the grant, so the caller need not belong to the session's workspace. Also answers what the shared page shows around the conversation: access (prompt links can send and stop; view links only read), the session's usage totals, and the owner's page branding, null when they set none. listCostUsd is always 0 here: the provider's list price is not for a link holder.

Path parameters:

- `token` (string, required)

Query parameters:

- `cursor` (string) — cursor from the previous page
- `limit` (integer)
- `order` (string) — desc reads newest-first; the cursor then continues older

Responses:

- `200` — OK
  - `access` (enum<string>, required) — "prompt" · "view"
  - `totals` (object, required)
    - `costUsd` (number)
    - `listCostUsd` (number)
    - `billedCostUsd` (number)
    - `runtimeCostUsd` (number)
    - `capabilityCallCostUsd` (number)
    - `connectorCallCostUsd` (number)
    - `costFinalizing` (boolean)
    - `tokens` (integer)
    - `turns` (integer)
    - `durationMs` (integer)
  - `branding` (object, required)
    - `brand_name` (string)
    - `logo_url` (string)
    - `brand_color` (string)
    - `accent_color` (string)
  - `session` (object, required)
    - `id` (string, required)
    - `title` (string, required)
    - `agent_type` (string, required)
    - `owner` (object, required)
      - `name` (string)
    - `workspace` (object, required)
      - `name` (string)
  - `events` (object[], required) — user.message and agent.message events, text parts only
  - `cursor` (string, required)
  - `hasMore` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/links/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0/events' \
  -H "Authorization: Bearer ast_..."
```

### POST /links/{token}/messages

Send a message through a guest share link, as any signed-in caller holding it (scope: write)

What the guest page's composer does: the turn runs and bills as the session's owner, and the caller does not become a member. Body {text}. Only a guest link (access prompt) can send: a view-only link is 403 link_view_only. Unknown, rotated, disabled and deleted links are 404 not_found. An Idempotency-Key header (up to 200 characters) makes retries of one message send it once. 402 owner_out_of_credits when the owner's balance is empty; sends are rate-limited per link (429 rate_limited with Retry-After). Needs a token with write scope from any workspace; the link is the grant. Output is read with GET /links/{token}/events.

Path parameters:

- `token` (string, required)

Body (application/json):

- `text` (string, required) — max length 100000

Responses:

- `202` — Accepted — body is {}
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/links/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0/messages \
  -H "Authorization: Bearer ast_..."
```

### POST /links/{token}/interrupt

Stop the running turn through a guest share link (scope: write)

What the guest page's Stop button does. Only a guest link can stop: a view-only link is 403 link_view_only; a link that does not resolve is 404 not_found. Never rate-limited. 502 interrupt_failed when the conversation plane refused.

Path parameters:

- `token` (string, required)

Responses:

- `200` — OK
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/links/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0/interrupt \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/archive

Archive the session — irreversible; blocks new events, history stays readable (scope: write)

Durably marks archived=true and sets status to terminated, tears down the pod and stored context after answering, and refuses further messages (400 session_archived); the record and its events remain readable. A running session is refused with 400 session_running: interrupt and wait for idle first. A changed active Session whose archive mark did not commit returns 409 session_changed. Idempotent when another request already archived it.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `session` (object, required)
    - `id` (string) — sess_… identifier
    - `agentId` (string | null) — The agent id (agent_…)
    - `title` (string | null)
    - `updatedAt` (string) — When the session last changed.
    - `status` (enum<string>) — provisioning = the sandbox is booting or installing the environment's packages (a turn sent meanwhile waits for it); running = a turn is in flight; terminated = archived or the last runtime was destroyed. Use archived for the durable archive receipt — "provisioning" · "idle" · "running" · "terminated"
    - `provisioningStage` (string | null) — Which part of its boot the session's computer is in, as the platform observed it: creating_computer until the sandbox provider reports the computer exists, then starting_agent until the agent in it answers. A provider that does not report the computer's creation stays at creating_computer. Null once the computer is up and whenever it is not booting. — "creating_computer" · "starting_agent" · null
    - `archived` (boolean) — True only after this Session's archive mark was durably written; false for an active Session whose runtime was destroyed
    - `agentType` (string)
    - `llm` (string) — The model this session runs on (PATCH to change; the agent's model is unchanged)
    - `harnessVersion` (string) — Harness release the session runs: the one its serving pod booted, the restored checkpoint's for a native-fork handoff, the agent's pin for ACP harnesses, otherwise the current release
    - `reasoningEffort` (string | null) — The model-compatible effort resolved from the session pin, then agent pin. Constrained models use an allowed fallback; no-setting models return null. Unpinned unconstrained models return null for the harness default.
    - `subscriptionApiFallback` (boolean) — Paid API continuation once no subscription account can run the task, preserving the same supported explicit model and wallet/budget gates. On unless set to false
    - `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription — "platform" · "account"
    - `idleTimeoutSeconds` (integer | null) — Seconds the session's machine stays awake after a turn ends before it is paused; null = the platform default of 60. Set it when people use apps on the session's exposed ports after the agent finishes
    - `browserProfile` (string) — Resolved browser: the session's choice, then the agent's default, then mine. mine is the browser of the person whose turn it is; fresh is signed out; user:<user id> is the sites that person shared with whoever runs the turn. Applied before the next browser turn when browser profiles are enabled.
    - `browserLoginsSavedAt` (string | null) — Most recent browser login save-back time, or null when this session has not saved changed logins.
    - `routineId` (string | null) — The routine whose run started this session, or null for any other session
    - `ownerId` (string) — The member who owns this session, as user_id in GET /universes/{slug}/members
    - `default` (boolean) — Is this the agent's default session
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `metadata` (object)
    - `budget` (object | null) — Hard spend cap, or null when the session has none. A reached budget pauses the session (402 budget_reached on new work) until the cap is raised above consumed_cost or removed — removal is one-way.
    - `parentSessionId` (string | null) — The session this one came from: a helper names the session that hired it, a handoff child names the session it continued; null for a root. Every session a task's root produced, with its role, is GET /tasks/{id}?by=session on any member's id.
    - `parentRelation` (string | null) — How this session relates to parentSessionId: `helper` was hired by it (actl hire or the orchestration API), `handoff` continued its conversation on another agent; null for a root. — "helper" · "handoff" · null
    - `resources` (object[]) — The files, GitHub repositories, and read-only memory stores mounted into the session, oldest first
      - option 1 (object)
        - `type` (enum<string>, required) — "file"
        - `id` (string, required) — sesrsc_…
        - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
        - `mount_path` (string, required) — Absolute, under /workspace
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 2 (object)
        - `type` (enum<string>, required) — "github_repository"
        - `id` (string, required) — sesrsc_…
        - `url` (string, required) — https://github.com/{owner}/{repo}
        - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
        - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
          - `type` (enum<string>) — "branch" · "commit"
          - `name` (string)
          - `sha` (string)
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 3 (object)
        - `type` (enum<string>, required) — "memory_store"
        - `id` (string, required) — smsr_…
        - `memory_store_id` (string, required) — memstore_…
        - `mount_path` (string, required) — Absolute, under /mnt/memory
        - `access` (enum<string>, required) — "read_only" · "read_write"
        - `instructions` (string) — Optional per-session guidance
        - `created_at` (string, required)
        - `updated_at` (string, required)
    - `workspaceDefaults` (object | null) — What the session started with because its workspace made it a default; everything else it carries was named at creation. Null when it took nothing.
    - `contextFiles` (object | null) — The workspace files the session loaded into its instructions when its sandbox was last provisioned (GET /workspace-context describes the set); null before that and for a session without its workspace's store. Every other file in the store is read on demand.
    - `continuedOnMac` (object) — Present when the owner moved this session to their own computer. Without `claimedAt` no computer has taken it yet, and a new turn here releases the move. With `claimedAt` the session refuses turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`.
      - `handoffId` (string, required)
      - `at` (string, required)
      - `machine` (string)
      - `claimedAt` (string)
    - `localControl` (object) — Present on a synced chat that runs on the caller's own Mac. `state` is `running`, `waiting_for_you` (a command waits for an answer), `idle`, or `unknown` while the Mac is offline, so a run is never shown as running from an offline Mac. `controllable` is the Mac's side only: each device or key still needs its own pairing (`POST /desktop/machines/{id}/controllers`), checked on every stop and answer. When false, `reason` is `mac_offline`, `phone_control_off` (turned off on the Mac), `terminal_session` (started in Terminal; read-only here) or `older_mac_app` (no Mac has reported its chats).
      - `mac` (object | null, required)
      - `state` (enum<string>, required) — "running" · "waiting_for_you" · "idle" · "unknown"
      - `controllable` (boolean, required)
      - `reason` (enum<string>) — "mac_offline" · "phone_control_off" · "terminal_session" · "older_mac_app"
      - `limit` (object) — The plan limit this chat's last run on the Mac reported: the same state the Mac shows above the composer. Absent until a run reports one and while the Mac is offline.
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `window` (string | null, required)
        - `utilization` (number | null, required)
        - `resetsAt` (string | null, required)
      - `pressure` (object) — This Mac's disk, memory and battery as it last reported them. Absent while the Mac is offline.
        - `disk` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
          - `freeBytes` (integer | null, required)
        - `memory` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `battery` (object)
          - `percent` (number, required)
          - `charging` (boolean, required)
    - `hostedBySeller` (object) — Present only when the session runs on its agent's maker's own server instead of a sandbox: what is sent to the session goes to this host. `agentType` and `llm` then name a stand-in that never runs.
      - `host` (string, required)
    - `attachments` (object[]) — Everything the session started with: its environment, vaults, mounted files and memory stores, and the workspace's always-available skills. The skills of the session's agent are on the agent and are not repeated here.
      - `type` (enum<string>, required) — "environment" · "vault" · "file" · "skill" · "memory_store"
      - `id` (string, required) — The id of the environment, vault, file, skill or memory store
      - `mountPath` (string | null, required) — Where a file or memory store is mounted; null for the other types
      - `source` (enum<string>, required) — default = the workspace supplied it; explicit = it was named when the session was created. A memory store on a session created before 2026-10-06 reads as explicit — "default" · "explicit"
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/archive \
  -H "Authorization: Bearer ast_..."
```

### PUT /sessions/{id}/mirror

Write a local mirror's messages — the copy of a conversation that ran on the person's own computer (scope: write)

Only for a session created with local_mirror, and only by its owner using a personal API key (a workspace key is 403). Body {messages: [{id, role: user|agent, created_at, parts}] (up to 200), title?, status?: running|idle, recorded_state?: unknown|working|completed|failed|cancelled}. recorded_state is the owner's latest native protocol observation, stored on the mirror and exposed as local_mirror.recorded_state in Task detail; it does not attest process liveness or task success. Missing state on a message write is unknown. Each message is upserted by its id, so a growing agent turn is sent again whole; values shaped like a secret are masked before storing. Limits: 512 KiB per message (413 message_too_large naming it), 4 MiB per body (413), 20,000 messages per session (422 mirror_quota_exceeded). A session that is not a mirror answers 409 not_a_mirror_session, an archived one 410. Nothing runs and nothing is billed.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `messages` (object[], required)
  - `id` (string, required)
  - `role` (enum<string>, required) — "user" · "agent"
  - `created_at` (string, required)
  - `parts` (object[], required)
- `title` (string) — max length 120
- `status` (enum<string>) — "running" · "idle"
- `recorded_state` (enum<string>) — "unknown" · "working" · "completed" · "failed" · "cancelled"

Responses:

- `200` — Stored
  - `stored` (integer)
  - `syncedAt` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/mirror \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/mirror/environment

Store the working folder of a local mirror, so its chat can continue in the cloud without the computer (scope: write)

Only for a session created with local_mirror, and only by its owner. Body {file_id, name, files}: file_id is a gzipped tar laid out as `<name>/…` that the owner uploaded to their personal files (POST /files/uploads without a workspace). It is copied into the session's private storage, checked against the upload's size and sha256 (422 environment_mismatch), and replaces the folder stored before; the same folder again is a no-op. The folder may hold secrets: it is never public, and it is restored into /workspace/<name> only in a continuation its owner starts. A file the caller did not upload personally answers 404; a session that is not a mirror 409 not_a_mirror_session, one already continued 409 continued_in_cloud, an archived one 410. Up to 2 GiB (413 archive_too_large). Nothing runs and nothing is billed.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `file_id` (string, required)
- `name` (string, required) — The folder's name: 1 to 80 letters, digits, spaces, dots, dashes or underscores — max length 80
- `files` (integer, required)

Responses:

- `200` — Stored
  - `sha256` (string)
  - `size_bytes` (integer)
  - `name` (string)
  - `files` (integer)
  - `staged_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/mirror/environment \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/mirror/environment

The working folder stored for a local mirror (scope: read)

Answers the folder its owner's computer last stored for this chat, to that owner only; 404 when none is stored.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — The stored folder
  - `sha256` (string)
  - `size_bytes` (integer)
  - `name` (string)
  - `files` (integer)
  - `staged_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/mirror/environment' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/mirror/checkpoint

Store the native session of a local mirror, so its owner's continuation resumes that exact conversation (scope: write)

Only for a session created with local_mirror, and only by its owner. Body {file_id, synced_at?}: synced_at is the syncedAt receipt from PUT /mirror before capturing the archive. Without it, continuation uses the synced messages. The file is an asteroids.native-checkpoint v1 ZIP of at most 16 MiB (the files Claude Code or Codex keep for the conversation) that the owner uploaded to their personal files. It is checked whole (400 checkpoint_invalid), must be this chat's own conversation on its own agent (409 checkpoint_mismatch), and replaces the checkpoint stored before. A continuation the owner starts on the same agent resumes it natively while nothing was synced after it; otherwise it continues from the synced messages. A file the caller did not upload personally answers 404; a session that is not a mirror 409 not_a_mirror_session, one already continued 409 continued_in_cloud, an archived one 410. Nothing runs and nothing is billed.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `file_id` (string, required)
- `synced_at` (string)

Responses:

- `200` — Stored
  - `sha256` (string)
  - `size_bytes` (integer)
  - `harness` (enum<string>) — "claude_code" · "codex"
  - `harness_version` (string | null)
  - `staged_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/mirror/checkpoint \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/mirror/checkpoint

The native session stored for a local mirror (scope: read)

Answers the checkpoint its owner's computer last stored for this chat, to that owner only; 404 when none is stored.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — The stored checkpoint
  - `sha256` (string)
  - `size_bytes` (integer)
  - `harness` (enum<string>) — "claude_code" · "codex"
  - `harness_version` (string | null)
  - `staged_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/mirror/checkpoint' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/trace/archive

Archive only after final trace upload (scope: write)

The existing archive writer, with a durable requirement to finalize the runtime trace before destroying compute. Refuses unsupported legacy runtimes or incomplete upload; the archived Session and sandbox remain available for operational recovery and retry. A distinct path prevents older deployments from ignoring the requirement. No training/export consent is granted.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — Archived session with preserved trace
  - `session` (object)
    - `id` (string) — sess_… identifier
    - `agentId` (string | null) — The agent id (agent_…)
    - `title` (string | null)
    - `updatedAt` (string) — When the session last changed.
    - `status` (enum<string>) — provisioning = the sandbox is booting or installing the environment's packages (a turn sent meanwhile waits for it); running = a turn is in flight; terminated = archived or the last runtime was destroyed. Use archived for the durable archive receipt — "provisioning" · "idle" · "running" · "terminated"
    - `provisioningStage` (string | null) — Which part of its boot the session's computer is in, as the platform observed it: creating_computer until the sandbox provider reports the computer exists, then starting_agent until the agent in it answers. A provider that does not report the computer's creation stays at creating_computer. Null once the computer is up and whenever it is not booting. — "creating_computer" · "starting_agent" · null
    - `archived` (boolean) — True only after this Session's archive mark was durably written; false for an active Session whose runtime was destroyed
    - `agentType` (string)
    - `llm` (string) — The model this session runs on (PATCH to change; the agent's model is unchanged)
    - `harnessVersion` (string) — Harness release the session runs: the one its serving pod booted, the restored checkpoint's for a native-fork handoff, the agent's pin for ACP harnesses, otherwise the current release
    - `reasoningEffort` (string | null) — The model-compatible effort resolved from the session pin, then agent pin. Constrained models use an allowed fallback; no-setting models return null. Unpinned unconstrained models return null for the harness default.
    - `subscriptionApiFallback` (boolean) — Paid API continuation once no subscription account can run the task, preserving the same supported explicit model and wallet/budget gates. On unless set to false
    - `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription — "platform" · "account"
    - `idleTimeoutSeconds` (integer | null) — Seconds the session's machine stays awake after a turn ends before it is paused; null = the platform default of 60. Set it when people use apps on the session's exposed ports after the agent finishes
    - `browserProfile` (string) — Resolved browser: the session's choice, then the agent's default, then mine. mine is the browser of the person whose turn it is; fresh is signed out; user:<user id> is the sites that person shared with whoever runs the turn. Applied before the next browser turn when browser profiles are enabled.
    - `browserLoginsSavedAt` (string | null) — Most recent browser login save-back time, or null when this session has not saved changed logins.
    - `routineId` (string | null) — The routine whose run started this session, or null for any other session
    - `ownerId` (string) — The member who owns this session, as user_id in GET /universes/{slug}/members
    - `default` (boolean) — Is this the agent's default session
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `metadata` (object)
    - `budget` (object | null) — Hard spend cap, or null when the session has none. A reached budget pauses the session (402 budget_reached on new work) until the cap is raised above consumed_cost or removed — removal is one-way.
    - `parentSessionId` (string | null) — The session this one came from: a helper names the session that hired it, a handoff child names the session it continued; null for a root. Every session a task's root produced, with its role, is GET /tasks/{id}?by=session on any member's id.
    - `parentRelation` (string | null) — How this session relates to parentSessionId: `helper` was hired by it (actl hire or the orchestration API), `handoff` continued its conversation on another agent; null for a root. — "helper" · "handoff" · null
    - `resources` (object[]) — The files, GitHub repositories, and read-only memory stores mounted into the session, oldest first
      - option 1 (object)
        - `type` (enum<string>, required) — "file"
        - `id` (string, required) — sesrsc_…
        - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
        - `mount_path` (string, required) — Absolute, under /workspace
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 2 (object)
        - `type` (enum<string>, required) — "github_repository"
        - `id` (string, required) — sesrsc_…
        - `url` (string, required) — https://github.com/{owner}/{repo}
        - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
        - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
          - `type` (enum<string>) — "branch" · "commit"
          - `name` (string)
          - `sha` (string)
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 3 (object)
        - `type` (enum<string>, required) — "memory_store"
        - `id` (string, required) — smsr_…
        - `memory_store_id` (string, required) — memstore_…
        - `mount_path` (string, required) — Absolute, under /mnt/memory
        - `access` (enum<string>, required) — "read_only" · "read_write"
        - `instructions` (string) — Optional per-session guidance
        - `created_at` (string, required)
        - `updated_at` (string, required)
    - `workspaceDefaults` (object | null) — What the session started with because its workspace made it a default; everything else it carries was named at creation. Null when it took nothing.
    - `contextFiles` (object | null) — The workspace files the session loaded into its instructions when its sandbox was last provisioned (GET /workspace-context describes the set); null before that and for a session without its workspace's store. Every other file in the store is read on demand.
    - `continuedOnMac` (object) — Present when the owner moved this session to their own computer. Without `claimedAt` no computer has taken it yet, and a new turn here releases the move. With `claimedAt` the session refuses turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`.
      - `handoffId` (string, required)
      - `at` (string, required)
      - `machine` (string)
      - `claimedAt` (string)
    - `localControl` (object) — Present on a synced chat that runs on the caller's own Mac. `state` is `running`, `waiting_for_you` (a command waits for an answer), `idle`, or `unknown` while the Mac is offline, so a run is never shown as running from an offline Mac. `controllable` is the Mac's side only: each device or key still needs its own pairing (`POST /desktop/machines/{id}/controllers`), checked on every stop and answer. When false, `reason` is `mac_offline`, `phone_control_off` (turned off on the Mac), `terminal_session` (started in Terminal; read-only here) or `older_mac_app` (no Mac has reported its chats).
      - `mac` (object | null, required)
      - `state` (enum<string>, required) — "running" · "waiting_for_you" · "idle" · "unknown"
      - `controllable` (boolean, required)
      - `reason` (enum<string>) — "mac_offline" · "phone_control_off" · "terminal_session" · "older_mac_app"
      - `limit` (object) — The plan limit this chat's last run on the Mac reported: the same state the Mac shows above the composer. Absent until a run reports one and while the Mac is offline.
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `window` (string | null, required)
        - `utilization` (number | null, required)
        - `resetsAt` (string | null, required)
      - `pressure` (object) — This Mac's disk, memory and battery as it last reported them. Absent while the Mac is offline.
        - `disk` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
          - `freeBytes` (integer | null, required)
        - `memory` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `battery` (object)
          - `percent` (number, required)
          - `charging` (boolean, required)
    - `hostedBySeller` (object) — Present only when the session runs on its agent's maker's own server instead of a sandbox: what is sent to the session goes to this host. `agentType` and `llm` then name a stand-in that never runs.
      - `host` (string, required)
    - `attachments` (object[]) — Everything the session started with: its environment, vaults, mounted files and memory stores, and the workspace's always-available skills. The skills of the session's agent are on the agent and are not repeated here.
      - `type` (enum<string>, required) — "environment" · "vault" · "file" · "skill" · "memory_store"
      - `id` (string, required) — The id of the environment, vault, file, skill or memory store
      - `mountPath` (string | null, required) — Where a file or memory store is mounted; null for the other types
      - `source` (enum<string>, required) — default = the workspace supplied it; explicit = it was named when the session was created. A memory store on a session created before 2026-10-06 reads as explicit — "default" · "explicit"
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/trace/archive \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/trace

Private runtime trace objects (scope: read, original owner only)

Paginated original capture objects, including raw frames, native transcripts and model-call bodies. Retained operating evidence remains readable after soft deletion; this does not restore the Session. Requires session management authority and the caller to own both the Session and its Agent definition; a hire, shared transcript or pod credential is insufficient. Object URLs expire after 15 minutes and bind the listed generation. Never log or persist URLs. Capture may be partial or missing; this is operating evidence, not a training/export consent grant.

Path parameters:

- `id` (string, required) — The session id

Query parameters:

- `cursor` (string)

Responses:

- `200` — Private trace page
  - `sessionId` (string, required)
  - `cursor` (string | null, required)
  - `objects` (object[], required)
    - `path` (string, required)
    - `generation` (string, required)
    - `size` (string, required)
    - `crc32c` (string, required)
    - `md5` (string)
    - `url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/trace' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/activity

How much a session has been used (scope: read)

What the Activity tab shows: every message on the session, how many in the last seven days, when a person or the agent last spoke (null when neither has), and the count by source, most first. Anyone who can view the session can read it; 404 not_found otherwise. Installed skills are on GET /agents/{id}.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `total_messages` (integer, required)
  - `last_7_days` (integer, required)
  - `last_active_at` (string, required)
  - `by_source` (object[], required)
    - `source` (string, required)
    - `label` (string, required)
    - `count` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/activity' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/raw-events

The session's raw message ledger, for developer accounts (scope: read)

What the Events tab shows: every persisted message row as the record holds it, newest first, with its metadata and the rows GET /sessions/{id}/events leaves out. Developer accounts only, with a credential for the whole account: another account reads 404 not_found, as it does for a session it cannot view, and a workspace key or restricted credential is 403. Pass next_before back as before for older rows; it is null on the last page. A before or limit outside its range is 400 invalid_request.

Path parameters:

- `id` (string, required) — The session id

Query parameters:

- `before` (integer) — next_before from the previous page
- `limit` (integer)

Responses:

- `200` — OK
  - `total` (integer, required) — Every row on the session.
  - `events` (object[], required)
    - `id` (integer, required)
    - `uiMessageId` (string, required)
    - `role` (string, required)
    - `source` (string, required)
    - `createdAt` (string, required)
    - `text` (string, required)
    - `parts` (any, required)
    - `metadata` (object, required)
  - `next_before` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/raw-events' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/usage

The session's charges and observed usage, oldest first (scope: read)

Totals plus ledger charges and authenticated subscription measurements (`native_usage`), with token breakdown, reported list value, billed dollars and duration. `limit` (default 100) pages with an opaque `cursor`; keep following `cursor` until it is null. Native measurements carry provenance and never create charges. Historical `authenticated_pod` measurements do not establish subscription funding (`coveredBy` is null). Missing duration stays unknown; `durationComplete` is not billing settlement. Dollar amounts here are numbers in USD, not the `{amount, currency}` cents object used elsewhere.

Path parameters:

- `id` (string, required) — The session id

Query parameters:

- `cursor` (string) — A cursor from a previous page
- `limit` (integer) — 1–500, default 100

Responses:

- `200` — OK
  - `session` (string, required) — The session's public id (sess_…)
  - `totals` (object, required) — Summed over the whole session, not just this page. Includes authenticated native subscription measurements; billed dollars still come only from the ledger. `durationComplete` means every observed model record carries duration, not that runtime charges are final. `tokenCostsUsd` is null when native measurements have no charge allocation.
    - `listCostUsd` (number | null) — Null when native raw cost has no proven additive scope; billed dollars remain known independently.
    - `modelListCostUsd` (number | null) — Model-only list value, unavailable for native raw cumulative reports without verified process boundaries and deltas.
    - `billedCostUsd` (number)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `cachedInputTokens` (integer)
    - `cacheCreationTokens` (integer)
    - `modelBilledCostUsd` (number)
    - `runtimeCostUsd` (number)
    - `capabilityCallCostUsd` (number)
    - `connectorCallCostUsd` (number)
    - `turns` (integer)
    - `durationMs` (integer)
    - `durationComplete` (boolean)
    - `coveredBy` (string | null) — "subscription" · "arena" · null
    - `tokenCostsUsd` (object | null)
  - `entries` (object[], required)
    - `kind` (string, required) — Ledger kind, or native_usage for an authenticated measurement that is not a charge.
    - `provenance` (enum<string>) — Present on native_usage. Historical authenticated_pod measurements have no frozen billing context and do not establish who paid; current session settings are not used to infer it. — "authenticated_pod" · "pod_with_host_context" · "bound_native_usage"
    - `at` (string, required)
    - `listCostUsd` (number | null)
    - `billedCostUsd` (number, required)
    - `coveredBy` (string | null) — Coverage from a ledger record (including an explicit Arena waiver), a matching host snapshot at receipt, or a bound native execution. Null for historical pod-only measurements; never inferred from today’s session billing mode. — "subscription" · "arena" · null
    - `model` (string | null)
    - `provider` (string | null)
    - `basis` (string | null)
    - `durationMs` (integer | null)
    - `interrupted` (boolean | null)
    - `tokens` (object, required)
      - `input` (integer)
      - `output` (integer)
      - `cachedInput` (integer)
      - `cacheCreation` (integer)
  - `budget` (object | null) — The session's budget summary — the same shape as `budget` on Session — or null when it has none
  - `cursor` (string | null, required) — Pass as ?cursor= for the next page; null on the last
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/usage' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/preview

The session's live site preview (scope: read)

When the session's agent has published a site preview: the URL the web's Preview tab opens, its version (publish time) and when it expires. 404 when there is none.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `url` (string, required)
  - `version` (string, required)
  - `expires_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/preview' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/assets/{asset_id}

Download media an agent delivered in the session (scope: read)

An image or file an agent posted in the session's transcript, which events carry as `blob://assets/<asset_id>`: the original bytes with their media type, as the web chat shows them. The asset must belong to the session's agent (or be the caller's own upload not yet adopted); anything else is 404.

Path parameters:

- `id` (string, required) — The session id
- `asset_id` (string, required) — The id after blob://assets/

Responses:

- `200` — The asset's bytes
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/assets/asset_id' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/subscription-recovery

Where a session blocked by its plan account stands (scope: read)

When a session's turn stops because the person's own Claude or ChatGPT plan account is exhausted, the platform tries their other accounts. This is the recovery generation, the account it selected, and the `revision` a paid continuation pins to.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/subscription-recovery' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/subscription-recovery

Continue this one session on AgentSky credits (scope: write)

Consent to continue this session on platform credits from `revision` (from the GET), as the chat's blocked notice does. Only this session moves; `POST /model-subscriptions/{provider}/switch-to-credits` moves every agent on a plan. 402 `insufficient_credits` when the balance cannot cover it; 503 `continuation_pending` means the consent is saved and the continuation retries on its own. A workspace key is refused: this consent is the person's.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `revision` (string, required)

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/subscription-recovery \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/policies

List session-level policy rules (scope: read)

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `rules` (object[])
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/policies' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/policies

Create a session-level policy rule (owner only) (scope: write)

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- option 1 (object)
  - `name` (string, required) — max length 128
  - `enabled` (boolean) — default: true
  - `position` (integer) — default: 0
  - `kind` ("TOOL_CALL", required)
  - `config` (object, required)
    - `action` (enum<string>, required) — "allow" · "ask" · "deny"
    - `matcher` (string) — max length 255
    - `commandPatterns` (string[]) — max length 500
- option 2 (object)
  - `name` (string, required) — max length 128
  - `enabled` (boolean) — default: true
  - `position` (integer) — default: 0
  - `kind` ("SPEND_CAP", required)
  - `config` (object, required)
    - `warnUsdMicros` (integer | null)
    - `hardCapUsdMicros` (integer, required)
- option 3 (object)
  - `name` (string, required) — max length 128
  - `enabled` (boolean) — default: true
  - `position` (integer) — default: 0
  - `kind` ("CALL_COUNT", required)
  - `config` (object, required)
    - `limitPerSession` (integer, required)
- option 4 (object)
  - `name` (string, required) — max length 128
  - `enabled` (boolean) — default: true
  - `position` (integer) — default: 0
  - `kind` ("CAPABILITY", required)
  - `config` (map<string, enum<string>>, required) — "allow" · "ask" · "deny"

Responses:

- `201` — Created
  - `rule` (object)
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/policies \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"name":"Spend cap","kind":"SPEND_CAP","config":{"hardCapUsdMicros":5000000,"warnUsdMicros":4000000}}'
```

### GET /sessions/{id}/policies/{ruleId}

Get a session-level policy rule (scope: read)

Path parameters:

- `id` (string, required) — The session id
- `ruleId` (string, required)

Responses:

- `200` — OK
  - `rule` (object)
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/policies/cmtb5p0l3r8w2k01s6x7n9q4' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /sessions/{id}/policies/{ruleId}

Update a session-level policy rule (owner only) (scope: write)

Path parameters:

- `id` (string, required) — The session id
- `ruleId` (string, required)

Body (application/json):

- `name` (string) — max length 128
- `enabled` (boolean)
- `position` (integer)
- `config` (object | map<string, enum<string>>)
  - option 1 (object)
    - `action` (enum<string>, required) — "allow" · "ask" · "deny"
    - `matcher` (string) — max length 255
    - `commandPatterns` (string[]) — max length 500
  - option 2 (object)
    - `warnUsdMicros` (integer | null)
    - `hardCapUsdMicros` (integer, required)
  - option 3 (object)
    - `limitPerSession` (integer, required)
  - option 4 (map<string, enum<string>>) — "allow" · "ask" · "deny"

Responses:

- `200` — OK
  - `rule` (object)
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/policies/cmtb5p0l3r8w2k01s6x7n9q4 \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"config":{"hardCapUsdMicros":10000000,"warnUsdMicros":8000000}}'
```

### DELETE /sessions/{id}/policies/{ruleId}

Delete a session-level policy rule (owner only) (scope: write)

Path parameters:

- `id` (string, required) — The session id
- `ruleId` (string, required)

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/policies/cmtb5p0l3r8w2k01s6x7n9q4 \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/effective-policy

Effective merged policy for a session across all layers (scope: read)

Returns all policy rules for workspace → agent → session, with a note when native tool policies prevent an unsupported runtime from starting.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `rules` (object[])
    - `id` (string, required)
    - `name` (string, required)
    - `kind` (enum<string>, required) — "TOOL_CALL" · "SPEND_CAP" · "CALL_COUNT" · "CAPABILITY"
    - `enabled` (boolean, required)
    - `config` (object, required)
    - `layer` (enum<string>, required) — "workspace" · "agent" · "session"
    - `position` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
  - `note` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/effective-policy' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/studio

Deprecated: the address of the web app running inside the session's pod (scope: write)

Replaced by `PUT /sessions/{id}/ports/{port}` and `POST …/ports/{port}/grants`; kept for one release while the consumer app moves. Minted once per session and stable afterwards. `port` is what the app inside the pod listens on — 1024–65535, defaulting to the studio's own port. An archived session answers 400 session_archived.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `port` (integer) — Omitted = the studio's default port

Responses:

- `200` — OK
  - `url` (string, required) — https://studio-<token>.agentsky.dev — the token is the whole address
  - `port` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/studio \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/ports

The session's exposed ports, oldest first (scope: read)

Every local server the agent runs inside the pod that has been exposed on an origin of its own.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `ports` (object[], required)
    - `port` (integer, required) — What the app listens on inside the pod
    - `id` (string, required) — Names the origin; not a credential
    - `url` (string, required) — https://app-<id>.agentsky.dev/ — stable for the port's life
    - `visibility` (enum<string>, required) — "private" · "public"
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/ports' \
  -H "Authorization: Bearer ast_..."
```

### PUT /sessions/{id}/ports/{port}

Expose a port the agent's local server listens on (scope: write)

Create-or-get: the port gets a stable origin `https://app-<id>.agentsky.dev/` relayed to the pod (HTTP and WebSocket) while the pod runs; calling again returns the same record, and a `visibility` in the body replaces the stored one in place. `port` is 1024–65535 and never the pod's own (400 invalid_request). A private port (the default) admits a browser only through an entry link from `POST …/grants`; a public port admits anyone with the address. A parked pod answers a paused page and is never woken by a visit. An archived session answers 400 session_archived.

Path parameters:

- `id` (string, required) — The session id
- `port` (integer, required) — The port the app listens on inside the pod

Body (application/json):

- `visibility` (enum<string>) — Omitted = keep the stored value (private for a new port) — "private" · "public"

Responses:

- `200` — OK
  - `port` (integer, required) — What the app listens on inside the pod
  - `id` (string, required) — Names the origin; not a credential
  - `url` (string, required) — https://app-<id>.agentsky.dev/ — stable for the port's life
  - `visibility` (enum<string>, required) — "private" · "public"
  - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/ports/port \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/ports/{port}

One exposed port (scope: read)

Path parameters:

- `id` (string, required) — The session id
- `port` (integer, required) — The port the app listens on inside the pod

Responses:

- `200` — OK
  - `port` (integer, required) — What the app listens on inside the pod
  - `id` (string, required) — Names the origin; not a credential
  - `url` (string, required) — https://app-<id>.agentsky.dev/ — stable for the port's life
  - `visibility` (enum<string>, required) — "private" · "public"
  - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/ports/port' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /sessions/{id}/ports/{port}

Stop exposing a port (scope: write)

The origin answers 404 from then on (within a few seconds); browsers that had entered are signed out with it.

Path parameters:

- `id` (string, required) — The session id
- `port` (integer, required) — The port the app listens on inside the pod

Responses:

- `204` — Revoked
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/ports/port \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/ports/{port}/grants

An entry link for an exposed port (scope: write)

For a private port: a single-use link, good for a minute, that signs the browser opening it in to the port's origin (a cookie that lives twelve hours) and lands on `path`; minting again supersedes the previous unused link. For a public port: the plain address. An archived session answers 400 session_archived.

Path parameters:

- `id` (string, required) — The session id
- `port` (integer, required) — The port the app listens on inside the pod

Body (application/json):

- `path` (string) — Where on the app to land after entering; a path on the port's origin, default /

Responses:

- `200` — OK
  - `url` (string, required) — A private port: a single-use entry link, good for a minute; a public port: the plain address
  - `expires_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/ports/port/grants \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/resources

List the session's resources, oldest first (scope: read)

`limit` (1–1000) pages the list with an opaque `page` cursor; omitted lists every resource in one answer.

Path parameters:

- `id` (string, required) — The session id (sess_…)

Query parameters:

- `limit` (integer)
- `page` (string) — A next_page cursor

Responses:

- `200` — OK
  - `data` (object[], required) — Oldest first
    - option 1 (object)
      - `type` (enum<string>, required) — "file"
      - `id` (string, required) — sesrsc_…
      - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
      - `mount_path` (string, required) — Absolute, under /workspace
      - `created_at` (string, required)
      - `updated_at` (string, required)
    - option 2 (object)
      - `type` (enum<string>, required) — "github_repository"
      - `id` (string, required) — sesrsc_…
      - `url` (string, required) — https://github.com/{owner}/{repo}
      - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
      - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
        - `type` (enum<string>) — "branch" · "commit"
        - `name` (string)
        - `sha` (string)
      - `created_at` (string, required)
      - `updated_at` (string, required)
    - option 3 (object)
      - `type` (enum<string>, required) — "memory_store"
      - `id` (string, required) — smsr_…
      - `memory_store_id` (string, required) — memstore_…
      - `mount_path` (string, required) — Absolute, under /mnt/memory
      - `access` (enum<string>, required) — "read_only" · "read_write"
      - `instructions` (string) — Optional per-session guidance
      - `created_at` (string, required)
      - `updated_at` (string, required)
  - `next_page` (string | null, required) — Pass back as ?page= for the next page; null when `limit` was omitted or the list ended
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/resources' \
  -H "Authorization: Bearer ast_..."
```

Example response (200 OK):

```json
{
  "data": [
    {
      "type": "file",
      "id": "sesrsc_cmtc1a2b",
      "file_id": "file_cmtc1a2c",
      "mount_path": "/workspace/data/signups.csv",
      "created_at": "2026-09-11T18:00:00.000Z",
      "updated_at": "2026-09-11T18:00:00.000Z"
    },
    {
      "type": "github_repository",
      "id": "sesrsc_cmtc1a2d",
      "url": "https://github.com/acme/growth",
      "mount_path": "/workspace/growth",
      "checkout": {
        "type": "branch",
        "name": "main"
      },
      "created_at": "2026-09-11T18:00:00.000Z",
      "updated_at": "2026-09-11T18:00:00.000Z"
    },
    {
      "type": "memory_store",
      "id": "smsr_cmtc1a2e",
      "memory_store_id": "memstore_cmtb9x4p",
      "mount_path": "/mnt/memory/memstore_cmtb9x4p",
      "access": "read_only",
      "created_at": "2026-09-11T18:00:00.000Z",
      "updated_at": "2026-09-11T18:00:00.000Z"
    }
  ],
  "next_page": null
}
```

### POST /sessions/{id}/resources

Add a file to a running session (scope: write)

Files only — repositories and memory stores can only be attached at session create. The file is copied read-only to `/workspace<mount_path>` before the session's next turn; `mount_path` follows the create rules (rooted under /workspace, no escape, no overlap with another resource). 400 too_many_resources past 500 per session; 400 session_archived on an archived session.

Path parameters:

- `id` (string, required) — The session id (sess_…)

Body (application/json):

- type: "file" (object)
  - `type` ("file", required)
  - `file_id` (string, required) — max length 128
  - `mount_path` (string | null) — max length 4096
- type: "github_repository" (object)
  - `type` ("github_repository", required)
  - `url` (string, required) — max length 2048
  - `authorization_token` (string) — max length 1024
  - `checkout` (object | null)
    - type: "branch" (object)
      - `type` ("branch", required)
      - `name` (string, required) — max length 255
    - type: "commit" (object)
      - `type` ("commit", required)
      - `sha` (string, required) — max length 64
  - `mount_path` (string | null) — max length 4096
- type: "memory_store" (object)
  - `type` ("memory_store", required)
  - `memory_store_id` (string, required) — max length 255
  - `access` (enum<string>, required) — "read_only" · "read_write"
  - `instructions` (string) — max length 4096
  - `mount_path` (string | null) — max length 4096

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/resources \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"type":"file","file_id":"file_cmtb9x4p","mount_path":"/data/signups.csv"}'
```

Example response (200 OK):

```json
{
  "type": "file",
  "id": "sesrsc_cmtc1a2b",
  "file_id": "file_cmtc1a2c",
  "mount_path": "/workspace/data/signups.csv",
  "created_at": "2026-09-11T18:00:00.000Z",
  "updated_at": "2026-09-11T18:00:00.000Z"
}
```

### GET /sessions/{id}/resources/{rid}

One resource (scope: read)

Path parameters:

- `id` (string, required) — The session id (sess_…)
- `rid` (string, required) — The resource id (sesrsc_… or smsr_…)

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/resources/sesrsc_cmtc1a2d' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/resources/{rid}

Rotate a repository's token (scope: write)

Only `github_repository` resources accept an update, and the token is the only field: it is re-encrypted and the session's egress policy is recompiled and pushed to its live pod — nothing changes inside the sandbox. A file or memory store answers 400. A token that conflicts with another secret's Authorization header on github.com answers 400 egress_header_conflict.

Path parameters:

- `id` (string, required) — The session id (sess_…)
- `rid` (string, required) — The resource id (sesrsc_… or smsr_…)

Body (application/json):

- `authorization_token` (string, required) — max length 1024

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/resources/sesrsc_cmtc1a2d \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"authorization_token":"github_pat_…"}'
```

### DELETE /sessions/{id}/resources/{rid}

Remove a file from the session (scope: write)

Files only — the resource and its per-session copy are deleted and the pod unlinks the file before the session's next turn. A repository or memory store answers 400: neither can be removed mid-session.

Path parameters:

- `id` (string, required) — The session id (sess_…)
- `rid` (string, required) — The resource id (sesrsc_… or smsr_…)

Responses:

- `200` — OK
  - `type` (enum<string>, required) — "session_resource_deleted"
  - `id` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/resources/sesrsc_cmtc1a2d \
  -H "Authorization: Bearer ast_..."
```

Example response (200 OK):

```json
{
  "type": "session_resource_deleted",
  "id": "sesrsc_cmtc1a2b"
}
```

### POST /sessions/{id}/show

Show something in a session's right panel (scope: write)

Asks whoever is watching this session on the web or the Mac to show an artifact, browser, pull request, changes, story, schedules or notes. It reaches viewers connected now and is never replayed. The answer is {shown: true, opens_on}: opens_on names the surfaces that have a panel for this kind (a pull_request opens only on the web; the Mac has no pull request pane). A viewer whose window is too narrow, or who is reading a different chat, is not interrupted. `request_id` makes a retry one request. 404 when the artifact is not in the session's workspace.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `resource` (object, required)
  - `kind` (enum<string>, required) — "artifact" · "browser" · "pull_request" · "changes" · "story" · "schedules" · "notes"
  - `id` (string) — The artifact id, for artifact.
  - `version` (integer) — An artifact's version; default the latest.
  - `url` (string) — The GitHub pull request URL, for pull_request.
- `request_id` (string) — 8 to 128 letters, digits, dashes or underscores.

Responses:

- `200` — Authorized browser state, or null when the session has no browser. Provider credentials, interactive viewer links and browser connection URLs are never returned.
  - `browser` (object | null, required)
    - `id` (string, required)
    - `status` (enum<string>, required) — "preparing" · "running" · "completed" · "blocked" · "failed" · "stopped"
    - `viewerUrl` (null, required) — Always null. Observation uses screenshots; interactive provider viewer links are never exposed.
    - `url` (string, required)
    - `startedAt` (string, required)
    - `expiresAt` (string, required)
    - `endedAt` (string | null, required)
    - `elapsedMs` (number, required)
    - `actionCount` (integer, required)
    - `progress` (string)
    - `claim` (string) — The agent's completion claim, separate from task verification.
    - `resolvedModel` (string) — Resolved Jev model reported by OpenRouter.
    - `error` (string)
    - `actions` (object[], required)
      - `id` (string, required)
      - `verb` (string, required)
      - `detail` (string, required)
      - `timestamp` (string, required)
      - `status` (string, required)
    - `verification` (object, required)
      - `status` (enum<string>, required) — "passed" · "failed" · "unverified"
      - `checks` (object[], required)
        - `label` (string, required)
        - `status` (enum<string>, required) — "passed" · "failed" · "unverified"
        - `detail` (string, required)
    - `lastScreenshot` (string | null, required) — Latest observed or final JPEG as a data URL when capture succeeded.
    - `lastScreenshotAt` (string | null) — Time the latest screenshot was captured successfully.
    - `cleanupPending` (boolean, required) — A terminal browser may still be releasing provider resources; cleanup is retried durably.
    - `costs` (object, required) — Recorded billed USD, including the fixed Mercury text-entry helper. Receipts can arrive after completion.
      - `coveredBy` (enum<string>) — Model coverage from stored receipts, including native subscription measurements. Arena requires every zero-charge ledger receipt to record that waiver and no native measurements. Unknown or mixed model coverage is null; subscription coverage does not waive runtime or tools. — "subscription" · "arena" · null
      - `pricingComplete` (boolean) — False when model prices are unknown, including native reports whose process-cumulative cost cannot establish a turn price.
      - `unpricedModelCalls` (integer)
      - `unpricedModels` (string[])
      - `decisionUsd` (number, required)
      - `helperUsd` (number, required)
      - `browserUsd` (number, required)
      - `runtimeUsd` (number, required)
      - `totalUsd` (number, required) — Known metered cost including waived usage; only a lower bound when pricingComplete is false.
      - `chargedUsd` (number, required) — Actual amount charged after billing waivers.
- `400` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/show \
  -H "Authorization: Bearer ast_..."
```

## Conversation

### POST /sessions/{id}/messages

Deprecated — use POST /sessions/{id}/events (scope: write)

The legacy input shape ({parts}); accepted for one release and translated to a single user.message, then 410. Optional Idempotency-Key header dedupes retries.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `parts` (object[], required)
  - type: "text" (object)
    - `index` (integer, required)
    - `type` ("text", required)
    - `text` (string) — default: ""
    - `stream_id` (string | null)
    - `stream_index` (integer | null)
  - type: "reasoning" (object)
    - `index` (integer, required)
    - `type` ("reasoning", required)
    - `text` (string) — default: ""
    - `redacted` (boolean) — default: false
    - `stream_id` (string | null)
    - `stream_index` (integer | null)
  - type: "tool_call" (object)
    - `index` (integer, required)
    - `type` ("tool_call", required)
    - `call_id` (string, required)
    - `tool_name` (string, required)
    - `args` (map<string, any>) — default: {}
    - `args_partial` (string | null)
  - type: "tool_result" (object)
    - `index` (integer, required)
    - `type` ("tool_result", required)
    - `call_id` (string, required)
    - `tool_name` (string, required)
    - `status` (enum<string>) — "ok" · "error" — default: "ok"
    - `result` (map<string, any>) — default: {}
  - type: "file" (object)
    - `index` (integer, required)
    - `type` ("file", required)
    - `name` (string, required)
    - `media_type` (string, required)
    - `uri` (string | null)
    - `data` (string | null)
    - `size_bytes` (integer | null)
  - type: "image" (object)
    - `index` (integer, required)
    - `type` ("image", required)
    - `media_type` (string, required)
    - `uri` (string | null)
    - `data` (string | null)
    - `alt` (string | null)
    - `width` (integer | null)
    - `height` (integer | null)
  - type: "video" (object)
    - `index` (integer, required)
    - `type` ("video", required)
    - `media_type` (string, required)
    - `uri` (string | null)
    - `data` (string | null)
    - `alt` (string | null)
    - `width` (integer | null)
    - `height` (integer | null)
    - `duration_ms` (integer | null)
    - `size_bytes` (integer | null)
    - `thumbnail_uri` (string | null)
  - type: "status" (object)
    - `index` (integer, required)
    - `type` ("status", required)
    - `level` (enum<string>, required) — "thinking" · "working" · "waiting" · "idle" · "done"
    - `text` (string | null)
  - type: "error" (object)
    - `index` (integer, required)
    - `type` ("error", required)
    - `code` (string, required)
    - `message` (string, required)
    - `retryable` (boolean) — default: false

Responses:

- `202` — Accepted — body is {}; output arrives on the stream
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/messages \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"parts":[{"type":"text","index":0,"text":"Summarize the signups from today"}]}'
```

Example response (202 Accepted):

```json
{}
```

### POST /sessions/{id}/events

Send events — the one input: user.message, user.interrupt, system.message (scope: write)

The conversation plane (edge-routed to the chat-proxy). Body {events: [...]} (1–50), optionally requireIdle: true for one user.message (and optional trailing system.message). Exclusive admission refuses a busy session with 409 before persisting or delivering the message; a successful echo's user id names the admitted run. Its admission field is created only when this POST committed the exclusive input; an idempotent replay returns replayed. This field is not part of history or SSE. This is a Session admission receipt, not proof that another client's earlier queued joined input has finished on the Pod. Ordinary sends may join an open run. A message of text alone to the caller's own chat that runs on their Mac is offered to that Mac: 200 with placement {kind: "mac", machine} when a Mac takes it. Files, a teammate's message, or no Mac online answer 409 runs_on_mac and nothing is sent. validated all-or-nothing. A user.message carries content blocks: text, image and document with base64 / url / file sources (inline base64 ≤ 20 MiB per request; larger content goes through POST /files). A user.message may set interaction_mode: "plan" (the agent inspects and answers with a reviewable plan, then waits for a choice to implement) or "build"; omitted, the session's own metadata.interaction_mode applies (build when unset). A system.message (text only) must be last and follow the user.message it accompanies: privileged context for that turn and, through the agent's transcript, later turns. user.interrupt stops the in-flight turn; with mode: "save" it instead asks the run to start no new work, save what it has (files plus a progress note in the working directory) and end its turn with a reply listing what was saved, and stops it only if it is still running after a 10 minute grace window (echo status saving, or no_turn when nothing is running). On a chat that runs on the owner's Mac, user.interrupt stops the run there: the echo has placement {kind: "mac", machine}, and only a key the Mac allowed may do it (403 controller_not_paired while it runs). A later user.message continues in the same session. Every event echoes back in the history shape with a stable id; sources are echoed as file sources naming per-session copies (never base64). Optional Idempotency-Key header: a replay returns the original echo. 402 insufficient_credits / budget_reached, 503 egress_policy_failed, 400 session_archived refuse the whole request before any row is written.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `events` (object[], required)
  - type: "user.message" (object)
    - `type` ("user.message", required)
    - `content` (object[], required)
      - type: "text" (object)
        - `type` ("text", required)
        - `text` (string, required)
      - type: "image" (object)
        - `type` ("image", required)
        - `source` (object, required)
          - type: "base64" (object)
            - `type` ("base64", required)
            - `media_type` (string, required)
            - `data` (string, required)
          - type: "url" (object)
            - `type` ("url", required)
            - `url` (string, required)
          - type: "file" (object)
            - `type` ("file", required)
            - `file_id` (string, required)
      - type: "document" (object)
        - `type` ("document", required)
        - `source` (object, required)
          - type: "base64" (object)
            - `type` ("base64", required)
            - `media_type` (string, required)
            - `data` (string, required)
          - type: "text" (object)
            - `type` ("text", required)
            - `media_type` ("text/plain") — default: "text/plain"
            - `data` (string, required)
          - type: "url" (object)
            - `type` ("url", required)
            - `url` (string, required)
          - type: "file" (object)
            - `type` ("file", required)
            - `file_id` (string, required)
        - `title` (string | null)
        - `context` (string | null)
    - `interaction_mode` (enum<string> | null) — "plan" · "build"
  - type: "system.message" (object)
    - `type` ("system.message", required)
    - `content` (object[], required)
      - `type` ("text", required)
      - `text` (string, required)
  - type: "user.interrupt" (object)
    - `type` ("user.interrupt", required)
    - `mode` (enum<string>) — "immediate" · "save"
- `requireIdle` (boolean)

Responses:

- `200` — OK — one echo per event, in order
  - `data` (any[], required) — One echo per event, in order, in the events-history shape
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/events \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"requireIdle":true,"events":[{"type":"user.message","content":[{"type":"text","text":"What is in this screenshot?"},{"type":"image","source":{"type":"file","file_id":"file_cmtb9x4p"}}]},{"type":"system.message","content":[{"type":"text","text":"Answer in one paragraph."}]}]}'
```

Example response (200 OK):

```json
{
  "data": [
    {
      "id": "api-user-3f2c…",
      "type": "user.message",
      "admission": "created",
      "sessionId": "sess_cmtb7q2j",
      "agentId": "agent_cmtb2f0a8m9k7x51q4ez6r0d",
      "at": "2026-09-10T18:00:00.000Z",
      "content": [
        {
          "type": "text",
          "text": "What is in this screenshot?"
        },
        {
          "type": "image",
          "source": {
            "type": "file",
            "file_id": "file_cmtb9y1q"
          }
        }
      ]
    },
    {
      "id": "api-user-3f2c…#system",
      "type": "system.message",
      "sessionId": "sess_cmtb7q2j",
      "agentId": "agent_cmtb2f0a8m9k7x51q4ez6r0d",
      "at": "2026-09-10T18:00:00.000Z",
      "content": [
        {
          "type": "text",
          "text": "Answer in one paragraph."
        }
      ]
    }
  ]
}
```

### GET /sessions/{id}/events

The event history — the same event objects the stream delivers (scope: read)

The session's history, one event per message: user.message and system.message (with content), agent.message (with parts), user.interrupt, and the turn marks session.status_running, session.status_idle (stop_reason.type is end_turn, retries_exhausted, provider_lost or budget_reached) and session.error. context.input_observed is an authenticated history-only bound context-presence fact, not model usage or task success. agent.reasoning, agent.tool_use, agent.tool_result and agent.status appear on the live stream only, not in history. Oldest-first with an opaque numeric cursor; order=desc reads newest-first and its cursor continues older, so a reader can open on the end of a long session. Every event carries rowId, the number the stream frames carry, so a reader resumes the stream after the newest one it holds. Reconnect = open the stream, list events, dedupe by event id. types[] filters (e.g. types[]=user.message&types[]=agent.message is the transcript view).

Path parameters:

- `id` (string, required) — The session id

Query parameters:

- `cursor` (string)
- `limit` (integer)
- `types[]` (array)
- `order` (string)

Responses:

- `200` — OK
  - `events` (object[], required) — Oldest-first; newest-first with order=desc
    - `id` (string, required) — Stable event id — the dedupe key across stream ∪ events
    - `rowId` (integer) — Position in the session's history; the stream resumes after the newest one a reader holds
    - `type` (string, required) — user.message · system.message (both history only — never on the live stream; they carry `content`) · agent.message · agent.reasoning · agent.tool_use · agent.tool_result · agent.status · user.interrupt · session.status_running · session.status_idle · session.error · session.status_terminated · session.deleted · context.input_observed (authenticated history only: host-admitted input/client UUID/response/gateway identifiers, scope digests and UTF-8 byte coverage; no pod-declared native session authority, raw capture or private pointer)
    - `sessionId` (string, required)
    - `agentId` (string | null) — The agent id (agent_…)
    - `at` (string) — ISO 8601
    - `messageId` (string) — agent.message
    - `parts` (object[]) — agent.message
      - type: "text" (object)
        - `index` (integer, required)
        - `type` ("text", required)
        - `text` (string) — default: ""
        - `stream_id` (string | null)
        - `stream_index` (integer | null)
      - type: "reasoning" (object)
        - `index` (integer, required)
        - `type` ("reasoning", required)
        - `text` (string) — default: ""
        - `redacted` (boolean) — default: false
        - `stream_id` (string | null)
        - `stream_index` (integer | null)
      - type: "tool_call" (object)
        - `index` (integer, required)
        - `type` ("tool_call", required)
        - `call_id` (string, required)
        - `tool_name` (string, required)
        - `args` (map<string, any>) — default: {}
        - `args_partial` (string | null)
      - type: "tool_result" (object)
        - `index` (integer, required)
        - `type` ("tool_result", required)
        - `call_id` (string, required)
        - `tool_name` (string, required)
        - `status` (enum<string>) — "ok" · "error" — default: "ok"
        - `result` (map<string, any>) — default: {}
      - type: "file" (object)
        - `index` (integer, required)
        - `type` ("file", required)
        - `name` (string, required)
        - `media_type` (string, required)
        - `uri` (string | null)
        - `data` (string | null)
        - `size_bytes` (integer | null)
      - type: "image" (object)
        - `index` (integer, required)
        - `type` ("image", required)
        - `media_type` (string, required)
        - `uri` (string | null)
        - `data` (string | null)
        - `alt` (string | null)
        - `width` (integer | null)
        - `height` (integer | null)
      - type: "video" (object)
        - `index` (integer, required)
        - `type` ("video", required)
        - `media_type` (string, required)
        - `uri` (string | null)
        - `data` (string | null)
        - `alt` (string | null)
        - `width` (integer | null)
        - `height` (integer | null)
        - `duration_ms` (integer | null)
        - `size_bytes` (integer | null)
        - `thumbnail_uri` (string | null)
      - type: "status" (object)
        - `index` (integer, required)
        - `type` ("status", required)
        - `level` (enum<string>, required) — "thinking" · "working" · "waiting" · "idle" · "done"
        - `text` (string | null)
      - type: "error" (object)
        - `index` (integer, required)
        - `type` ("error", required)
        - `code` (string, required)
        - `message` (string, required)
        - `retryable` (boolean) — default: false
    - `text` (string) — agent.message — parts flattened to plain text
    - `content` (object[]) — user.message / system.message — the CMA content blocks as sent (text · image · document); every image/document source is a `file` source naming a per-session copy readable through GET /files/{file_id}/content
    - `part` (object) — reasoning / tool_use / tool_result / status events
      - type: "text" (object)
        - `index` (integer, required)
        - `type` ("text", required)
        - `text` (string) — default: ""
        - `stream_id` (string | null)
        - `stream_index` (integer | null)
      - type: "reasoning" (object)
        - `index` (integer, required)
        - `type` ("reasoning", required)
        - `text` (string) — default: ""
        - `redacted` (boolean) — default: false
        - `stream_id` (string | null)
        - `stream_index` (integer | null)
      - type: "tool_call" (object)
        - `index` (integer, required)
        - `type` ("tool_call", required)
        - `call_id` (string, required)
        - `tool_name` (string, required)
        - `args` (map<string, any>) — default: {}
        - `args_partial` (string | null)
      - type: "tool_result" (object)
        - `index` (integer, required)
        - `type` ("tool_result", required)
        - `call_id` (string, required)
        - `tool_name` (string, required)
        - `status` (enum<string>) — "ok" · "error" — default: "ok"
        - `result` (map<string, any>) — default: {}
      - type: "file" (object)
        - `index` (integer, required)
        - `type` ("file", required)
        - `name` (string, required)
        - `media_type` (string, required)
        - `uri` (string | null)
        - `data` (string | null)
        - `size_bytes` (integer | null)
      - type: "image" (object)
        - `index` (integer, required)
        - `type` ("image", required)
        - `media_type` (string, required)
        - `uri` (string | null)
        - `data` (string | null)
        - `alt` (string | null)
        - `width` (integer | null)
        - `height` (integer | null)
      - type: "video" (object)
        - `index` (integer, required)
        - `type` ("video", required)
        - `media_type` (string, required)
        - `uri` (string | null)
        - `data` (string | null)
        - `alt` (string | null)
        - `width` (integer | null)
        - `height` (integer | null)
        - `duration_ms` (integer | null)
        - `size_bytes` (integer | null)
        - `thumbnail_uri` (string | null)
      - type: "status" (object)
        - `index` (integer, required)
        - `type` ("status", required)
        - `level` (enum<string>, required) — "thinking" · "working" · "waiting" · "idle" · "done"
        - `text` (string | null)
      - type: "error" (object)
        - `index` (integer, required)
        - `type` ("error", required)
        - `code` (string, required)
        - `message` (string, required)
        - `retryable` (boolean) — default: false
    - `stop_reason` (object) — session.status_idle — discriminate on type; never break on bare idle
      - `type` (string) — "end_turn" (also after an interrupt) | "retries_exhausted" (preceded by an exhausted engine error) | "provider_lost" (confirmed runtime Pod loss, preceded by an exhausted session.error) | "budget_reached"; more reserved
    - `error` (object) — session.error — the stream stays open; a session.status_idle follows once the turn is over
      - `type` (string) — e.g. "pod_unavailable"
      - `message` (string)
      - `retry_status` (string) — "retrying" (the turn continues) | "exhausted" (the turn is over)
    - `by` (string) — user.interrupt — who requested the interrupt
    - `mode` (enum<string>) — user.interrupt — present on a save interrupt: the run was asked to save its work and end itself — "save"
    - `deadline_at` (string) — user.interrupt with mode save — when the run is stopped if it has not ended by then
    - `cause` (enum<string>) — user.interrupt — present when the platform stopped a run whose save grace window ran out — "save_timeout"
    - `actor` (object) — user.message only, in history and in the send echo: who sent it, present only when that was not the session's owner
      - `id` (string)
      - `name` (string | null)
  - `cursor` (string | null, required) — Pass back as ?cursor= for the next page; null when the session has no events
  - `hasMore` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/events' \
  -H "Authorization: Bearer ast_..."
```

Example response (200 OK):

```json
{
  "events": [
    {
      "id": "api-user-8c41f0…#idle",
      "rowId": 42,
      "type": "session.status_idle",
      "sessionId": "sess-8c41f0…",
      "agent": "agent_cmtb2f0a8m9k7x51q4ez6r0d",
      "stop_reason": {
        "type": "end_turn"
      }
    }
  ],
  "cursor": "42",
  "hasMore": false
}
```

### GET /sessions/{id}/stream

The standing event stream (SSE) (scope: read)

text/event-stream, stays open across turns. If a run is in flight when the stream opens, its status marks so far (session.status_running, session.error, user.interrupt) are replayed from history under their own ids and timestamps, so a stream opened mid-run still sees the boundary its duration is measured from; a run that has already ended is not replayed — read it from the event history. Everything else is live. Dedupe by event id. Events: agent.message, agent.reasoning, agent.tool_use, agent.tool_result, agent.status, session.status_running, session.status_idle (carries stop_reason — never break on bare idle), session.error (the stream stays open; an idle follows), user.interrupt, session.status_terminated (terminal), session.deleted (terminal). User messages are not sent on the live stream — they appear in the event history only. Reconnect = reopen + list events + dedupe by event id.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — SSE stream
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -N 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/stream' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/interrupt

Abort the in-flight turn (scope: write)

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `status` (enum<string>, required) — no_turn = nothing in flight, on a chat that runs on the owner's Mac too; otherwise user.interrupt echoes on the stream and the pod's session.status_idle follows — "interrupting" · "no_turn"
  - `placement` (object) — Present when the stop reached the owner's Mac: the chat runs there, so the Mac stops it.
    - `kind` (enum<string>) — "mac"
    - `machine` (string) — The Mac's name
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/interrupt \
  -H "Authorization: Bearer ast_..."
```

Example response (200 OK):

```json
{
  "status": "interrupting"
}
```

## Goals

### GET /sessions/{id}/goal

The session's standing goal, or null (scope: read)

A goal is an objective the session works toward on its own: after each turn settles, the platform grades the work against the goal's criteria and either takes another turn or stops. At most one goal per session.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `goal` (object | null, required)
    - `id` (string, required) — goal_…
    - `session` (string, required) — sess_…
    - `objective` (string, required)
    - `criteria` (object[], required)
      - `id` (string, required) — Stable within the goal, e.g. c1
      - `text` (string, required)
      - `command` (string) — Present when a shell command decides this criterion: it runs in the session's workspace after each iteration, and exit 0 means met. The grader cannot overturn it.
    - `criteria_source` (enum<string>, required) — Whether the caller supplied the criteria or the platform derived them from the objective — "user" · "derived"
    - `status` (enum<string>, required) — "active" · "paused" · "completed" · "stopped"
    - `stop_reason` (string | null, required) — Why a stopped goal stopped; null in every other status — "failed" · "max_iterations" · "spend_budget" · "token_budget" · "time_budget" · "no_progress" · "cleared" · "session_ended" · null
    - `iteration` (integer, required) — Self-started turns taken so far
    - `max_iterations` (integer, required)
    - `max_spend` (any | null, required)
    - `consumed_spend` (any, required) — What this session has spent since the goal started
    - `max_tokens` (integer | null, required) — Token ceiling for this goal; null = none
    - `consumed_tokens` (integer, required) — Uncached input plus output tokens over the session's metered model calls since the goal started, grading included. Calls on the session's own model subscription are not metered and not counted.
    - `deadline_at` (string | null, required)
    - `last_evaluation` (any | null, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/goal' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/goal

Set the session's goal, replacing any existing one (scope: write)

Work starts immediately — no separate message is needed, and sending one is not how a goal begins. Criteria are optional: omitted, they are derived from the objective so completion is always judged against an explicit list, which the response returns and PATCH can correct. A criterion given as { text, command } is decided by running the command in the session's workspace (exit 0 = met) instead of by the grader. A person's message always outranks the loop: while a turn is running the goal waits, and takes the turn after it. Grading is a model call billed to the session; with an empty wallet deriving criteria is refused with 402 insufficient_credits. Setting a goal stops the run the goal it replaces had started.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `objective` (string, required) — What the agent should work toward, in the user's words — max length 4000
- `criteria` ((string | object)[]) — Independently checkable requirements; omitted = derived from the objective
  - option 1 (string) — max length 500
  - option 2 (object)
    - `text` (string, required) — What the criterion requires, in words — max length 500
    - `command` (string) — Shell command run in the session's workspace; exit 0 means the criterion is met — max length 1000
- `max_iterations` (integer | null) — Self-started turns this goal may take before it stops. Omitted = 20; null = no iteration ceiling
- `max_no_progress` (integer | null) — Consecutive turns without a tool call before stopping. Omitted = 3; null = no no-progress ceiling
- `max_spend` (object | null) — Spend ceiling for this goal; null = none
  - `amount` (string, required) — Whole US cents as an integer decimal string, e.g. "500" for $5.00 — max length 15
  - `currency` ("USD", required)
- `max_tokens` (integer | null)
- `max_duration_minutes` (integer | null) — Wall-clock ceiling from the goal's start, extended by any time it spends paused

Responses:

- `201` — Created
  - `goal` (object, required)
    - `id` (string, required) — goal_…
    - `session` (string, required) — sess_…
    - `objective` (string, required)
    - `criteria` (object[], required)
      - `id` (string, required) — Stable within the goal, e.g. c1
      - `text` (string, required)
      - `command` (string) — Present when a shell command decides this criterion: it runs in the session's workspace after each iteration, and exit 0 means met. The grader cannot overturn it.
    - `criteria_source` (enum<string>, required) — Whether the caller supplied the criteria or the platform derived them from the objective — "user" · "derived"
    - `status` (enum<string>, required) — "active" · "paused" · "completed" · "stopped"
    - `stop_reason` (string | null, required) — Why a stopped goal stopped; null in every other status — "failed" · "max_iterations" · "spend_budget" · "token_budget" · "time_budget" · "no_progress" · "cleared" · "session_ended" · null
    - `iteration` (integer, required) — Self-started turns taken so far
    - `max_iterations` (integer, required)
    - `max_spend` (object | null, required)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `consumed_spend` (any, required) — What this session has spent since the goal started
    - `max_tokens` (integer | null, required) — Token ceiling for this goal; null = none
    - `consumed_tokens` (integer, required) — Uncached input plus output tokens over the session's metered model calls since the goal started, grading included. Calls on the session's own model subscription are not metered and not counted.
    - `deadline_at` (string | null, required)
    - `last_evaluation` (object | null, required)
      - `result` (enum<string>, required) — "satisfied" · "needs_revision" · "failed"
      - `explanation` (string, required)
      - `criteria` (object[], required)
        - `id` (string, required)
        - `met` (boolean, required)
        - `reason` (string, required)
        - `judged_by` (enum<string>) — What decided this criterion on this iteration — "grader" · "command"
      - `iteration` (integer, required)
      - `at` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/goal \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"objective":"Get the failing integration tests in packages/api passing without weakening them.","criteria":[{"text":"The integration tests pass","command":"cd packages/api && npm test"},"No test assertion was deleted, skipped, or loosened","The fix is in source, not in the tests"],"max_iterations":15,"max_spend":{"amount":"500","currency":"USD"},"max_tokens":2000000}'
```

### PATCH /sessions/{id}/goal

Edit the goal in place (scope: write)

A course correction for an active or paused goal, not a restart: the iteration count and spend already consumed carry over. Editing criteria marks them as the caller's. A completed or stopped goal returns 409; POST a new goal to start another outcome.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `objective` (string) — max length 4000
- `criteria` ((string | object)[])
  - option 1 (string) — max length 500
  - option 2 (object)
    - `text` (string, required) — What the criterion requires, in words — max length 500
    - `command` (string) — Shell command run in the session's workspace; exit 0 means the criterion is met — max length 1000
- `max_iterations` (integer | null)
- `max_no_progress` (integer | null)
- `max_spend` (object | null)
  - `amount` (string, required) — Whole US cents as an integer decimal string, e.g. "500" for $5.00 — max length 15
  - `currency` ("USD", required)
- `max_tokens` (integer | null)
- `max_duration_minutes` (integer | null)

Responses:

- `200` — OK
  - `goal` (object, required)
    - `id` (string, required) — goal_…
    - `session` (string, required) — sess_…
    - `objective` (string, required)
    - `criteria` (object[], required)
      - `id` (string, required) — Stable within the goal, e.g. c1
      - `text` (string, required)
      - `command` (string) — Present when a shell command decides this criterion: it runs in the session's workspace after each iteration, and exit 0 means met. The grader cannot overturn it.
    - `criteria_source` (enum<string>, required) — Whether the caller supplied the criteria or the platform derived them from the objective — "user" · "derived"
    - `status` (enum<string>, required) — "active" · "paused" · "completed" · "stopped"
    - `stop_reason` (string | null, required) — Why a stopped goal stopped; null in every other status — "failed" · "max_iterations" · "spend_budget" · "token_budget" · "time_budget" · "no_progress" · "cleared" · "session_ended" · null
    - `iteration` (integer, required) — Self-started turns taken so far
    - `max_iterations` (integer, required)
    - `max_spend` (object | null, required)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `consumed_spend` (any, required) — What this session has spent since the goal started
    - `max_tokens` (integer | null, required) — Token ceiling for this goal; null = none
    - `consumed_tokens` (integer, required) — Uncached input plus output tokens over the session's metered model calls since the goal started, grading included. Calls on the session's own model subscription are not metered and not counted.
    - `deadline_at` (string | null, required)
    - `last_evaluation` (object | null, required)
      - `result` (enum<string>, required) — "satisfied" · "needs_revision" · "failed"
      - `explanation` (string, required)
      - `criteria` (object[], required)
        - `id` (string, required)
        - `met` (boolean, required)
        - `reason` (string, required)
        - `judged_by` (enum<string>) — What decided this criterion on this iteration — "grader" · "command"
      - `iteration` (integer, required)
      - `at` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/goal \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"criteria":[{"text":"The integration tests pass","command":"cd packages/api && npm test"},"No test assertion was deleted, skipped, or loosened"]}'
```

### DELETE /sessions/{id}/goal

Clear the goal (scope: write)

Stops the loop for good with stop_reason "cleared", and interrupts the run the goal itself started if one is going. The record stays readable so the session can still report what it was working on; setting a new goal replaces it.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `goal` (object, required)
    - `id` (string, required) — goal_…
    - `session` (string, required) — sess_…
    - `objective` (string, required)
    - `criteria` (object[], required)
      - `id` (string, required) — Stable within the goal, e.g. c1
      - `text` (string, required)
      - `command` (string) — Present when a shell command decides this criterion: it runs in the session's workspace after each iteration, and exit 0 means met. The grader cannot overturn it.
    - `criteria_source` (enum<string>, required) — Whether the caller supplied the criteria or the platform derived them from the objective — "user" · "derived"
    - `status` (enum<string>, required) — "active" · "paused" · "completed" · "stopped"
    - `stop_reason` (string | null, required) — Why a stopped goal stopped; null in every other status — "failed" · "max_iterations" · "spend_budget" · "token_budget" · "time_budget" · "no_progress" · "cleared" · "session_ended" · null
    - `iteration` (integer, required) — Self-started turns taken so far
    - `max_iterations` (integer, required)
    - `max_spend` (object | null, required)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `consumed_spend` (any, required) — What this session has spent since the goal started
    - `max_tokens` (integer | null, required) — Token ceiling for this goal; null = none
    - `consumed_tokens` (integer, required) — Uncached input plus output tokens over the session's metered model calls since the goal started, grading included. Calls on the session's own model subscription are not metered and not counted.
    - `deadline_at` (string | null, required)
    - `last_evaluation` (object | null, required)
      - `result` (enum<string>, required) — "satisfied" · "needs_revision" · "failed"
      - `explanation` (string, required)
      - `criteria` (object[], required)
        - `id` (string, required)
        - `met` (boolean, required)
        - `reason` (string, required)
        - `judged_by` (enum<string>) — What decided this criterion on this iteration — "grader" · "command"
      - `iteration` (integer, required)
      - `at` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/goal \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/goal/pause

Stop driving the goal (scope: write)

Stops taking turns and interrupts the run the goal itself started, if one is going. A run a person started is left to finish; POST /sessions/{id}/interrupt stops that. Refused with 409 invalid_state unless the goal is active.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `goal` (object, required)
    - `id` (string, required) — goal_…
    - `session` (string, required) — sess_…
    - `objective` (string, required)
    - `criteria` (object[], required)
      - `id` (string, required) — Stable within the goal, e.g. c1
      - `text` (string, required)
      - `command` (string) — Present when a shell command decides this criterion: it runs in the session's workspace after each iteration, and exit 0 means met. The grader cannot overturn it.
    - `criteria_source` (enum<string>, required) — Whether the caller supplied the criteria or the platform derived them from the objective — "user" · "derived"
    - `status` (enum<string>, required) — "active" · "paused" · "completed" · "stopped"
    - `stop_reason` (string | null, required) — Why a stopped goal stopped; null in every other status — "failed" · "max_iterations" · "spend_budget" · "token_budget" · "time_budget" · "no_progress" · "cleared" · "session_ended" · null
    - `iteration` (integer, required) — Self-started turns taken so far
    - `max_iterations` (integer, required)
    - `max_spend` (object | null, required)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `consumed_spend` (any, required) — What this session has spent since the goal started
    - `max_tokens` (integer | null, required) — Token ceiling for this goal; null = none
    - `consumed_tokens` (integer, required) — Uncached input plus output tokens over the session's metered model calls since the goal started, grading included. Calls on the session's own model subscription are not metered and not counted.
    - `deadline_at` (string | null, required)
    - `last_evaluation` (object | null, required)
      - `result` (enum<string>, required) — "satisfied" · "needs_revision" · "failed"
      - `explanation` (string, required)
      - `criteria` (object[], required)
        - `id` (string, required)
        - `met` (boolean, required)
        - `reason` (string, required)
        - `judged_by` (enum<string>) — What decided this criterion on this iteration — "grader" · "command"
      - `iteration` (integer, required)
      - `at` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/goal/pause \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/goal/resume

Drive the goal again (scope: write)

Any wall-clock deadline moves out by the time the pause consumed. Refused with 409 invalid_state unless the goal is paused.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `goal` (object, required)
    - `id` (string, required) — goal_…
    - `session` (string, required) — sess_…
    - `objective` (string, required)
    - `criteria` (object[], required)
      - `id` (string, required) — Stable within the goal, e.g. c1
      - `text` (string, required)
      - `command` (string) — Present when a shell command decides this criterion: it runs in the session's workspace after each iteration, and exit 0 means met. The grader cannot overturn it.
    - `criteria_source` (enum<string>, required) — Whether the caller supplied the criteria or the platform derived them from the objective — "user" · "derived"
    - `status` (enum<string>, required) — "active" · "paused" · "completed" · "stopped"
    - `stop_reason` (string | null, required) — Why a stopped goal stopped; null in every other status — "failed" · "max_iterations" · "spend_budget" · "token_budget" · "time_budget" · "no_progress" · "cleared" · "session_ended" · null
    - `iteration` (integer, required) — Self-started turns taken so far
    - `max_iterations` (integer, required)
    - `max_spend` (object | null, required)
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `consumed_spend` (any, required) — What this session has spent since the goal started
    - `max_tokens` (integer | null, required) — Token ceiling for this goal; null = none
    - `consumed_tokens` (integer, required) — Uncached input plus output tokens over the session's metered model calls since the goal started, grading included. Calls on the session's own model subscription are not metered and not counted.
    - `deadline_at` (string | null, required)
    - `last_evaluation` (object | null, required)
      - `result` (enum<string>, required) — "satisfied" · "needs_revision" · "failed"
      - `explanation` (string, required)
      - `criteria` (object[], required)
        - `id` (string, required)
        - `met` (boolean, required)
        - `reason` (string, required)
        - `judged_by` (enum<string>) — What decided this criterion on this iteration — "grader" · "command"
      - `iteration` (integer, required)
      - `at` (string, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/goal/resume \
  -H "Authorization: Bearer ast_..."
```

## Participants

### GET /sessions/{id}/people

Everyone who may send the session turns (scope: read)

The owner, the members of its workspace when the session is visible to the workspace, and people listed with the right to prompt. These are the people a turn can name with @ and the session can be assigned to. Requires the right to prompt the session.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `people` (object[], required)
    - `user_id` (string, required)
    - `name` (string, required)
    - `email` (string, required)
    - `avatar_url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/people' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/presence

People who have the session open right now (scope: read)

Everyone whose open view refreshed its presence within the last 30 seconds, most recent first. Requires the right to prompt the session.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `people` (any[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/presence' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/presence

Say that you have the session open (scope: read)

Repeat about every 15 seconds while the session is on screen. Answers who else has it open. Requires the right to prompt the session.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `people` (object[], required)
    - `user_id` (string, required)
    - `name` (string, required)
    - `email` (string, required)
    - `avatar_url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/presence \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/assign

Who the session is assigned to (scope: read)

Requires the right to prompt the session.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `assignee` (any | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/assign' \
  -H "Authorization: Bearer ast_..."
```

### PUT /sessions/{id}/assign

Assign the session to someone who may use it, or clear it with null (scope: write)

Replaces any earlier assignment. The assignee sees the session as waiting on them until they open it and is sent a notice, unless they assigned it to themselves. Requires the right to prompt the session. 400 invalid_request when user_id is not someone who may use it; 503 not_available before the platform supports assignments.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `user_id` (string, required)

Responses:

- `200` — OK
  - `assignee` (any | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/assign \
  -H "Authorization: Bearer ast_..."
```

### DELETE /sessions/{id}/assign

Clear the session's assignment (scope: write)

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `assignee` (any | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/assign \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/mentions

Record the people your turn named with @ (scope: write)

Send the text of a turn you sent. Each "@Name" — a person's name or their email's local part — of someone who may use the session is recorded, asks for that person's attention in their task list until they open the session, and queues them a notice. Naming yourself is ignored. Requires the right to prompt the session.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `text` (string, required) — max length 100000

Responses:

- `200` — OK
  - `mentioned` (object[], required)
    - `user_id` (string, required)
    - `name` (string, required)
    - `email` (string, required)
    - `avatar_url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/mentions \
  -H "Authorization: Bearer ast_..."
```

## Handoff

### POST /sessions/{id}/handoff

Hand this session's context to another agent (scope: write)

Accepted immediately; the move runs in the background. Poll the `status_url` in the response (also sent as the `Location` header) until `status` is terminal, then talk to `target_session`. `target_agent` is an agent id or a catalog `@handle`; `llm` and `reasoningEffort` choose the new session's model and thinking level. `last_message_id` bounds how much history is carried; omitted = all of it. The `Idempotency-Key` header is required and dedupes retries.

Path parameters:

- `id` (string, required) — The source session id (sess_…)

Body (application/json):

- `target_agent` (string, required) — The agent to continue with: an agent id, or "@handle" for an agent from the catalog — max length 256
- `last_message_id` (string) — max length 256
- `llm` (string) — The new session's model; omitted = the target agent's model — max length 256
- `reasoningEffort` (enum<string> | null) — The new session's thinking level; omitted or null = the target agent's — "none" · "off" · "minimal" · "low" · "medium" · "high" · "xhigh" · "max" · "ultra"

Responses:

- `202` — Accepted — poll status_url
  - `handoff` (object, required) — `resolved_mode` is how the move was actually made: `native_fork` when source and target share a harness and the pod's own state could be forked, else `summary` — a written handover the target reads as history, never as instructions. `target_session` is null until the move completes.
    - `id` (string, required) — handoff_…
    - `source_session` (string | null)
    - `target_session` (string | null)
    - `conversation_vault_id` (string) — Optional vault bound by the platform to a first-party continuation. An identifier only; secret values are never returned.
    - `last_message_id` (string | null)
    - `target_agent` (string | null)
    - `status` (string, required) — Lowercased HandoffStatus: pending · checkpointing · provisioning · restoring · completed · retry_wait · failed · cancelled. Terminal: completed, failed, cancelled.
    - `resolved_mode` (enum<string>, required) — "native_fork" · "summary"
    - `resolution_reason` (string | null)
    - `hands` (string | null) — `carry` copies the source's workspace files into the new session's sandbox; `attach` keeps the source's sandbox under the new agent — "carry" · "attach" · null
    - `workspace_carried` (boolean | null) — For `carry`: whether the workspace files were copied. False when the source sandbox was too old to export them; the conversation still moved
    - `workspace_folder` (string | null) — For a Mac-synced chat its owner continued: where the folder the Mac stored was restored in the new session. Null otherwise
    - `checkpoint` (object | null) — What was carried across, without its content
    - `summary` (object | null) — What was carried across, without its content
    - `error` (object | null)
    - `status_url` (string, required) — GET it to poll the move
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/handoff \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/local-handoff

Continue this session on your own computer (scope: write)

For an idle Claude Code or Codex session, by its owner only. Accepted immediately; poll `status_url` until `status` is terminal. On `completed` the session's native conversation can be downloaded from `GET /session-handoffs/{id}/checkpoint` and, when `workspace_carried` is true, its workspace from `GET /session-handoffs/{id}/workspace`; resume it with the same CLI on that computer. The session is then marked `continuedOnMac`. Until a computer downloads the checkpoint the mark has no `claimedAt` and the session still belongs to the cloud: a request from another computer joins this move, and a new turn in the cloud releases it. The first download sets `claimedAt`; the session then refuses new turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`. The `Idempotency-Key` header is required and dedupes retries. Refusals: 403 `owner_only`; 409 `harness_unsupported`, `runs_on_mac`, `continued_on_mac`, `session_archived`, `session_running`, `source_unavailable`.

Path parameters:

- `id` (string, required) — The source session id (sess_…)

Body (application/json):

- `machine` (string) — The computer's label, e.g. its hostname, shown where the chat now continues — max length 120

Responses:

- `202` — Accepted — poll status_url
  - `handoff` (object, required) — `resolved_mode` is how the move was actually made: `native_fork` when source and target share a harness and the pod's own state could be forked, else `summary` — a written handover the target reads as history, never as instructions. `target_session` is null until the move completes.
    - `id` (string, required) — handoff_…
    - `source_session` (string | null)
    - `target_session` (string | null)
    - `conversation_vault_id` (string) — Optional vault bound by the platform to a first-party continuation. An identifier only; secret values are never returned.
    - `last_message_id` (string | null)
    - `target_agent` (string | null)
    - `status` (string, required) — Lowercased HandoffStatus: pending · checkpointing · provisioning · restoring · completed · retry_wait · failed · cancelled. Terminal: completed, failed, cancelled.
    - `resolved_mode` (enum<string>, required) — "native_fork" · "summary"
    - `resolution_reason` (string | null)
    - `hands` (string | null) — `carry` copies the source's workspace files into the new session's sandbox; `attach` keeps the source's sandbox under the new agent — "carry" · "attach" · null
    - `workspace_carried` (boolean | null) — For `carry`: whether the workspace files were copied. False when the source sandbox was too old to export them; the conversation still moved
    - `workspace_folder` (string | null) — For a Mac-synced chat its owner continued: where the folder the Mac stored was restored in the new session. Null otherwise
    - `checkpoint` (object | null) — What was carried across, without its content
    - `summary` (object | null) — What was carried across, without its content
    - `error` (object | null)
    - `status_url` (string, required) — GET it to poll the move
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/local-handoff \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/return-to-cloud

Bring a session continued on a computer back to the cloud (scope: write)

By the session's owner only. Removes the `continuedOnMac` mark, so the session takes turns again from where the cloud last left it. Anything done on the computer since stays there; AgentSky for Mac makes its copy read-only once it hears. To carry that work back instead, use Continue in the cloud in the Mac app. Idempotent: a session with no mark answers as it is. Refusals: 403 `owner_only`; 404 `not_found`; 409 `session_archived`.

Path parameters:

- `id` (string, required) — The source session id (sess_…)

Responses:

- `200` — The session, back in the cloud
  - `session` (object, required)
    - `id` (string) — sess_… identifier
    - `agentId` (string | null) — The agent id (agent_…)
    - `title` (string | null)
    - `updatedAt` (string) — When the session last changed.
    - `status` (enum<string>) — provisioning = the sandbox is booting or installing the environment's packages (a turn sent meanwhile waits for it); running = a turn is in flight; terminated = archived or the last runtime was destroyed. Use archived for the durable archive receipt — "provisioning" · "idle" · "running" · "terminated"
    - `provisioningStage` (string | null) — Which part of its boot the session's computer is in, as the platform observed it: creating_computer until the sandbox provider reports the computer exists, then starting_agent until the agent in it answers. A provider that does not report the computer's creation stays at creating_computer. Null once the computer is up and whenever it is not booting. — "creating_computer" · "starting_agent" · null
    - `archived` (boolean) — True only after this Session's archive mark was durably written; false for an active Session whose runtime was destroyed
    - `agentType` (string)
    - `llm` (string) — The model this session runs on (PATCH to change; the agent's model is unchanged)
    - `harnessVersion` (string) — Harness release the session runs: the one its serving pod booted, the restored checkpoint's for a native-fork handoff, the agent's pin for ACP harnesses, otherwise the current release
    - `reasoningEffort` (string | null) — The model-compatible effort resolved from the session pin, then agent pin. Constrained models use an allowed fallback; no-setting models return null. Unpinned unconstrained models return null for the harness default.
    - `subscriptionApiFallback` (boolean) — Paid API continuation once no subscription account can run the task, preserving the same supported explicit model and wallet/budget gates. On unless set to false
    - `modelBilling` (enum<string>) — Who pays for model calls: platform wallet or the user's connected subscription — "platform" · "account"
    - `idleTimeoutSeconds` (integer | null) — Seconds the session's machine stays awake after a turn ends before it is paused; null = the platform default of 60. Set it when people use apps on the session's exposed ports after the agent finishes
    - `browserProfile` (string) — Resolved browser: the session's choice, then the agent's default, then mine. mine is the browser of the person whose turn it is; fresh is signed out; user:<user id> is the sites that person shared with whoever runs the turn. Applied before the next browser turn when browser profiles are enabled.
    - `browserLoginsSavedAt` (string | null) — Most recent browser login save-back time, or null when this session has not saved changed logins.
    - `routineId` (string | null) — The routine whose run started this session, or null for any other session
    - `ownerId` (string) — The member who owns this session, as user_id in GET /universes/{slug}/members
    - `default` (boolean) — Is this the agent's default session
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `metadata` (object)
    - `budget` (object | null) — Hard spend cap, or null when the session has none. A reached budget pauses the session (402 budget_reached on new work) until the cap is raised above consumed_cost or removed — removal is one-way.
    - `parentSessionId` (string | null) — The session this one came from: a helper names the session that hired it, a handoff child names the session it continued; null for a root. Every session a task's root produced, with its role, is GET /tasks/{id}?by=session on any member's id.
    - `parentRelation` (string | null) — How this session relates to parentSessionId: `helper` was hired by it (actl hire or the orchestration API), `handoff` continued its conversation on another agent; null for a root. — "helper" · "handoff" · null
    - `resources` (object[]) — The files, GitHub repositories, and read-only memory stores mounted into the session, oldest first
      - option 1 (object)
        - `type` (enum<string>, required) — "file"
        - `id` (string, required) — sesrsc_…
        - `file_id` (string, required) — The per-session copy (file_…), read-only at mount_path
        - `mount_path` (string, required) — Absolute, under /workspace
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 2 (object)
        - `type` (enum<string>, required) — "github_repository"
        - `id` (string, required) — sesrsc_…
        - `url` (string, required) — https://github.com/{owner}/{repo}
        - `mount_path` (string, required) — Absolute, under /workspace; the clone's root
        - `checkout` (object) — {type:"branch", name} or {type:"commit", sha}; absent = the default branch
          - `type` (enum<string>) — "branch" · "commit"
          - `name` (string)
          - `sha` (string)
        - `created_at` (string, required)
        - `updated_at` (string, required)
      - option 3 (object)
        - `type` (enum<string>, required) — "memory_store"
        - `id` (string, required) — smsr_…
        - `memory_store_id` (string, required) — memstore_…
        - `mount_path` (string, required) — Absolute, under /mnt/memory
        - `access` (enum<string>, required) — "read_only" · "read_write"
        - `instructions` (string) — Optional per-session guidance
        - `created_at` (string, required)
        - `updated_at` (string, required)
    - `workspaceDefaults` (object | null) — What the session started with because its workspace made it a default; everything else it carries was named at creation. Null when it took nothing.
    - `contextFiles` (object | null) — The workspace files the session loaded into its instructions when its sandbox was last provisioned (GET /workspace-context describes the set); null before that and for a session without its workspace's store. Every other file in the store is read on demand.
    - `continuedOnMac` (object) — Present when the owner moved this session to their own computer. Without `claimedAt` no computer has taken it yet, and a new turn here releases the move. With `claimedAt` the session refuses turns with 409 `continued_on_mac` until `POST /sessions/{id}/return-to-cloud`.
      - `handoffId` (string, required)
      - `at` (string, required)
      - `machine` (string)
      - `claimedAt` (string)
    - `localControl` (object) — Present on a synced chat that runs on the caller's own Mac. `state` is `running`, `waiting_for_you` (a command waits for an answer), `idle`, or `unknown` while the Mac is offline, so a run is never shown as running from an offline Mac. `controllable` is the Mac's side only: each device or key still needs its own pairing (`POST /desktop/machines/{id}/controllers`), checked on every stop and answer. When false, `reason` is `mac_offline`, `phone_control_off` (turned off on the Mac), `terminal_session` (started in Terminal; read-only here) or `older_mac_app` (no Mac has reported its chats).
      - `mac` (object | null, required)
      - `state` (enum<string>, required) — "running" · "waiting_for_you" · "idle" · "unknown"
      - `controllable` (boolean, required)
      - `reason` (enum<string>) — "mac_offline" · "phone_control_off" · "terminal_session" · "older_mac_app"
      - `limit` (object) — The plan limit this chat's last run on the Mac reported: the same state the Mac shows above the composer. Absent until a run reports one and while the Mac is offline.
        - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `window` (string | null, required)
        - `utilization` (number | null, required)
        - `resetsAt` (string | null, required)
      - `pressure` (object) — This Mac's disk, memory and battery as it last reported them. Absent while the Mac is offline.
        - `disk` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
          - `freeBytes` (integer | null, required)
        - `memory` (object)
          - `level` (enum<string>, required) — "ok" · "warn" · "critical"
        - `battery` (object)
          - `percent` (number, required)
          - `charging` (boolean, required)
    - `hostedBySeller` (object) — Present only when the session runs on its agent's maker's own server instead of a sandbox: what is sent to the session goes to this host. `agentType` and `llm` then name a stand-in that never runs.
      - `host` (string, required)
    - `attachments` (object[]) — Everything the session started with: its environment, vaults, mounted files and memory stores, and the workspace's always-available skills. The skills of the session's agent are on the agent and are not repeated here.
      - `type` (enum<string>, required) — "environment" · "vault" · "file" · "skill" · "memory_store"
      - `id` (string, required) — The id of the environment, vault, file, skill or memory store
      - `mountPath` (string | null, required) — Where a file or memory store is mounted; null for the other types
      - `source` (enum<string>, required) — default = the workspace supplied it; explicit = it was named when the session was created. A memory store on a session created before 2026-10-06 reads as explicit — "default" · "explicit"
    - `createdAt` (string) — ISO 8601
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/return-to-cloud \
  -H "Authorization: Bearer ast_..."
```

### GET /session-handoffs/{id}/checkpoint

Download a local handoff's native conversation (scope: read)

The `asteroids.native-checkpoint` v1 ZIP of a completed local handoff, to its owner only: the CLI's own session files under its state folder layout (`projects/` for Claude Code, `sessions/` and `codex-thread.json` for Codex), with a manifest of every file's size and SHA-256. 409 `handoff_not_ready` until it completes; 410 `archive_gone` when it is no longer stored.

Path parameters:

- `id` (string, required) — The handoff id (handoff_…), as returned by POST /sessions/{id}/handoff

Responses:

- `200` — The checkpoint ZIP
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/session-handoffs/sess_cmtb7q2j/checkpoint' \
  -H "Authorization: Bearer ast_..."
```

### GET /session-handoffs/{id}/workspace

Download a local handoff's workspace (scope: read)

The sandbox's workspace as a gzipped tar, for a completed local handoff that carried it, to its owner only. 404 `workspace_not_carried` when it was not copied; 409 `handoff_not_ready` until it completes.

Path parameters:

- `id` (string, required) — The handoff id (handoff_…), as returned by POST /sessions/{id}/handoff

Responses:

- `200` — The workspace archive
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/session-handoffs/sess_cmtb7q2j/workspace' \
  -H "Authorization: Bearer ast_..."
```

### GET /session-handoffs/{id}

The progress of one handoff (scope: read)

Path parameters:

- `id` (string, required) — The handoff id (handoff_…), as returned by POST /sessions/{id}/handoff

Responses:

- `200` — OK
  - `handoff` (object, required) — `resolved_mode` is how the move was actually made: `native_fork` when source and target share a harness and the pod's own state could be forked, else `summary` — a written handover the target reads as history, never as instructions. `target_session` is null until the move completes.
    - `id` (string, required) — handoff_…
    - `source_session` (string | null)
    - `target_session` (string | null)
    - `conversation_vault_id` (string) — Optional vault bound by the platform to a first-party continuation. An identifier only; secret values are never returned.
    - `last_message_id` (string | null)
    - `target_agent` (string | null)
    - `status` (string, required) — Lowercased HandoffStatus: pending · checkpointing · provisioning · restoring · completed · retry_wait · failed · cancelled. Terminal: completed, failed, cancelled.
    - `resolved_mode` (enum<string>, required) — "native_fork" · "summary"
    - `resolution_reason` (string | null)
    - `hands` (string | null) — `carry` copies the source's workspace files into the new session's sandbox; `attach` keeps the source's sandbox under the new agent — "carry" · "attach" · null
    - `workspace_carried` (boolean | null) — For `carry`: whether the workspace files were copied. False when the source sandbox was too old to export them; the conversation still moved
    - `workspace_folder` (string | null) — For a Mac-synced chat its owner continued: where the folder the Mac stored was restored in the new session. Null otherwise
    - `checkpoint` (object | null) — What was carried across, without its content
    - `summary` (object | null) — What was carried across, without its content
    - `error` (object | null)
    - `status_url` (string, required) — GET it to poll the move
    - `created_at` (string, required)
    - `updated_at` (string, required)
    - `completed_at` (string | null)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/session-handoffs/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

## Session record

### GET /sessions/{id}/threads

The threads of this session's task (scope: read)

The root session first (relation primary, parent_id null), then every member the caller may see, oldest first: helper (a pod created it), handoff (a handoff branched it), child (a client recorded it). Each thread names its source (cloud, local_mirror, imported, tycoon), its agent's harness and model, its status, and what it has spent. A session nothing created is a task of one and lists itself. See docs/asteroids/architecture/session-record.md.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `threads` (object[])
    - `id` (string)
    - `parent_id` (string)
    - `root_id` (string)
    - `relation` (enum<string>) — "primary" · "helper" · "handoff" · "child"
    - `source` (enum<string>) — "cloud" · "local_mirror" · "imported" · "tycoon"
    - `agent` (object)
      - `id` (string)
      - `harness` (string)
      - `model` (string)
    - `status` (string)
    - `title` (string)
    - `usage` (object)
      - `spent_usd_micros` (string)
      - `tool_calls` (integer)
    - `environment` (object) — repo, commit, branch, instructions_hash, digest, cwd — as the creating client recorded them in metadata.environment
      - `repo` (string)
      - `commit` (string)
      - `branch` (string)
      - `instructions_hash` (string)
      - `digest` (string)
      - `cwd` (string)
    - `created_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/threads' \
  -H "Authorization: Bearer ast_..."
```

Example response (200 OK):

```json
{
  "threads": [
    {
      "id": "sess_cmtb7q2j",
      "parent_id": null,
      "root_id": "sess_cmtb7q2j",
      "relation": "primary",
      "source": "cloud",
      "agent": {
        "id": "agent_cmtb2f0a8m9k7x51q4ez6r0d",
        "harness": "claude_code",
        "model": "claude-opus-5-5"
      },
      "status": "idle",
      "title": "Fix the billing flow",
      "usage": {
        "spent_usd_micros": "184000",
        "tool_calls": 42
      },
      "environment": {
        "repo": "https://github.com/acme/site",
        "commit": "9f3c2a1",
        "branch": "main",
        "instructions_hash": "sha256:1c8e…"
      },
      "created_at": "2026-10-20T10:00:00.000Z"
    },
    {
      "id": "sess_cmtb8r3k",
      "parent_id": "sess_cmtb7q2j",
      "root_id": "sess_cmtb7q2j",
      "relation": "helper",
      "source": "cloud",
      "agent": {
        "id": "agent_cmtb2f0a8m9k7x51q4ez6r0d",
        "harness": "codex",
        "model": "gpt-6"
      },
      "status": "idle",
      "title": "Review the patch",
      "usage": {
        "spent_usd_micros": "21000",
        "tool_calls": 7
      },
      "environment": null,
      "created_at": "2026-10-20T10:04:12.000Z"
    }
  ]
}
```

### GET /sessions/{id}/record

The session record: decisions and outcomes written about this session (scope: read)

The human.decision and outcome.observed events of this session, oldest first — the same rows GET /sessions/{id}/events returns with types[]=human.decision&types[]=outcome.observed, without the rest of the transcript.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `events` (object[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/record' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/record

Record a decision about this session's result, or what became of it (scope: write)

Writes one mark on the session; never a turn, never a status change. `type` human.decision takes payload {kind: adopt|rerun|revise|discard|vote|did_the_job|approve, target_session_id?, value? (required for did_the_job and approve), reason? (≤2000 chars), surface?}; a human.decision written with an API key comes back with `actor.agent: true` and never counts as a person's decision; For a Mac Create PR adoption, optional `payload.github_pr` takes {url, head_sha, export_receipt}; the receipt comes from workspace/patch with record_provenance: true and is verified against the exact GitHub result before storing provenance. `type` outcome.observed takes {kind: pr_merged|deployed|reopened|later_failure|shipped, ref? (≤500 chars), observer?}. An Idempotency-Key header makes a repeat answer 200 with the same event; without one, the same decision by the same caller within a minute lands once. 404 when the session, or a named target_session_id, is not one the caller can see. Nothing writes a decision on a person's behalf: a session without one is undecided.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `type` (enum<string>, required) — "human.decision" · "outcome.observed"
- `payload` (object, required)

Responses:

- `200` — Already recorded
  - `event` (object)
- `201` — Created
  - `event` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/record \
  -H "Authorization: Bearer ast_..."
```

Example response (201 Created):

```json
{
  "event": {
    "id": "record:human.decision:pr-9",
    "rowId": 57,
    "sessionId": "sess_cmtb7q2j",
    "type": "human.decision",
    "at": "2026-10-20T10:31:02.000Z",
    "kind": "adopt",
    "target_session_id": null,
    "value": null,
    "reason": "Used this patch as is",
    "surface": "mac",
    "actor": {
      "userId": "cmtb3u5r7k2p9x01s6q8n4w2"
    }
  }
}
```

### GET /record/agents

Agent performance as the session record tells it (scope: read)

For every harness and model the caller's visible sessions ran on, created between `since` and `until` (default the last 30 days): sessions and their sources; decisions people recorded (adopted; votes won, lost and undecided; rerun, revise, discard; did_the_job and approve yes/no); outcomes by kind; sessions nobody decided on; total and median spend in USD micros. A read model rebuilt on each request from the record marks — nothing is stored, nothing is inferred: a session without a human.decision is undecided. See docs/asteroids/architecture/session-record.md.

Query parameters:

- `since` (string) — Default: 30 days before until
- `until` (string) — Default: now

Responses:

- `200` — OK
  - `since` (string)
  - `until` (string)
  - `agents` (object[])
    - `key` (string)
    - `agent_id` (string)
    - `harness` (string)
    - `model` (string)
    - `sessions` (integer)
    - `by_source` (object)
    - `decisions` (object)
    - `outcomes` (object)
    - `undecided_sessions` (integer)
    - `spend` (object)
      - `total_usd_micros` (string)
      - `median_usd_micros` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/record/agents' \
  -H "Authorization: Bearer ast_..."
```

Example response (200 OK):

```json
{
  "since": "2026-09-20T00:00:00.000Z",
  "until": "2026-10-20T00:00:00.000Z",
  "agents": [
    {
      "key": "claude_code:claude-opus-5-5",
      "agent_id": "agent_cmtb2f0a8m9k7x51q4ez6r0d",
      "harness": "claude_code",
      "model": "claude-opus-5-5",
      "sessions": 42,
      "by_source": {
        "cloud": 30,
        "local_mirror": 12
      },
      "decisions": {
        "adopted": 9,
        "won": 14,
        "lost": 6,
        "undecided_votes": 3,
        "rerun": 4,
        "revise": 7,
        "discard": 1,
        "did_the_job": {
          "yes": 11,
          "no": 2
        },
        "approved": {
          "yes": 0,
          "no": 0
        }
      },
      "outcomes": {
        "pr_merged": 5,
        "reopened": 1
      },
      "undecided_sessions": 12,
      "spend": {
        "total_usd_micros": "18400000",
        "median_usd_micros": "310000"
      }
    }
  ]
}
```

## Tasks

### GET /tasks/{id}/graph

A task's events and inferred cross-thread associations (scope: read)

Includes events sharing exact file hashes, document identities or conversation threads with the task. Inferred links always carry confidence and evidence, and never grant source access. Corrections are personal. Follow next_cursor until null; each page is ordered by occurred_at and event id.

Path parameters:

- `id` (string, required)

Query parameters:

- `cursor` (string)
- `limit` (integer)
- `related` (boolean) — Only inferred or confirmed associations

Responses:

- `200` — One page of the graph
  - `task_id` (string)
  - `next_cursor` (string | null)
  - `data` (object[])
    - `event` (object)
      - `id` (string) — evt_…, time-ordered
      - `log` (enum<string>) — The caller's private log, or the workspace's shared log — "person" · "workspace"
      - `kind` (string) — Dotted event type, e.g. session.message, taskfile.version_created, artifact.revised, result.obtained
      - `occurred_at` (string)
      - `recorded_at` (string)
      - `clock_source` (enum<string>) — "server" · "device" · "platform"
      - `skew_ms` (integer | null)
      - `actor` (object) — {kind: person|agent|teammate|guest|external|system, user_id?, session_id?, platform_user?}
      - `surface` (string) — web, mac, api, pod, channel:<platform>, connector:<app>…
      - `source` (object)
        - `system` (string)
        - `kind` (string)
        - `version` (string | null)
      - `objects` (object[]) — Every object the event touched: sha256 of file contents, documents, sessions, messages
        - `type` (string)
        - `id` (string)
        - `role` (string)
      - `payload` (object | null)
      - `payload_sha256` (string | null) — Set when the payload was large and is read through /events/{id}/body?part=payload
      - `payload_removed_at` (string | null)
      - `provenance` (object | null)
      - `correlation` (object) — Explicit links: task_id, session_id, thread, calendar event, PR…
      - `task_id` (string | null)
      - `session_id` (string | null)
    - `link` (object)
      - `kind` (enum<string>) — "explicit" · "inferred" · "confirmed"
      - `confidence` (number)
      - `pinned` (boolean)
      - `version` (integer)
      - `evidence` (object[])
        - `type` (string)
        - `id` (string)
        - `reason` (string)
        - `confidence` (number) — Association score, not a calibrated probability
        - `shared_tasks` (integer) — Distinct visible tasks sharing this identity
- `400` — Invalid query or correction
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — A person's identity is required for corrections
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Task or source event is unavailable to the caller
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — The link changed; refresh and use its current version
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Associations are not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/graph' \
  -H "Authorization: Bearer ast_..."
```

### POST /tasks/{id}/graph/edges

Confirm, remove or move an event's task association (scope: write)

Changes only the caller's task view and appends an edge.corrected audit event. Does not move the source event or share it. A move confirms the destination and excludes the source, atomically, within one workspace. expected_version is the current link version (0 before any correction).

Path parameters:

- `id` (string, required)

Body (application/json):

- `event_id` (string, required)
- `action` (enum<string>, required) — "confirm" · "remove" · "move"
- `expected_version` (integer, required)
- `target_task_id` (string) — Required only for move

Responses:

- `200` — The updated associations and their versions
- `400` — Invalid query or correction
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Authentication required
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — A person's identity is required for corrections
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Task or source event is unavailable to the caller
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — The link changed; refresh and use its current version
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Associations are not migrated yet
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/graph/edges \
  -H "Authorization: Bearer ast_..."
```

### GET /tasks/{id}/subscriptions

The threads a ticket follows (scope: read)

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `subscriptions` (object[], required)
    - `surface` (string, required)
    - `thread_key` (string, required)
    - `kind` (enum<string>, required) — "work" · "context"
    - `role` (enum<string>, required) — "origin" · "discussion" · "evidence"
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/subscriptions' \
  -H "Authorization: Bearer ast_..."
```

### POST /tasks/{id}/subscriptions

Attach a thread to a ticket (scope: write)

work lets a person's message reach the ticket; context is information only and lends no authority.

Path parameters:

- `id` (string, required)

Body (application/json):

- `surface` (string, required)
- `thread_key` (string, required)
- `kind` (enum<string>, required) — "work" · "context"
- `role` (enum<string>) — "origin" · "discussion" · "evidence"

Responses:

- `201` — Attached
  - `subscriptions` (object[], required)
    - `surface` (string, required)
    - `thread_key` (string, required)
    - `kind` (enum<string>, required) — "work" · "context"
    - `role` (enum<string>, required) — "origin" · "discussion" · "evidence"
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/subscriptions \
  -H "Authorization: Bearer ast_..."
```

### DELETE /tasks/{id}/subscriptions

Detach a thread from a ticket (scope: write)

Path parameters:

- `id` (string, required)

Query parameters:

- `surface` (string, required)
- `thread_key` (string, required)

Responses:

- `204` — Detached
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/subscriptions \
  -H "Authorization: Bearer ast_..."
```

### GET /tasks

List the workspace's tasks (scope: read)

Most recent activity first. Helper and handoff sessions are counted inside their task and never listed on their own.

Query parameters:

- `mine` (string) — 1 keeps the caller's own tasks and leaves out teammates'
- `attention` (string) — Return only tasks in this state
- `archived` (string) — `false` leaves out tasks whose root session is archived
- `limit` (integer) — Read only the tasks of this many most recently changed sessions. Without `limit` or `session_id[]`, every task of the workspace is read
- `session_id[]` (array) — Read the tasks of these sessions, with `limit` if given
- `include` (string) — `requests` adds `requests` to each task, its open requests for the caller as `GET /tasks/{id}` lists them, and `failure`: the latest turn that ran out of retries and the caller has not looked at since ({session_id, message, at}), or null. A failure the caller has not seen makes the task and that session read `needs_you` unless the task is working or already asking, and marks that session `failed`

Responses:

- `200` — OK
  - `tasks` (object[], required)
    - `id` (string, required) — sess_… — the root session's id
    - `title` (string | null, required)
    - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
    - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
    - `open_request_count` (integer, required) — Open requests addressed to the caller
    - `session_count` (integer, required) — The root session plus its helper and handoff sessions
    - `sessions` (object[], required) — Every session in the task, root first, each with its own share of the state: its own open requests, its own run and its own latest result, measured against the task's seen mark.
      - `id` (string, required) — sess_…
      - `role` (enum<string>, required) — "primary" · "helper" · "handoff"
      - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
      - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
      - `attention_reason` (string) — Why this session's latest turn reads as it does, when a judgment of that turn gave a reason.
      - `failed` (boolean) — `GET /tasks` only: this session's latest run ran out of retries after the caller last looked, and that failure is why the task reads `needs_you` (nothing is running and nothing else asks the caller). Its `status_line` is the failure's message
    - `agent_id` (string | null, required) — The root session's agent (agent_…)
    - `agent_type` (string, required)
    - `llm` (string, required)
    - `archived` (boolean, required)
    - `last_activity_at` (string, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks' \
  -H "Authorization: Bearer ast_..."
```

### GET /tasks/{id}

One task with its sessions, open requests and cost (scope: read)

By default the id must name a task root. With by=session, resolves an accessible helper or handoff session to its containing task; both the member and root must be accessible.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Query parameters:

- `by` (string) — Resolve this session to its existing task root.

Responses:

- `200` — OK
  - `task` (object, required)
    - `id` (string, required) — sess_… — the root session's id
    - `title` (string | null, required)
    - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
    - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
    - `open_request_count` (integer, required) — Open requests addressed to the caller
    - `session_count` (integer, required) — The root session plus its helper and handoff sessions
    - `sessions` (object[], required) — The root first, then the others in the order they joined
      - `id` (string, required) — sess_…
      - `role` (enum<string>, required) — "primary" · "helper" · "handoff"
      - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
      - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
      - `title` (string | null, required)
      - `status` (enum<string>, required) — "provisioning" · "idle" · "running" · "terminated"
      - `agent_id` (string | null, required)
      - `agent_type` (string, required)
      - `llm` (string, required)
      - `consumed_cost` (object, required) — A US-dollar amount. `amount` is whole US cents as an integer decimal string — "125" is $1.25 — rounded half-up to the cent.
        - `amount` (string, required) — Whole US cents
        - `currency` (enum<string>, required) — "USD"
        - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
        - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
      - `model_paid_by` (object) — Who pays for the model in this session: the wallet, or the caller's own account at a vendor. Runtime is charged to the wallet either way. Present where external accounts are turned on.
        - `source` (enum<string>, required) — "wallet" · "account"
        - `vendor` (string)
        - `name` (string)
      - `created_at` (string, required)
    - `agent_id` (string | null, required) — The root session's agent (agent_…)
    - `agent_type` (string, required)
    - `llm` (string, required)
    - `archived` (boolean, required)
    - `last_activity_at` (string, required)
    - `created_at` (string, required)
    - `consumed_cost` (object, required) — Billed cost summed over every session in the task, a paid agent's flat fee included
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `completion_answer` (object | null, required) — What the caller said about whether this task did the job; null until they answer. Other people's answers are not shown.
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `agent_fees` (object[]) — The flat fees of paid agents in this task. Present only when the task has one.
      - `session_id` (string, required)
      - `handle` (string, required)
      - `fee` (object, required)
        - `amount` (string, required) — Whole US cents
        - `currency` (enum<string>, required) — "USD"
      - `status` (enum<string>, required) — `held`: set aside from the caller's credit when the task started. `captured`: taken, on the task's first result. `released`: given back because the task was archived or deleted without a result. `disputed`, `refunded`: see the dispute route. — "awaiting_confirmation" · "declined" · "held" · "captured" · "disputed" · "released" · "refunded"
      - `dispute_until` (string | null, required) — Until when the caller may say the task was not completed; null unless the fee is captured and undisputed
      - `dispute` (object | null, required) — What the caller said and how it was ruled; null when the fee was never disputed.
    - `requests` (object[], required) — Open requests addressed to the caller, oldest first. Answer one by sending its reply to `session_id` as a message, exactly as a question is answered in that session.
      - `id` (string, required) — The request id the agent or the platform assigned
      - `session_id` (string, required) — The session that is waiting (sess_…)
      - `message_id` (string, required)
      - `kind` (enum<string>, required) — `question`: an agent asked. `approval`: a tool needs the caller's go-ahead before it runs (options `allow`, `deny`), or a workspace rule asks for it before the task itself starts (options `confirm`, `decline`; nothing has run, and declining archives the task), or a skill or lesson change suggested after the task finished awaits the workspace's owner or an admin (options `approve`, which writes it for the whole workspace, and `decline`; nothing is sent to the agent). `connect_app`: the agent needs an app that is not connected; it resolves by itself when the caller connects the app, or by answering `skip`. `connect_account`: the task cannot run without the caller's own account at a vendor, or that account has no usage left; what the caller sent is kept and nothing has run. It resolves by itself when the account is connected (`POST /external_accounts`), or by answering `use_wallet` (offered only when the account is exhausted or expired and the task can run on a platform model) or `wait`. `spend`: an agent whose maker asks a flat fee is about to be used for the first time at that price, either as this task's own agent (nothing has run, and nothing runs until it is answered) or as a helper an agent in the task wants to hire. Answer `confirm` or `decline`; a confirmation is remembered for that agent at that price. `browser_handoff`: the agent stopped in its own browser at something only the caller can do (a CAPTCHA, a two-step code, a sign-in or consent screen); the caller takes over the browser (`GET`/`POST /sessions/{id}/browser-handoff`), then answers `done` to hand it back or `skip` to tell the agent it could not be done. — "question" · "approval" · "connect_app" · "connect_account" · "spend" · "browser_handoff"
      - `subject` (string | null, required) — For `connect_app`, the app's slug; for `connect_account`, the vendor; for `spend`, the agent's handle; for `browser_handoff`, the site the browser is on
      - `question` (string, required)
      - `options` (object[], required)
        - `id` (string, required)
        - `label` (string, required)
        - `description` (string)
      - `allow_free_text` (boolean, required)
      - `expected_question` (object) — For file input only: pass this exact saved question with file_ids when answering.
      - `input` (object)
        - `type` ("files", required)
        - `multiple` (boolean)
      - `required_user_id` (string | null, required) — Set when only one person may answer
      - `due_at` (string | null, required)
      - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### POST /tasks/{id}/seen

Mark the task seen by the caller (scope: write)

Records that the caller has looked at the task now, so a result that already arrived stops reading as `done` for them. Optional session_ids scopes the read to those task members; other members keep their unread results. Other people's view is unchanged. Answers 503 `not_available` until the platform's task tables are in place.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Body (application/json):

- `session_ids` (string[]) — Only these task members are marked seen; omitted marks all current members. — max length 256

Responses:

- `200` — OK
  - `task` (object, required)
    - `id` (string, required) — sess_… — the root session's id
    - `title` (string | null, required)
    - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
    - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
    - `open_request_count` (integer, required) — Open requests addressed to the caller
    - `session_count` (integer, required) — The root session plus its helper and handoff sessions
    - `sessions` (object[], required) — The root first, then the others in the order they joined
      - `id` (string, required) — sess_…
      - `role` (enum<string>, required) — "primary" · "helper" · "handoff"
      - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
      - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
      - `title` (string | null, required)
      - `status` (enum<string>, required) — "provisioning" · "idle" · "running" · "terminated"
      - `agent_id` (string | null, required)
      - `agent_type` (string, required)
      - `llm` (string, required)
      - `consumed_cost` (object, required) — A US-dollar amount. `amount` is whole US cents as an integer decimal string — "125" is $1.25 — rounded half-up to the cent.
        - `amount` (string, required) — Whole US cents
        - `currency` (enum<string>, required) — "USD"
        - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
        - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
      - `model_paid_by` (object) — Who pays for the model in this session: the wallet, or the caller's own account at a vendor. Runtime is charged to the wallet either way. Present where external accounts are turned on.
        - `source` (enum<string>, required) — "wallet" · "account"
        - `vendor` (string)
        - `name` (string)
      - `created_at` (string, required)
    - `agent_id` (string | null, required) — The root session's agent (agent_…)
    - `agent_type` (string, required)
    - `llm` (string, required)
    - `archived` (boolean, required)
    - `last_activity_at` (string, required)
    - `created_at` (string, required)
    - `consumed_cost` (object, required) — Billed cost summed over every session in the task, a paid agent's flat fee included
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `completion_answer` (object | null, required) — What the caller said about whether this task did the job; null until they answer. Other people's answers are not shown.
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `agent_fees` (object[]) — The flat fees of paid agents in this task. Present only when the task has one.
      - `session_id` (string, required)
      - `handle` (string, required)
      - `fee` (object, required)
        - `amount` (string, required) — Whole US cents
        - `currency` (enum<string>, required) — "USD"
      - `status` (enum<string>, required) — `held`: set aside from the caller's credit when the task started. `captured`: taken, on the task's first result. `released`: given back because the task was archived or deleted without a result. `disputed`, `refunded`: see the dispute route. — "awaiting_confirmation" · "declined" · "held" · "captured" · "disputed" · "released" · "refunded"
      - `dispute_until` (string | null, required) — Until when the caller may say the task was not completed; null unless the fee is captured and undisputed
      - `dispute` (object | null, required) — What the caller said and how it was ruled; null when the fee was never disputed.
    - `requests` (object[], required) — Open requests addressed to the caller, oldest first. Answer one by sending its reply to `session_id` as a message, exactly as a question is answered in that session.
      - `id` (string, required) — The request id the agent or the platform assigned
      - `session_id` (string, required) — The session that is waiting (sess_…)
      - `message_id` (string, required)
      - `kind` (enum<string>, required) — `question`: an agent asked. `approval`: a tool needs the caller's go-ahead before it runs (options `allow`, `deny`), or a workspace rule asks for it before the task itself starts (options `confirm`, `decline`; nothing has run, and declining archives the task), or a skill or lesson change suggested after the task finished awaits the workspace's owner or an admin (options `approve`, which writes it for the whole workspace, and `decline`; nothing is sent to the agent). `connect_app`: the agent needs an app that is not connected; it resolves by itself when the caller connects the app, or by answering `skip`. `connect_account`: the task cannot run without the caller's own account at a vendor, or that account has no usage left; what the caller sent is kept and nothing has run. It resolves by itself when the account is connected (`POST /external_accounts`), or by answering `use_wallet` (offered only when the account is exhausted or expired and the task can run on a platform model) or `wait`. `spend`: an agent whose maker asks a flat fee is about to be used for the first time at that price, either as this task's own agent (nothing has run, and nothing runs until it is answered) or as a helper an agent in the task wants to hire. Answer `confirm` or `decline`; a confirmation is remembered for that agent at that price. `browser_handoff`: the agent stopped in its own browser at something only the caller can do (a CAPTCHA, a two-step code, a sign-in or consent screen); the caller takes over the browser (`GET`/`POST /sessions/{id}/browser-handoff`), then answers `done` to hand it back or `skip` to tell the agent it could not be done. — "question" · "approval" · "connect_app" · "connect_account" · "spend" · "browser_handoff"
      - `subject` (string | null, required) — For `connect_app`, the app's slug; for `connect_account`, the vendor; for `spend`, the agent's handle; for `browser_handoff`, the site the browser is on
      - `question` (string, required)
      - `options` (object[], required)
        - `id` (string, required)
        - `label` (string, required)
        - `description` (string)
      - `allow_free_text` (boolean, required)
      - `expected_question` (object) — For file input only: pass this exact saved question with file_ids when answering.
      - `input` (object)
        - `type` ("files", required)
        - `multiple` (boolean)
      - `required_user_id` (string | null, required) — Set when only one person may answer
      - `due_at` (string | null, required)
      - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/seen \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"session_ids":["sess_cmtb7q2j"]}'
```

### PUT /tasks/{id}/completion_answer

Say whether the task did the job (scope: write)

The caller's own answer for a task that has a result. Each person has one answer per task; sending it again replaces the earlier one. It counts toward `stats.completed_yes` or `stats.completed_no` of the catalog listing the task's agent stands for. 409 `no_result` while no session of the task has replied. 404 for a task the caller cannot see. Answers 503 `not_migrated` until the platform's answer table is in place.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Body (application/json):

- `did_the_job` (boolean, required)

Responses:

- `200` — OK
  - `task` (object, required)
    - `id` (string, required) — sess_… — the root session's id
    - `title` (string | null, required)
    - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
    - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
    - `open_request_count` (integer, required) — Open requests addressed to the caller
    - `session_count` (integer, required) — The root session plus its helper and handoff sessions
    - `sessions` (object[], required) — The root first, then the others in the order they joined
      - `id` (string, required) — sess_…
      - `role` (enum<string>, required) — "primary" · "helper" · "handoff"
      - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
      - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
      - `title` (string | null, required)
      - `status` (enum<string>, required) — "provisioning" · "idle" · "running" · "terminated"
      - `agent_id` (string | null, required)
      - `agent_type` (string, required)
      - `llm` (string, required)
      - `consumed_cost` (object, required) — A US-dollar amount. `amount` is whole US cents as an integer decimal string — "125" is $1.25 — rounded half-up to the cent.
        - `amount` (string, required) — Whole US cents
        - `currency` (enum<string>, required) — "USD"
        - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
        - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
      - `model_paid_by` (object) — Who pays for the model in this session: the wallet, or the caller's own account at a vendor. Runtime is charged to the wallet either way. Present where external accounts are turned on.
        - `source` (enum<string>, required) — "wallet" · "account"
        - `vendor` (string)
        - `name` (string)
      - `created_at` (string, required)
    - `agent_id` (string | null, required) — The root session's agent (agent_…)
    - `agent_type` (string, required)
    - `llm` (string, required)
    - `archived` (boolean, required)
    - `last_activity_at` (string, required)
    - `created_at` (string, required)
    - `consumed_cost` (object, required) — Billed cost summed over every session in the task, a paid agent's flat fee included
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `completion_answer` (object | null, required) — What the caller said about whether this task did the job; null until they answer. Other people's answers are not shown.
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `agent_fees` (object[]) — The flat fees of paid agents in this task. Present only when the task has one.
      - `session_id` (string, required)
      - `handle` (string, required)
      - `fee` (object, required)
        - `amount` (string, required) — Whole US cents
        - `currency` (enum<string>, required) — "USD"
      - `status` (enum<string>, required) — `held`: set aside from the caller's credit when the task started. `captured`: taken, on the task's first result. `released`: given back because the task was archived or deleted without a result. `disputed`, `refunded`: see the dispute route. — "awaiting_confirmation" · "declined" · "held" · "captured" · "disputed" · "released" · "refunded"
      - `dispute_until` (string | null, required) — Until when the caller may say the task was not completed; null unless the fee is captured and undisputed
      - `dispute` (object | null, required) — What the caller said and how it was ruled; null when the fee was never disputed.
    - `requests` (object[], required) — Open requests addressed to the caller, oldest first. Answer one by sending its reply to `session_id` as a message, exactly as a question is answered in that session.
      - `id` (string, required) — The request id the agent or the platform assigned
      - `session_id` (string, required) — The session that is waiting (sess_…)
      - `message_id` (string, required)
      - `kind` (enum<string>, required) — `question`: an agent asked. `approval`: a tool needs the caller's go-ahead before it runs (options `allow`, `deny`), or a workspace rule asks for it before the task itself starts (options `confirm`, `decline`; nothing has run, and declining archives the task), or a skill or lesson change suggested after the task finished awaits the workspace's owner or an admin (options `approve`, which writes it for the whole workspace, and `decline`; nothing is sent to the agent). `connect_app`: the agent needs an app that is not connected; it resolves by itself when the caller connects the app, or by answering `skip`. `connect_account`: the task cannot run without the caller's own account at a vendor, or that account has no usage left; what the caller sent is kept and nothing has run. It resolves by itself when the account is connected (`POST /external_accounts`), or by answering `use_wallet` (offered only when the account is exhausted or expired and the task can run on a platform model) or `wait`. `spend`: an agent whose maker asks a flat fee is about to be used for the first time at that price, either as this task's own agent (nothing has run, and nothing runs until it is answered) or as a helper an agent in the task wants to hire. Answer `confirm` or `decline`; a confirmation is remembered for that agent at that price. `browser_handoff`: the agent stopped in its own browser at something only the caller can do (a CAPTCHA, a two-step code, a sign-in or consent screen); the caller takes over the browser (`GET`/`POST /sessions/{id}/browser-handoff`), then answers `done` to hand it back or `skip` to tell the agent it could not be done. — "question" · "approval" · "connect_app" · "connect_account" · "spend" · "browser_handoff"
      - `subject` (string | null, required) — For `connect_app`, the app's slug; for `connect_account`, the vendor; for `spend`, the agent's handle; for `browser_handoff`, the site the browser is on
      - `question` (string, required)
      - `options` (object[], required)
        - `id` (string, required)
        - `label` (string, required)
        - `description` (string)
      - `allow_free_text` (boolean, required)
      - `expected_question` (object) — For file input only: pass this exact saved question with file_ids when answering.
      - `input` (object)
        - `type` ("files", required)
        - `multiple` (boolean)
      - `required_user_id` (string | null, required) — Set when only one person may answer
      - `due_at` (string | null, required)
      - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/completion_answer \
  -H "Authorization: Bearer ast_..."
```

### POST /tasks/{id}/requests/{request_id}/answer

Answer a request the task is waiting on (scope: write)

Sends the caller's answer to the session that asked, in the same form a click in the app produces: a turn still running receives it, because it may be waiting on it, and an idle session starts its next turn. Pass `option_id` for one of the request's options, or `text` where the request accepts free text. A file request has `input.type=files`; upload through the existing Files API, then pass the exact `expected_question` from `get_task` and 1-20 `file_ids` (one unless `input.multiple` is true). The same IDs retry the same delivery without sending the answer twice. A `spend` request is applied before anything is sent: confirming remembers the price and, when the task itself was waiting to start, holds the fee and starts it with what it was given (402 `insufficient_credits` when the caller's credit does not cover the fee; the request stays open). Declining such a start closes the request and the task never runs. A `spend` request that asks to raise a member's monthly limit in a workspace is answered by an owner or admin of that workspace with `option_id` `raise` or `decline` (403 `request_not_yours` for anyone else, the member included): raising sets the limit the request offered and sends on what the member's waiting tasks were given. An optional `note` is sent to the agent after the answer, in the same turn, and is not part of the answer: a surface other than the app uses it to say where the answer came from and how to reply there. 404 when the task has no open request with that id, 403 `request_not_yours` when it is addressed to someone else, 400 when the answer is not one the request accepts (retry once the session is idle).

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)
- `request_id` (string, required) — The request's `id` from the task's `requests`

Body (application/json):

- option 1 (object)
  - `option_id` (string, required)
  - `note` (string) — max length 4000
- option 2 (object)
  - `text` (string, required) — max length 20000
  - `note` (string) — max length 4000
- option 3 (object)
  - `expected_question` (object, required) — The exact expected_question returned by get_task; stale versions are refused.
  - `file_ids` (string[], required) — pattern ^file_[A-Za-z0-9_-]+$
  - `note` (string) — max length 4000

Responses:

- `200` — OK
  - `session_id` (string, required) — The session that asked
  - `message_id` (string | null, required) — The message whose turn to follow: the run the answer reached, or the answer's own when it opened the turn. Null when a `spend` request was declined, or confirmed for a task that was given nothing to start with.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/requests/ask-7f3c2a/answer \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"option_id":"approve"}'
```

### POST /tasks/{id}/agent-fee/dispute

Say a paid agent did not complete the task (scope: write)

For the person who hired, within 72 hours of the task's first result. The fee and the seller's earning then wait for a reviewer, who either refunds the fee to the caller's credit or lets the charge stand. Usage is not refunded. 404 when the task has no agent fee of the caller's, 409 `not_disputable` outside the 72 hours or once it has been disputed, 400 when the task holds more than one fee and `session_id` does not name one.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Body (application/json):

- `reason` (string, required) — max length 1000
- `session_id` (string)

Responses:

- `200` — OK
  - `task` (object, required)
    - `id` (string, required) — sess_… — the root session's id
    - `title` (string | null, required)
    - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
    - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
    - `open_request_count` (integer, required) — Open requests addressed to the caller
    - `session_count` (integer, required) — The root session plus its helper and handoff sessions
    - `sessions` (object[], required) — The root first, then the others in the order they joined
      - `id` (string, required) — sess_…
      - `role` (enum<string>, required) — "primary" · "helper" · "handoff"
      - `attention` (enum<string>, required) — What the caller should do about the task. `needs_you`: a request addressed to the caller is open. `working`: a session in the task is running or starting, or the task is waiting on somebody else. `done`: a result arrived since the caller last marked the task seen. `idle`: nothing new. — "needs_you" · "working" · "done" · "idle"
      - `status_line` (string | null, required) — One line, at most 140 characters, on where it stands: the oldest question waiting on the caller, else the start of the latest thing an agent said. Null when no agent has said anything.
      - `title` (string | null, required)
      - `status` (enum<string>, required) — "provisioning" · "idle" · "running" · "terminated"
      - `agent_id` (string | null, required)
      - `agent_type` (string, required)
      - `llm` (string, required)
      - `consumed_cost` (object, required) — A US-dollar amount. `amount` is whole US cents as an integer decimal string — "125" is $1.25 — rounded half-up to the cent.
        - `amount` (string, required) — Whole US cents
        - `currency` (enum<string>, required) — "USD"
        - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
        - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
      - `model_paid_by` (object) — Who pays for the model in this session: the wallet, or the caller's own account at a vendor. Runtime is charged to the wallet either way. Present where external accounts are turned on.
        - `source` (enum<string>, required) — "wallet" · "account"
        - `vendor` (string)
        - `name` (string)
      - `created_at` (string, required)
    - `agent_id` (string | null, required) — The root session's agent (agent_…)
    - `agent_type` (string, required)
    - `llm` (string, required)
    - `archived` (boolean, required)
    - `last_activity_at` (string, required)
    - `created_at` (string, required)
    - `consumed_cost` (object, required) — Billed cost summed over every session in the task, a paid agent's flat fee included
      - `amount` (string, required) — Whole US cents
      - `currency` (enum<string>, required) — "USD"
      - `unit` (enum<string>) — The unit of `amount`; present on every amount the API returns — "cents"
      - `amount_usd` (string) — The exact amount in US dollars, up to six decimals — "0.0038" for spend that rounds to 0 cents. Returned, never accepted.
    - `completion_answer` (object | null, required) — What the caller said about whether this task did the job; null until they answer. Other people's answers are not shown.
    - `payer` (object) — Who pays for it, decided once when it was created and never changed. Present only when a payer was recorded, which happens in a team workspace where workspace wallets are on; absent means its owner's own balance pays.
      - `type` (enum<string>, required) — `workspace`: the team workspace's own wallet. `personal`: the balance of the person who started it. — "workspace" · "personal"
      - `workspace` (object) — The paying workspace; only with type workspace
        - `slug` (string)
        - `name` (string)
    - `agent_fees` (object[]) — The flat fees of paid agents in this task. Present only when the task has one.
      - `session_id` (string, required)
      - `handle` (string, required)
      - `fee` (object, required)
        - `amount` (string, required) — Whole US cents
        - `currency` (enum<string>, required) — "USD"
      - `status` (enum<string>, required) — `held`: set aside from the caller's credit when the task started. `captured`: taken, on the task's first result. `released`: given back because the task was archived or deleted without a result. `disputed`, `refunded`: see the dispute route. — "awaiting_confirmation" · "declined" · "held" · "captured" · "disputed" · "released" · "refunded"
      - `dispute_until` (string | null, required) — Until when the caller may say the task was not completed; null unless the fee is captured and undisputed
      - `dispute` (object | null, required) — What the caller said and how it was ruled; null when the fee was never disputed.
    - `requests` (object[], required) — Open requests addressed to the caller, oldest first. Answer one by sending its reply to `session_id` as a message, exactly as a question is answered in that session.
      - `id` (string, required) — The request id the agent or the platform assigned
      - `session_id` (string, required) — The session that is waiting (sess_…)
      - `message_id` (string, required)
      - `kind` (enum<string>, required) — `question`: an agent asked. `approval`: a tool needs the caller's go-ahead before it runs (options `allow`, `deny`), or a workspace rule asks for it before the task itself starts (options `confirm`, `decline`; nothing has run, and declining archives the task), or a skill or lesson change suggested after the task finished awaits the workspace's owner or an admin (options `approve`, which writes it for the whole workspace, and `decline`; nothing is sent to the agent). `connect_app`: the agent needs an app that is not connected; it resolves by itself when the caller connects the app, or by answering `skip`. `connect_account`: the task cannot run without the caller's own account at a vendor, or that account has no usage left; what the caller sent is kept and nothing has run. It resolves by itself when the account is connected (`POST /external_accounts`), or by answering `use_wallet` (offered only when the account is exhausted or expired and the task can run on a platform model) or `wait`. `spend`: an agent whose maker asks a flat fee is about to be used for the first time at that price, either as this task's own agent (nothing has run, and nothing runs until it is answered) or as a helper an agent in the task wants to hire. Answer `confirm` or `decline`; a confirmation is remembered for that agent at that price. `browser_handoff`: the agent stopped in its own browser at something only the caller can do (a CAPTCHA, a two-step code, a sign-in or consent screen); the caller takes over the browser (`GET`/`POST /sessions/{id}/browser-handoff`), then answers `done` to hand it back or `skip` to tell the agent it could not be done. — "question" · "approval" · "connect_app" · "connect_account" · "spend" · "browser_handoff"
      - `subject` (string | null, required) — For `connect_app`, the app's slug; for `connect_account`, the vendor; for `spend`, the agent's handle; for `browser_handoff`, the site the browser is on
      - `question` (string, required)
      - `options` (object[], required)
        - `id` (string, required)
        - `label` (string, required)
        - `description` (string)
      - `allow_free_text` (boolean, required)
      - `expected_question` (object) — For file input only: pass this exact saved question with file_ids when answering.
      - `input` (object)
        - `type` ("files", required)
        - `multiple` (boolean)
      - `required_user_id` (string | null, required) — Set when only one person may answer
      - `due_at` (string | null, required)
      - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/agent-fee/dispute \
  -H "Authorization: Bearer ast_..."
```

### GET /tasks/{id}/files

List the files in the task's file space (scope: read)

The folder every session of the task has at `/workspace/task/`: a handoff session and a helper see the same files as the session that wrote them. Current files only, by path. Answers 503 `not_migrated` until the platform's task file tables are in place.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Responses:

- `200` — OK
  - `files` (object[], required)
    - `path` (string, required)
    - `size_bytes` (integer, required)
    - `sha256` (string, required)
    - `updated_at` (string, required)
    - `updated_by_session` (string | null, required) — The session that last wrote it; null when a person or developer did
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/files' \
  -H "Authorization: Bearer ast_..."
```

### GET /tasks/{id}/story

What happened in the task, and who did it (scope: read)

One time-ordered list assembled from what the task's sessions, files, artifacts and connector calls already recorded and from the task's work graph events: each message with who sent it (a person, an agent, a workspace key or a share-link guest), each tool call an agent's message carries (tool, a short summary of its arguments, ok or error), the sessions it started, requests and their answers, decisions and outcomes, mentions and assignments, task file versions, artifact publications and comments, connector calls (app, method, host, status, and the person whose turn made the call), recorded meetings, every other event of the task by its own kind (connector and context results with links to their stored bodies, stored files, handoffs, GitHub pull requests and checks linked to a session), and each session's cost. An event that describes a row already listed appears once. Nothing is stored. Each part follows its own read rule: a session the caller may only view contributes its messages' text and nothing else; an artifact appears only when the caller may open it; events come from the task's workspace log and the caller's own private log only, so a teammate's connector replies are never shown. The story has no size limit: page through it with `cursor`. With by=session, a helper or handoff session's id names its task. 400 `invalid_request` for a cursor this route did not return or an `order` that differs from the cursor's.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Query parameters:

- `limit` (integer) — Entries per page
- `order` (string) — `asc` reads from the task's start forward, `desc` from now back. Without it (and without `cursor`) the page is the newest entries, oldest first
- `cursor` (string) — A page's `next_cursor`; the next page keeps that page's order
- `by` (string) — Resolve this session to its existing task root.

Responses:

- `200` — OK
  - `story` (object, required)
    - `task_id` (string, required)
    - `title` (string | null, required)
    - `sessions` (object[], required)
      - `id` (string, required)
      - `role` (enum<string>, required) — "primary" · "helper" · "handoff"
      - `title` (string | null, required)
      - `agent_type` (string, required)
      - `llm` (string, required)
      - `started_by` (object, required) — Who did it. `person` is named as the workspace knows them (a null user_id is someone the record does not name, such as a file written through the API); `agent` names the session it ran in; `key` is a workspace key; `guest` wrote through a share link; `platform` raised it itself.
        - `kind` (enum<string>, required) — "person" · "agent" · "key" · "guest" · "platform"
        - `user_id` (string | null)
        - `name` (string | null)
        - `session_id` (string)
        - `agent_type` (string)
        - `key_id` (string)
      - `created_at` (string, required)
      - `consumed_cost` (any | null, required) — Null where the caller may only read the conversation
      - `visibility` (enum<string>, required) — `messages`: the caller may only view this session, so only its messages' text is in the story — "full" · "messages"
    - `people` (object[], required) — Everyone this page names, and every session's owner
      - `user_id` (string, required)
      - `name` (string, required)
    - `entries` (object[], required) — In the page's `order`; without `order` or `cursor`, the newest `limit` entries oldest first
      - `id` (string, required) — Stable for the row it was read from
      - `at` (string, required)
      - `kind` (string, required) — One of `session.started`, `message`, `tool.call`, `request.asked`, `request.answered`, `decision`, `outcome`, `mention`, `assignment`, `file.changed`, `artifact.published`, `artifact.comment`, `connector.call`, `meeting.recorded`; any other value is a work graph event's own kind (`result.obtained`, `file.stored`, `handoff.requested`, `github.pr_opened`, …), and new kinds appear without notice
      - `session_id` (string | null, required) — The task session it happened in; null for task files and artifact comments not tied to one
      - `actor` (any, required)
      - `text` (string | null, required) — One line to show, at most 400 characters: the message, the tool call's summary, the question, the answer, the file path, the artifact name, the connector call, the event's title or name
      - `detail` (object, required) — The kind's own fields: `role` and `message_id` (message); `tool_name`, `call_id`, `summary`, `status` (`ok`, `error`, or null when no result is recorded) and `message_id` (tool.call); `request_id`, `request_kind`, `options`, `required_user_id` (request.asked); `request_id` (request.answered); `kind`, `value`, `ref` (decision, outcome); `target_user_id` (mention); `assignee_user_id` (assignment); `path`, `version_id`, `size_bytes`, `conflict` (file.changed); `artifact_id`, `name`, `version`, `comment_id`, `parent_id` (artifact.*); `app`, `app_name`, `method`, `host`, `status`, `provider`, `agent_session_id`, and, when the caller's own log holds the call's full reply, `event_id`, `url` and `bodies` (connector.call); `status`, `note_file_id` (meeting.recorded); `role`, `agent_type`, `llm` (session.started). An event's entry carries the event's scalar payload fields, `event_id`, `source`, `surface`, `objects` and `bodies`: each stored body's `GET /v1/events/{id}/body` path by part.
    - `order` (enum<string>, required) — Which way `next_cursor` continues — "asc" · "desc"
    - `next_cursor` (string | null, required) — Pass as `cursor` for the next page in the same order; null when nothing is left
    - `truncated` (boolean, required) — Without `order` or `cursor`: older entries exist (read them with `next_cursor`)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/story' \
  -H "Authorization: Bearer ast_..."
```

### GET /tasks/{id}/email-threads

Search Gmail for a thread to attach to the task (scope: write)

Searches the caller's own Gmail connection, or a Gmail connection a teammate shared with the task's workspace, with Gmail's search syntax (`q`, e.g. `from:supplier@example.com invoice`). At most 10 threads. Read-only on Gmail. Write scope because each Gmail read is a billed connector call. Needs a person's own credential (403 `person_required` for a workspace key, an app or a task pass) and the right to send the task's first session messages (404 otherwise, as for an unknown task); 404 `not_connected` when there is no Gmail connection to read through; the workspace's tool-call rules apply (403 `capability_denied`); 424 `gmail_error` when Gmail refuses the read or its answer cannot be read.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Query parameters:

- `q` (string)
- `connection_id` (string) — Which Gmail connection to read through; default your own

Responses:

- `200` — OK
  - `connection` (object, required)
    - `id` (string, required)
    - `label` (string, required) — Your own connection's account, or whose shared connection it is
    - `shared_by` (string | null, required) — The teammate who shared it with the workspace; null for your own
  - `connections` (object[], required)
    - `id` (string, required)
    - `label` (string, required) — Your own connection's account, or whose shared connection it is
    - `shared_by` (string | null, required) — The teammate who shared it with the workspace; null for your own
  - `threads` (object[], required)
    - `id` (string, required) — Gmail thread id; pass it as `thread` to attach
    - `subject` (string, required)
    - `from` (string | null, required)
    - `date` (string | null, required) — When its latest message was sent
    - `snippet` (string, required)
    - `messages` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/email-threads' \
  -H "Authorization: Bearer ast_..."
```

### POST /tasks/{id}/email-threads

Attach a Gmail thread to the task (scope: write)

Reads one Gmail thread and keeps it in the task's files as plain text at `email/<subject>-<thread id>.md`: subject, participants, and every message with sender, recipients, time and text; attachments are listed by name and never copied. Every session of the task reads it at its next turn, and the task story shows it as `file.changed` by the caller with `detail.email`. Attaching the same thread again writes a new version only when it changed (200 instead of 201). Nothing is sent from Gmail. Same access rules as the search; 400 `invalid_thread` for something that is not a thread id or a Gmail address ending in one; 404 `thread_not_found`; 424 `gmail_error` when Gmail refuses the read or its answer cannot be read.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Body (application/json):

- `thread` (string, required) — A Gmail thread id, or a mail.google.com address ending in one — max length 2000
- `connection_id` (string)

Responses:

- `200` — Already attached and unchanged; same body
- `201` — Attached
  - `attached` (object, required)
    - `task_id` (string, required)
    - `thread_id` (string, required)
    - `subject` (string, required)
    - `messages` (integer, required)
    - `file` (object, required)
      - `path` (string, required)
      - `size_bytes` (integer, required)
      - `sha256` (string, required)
      - `updated_at` (string, required)
      - `updated_by_session` (string | null, required) — The session that last wrote it; null when a person or developer did
    - `changed` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/email-threads \
  -H "Authorization: Bearer ast_..."
```

### GET /tasks/{id}/export

Download the task's files as one archive (scope: read)

A zip archive of the current files in the task's file space, each at its own path. 413 `export_too_large` when they are more than 64 MiB together; download them one at a time then.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)

Responses:

- `200` — The archive
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/export' \
  -H "Authorization: Bearer ast_..."
```

### GET /tasks/{id}/files/{path}

Read one task file, or its history (scope: read)

Streams the file's bytes with a SHA-256 ETag and Accept-Ranges: bytes. Select an immutable saved version with `version_id`. A single byte Range returns 206; pair it with the saved ETag in If-Range to resume the same bytes. An If-Range mismatch returns the whole selected file, and an invalid or unsatisfiable range returns 416. With `versions=true` returns instead every recorded write of that path, newest first, including writes to a path that has since been deleted; do not combine versions and version_id.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)
- `path` (string, required) — The file's path inside the task's file space, such as report.md or data/rows.csv

Query parameters:

- `versions` (string)
- `version_id` (string) — Read this immutable version instead of the current file; exclusive with versions=true.

Responses:

- `200` — The bytes, or the version list
  - `versions` (object[], required)
    - `id` (string, required)
    - `sha256` (string, required)
    - `size_bytes` (integer, required)
    - `session` (string | null, required)
    - `conflict` (boolean, required) — The writer had not seen what was current when it wrote
    - `created_at` (string, required)
- `206` — The requested byte range
- `416` — Invalid or unsatisfiable byte range
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/files/report.md' \
  -H "Authorization: Bearer ast_..."
```

### PUT /tasks/{id}/files/{path}

Write one task file (scope: write)

Streams raw body bytes into the current file with no application single-file, total-size or file-count limit; byte counts must be exactly representable integers. For a resumable transfer, first complete `/files/uploads`, then supply its `file_id` here and omit the body. The referenced file must pass the caller's downloadable-file authorization; its size and SHA-256 receipt are verified while streaming into the same version writer. `base_sha256` names what the caller last saw at the path (empty for nothing); when something else is current the default write is still made, both versions are kept, and the response says `conflict: true`. With `require_base_match=true`, a base is required and a mismatch instead returns 409 `revision_conflict` without updating the file. Sessions of the task pick the file up at the start of their next turn.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)
- `path` (string, required) — The file's path inside the task's file space, such as report.md or data/rows.csv

Query parameters:

- `base_sha256` (string)
- `require_base_match` (boolean)
- `file_id` (string) — A completed upload's file_… id; omit the body to import its authorized bytes and verify its receipt.

Responses:

- `200` — OK
  - `file` (object, required)
    - `path` (string, required)
    - `size_bytes` (integer, required)
    - `sha256` (string, required)
    - `updated_at` (string, required)
    - `updated_by_session` (string | null, required) — The session that last wrote it; null when a person or developer did
  - `conflict` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/files/report.md \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: text/markdown" \
  --data-binary @report.md
```

### DELETE /tasks/{id}/files/{path}

Remove one task file (scope: write)

Removes the path from the current files. Its history stays readable with `versions=true`.

Path parameters:

- `id` (string, required) — The task id: the id of its root session (sess_…)
- `path` (string, required) — The file's path inside the task's file space, such as report.md or data/rows.csv

Responses:

- `200` — OK
  - `ok` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/files/report.md \
  -H "Authorization: Bearer ast_..."
```

### POST /tasks/{id}/callback

Report on a task from the server its agent runs on (scope: task pass)

Authorized by the pass handed to that server with the turn, sent as `Authorization: Bearer`, and by nothing else: any other credential is refused with 403. `message` shows progress and keeps the turn open. `result` is the answer; `request` asks the person a question, which they answer like any other request on the task; `error` says the work could not be done. Those three end the turn and the pass, so write the task's files first. 409 `turn_ended` once the turn is over; 401 for a pass that has ended.

Path parameters:

- `id` (string, required) — The task's id.

Body (application/json):

- type: "message" (object) — Something to show while the work goes on. The turn stays open.
  - `type` ("message", required)
  - `text` (string, required) — max length 200000
- type: "result" (object) — The answer. Ends the turn and the pass.
  - `type` ("result", required)
  - `text` (string, required) — max length 200000
- type: "request" (object) — A question for the person. Ends the turn and the pass; the answer arrives as the task's next turn, with a new pass.
  - `type` ("request", required)
  - `question` (string, required) — max length 2000
  - `options` (object[])
    - `id` (string, required) — max length 200
    - `label` (string, required) — max length 200
    - `description` (string) — max length 500
  - `allow_free_text` (boolean) — Whether the person may type an answer. Defaults to true; must be true when there are no options.
- type: "error" (object) — The work could not be done. Ends the turn and the pass; the person reads the message.
  - `type` ("error", required)
  - `message` (string, required) — max length 500

Responses:

- `200` — Recorded
  - `ok` (boolean, required)
  - `request_id` (string) — The id of the request that was raised, for `request`.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/tasks/sess_cmtb7q2j/callback \
  -H "Authorization: Bearer ast_..."
```

## Task traces

### POST /traces

Start a trace (scope: write)

A trace correlates one task across local agents and platform sessions. It holds metadata, plus redacted content where a grant allows it, and is deleted 30 days after creation with everything admitted to it. It is never exported. Returns 404 when the TASK_TRACES switch is off for the workspace and 503 not_migrated before the tables exist.

Body (application/json):

- `name` (string) — max length 200

Responses:

- `201` — Created
  - `trace` (object, required)
    - `id` (string, required) — trc_… — the public id
    - `name` (string | null, required)
    - `created_at` (string, required)
    - `expires_at` (string, required) — 30 days after creation; the trace and its events are deleted then
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/traces \
  -H "Authorization: Bearer ast_..."
```

### GET /traces/{id}

The trace bundle (scope: read)

Spans, the sessions and tasks they reach, cost counted once per session, and gaps. A session joins by an event naming it or by its own `metadata.trace_id`. Returns 404 when the TASK_TRACES switch is off for the workspace and 503 not_migrated before the tables exist.

Path parameters:

- `id` (string, required) — The trace id (trc_…)

Responses:

- `200` — OK
  - `trace` (object, required)
    - `id` (string, required) — trc_… — the public id
    - `name` (string | null, required)
    - `created_at` (string, required)
    - `expires_at` (string, required) — 30 days after creation; the trace and its events are deleted then
  - `coverage` (enum<string>, required) — metadata_only when no event carries content; redacted when any kept content had a value replaced or was dropped — "metadata_only" · "partial" · "redacted"
  - `spans` (object[], required) — What sources reported, oldest first. `edge` is root, resolved, pending (its parent may still arrive) or unresolved (the parent never arrived within 10 minutes). A span its source left open that names a session ends with that session's turn (`outcome_source: platform`): failed on `session.error`, completed on `session.status_idle`, cancelled when the session was archived or deleted first. Events with content carry `content.text`, up to 4 MiB per bundle.
  - `sessions` (object[], required) — Platform sessions the trace reaches, with their tasks' members; each listed once
  - `task_ids` (string[], required)
  - `consumed_cost` (any, required) — Summed over the listed sessions, each counted once; external spend is not known and not included
  - `gaps` (object[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/traces/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### POST /traces/{id}/grants

Mint a grant for one source (scope: write)

The token (tgr_…) is shown once. It may only add events to this trace, as this source, in the content scopes it names, until it expires (default 24 hours, at most 7 days, never past the trace). Returns 404 when the TASK_TRACES switch is off for the workspace and 503 not_migrated before the tables exist.

Path parameters:

- `id` (string, required) — The trace id (trc_…)

Body (application/json):

- `source` (string, required) — pattern ^[A-Za-z0-9._:@-]{1,128}$
- `ttl_seconds` (integer)
- `content_scopes` (enum<string>[]) — Content the source may send beside metadata; omitted admits metadata only — "prompts" · "tool_output" · "files"

Responses:

- `201` — Created
  - `grant` (object, required)
    - `id` (string, required) — tgrant_…
    - `trace_id` (string, required)
    - `source` (string, required) — The one source this grant may report as
    - `content_scopes` (enum<string>[]) — The content this grant admits beside metadata; empty admits metadata only — "prompts" · "tool_output" · "files"
    - `expires_at` (string, required)
    - `revoked_at` (string | null, required)
    - `created_at` (string, required)
  - `token` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/traces/sess_cmtb7q2j/grants \
  -H "Authorization: Bearer ast_..."
```

### DELETE /traces/{id}/grants/{grant_id}

Revoke a grant (scope: write)

Its source can add nothing more; what was admitted stays. Returns 404 when the TASK_TRACES switch is off for the workspace and 503 not_migrated before the tables exist.

Path parameters:

- `id` (string, required) — The trace id (trc_…)
- `grant_id` (string, required) — The grant id (tgrant_…)

Responses:

- `200` — OK
  - `grant` (object, required)
    - `id` (string, required) — tgrant_…
    - `trace_id` (string, required)
    - `source` (string, required) — The one source this grant may report as
    - `content_scopes` (enum<string>[]) — The content this grant admits beside metadata; empty admits metadata only — "prompts" · "tool_output" · "files"
    - `expires_at` (string, required)
    - `revoked_at` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/traces/sess_cmtb7q2j/grants/grant_id \
  -H "Authorization: Bearer ast_..."
```

### POST /traces/{id}/events

Admit events (scope: trace grant)

Authenticated by a trace grant token (Bearer tgr_…), not an API key. At most 256 events, 64 KiB each, 4 MiB per request. Each event is judged on its own: the same event id and content returns its first receipt; different content, a session outside the workspace, another source's span, a changed parent, a parent cycle or content outside the grant's scopes is refused. Returns 404 when the TASK_TRACES switch is off for the workspace and 503 not_migrated before the tables exist.

Path parameters:

- `id` (string, required) — The trace id (trc_…)

Body (application/json):

- `events` (object[], required)
  - `event_id` (string, required) — Unique per source; resending the same event returns its first receipt — pattern ^[A-Za-z0-9._:@-]{1,128}$
  - `sequence` (integer, required) — Order within the source
  - `span_id` (string, required) — pattern ^[A-Za-z0-9._:@-]{1,128}$
  - `parent_span_id` (string | null) — Set once, by the span's first event; a different parent later is refused — pattern ^[A-Za-z0-9._:@-]{1,128}$
  - `kind` (enum<string>, required) — "start" · "end" · "event"
  - `name` (string) — max length 200
  - `outcome` (enum<string>) — "running" · "completed" · "failed" · "cancelled" · "unknown"
  - `coverage` (enum<string>) — "complete" · "partial" · "redacted" · "metadata_only"
  - `session_id` (string) — A session of the trace's workspace (sess_…)
  - `task_id` (string) — A task of the trace's workspace (its root session id)
  - `source_time` (string) — The source's clock; informative only
  - `attributes` (map<string, string | number | boolean | null>)
  - `content` (object) — Only in a scope the grant names. Redacted again on arrival: a credential-shaped value is replaced and the event reads `redacted`; text that cannot be redacted is not kept and the event reads `metadata_only`.
    - `scope` (enum<string>, required) — "prompts" · "tool_output" · "files"
    - `text` (string, required) — At most 48 KiB (UTF-8)
    - `path` (string) — For files, and only for files — max length 1024
    - `truncated` (boolean) — The source cut the text to fit
    - `redactions` (integer) — Values the source already replaced

Responses:

- `200` — OK
  - `trace_id` (string, required)
  - `source` (string, required)
  - `results` (object[], required)
    - `event_id` (string, required)
    - `status` (enum<string>, required) — "admitted" · "duplicate" · "refused"
    - `receipt` (string)
    - `received_at` (string)
    - `code` (enum<string>) — "event_conflict" · "foreign_reference" · "span_owned" · "parent_changed" · "parent_cycle" · "content_not_granted"
    - `message` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/traces/sess_cmtb7q2j/events \
  -H "Authorization: Bearer ast_..."
```

## Trace library

### GET /trace-library

List the workspace's trace library (scope: read)

Every uploaded local session in the current workspace, most recently updated first. Workspace keys are refused: uploads and reads belong to a person. Returns 503 not_migrated before the tables exist.

Query parameters:

- `limit` (integer)
- `cursor` (string)
- `uploader` (string) — Only this member's uploads
- `harness` (string)
- `project` (string)

Responses:

- `200` — OK
  - `traces` (object[], required)
    - `id` (string, required) — ltr_…
    - `harness` (string, required)
    - `session_id` (string, required)
    - `title` (string | null)
    - `project` (string | null) — The repository's folder name
    - `cwd` (string | null) — Where the session ran, home written as ~
    - `git_branch` (string | null)
    - `git_commit` (string | null)
    - `git_remote` (string | null) — The repository URL, without credentials
    - `model` (string | null) — The model that answered most
    - `models` (string[]) — Every model that answered, most-used first; empty when the upload named none
    - `harness_version` (string | null)
    - `client` (string | null) — The front end that ran the harness, such as a Claude Code entrypoint or a Codex originator
    - `model_provider` (string | null)
    - `effort` (string | null)
    - `usage` (object | null) — Token totals the source reported, by kind
    - `uploader_id` (string, required)
    - `device` (string | null)
    - `started_at` (string | null)
    - `ended_at` (string | null)
    - `user_turns` (integer)
    - `tool_calls` (integer)
    - `messages` (integer, required) — Stored messages, after redaction
    - `coverage` (enum<string>, required) — "complete" · "partial" · "redacted"
    - `version` (integer, required) — Raised each time a changed upload replaces it
    - `updated_at` (string, required)
    - `environment` (object | null) — The working folder the session ran in, uploaded with it as one of the uploader's files
  - `next_cursor` (string | null, required)
  - `total` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/trace-library' \
  -H "Authorization: Bearer ast_..."
```

### POST /trace-library/check

Ask which sessions to upload (scope: write)

For each named session: upload (new or changed), unchanged (same sha256 already stored) or owned (another member uploaded it). Workspace keys are refused: uploads and reads belong to a person. Returns 503 not_migrated before the tables exist.

Body (application/json):

- `sessions` (object[], required)
  - `harness` (string, required)
  - `session_id` (string, required)
  - `sha256` (string, required) — pattern ^[0-9a-f]{64}$

Responses:

- `200` — OK
  - `sessions` (object[])
    - `harness` (string)
    - `session_id` (string)
    - `status` (enum<string>) — "upload" · "unchanged" · "owned"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/trace-library/check \
  -H "Authorization: Bearer ast_..."
```

### PUT /trace-library/{harness}/{session_id}

Upload one session (scope: write)

Stores the session's messages, redacted again on arrival and cut to 8 KiB each, replacing an earlier version. The same sha256 is a no-op (unchanged). A session another member uploaded answers 409 trace_owned. The body is at most 8 MiB. Workspace keys are refused: uploads and reads belong to a person. Returns 503 not_migrated before the tables exist.

Path parameters:

- `harness` (string, required) — claude_code, codex, or another harness name
- `session_id` (string, required) — The harness's own session id

Body (application/json):

- `sha256` (string, required) — The device's digest of the messages; repeats of it are not stored again — pattern ^[0-9a-f]{64}$
- `title` (string) — max length 300
- `cwd` (string) — max length 1024
- `project` (string) — max length 200
- `git_branch` (string) — max length 300
- `git_commit` (string) — max length 80
- `git_remote` (string) — The repository URL, without credentials — max length 1024
- `model` (string) — The model that answered most — max length 200
- `models` (string[]) — Every model that answered, most-used first — max length 200
- `harness_version` (string) — max length 80
- `client` (string) — max length 200
- `model_provider` (string) — max length 100
- `effort` (string) — max length 100
- `usage` (object)
  - `input_tokens` (integer)
  - `output_tokens` (integer)
  - `cache_read_tokens` (integer)
  - `cache_write_tokens` (integer)
  - `reasoning_tokens` (integer)
- `device` (string) — max length 200
- `started_at` (string)
- `ended_at` (string)
- `user_turns` (integer)
- `tool_calls` (integer)
- `partial` (boolean) — The device left messages out to fit
- `environment` (object) — The working folder the session ran in, already uploaded as one of your files in this workspace; 400 invalid_environment for a file you cannot see. Fold its file_id into sha256 so linking it later is a changed upload.
  - `file_id` (string, required)
  - `name` (string, required) — max length 80
  - `bytes` (integer, required)
  - `files` (integer, required)
  - `sha256` (string, required) — pattern ^[0-9a-f]{64}$
- `messages` (object[], required)
  - `role` (enum<string>, required) — "user" · "assistant" · "tool"
  - `at` (string)
  - `text` (string, required) — max length 65536

Responses:

- `200` — Updated or unchanged
  - `status` (enum<string>) — "updated" · "unchanged"
  - `trace` (object)
    - `id` (string, required) — ltr_…
    - `harness` (string, required)
    - `session_id` (string, required)
    - `title` (string | null)
    - `project` (string | null) — The repository's folder name
    - `cwd` (string | null) — Where the session ran, home written as ~
    - `git_branch` (string | null)
    - `git_commit` (string | null)
    - `git_remote` (string | null) — The repository URL, without credentials
    - `model` (string | null) — The model that answered most
    - `models` (string[]) — Every model that answered, most-used first; empty when the upload named none
    - `harness_version` (string | null)
    - `client` (string | null) — The front end that ran the harness, such as a Claude Code entrypoint or a Codex originator
    - `model_provider` (string | null)
    - `effort` (string | null)
    - `usage` (object | null) — Token totals the source reported, by kind
    - `uploader_id` (string, required)
    - `device` (string | null)
    - `started_at` (string | null)
    - `ended_at` (string | null)
    - `user_turns` (integer)
    - `tool_calls` (integer)
    - `messages` (integer, required) — Stored messages, after redaction
    - `coverage` (enum<string>, required) — "complete" · "partial" · "redacted"
    - `version` (integer, required) — Raised each time a changed upload replaces it
    - `updated_at` (string, required)
    - `environment` (object | null) — The working folder the session ran in, uploaded with it as one of the uploader's files
- `201` — Created
  - `status` (enum<string>) — "created"
  - `trace` (object)
    - `id` (string, required) — ltr_…
    - `harness` (string, required)
    - `session_id` (string, required)
    - `title` (string | null)
    - `project` (string | null) — The repository's folder name
    - `cwd` (string | null) — Where the session ran, home written as ~
    - `git_branch` (string | null)
    - `git_commit` (string | null)
    - `git_remote` (string | null) — The repository URL, without credentials
    - `model` (string | null) — The model that answered most
    - `models` (string[]) — Every model that answered, most-used first; empty when the upload named none
    - `harness_version` (string | null)
    - `client` (string | null) — The front end that ran the harness, such as a Claude Code entrypoint or a Codex originator
    - `model_provider` (string | null)
    - `effort` (string | null)
    - `usage` (object | null) — Token totals the source reported, by kind
    - `uploader_id` (string, required)
    - `device` (string | null)
    - `started_at` (string | null)
    - `ended_at` (string | null)
    - `user_turns` (integer)
    - `tool_calls` (integer)
    - `messages` (integer, required) — Stored messages, after redaction
    - `coverage` (enum<string>, required) — "complete" · "partial" · "redacted"
    - `version` (integer, required) — Raised each time a changed upload replaces it
    - `updated_at` (string, required)
    - `environment` (object | null) — The working folder the session ran in, uploaded with it as one of the uploader's files
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/trace-library/harness/session_id \
  -H "Authorization: Bearer ast_..."
```

### DELETE /trace-library/{harness}/{session_id}

Delete one session (scope: write)

Its uploader or the workspace owner may. Workspace keys are refused: uploads and reads belong to a person. Returns 503 not_migrated before the tables exist.

Path parameters:

- `harness` (string, required) — claude_code, codex, or another harness name
- `session_id` (string, required) — The harness's own session id

Responses:

- `204` — Deleted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/trace-library/harness/session_id \
  -H "Authorization: Bearer ast_..."
```

## Notifications

### GET /notification-actions

The answers a notification about a chat offers the caller (scope: write)

What the person's notification about this chat can answer, and a token minted for the caller's key that runs it: Allow and Deny for a permission prompt, Reply for a question asked in words or a finished chat. `notice` is null when the chat is working or what it waits on needs the app (a price, a start rule, a connection, a hand-off, a file). Only a person's own key may ask: a workspace key, a task pass, a restricted key or an app is refused 403 `person_required`. The Mac app asks this when it shows a notification.

Query parameters:

- `session_id` (string, required)

Responses:

- `200` — OK
  - `notice` (object | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/notification-actions?session_id=session_id' \
  -H "Authorization: Bearer ast_..."
```

### POST /notification-actions

Answer a notification with its action token

Runs one answer of a notification, as the person it was sent to, through the same path as the card in the chat. No key: the `token` from the push (`action_token`) is the credential, so a phone's lock screen can answer. A retried or doubled press admits one turn. 409 `already_answered` once the request is closed (answered on another device or withdrawn), 410 `expired` past the token's deadline (a day, or the request's own), 401 `invalid_token` for a token this platform did not sign or whose device was signed out, 400 for an answer the token does not offer or a Reply without text.

Body (application/json):

- `token` (string, required)
- `action` (enum<string>, required) — "allow" · "deny" · "reply"
- `text` (string) — Required for reply. — max length 20000

Responses:

- `200` — OK
  - `session_id` (string, required)
  - `message_id` (string | null, required) — The turn the answer started.
  - `line` (string, required) — What the notification says now: Allowed, Denied or Sent. A refusal's message is its line: Already answered, This request expired, or Not sent. Open the chat to answer.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/notification-actions \
  -H "Authorization: Bearer ast_..."
```

### POST /notification-actions/state

Whether a notification can still be answered

What an action token's notice offers and where it stands: `open`, `answered` (here or on another device) or `expired`. No key: the token in the body is the credential. 401 `invalid_token` for a token this platform did not sign or whose device was signed out.

Body (application/json):

- `token` (string, required)

Responses:

- `200` — OK
  - `notice` (object, required)
    - `task_id` (string, required)
    - `session_id` (string, required) — The session that asked, or the chat a Reply goes to.
    - `request_id` (string | null, required) — The request the answer closes; null for a Reply into a chat.
    - `kind` (enum<string>, required) — "needs_you" · "done"
    - `actions` (object[], required)
      - `id` (enum<string>, required) — "allow" · "deny" · "reply"
      - `label` (string, required) — The words on the button: Allow, Deny or Reply.
      - `input` (enum<string>) — Present when the answer is typed (Reply). — "text"
      - `requires_unlock` (boolean, required) — The device asks to be unlocked before it runs.
    - `expires_at` (string, required)
    - `state` (enum<string>, required) — "open" · "answered" · "expired"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/notification-actions/state \
  -H "Authorization: Bearer ast_..."
```

### POST /notifications

Tell the caller's person something about a chat (scope: write)

Names what and which kind, never a channel. It shows in the app when the person is there, as a system notification when they are away, and by push and email a minute later if unseen, each as they chose. 429 `too_many_notices` past 30 in an hour; 503 `not_migrated` until the table exists.

Body (application/json):

- `session_id` (string, required) — A chat the caller may prompt.
- `kind` (enum<string>, required) — "needs_you" · "done"
- `title` (string, required) — One line that stands alone. — max length 120
- `body` (string) — max length 300

Responses:

- `201` — Created
  - `notice` (object, required)
    - `id` (string, required)
    - `session_id` (string, required) — The chat it opens.
    - `kind` (enum<string>, required) — "needs_you" · "done"
    - `title` (string, required)
    - `body` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/notifications \
  -H "Authorization: Bearer ast_..."
```

### GET /notifications

The caller's latest notices (scope: read)

At most 20, oldest first, from the last day or after `after`.

Query parameters:

- `after` (string)

Responses:

- `200` — OK
  - `data` (object[], required)
    - `id` (string, required)
    - `session_id` (string, required) — The chat it opens.
    - `kind` (enum<string>, required) — "needs_you" · "done"
    - `title` (string, required)
    - `body` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/notifications' \
  -H "Authorization: Bearer ast_..."
```

### GET /notification-preferences

Which task events the caller is emailed and pushed about (scope: read)

A person who has never chosen gets the defaults: for email `needs_you` and `shared` on and `done` off, for push all on. Every task email also carries a link that turns its kind off without signing in.

Responses:

- `200` — OK
  - `notification_preferences` (object, required) — The caller's own choices. They follow the person across workspaces.
    - `chat` (object, required) — Which chat apps each kind also goes to, in the caller's own direct chat there. A minute after it happens and only if unseen, like email. Empty unless chosen; a group chat is never used.
      - `needs_you` (enum<string>[], required) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"
      - `done` (enum<string>[], required) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"
      - `shared` (enum<string>[], required) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"
    - `popup` (object, required) — When each kind pops up on the caller's Mac and browsers: `always` in the app or as a system notification, `away` only as a system notification while the app is not in front, `never` not at all (the rail still shows it).
      - `needs_you` (enum<string>, required) — A task starts waiting on me. `always` unless changed. — "always" · "away" · "never"
      - `done` (enum<string>, required) — A task finishes. `away` unless changed. — "always" · "away" · "never"
      - `shared` (enum<string>, required) — Someone shares a chat with me. `always` unless changed. — "always" · "away" · "never"
    - `sound` (boolean, required) — Whether a pop-up makes a sound. On unless turned off.
    - `attention_rules` (string) — The person's own words on what deserves their attention, read when a turn they did not start is judged. Empty when they wrote none.
    - `push` (object, required) — Which kinds reach the devices the caller subscribed (`/push-subscriptions`). Both on unless turned off; without a subscribed device nothing is pushed.
      - `needs_you` (boolean, required) — Notify my devices when one of my tasks starts waiting on me.
      - `done` (boolean, required) — Notify my devices when one of my tasks produces a result while I am away.
      - `shared` (boolean, required) — Notify my devices when someone shares a chat with me.
    - `email` (object, required)
      - `needs_you` (boolean, required) — Email me when one of my tasks starts waiting on me and I have not looked at it. On unless turned off.
      - `done` (boolean, required) — Email me when one of my tasks produces a result while I am away. Off unless turned on.
      - `shared` (boolean, required) — Email me when someone shares a chat with me. On unless turned off.
      - `seller` (boolean, required) — Email me when something is decided about an agent I sell. On unless turned off.
      - `workspace_balance` (boolean, required) — Email me when the balance of a workspace I manage runs low. On unless turned off.
      - `marketing` (boolean, required) — Whether the caller's address still gets AgentSky marketing email. False once they unsubscribed, by an email's link or by this API. A bounce stops delivery but is not an unsubscribe. Login and account email are never affected.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/notification-preferences' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /notification-preferences

Change which task events the caller is emailed and pushed about (scope: write)

Send `email`, `push` or both, each with only the kinds to change; the response holds all of them. `email.marketing: false` unsubscribes the caller's own address from marketing email, the same opt-out as the unsubscribe link in a marketing email; 409 `no_email` for an account without an address. Answers 503 `not_available` for task kinds until the platform's notification tables are in place.

Body (application/json):

- `email` (object)
  - `needs_you` (boolean)
  - `done` (boolean)
  - `shared` (boolean)
  - `seller` (boolean) — 503 not_migrated where seller notices are not available yet.
  - `workspace_balance` (enum<boolean>) — false turns a workspace's low-balance emails off; true is refused (400), since no surface offers turning them back on. 503 not_migrated while they cannot be turned off yet. — false
  - `marketing` (enum<boolean>) — false unsubscribes the caller's own address from marketing email; true is refused (400), since no surface offers subscribing — false
- `push` (object)
  - `needs_you` (boolean)
  - `done` (boolean)
  - `shared` (boolean)
- `popup` (object) — When each kind pops up: `always`, `away` or `never`.
  - `needs_you` (enum<string>) — "always" · "away" · "never"
  - `done` (enum<string>) — "always" · "away" · "never"
  - `shared` (enum<string>) — "always" · "away" · "never"
- `sound` (boolean) — Whether a pop-up makes a sound.
- `attention_rules` (string) — Replaces the person's own words on what deserves their attention; empty removes them. — max length 2000
- `chat` (object) — Replaces the chat apps of each kind named.
  - `needs_you` (enum<string>[]) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"
  - `done` (enum<string>[]) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"
  - `shared` (enum<string>[]) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"

Responses:

- `200` — OK
  - `notification_preferences` (object, required) — The caller's own choices. They follow the person across workspaces.
    - `chat` (object, required) — Which chat apps each kind also goes to, in the caller's own direct chat there. A minute after it happens and only if unseen, like email. Empty unless chosen; a group chat is never used.
      - `needs_you` (enum<string>[], required) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"
      - `done` (enum<string>[], required) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"
      - `shared` (enum<string>[], required) — "imessage" · "slack" · "telegram" · "lark" · "discord" · "whatsapp"
    - `popup` (object, required) — When each kind pops up on the caller's Mac and browsers: `always` in the app or as a system notification, `away` only as a system notification while the app is not in front, `never` not at all (the rail still shows it).
      - `needs_you` (enum<string>, required) — A task starts waiting on me. `always` unless changed. — "always" · "away" · "never"
      - `done` (enum<string>, required) — A task finishes. `away` unless changed. — "always" · "away" · "never"
      - `shared` (enum<string>, required) — Someone shares a chat with me. `always` unless changed. — "always" · "away" · "never"
    - `sound` (boolean, required) — Whether a pop-up makes a sound. On unless turned off.
    - `attention_rules` (string) — The person's own words on what deserves their attention, read when a turn they did not start is judged. Empty when they wrote none.
    - `push` (object, required) — Which kinds reach the devices the caller subscribed (`/push-subscriptions`). Both on unless turned off; without a subscribed device nothing is pushed.
      - `needs_you` (boolean, required) — Notify my devices when one of my tasks starts waiting on me.
      - `done` (boolean, required) — Notify my devices when one of my tasks produces a result while I am away.
      - `shared` (boolean, required) — Notify my devices when someone shares a chat with me.
    - `email` (object, required)
      - `needs_you` (boolean, required) — Email me when one of my tasks starts waiting on me and I have not looked at it. On unless turned off.
      - `done` (boolean, required) — Email me when one of my tasks produces a result while I am away. Off unless turned on.
      - `shared` (boolean, required) — Email me when someone shares a chat with me. On unless turned off.
      - `seller` (boolean, required) — Email me when something is decided about an agent I sell. On unless turned off.
      - `workspace_balance` (boolean, required) — Email me when the balance of a workspace I manage runs low. On unless turned off.
      - `marketing` (boolean, required) — Whether the caller's address still gets AgentSky marketing email. False once they unsubscribed, by an email's link or by this API. A bounce stops delivery but is not an unsubscribe. Login and account email are never affected.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/notification-preferences \
  -H "Authorization: Bearer ast_..."
```

### GET /push-subscriptions

The devices the caller is notified on (scope: read)

A subscribed device gets a push notification when one of the caller's tasks starts waiting on them or has a result, under the same rules as task emails, for the kinds left on under `push` in `/notification-preferences`. `application_server_key` is the key a browser subscribes with; it is null where browser push is not configured, and the list is empty where push is not turned on.

Responses:

- `200` — OK
  - `application_server_key` (string, required)
  - `data` (object[], required)
    - `id` (string, required)
    - `kind` (enum<string>, required) — `web` for a browser, `expo` for the phone app. — "web" · "expo"
    - `endpoint` (string, required) — The push service's address for that browser, or the phone app's Expo device token.
    - `created_at` (string, required)
    - `last_seen_at` (string, required) — When that device last subscribed.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/push-subscriptions' \
  -H "Authorization: Bearer ast_..."
```

### POST /push-subscriptions

Subscribe a device to push notifications (scope: write)

From a browser, send what its `pushManager.subscribe()` returned. From the phone app, send `{ kind: "expo", token }` with the device token Expo issued. Subscribing the same device again keeps one subscription. Answers 403 `not_enabled` where push is not turned on, 400 for an endpoint that is not a browser push service's or a token that is not Expo's, and 503 `not_migrated` until the platform's push tables are in place.

Body (application/json):

- `endpoint` (string) — A browser push service's address. With `keys`.
- `keys` (object)
  - `p256dh` (string, required)
  - `auth` (string, required)
- `kind` (enum<string>) — `expo`, for the phone app. With `token`. — "expo"
- `token` (string) — The device token Expo issued to this phone.

Responses:

- `201` — Created
  - `subscription` (object, required) — One device the caller asked to be notified on. A browser's keys are never returned.
    - `id` (string, required)
    - `kind` (enum<string>, required) — `web` for a browser, `expo` for the phone app. — "web" · "expo"
    - `endpoint` (string, required) — The push service's address for that browser, or the phone app's Expo device token.
    - `created_at` (string, required)
    - `last_seen_at` (string, required) — When that device last subscribed.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/push-subscriptions \
  -H "Authorization: Bearer ast_..."
```

### DELETE /push-subscriptions/{id}

Stop notifying one of the caller's devices (scope: write)

Path parameters:

- `id` (string, required)

Responses:

- `204` — Removed
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/push-subscriptions/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

## Agent catalog

### GET /catalog/engines

Read operational harness availability (scope: public)

The delisted engine identities, read without an HTTP cache. New acquisition rejects them; existing sessions are retained.

Responses:

- `200` — Current delisting state
  - `delisted` (string[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/engines' \
  -H "Authorization: Bearer ast_..."
```

### GET /catalog/agents

List hireable agents (scope: public)

Every listed agent: platform engines, and other people's agents that were reviewed and approved, each served as it was approved and carrying `seller`. Needs no credentials; a caller that sends them also gets its own workspace's listings. Answers 503 `not_migrated` until the platform's catalog tables are in place.

Query parameters:

- `category` (string)
- `q` (string) — Matches handle, name, tagline and description
- `sort` (string)
- `requires` (string) — Keep the agents whose stated requirements match: `account` needs the caller's own account at a vendor, `no_account` needs none, `mcp_servers` can use MCP servers. An account requirement is stated only where external accounts are turned on.

Responses:

- `200` — OK
  - `agents` (object[], required)
    - `handle` (string, required) — Globally unique and stable: lower-case letters, digits and underscores. What a person types after "/".
    - `kind` (enum<string>, required) — A platform engine, or an agent a person listed — "engine" · "agent"
    - `engine_type` (string | null, required) — The agent type to create an agent with, for an engine listing
    - `agent_id` (string | null, required) — The agent one of the caller's own workspace listings stands for; null for an engine and for another person's agent
    - `visibility` (enum<string>, required) — public for everyone: an engine, or another person's agent that was reviewed and approved. workspace for the caller's own listing, whether or not it is also public. — "public" · "workspace"
    - `seller` (object | null, required) — Who made a public agent that is not a platform engine, by the name they chose. Null for an engine and for the caller's own listing.
    - `name` (string, required)
    - `tagline` (string, required) — One line, at most 140 characters
    - `description` (string, required)
    - `does` (string[], required) — What it does. Empty when not yet written; never guessed.
    - `does_not` (string[], required) — What it does not do. Empty when not yet written.
    - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
    - `examples` (string[], required) — Example tasks
    - `requirements` (object, required) — What the agent needs, stated rather than hidden. `mcp_servers` says whether it can use MCP servers; `website` is the engine's own site. `hosted_by_seller: { host }` is present when the agent runs on its maker's own server instead of a sandbox: what a person sends it, and the files of the task, go to that host, and a person's first task with it waits for them to agree (a task request).
    - `pricing` (object, required) — `{ mode: "usage" }`: the model and tool usage the task incurs, with no agent fee. `{ mode: "per_task", fee: { amount, currency } }`: usage, plus a flat fee the agent's maker asks for each task; `amount` is whole US cents as a string. Starting such an agent asks the person to confirm the price the first time (a task request of kind `spend`), holds the fee on their credit when the task starts and takes it when the task gives its first result.
    - `stats` (object, required) — Counts from real use, recounted hourly; never estimated. `uses`: sessions started on the agent. `comparisons` and `wins`: decided side-by-side comparisons the agent took part in, and the ones a person picked it in. `completed_yes` and `completed_no`: people who said a task on this agent did the job, and people who said it did not (`PUT /tasks/{id}/completion_answer`).
      - `uses` (integer, required)
      - `comparisons` (integer, required)
      - `wins` (integer, required)
      - `completed_yes` (integer, required)
      - `completed_no` (integer, required)
      - `usage` (object | null) — What one task typically consumes: medians over the agent's sessions of the last 30 days that metered model usage. Null until at least 10 such sessions exist.
    - `conformance` (object | null, required) — The verdicts of the listing's latest finished conformance run; for another person's agent, of the run it was submitted with. Null when it has never finished one.
    - `created_at` (string, required)
    - `installed` (boolean) — Whether the caller's workspace installed this agent from the catalog and left it enabled. Only on a read made for a workspace.
    - `default_model` (string | null) — The model the caller's workspace starts this agent with by default; null when it set none. Only with installed.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/agents' \
  -H "Authorization: Bearer ast_..."
```

### GET /catalog/agents/{handle}

One agent by handle (scope: public)

Path parameters:

- `handle` (string, required) — The agent's handle; a leading @ is accepted

Responses:

- `200` — OK
  - `agent` (object, required)
    - `handle` (string, required) — Globally unique and stable: lower-case letters, digits and underscores. What a person types after "/".
    - `kind` (enum<string>, required) — A platform engine, or an agent a person listed — "engine" · "agent"
    - `engine_type` (string | null, required) — The agent type to create an agent with, for an engine listing
    - `agent_id` (string | null, required) — The agent one of the caller's own workspace listings stands for; null for an engine and for another person's agent
    - `visibility` (enum<string>, required) — public for everyone: an engine, or another person's agent that was reviewed and approved. workspace for the caller's own listing, whether or not it is also public. — "public" · "workspace"
    - `seller` (object | null, required) — Who made a public agent that is not a platform engine, by the name they chose. Null for an engine and for the caller's own listing.
    - `name` (string, required)
    - `tagline` (string, required) — One line, at most 140 characters
    - `description` (string, required)
    - `does` (string[], required) — What it does. Empty when not yet written; never guessed.
    - `does_not` (string[], required) — What it does not do. Empty when not yet written.
    - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
    - `examples` (string[], required) — Example tasks
    - `requirements` (object, required) — What the agent needs, stated rather than hidden. `mcp_servers` says whether it can use MCP servers; `website` is the engine's own site. `hosted_by_seller: { host }` is present when the agent runs on its maker's own server instead of a sandbox: what a person sends it, and the files of the task, go to that host, and a person's first task with it waits for them to agree (a task request).
    - `pricing` (object, required) — `{ mode: "usage" }`: the model and tool usage the task incurs, with no agent fee. `{ mode: "per_task", fee: { amount, currency } }`: usage, plus a flat fee the agent's maker asks for each task; `amount` is whole US cents as a string. Starting such an agent asks the person to confirm the price the first time (a task request of kind `spend`), holds the fee on their credit when the task starts and takes it when the task gives its first result.
    - `stats` (object, required) — Counts from real use, recounted hourly; never estimated. `uses`: sessions started on the agent. `comparisons` and `wins`: decided side-by-side comparisons the agent took part in, and the ones a person picked it in. `completed_yes` and `completed_no`: people who said a task on this agent did the job, and people who said it did not (`PUT /tasks/{id}/completion_answer`).
      - `uses` (integer, required)
      - `comparisons` (integer, required)
      - `wins` (integer, required)
      - `completed_yes` (integer, required)
      - `completed_no` (integer, required)
      - `usage` (object | null) — What one task typically consumes: medians over the agent's sessions of the last 30 days that metered model usage. Null until at least 10 such sessions exist.
    - `conformance` (object | null, required) — The verdicts of the listing's latest finished conformance run; for another person's agent, of the run it was submitted with. Null when it has never finished one.
    - `created_at` (string, required)
    - `installed` (boolean) — Whether the caller's workspace installed this agent from the catalog and left it enabled. Only on a read made for a workspace.
    - `default_model` (string | null) — The model the caller's workspace starts this agent with by default; null when it set none. Only with installed.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/agents/handle' \
  -H "Authorization: Bearer ast_..."
```

### POST /catalog/listings

List one of your own agents under a handle (scope: write)

The listing is visible to your workspace only, and `agent: "@handle"` then starts a session with that agent. A handle is unique across the platform, engines included; a taken one is 409 `handle_taken`. Listing the same agent again replaces its listing and frees the old handle. A listing whose agent is archived or deleted stops being offered.

Body (application/json):

- `agent_id` (string, required)
- `handle` (string, required) — 2 to 40 lower-case letters, digits or underscores; a leading @ is accepted
- `tagline` (string, required) — max length 140
- `description` (string) — max length 4000
- `categories` (enum<string>[]) — Defaults to general — "websites" · "content" · "video" · "code" · "research" · "general"
- `does` (string[]) — max length 300
- `does_not` (string[]) — max length 300
- `examples` (string[]) — max length 300

Responses:

- `201` — Created
  - `agent` (object, required)
    - `handle` (string, required) — Globally unique and stable: lower-case letters, digits and underscores. What a person types after "/".
    - `kind` (enum<string>, required) — A platform engine, or an agent a person listed — "engine" · "agent"
    - `engine_type` (string | null, required) — The agent type to create an agent with, for an engine listing
    - `agent_id` (string | null, required) — The agent one of the caller's own workspace listings stands for; null for an engine and for another person's agent
    - `visibility` (enum<string>, required) — public for everyone: an engine, or another person's agent that was reviewed and approved. workspace for the caller's own listing, whether or not it is also public. — "public" · "workspace"
    - `seller` (object | null, required) — Who made a public agent that is not a platform engine, by the name they chose. Null for an engine and for the caller's own listing.
    - `name` (string, required)
    - `tagline` (string, required) — One line, at most 140 characters
    - `description` (string, required)
    - `does` (string[], required) — What it does. Empty when not yet written; never guessed.
    - `does_not` (string[], required) — What it does not do. Empty when not yet written.
    - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
    - `examples` (string[], required) — Example tasks
    - `requirements` (object, required) — What the agent needs, stated rather than hidden. `mcp_servers` says whether it can use MCP servers; `website` is the engine's own site. `hosted_by_seller: { host }` is present when the agent runs on its maker's own server instead of a sandbox: what a person sends it, and the files of the task, go to that host, and a person's first task with it waits for them to agree (a task request).
    - `pricing` (object, required) — `{ mode: "usage" }`: the model and tool usage the task incurs, with no agent fee. `{ mode: "per_task", fee: { amount, currency } }`: usage, plus a flat fee the agent's maker asks for each task; `amount` is whole US cents as a string. Starting such an agent asks the person to confirm the price the first time (a task request of kind `spend`), holds the fee on their credit when the task starts and takes it when the task gives its first result.
    - `stats` (object, required) — Counts from real use, recounted hourly; never estimated. `uses`: sessions started on the agent. `comparisons` and `wins`: decided side-by-side comparisons the agent took part in, and the ones a person picked it in. `completed_yes` and `completed_no`: people who said a task on this agent did the job, and people who said it did not (`PUT /tasks/{id}/completion_answer`).
      - `uses` (integer, required)
      - `comparisons` (integer, required)
      - `wins` (integer, required)
      - `completed_yes` (integer, required)
      - `completed_no` (integer, required)
      - `usage` (object | null) — What one task typically consumes: medians over the agent's sessions of the last 30 days that metered model usage. Null until at least 10 such sessions exist.
    - `conformance` (object | null, required) — The verdicts of the listing's latest finished conformance run; for another person's agent, of the run it was submitted with. Null when it has never finished one.
    - `created_at` (string, required)
    - `installed` (boolean) — Whether the caller's workspace installed this agent from the catalog and left it enabled. Only on a read made for a workspace.
    - `default_model` (string | null) — The model the caller's workspace starts this agent with by default; null when it set none. Only with installed.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/catalog/listings \
  -H "Authorization: Bearer ast_..."
```

### DELETE /catalog/listings/{handle}

Take one of your own listings down (scope: write)

The agent itself is untouched. 404 for a handle that is not one of this workspace's listings.

Path parameters:

- `handle` (string, required) — The agent's handle; a leading @ is accepted

Responses:

- `200` — OK
  - `ok` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/catalog/listings/handle \
  -H "Authorization: Bearer ast_..."
```

### POST /catalog/listings/{handle}/conformance

Start a conformance run of one of your own listings (scope: write)

Answers at once with the run as `running`; read it back with GET. The suite uses the listing the way a customer would, through this API and as you: it starts sessions in your workspace, which you pay for, and deletes them when it is done. 404 for a handle that is not one of this workspace's listings, an engine included. 409 `conformance_running` while a run of that listing is still going.

Path parameters:

- `handle` (string, required) — The agent's handle; a leading @ is accepted

Responses:

- `202` — Accepted
  - `run` (object, required)
    - `id` (string, required)
    - `handle` (string, required)
    - `status` (enum<string>, required) — A run still going after 30 minutes is reported as failed. — "running" · "finished" · "failed"
    - `started_at` (string, required)
    - `finished_at` (string | null, required)
    - `reason` (string | null, required) — Why the run could not finish; null unless it failed
    - `required_passed` (boolean, required) — No required check failed and at least one ran. False until the run finished.
    - `all_passed` (boolean, required) — Every check ran and passed. False until the run finished.
    - `report` (object | null, required) — Every check with its outcome; null until the run finished.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/catalog/listings/handle/conformance \
  -H "Authorization: Bearer ast_..."
```

### GET /catalog/listings/{handle}/conformance

The latest conformance run of one of your own listings (scope: read)

`run` is null when the listing has never been run. 404 for a handle that is not one of this workspace's listings.

Path parameters:

- `handle` (string, required) — The agent's handle; a leading @ is accepted

Responses:

- `200` — OK
  - `run` (object | null, required)
    - `id` (string, required)
    - `handle` (string, required)
    - `status` (enum<string>, required) — A run still going after 30 minutes is reported as failed. — "running" · "finished" · "failed"
    - `started_at` (string, required)
    - `finished_at` (string | null, required)
    - `reason` (string | null, required) — Why the run could not finish; null unless it failed
    - `required_passed` (boolean, required) — No required check failed and at least one ran. False until the run finished.
    - `all_passed` (boolean, required) — Every check ran and passed. False until the run finished.
    - `report` (object | null, required) — Every check with its outcome; null until the run finished.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/listings/handle/conformance' \
  -H "Authorization: Bearer ast_..."
```

### GET /catalog/listings/{handle}/submission

Where one of your own listings stands with the public Market (scope: read)

Whether it can be submitted and what is missing, its latest submission, and the approved version being served. 404 for a handle that is not one of this workspace's listings.

Path parameters:

- `handle` (string, required) — The agent's handle; a leading @ is accepted

Responses:

- `200` — OK
  - `open` (boolean, required) — Whether this workspace may submit listings to the public Market
  - `missing` (string[], required) — What still has to be true before the listing can be submitted, in words. Empty when it can be.
  - `pricing` (object) — Present only where this workspace may set a flat fee on its public listings.
    - `seller_share_percent` (number, required) — The part of each fee the seller keeps
    - `fee_cents_min` (integer, required)
    - `fee_cents_max` (integer, required)
  - `submission` (object | null, required) — The latest submission; null when the listing has never been submitted.
  - `published` (object | null, required) — The approved version being served to everyone; null when the listing is not public.
  - `taken_down` (object | null, required) — Set when a reviewer took the public listing down and it has not been submitted again.
  - `scheduled_check` (object) — What the scheduled checks of the approved version found. A public listing's approved version is checked when it is approved and then by the weekly conformance sweep, as its seller and on the seller's credit for usage, under a spend cap. Absent when the listing is not public.
    - `passing` (boolean | null, required) — Whether the required checks passed at the last scheduled run that finished; null before the first. False takes the listing's `conformance.required_passed` away for everyone; the listing stays public.
    - `reason` (string | null, required) — The required checks that failed, or why the latest run was skipped or could not finish
    - `checked_at` (string | null, required)
    - `running` (boolean, required) — Whether a scheduled run of this version is going now
    - `next_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/listings/handle/submission' \
  -H "Authorization: Bearer ast_..."
```

### POST /catalog/listings/{handle}/submission

Submit one of your own listings for the public Market (scope: write)

Stores the listing and its agent as they are now and puts them in front of a reviewer. Once approved, everyone sees the listing and can start it with `agent: "@handle"`; their session runs a hidden copy of the approved agent in their own workspace, on their own wallet. Later edits are not served until a new submission is approved. `fee` asks a flat fee for each task on top of usage; like everything else it takes effect, and changes, only when a submission carrying it is approved, and a submission without it makes the listing usage-only again. 403 `submissions_closed` when this workspace may not submit. 403 `pricing_closed` when `fee` is sent and this workspace may not set a price. 422 `not_submittable` when something is missing: the message names every item. 409 `already_in_review` while an earlier submission is waiting.

Path parameters:

- `handle` (string, required) — The agent's handle; a leading @ is accepted

Body (application/json):

- `seller_name` (string, required) — The name the Market shows as the maker. Not an email address. — max length 60
- `fee` (object) — The flat fee for each task, in whole US cents: 1 to 100000
  - `amount` (string, required) — Whole US cents — pattern ^[1-9][0-9]*$
  - `currency` (enum<string>, required) — "USD"

Responses:

- `201` — Submitted
  - `open` (boolean, required) — Whether this workspace may submit listings to the public Market
  - `missing` (string[], required) — What still has to be true before the listing can be submitted, in words. Empty when it can be.
  - `pricing` (object) — Present only where this workspace may set a flat fee on its public listings.
    - `seller_share_percent` (number, required) — The part of each fee the seller keeps
    - `fee_cents_min` (integer, required)
    - `fee_cents_max` (integer, required)
  - `submission` (object | null, required) — The latest submission; null when the listing has never been submitted.
  - `published` (object | null, required) — The approved version being served to everyone; null when the listing is not public.
  - `taken_down` (object | null, required) — Set when a reviewer took the public listing down and it has not been submitted again.
  - `scheduled_check` (object) — What the scheduled checks of the approved version found. A public listing's approved version is checked when it is approved and then by the weekly conformance sweep, as its seller and on the seller's credit for usage, under a spend cap. Absent when the listing is not public.
    - `passing` (boolean | null, required) — Whether the required checks passed at the last scheduled run that finished; null before the first. False takes the listing's `conformance.required_passed` away for everyone; the listing stays public.
    - `reason` (string | null, required) — The required checks that failed, or why the latest run was skipped or could not finish
    - `checked_at` (string | null, required)
    - `running` (boolean, required) — Whether a scheduled run of this version is going now
    - `next_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/catalog/listings/handle/submission \
  -H "Authorization: Bearer ast_..."
```

### DELETE /catalog/listings/{handle}/submission

Withdraw a submission that is waiting for review (scope: write)

404 when nothing of this listing is waiting.

Path parameters:

- `handle` (string, required) — The agent's handle; a leading @ is accepted

Responses:

- `200` — OK
  - `open` (boolean, required) — Whether this workspace may submit listings to the public Market
  - `missing` (string[], required) — What still has to be true before the listing can be submitted, in words. Empty when it can be.
  - `pricing` (object) — Present only where this workspace may set a flat fee on its public listings.
    - `seller_share_percent` (number, required) — The part of each fee the seller keeps
    - `fee_cents_min` (integer, required)
    - `fee_cents_max` (integer, required)
  - `submission` (object | null, required) — The latest submission; null when the listing has never been submitted.
  - `published` (object | null, required) — The approved version being served to everyone; null when the listing is not public.
  - `taken_down` (object | null, required) — Set when a reviewer took the public listing down and it has not been submitted again.
  - `scheduled_check` (object) — What the scheduled checks of the approved version found. A public listing's approved version is checked when it is approved and then by the weekly conformance sweep, as its seller and on the seller's credit for usage, under a spend cap. Absent when the listing is not public.
    - `passing` (boolean | null, required) — Whether the required checks passed at the last scheduled run that finished; null before the first. False takes the listing's `conformance.required_passed` away for everyone; the listing stays public.
    - `reason` (string | null, required) — The required checks that failed, or why the latest run was skipped or could not finish
    - `checked_at` (string | null, required)
    - `running` (boolean, required) — Whether a scheduled run of this version is going now
    - `next_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/catalog/listings/handle/submission \
  -H "Authorization: Bearer ast_..."
```

### DELETE /catalog/listings/{handle}/publication

Stop serving one of your own listings to everyone else (scope: write)

The workspace listing and the agent stay. Sessions other people already started keep running. 404 when the listing is not public.

Path parameters:

- `handle` (string, required) — The agent's handle; a leading @ is accepted

Responses:

- `200` — OK
  - `open` (boolean, required) — Whether this workspace may submit listings to the public Market
  - `missing` (string[], required) — What still has to be true before the listing can be submitted, in words. Empty when it can be.
  - `pricing` (object) — Present only where this workspace may set a flat fee on its public listings.
    - `seller_share_percent` (number, required) — The part of each fee the seller keeps
    - `fee_cents_min` (integer, required)
    - `fee_cents_max` (integer, required)
  - `submission` (object | null, required) — The latest submission; null when the listing has never been submitted.
  - `published` (object | null, required) — The approved version being served to everyone; null when the listing is not public.
  - `taken_down` (object | null, required) — Set when a reviewer took the public listing down and it has not been submitted again.
  - `scheduled_check` (object) — What the scheduled checks of the approved version found. A public listing's approved version is checked when it is approved and then by the weekly conformance sweep, as its seller and on the seller's credit for usage, under a spend cap. Absent when the listing is not public.
    - `passing` (boolean | null, required) — Whether the required checks passed at the last scheduled run that finished; null before the first. False takes the listing's `conformance.required_passed` away for everyone; the listing stays public.
    - `reason` (string | null, required) — The required checks that failed, or why the latest run was skipped or could not finish
    - `checked_at` (string | null, required)
    - `running` (boolean, required) — Whether a scheduled run of this version is going now
    - `next_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/catalog/listings/handle/publication \
  -H "Authorization: Bearer ast_..."
```

### GET /seller/earnings

What you have earned from the fees on your public listings (scope: read)

Totals, a line per listing, a line per captured fee (newest first) and the payouts they went into. The seller keeps the share shown on each line; the rest is the platform's. A `referral` line is the caller's share of a fee another seller's agent was paid by a person the caller brought; it counts in `earned`, `paid` and `unpaid`, not in `gross` or `listings`. A fee is payable once the 72 hours its buyer has to dispute it have passed, and payouts are made once a month. Nothing here identifies a buyer. 404 where flat fees are not offered.

Responses:

- `200` — OK
  - `totals` (object, required)
    - `gross` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
    - `earned` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
    - `paid` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
    - `unpaid` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
  - `listings` (object[], required)
    - `handle` (string, required)
    - `tasks` (integer, required)
    - `gross` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
    - `earned` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
  - `lines` (object[], required)
    - `id` (string, required)
    - `handle` (string, required)
    - `kind` (enum<string>, required) — `reversal`: a fee refunded after it had been paid out, taken off the next payout. `referral`: the caller's share of a fee another seller's agent was paid by a person the caller referred (`POST /seller/referrals`); its `fee` is that fee — "earning" · "reversal" · "referral"
    - `source` (enum<string>, required) — Who brought the buyer; `referral` on a referral line — "shelf" · "seller_referred" · "helper" · "referral"
    - `fee` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
    - `share_percent` (number, required)
    - `earned` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
    - `status` (enum<string>, required) — "waiting" · "disputed" · "refunded" · "payable" · "in_payout" · "paid"
    - `payable_at` (string, required)
    - `created_at` (string, required)
  - `payouts` (object[], required)
    - `id` (string, required)
    - `period_start` (string, required)
    - `period_end` (string, required)
    - `amount` (object, required)
      - `amount` (string, required) — Whole US cents; negative on a reversal
      - `currency` (enum<string>, required) — "USD"
    - `status` (enum<string>, required) — "owed" · "paid"
    - `paid_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/seller/earnings' \
  -H "Authorization: Bearer ast_..."
```

### GET /seller/account

Your seller account status (scope: read)

Returns the Stripe Connect account status for the caller. 404 when the caller has no seller account record or the payout tables are not yet migrated.

Responses:

- `200` — OK
  - `account_status` (enum<string>, required) — "pending" · "active" · "restricted"
  - `payout_connected` (boolean, required) — True when the Stripe Connect account is active and transfers can be sent
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/seller/account' \
  -H "Authorization: Bearer ast_..."
```

### POST /seller/account

Create your seller account record (scope: write)

Creates or upserts the caller's seller account record. Idempotent — calling it again when a record already exists is a no-op. 404 when the payout tables are not yet migrated.

Responses:

- `201` — Created
  - `ok` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/seller/account \
  -H "Authorization: Bearer ast_..."
```

### POST /seller/account/connect

Start or resume Stripe Connect onboarding (scope: write)

Returns a single-use Stripe account-link URL the seller opens to complete payout setup. 404 when the payout tables are not yet migrated. 503 when the payment processor is not configured.

Responses:

- `200` — OK
  - `url` (string, required) — Single-use Stripe account-link URL; expires quickly
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/seller/account/connect \
  -H "Authorization: Bearer ast_..."
```

### POST /seller/referrals

Record that a user was referred by you (scope: write)

Records that the target user was brought to the platform by the caller. A user can have at most one referral source; a second call for the same target is a no-op (200, `recorded: false`). 404 when the payout tables are not yet migrated.

Body (application/json):

- `referred_user_id` (string, required) — The id of the user who was referred

Responses:

- `200` — OK
  - `recorded` (boolean, required) — true when this call created the referral row; false when it already existed
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/seller/referrals \
  -H "Authorization: Bearer ast_..."
```

### GET /seller/notices

What you were told about the agents you sell (scope: read)

Newest first: a submission approved or sent back, a listing taken down, a lost `Checked` mark, a ruling on a disputed fee, a payout recorded. Each is also mailed once to the seller where task emails are on for the seller's workspace, unless the seller turned these emails off with the link in one of them. `handle` narrows the list to one listing plus the notices that are about none. 404 where neither public submissions nor flat fees are offered.

Query parameters:

- `handle` (string)

Responses:

- `200` — OK
  - `data` (object[], required)
    - `id` (string, required)
    - `kind` (enum<string>, required) — "approved" · "sent_back" · "taken_down" · "checks_failed" · "dispute_refunded" · "dispute_upheld" · "payout_paid"
    - `handle` (string | null, required)
    - `title` (string, required)
    - `text` (string, required) — The notice in words, with the reviewer's reason or the amount
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/seller/notices' \
  -H "Authorization: Bearer ast_..."
```

### PUT /catalog/comparison_counts

Report comparison counts per handle (scope: first-party)

For the first-party client that records side-by-side comparison verdicts; any other token is refused with 403. The body is a full snapshot taken at `reported_at`: each handle is set to its totals and a handle left out is removed, so sending the same snapshot again changes nothing and an older one never overwrites a newer one. The totals reach `stats.comparisons` and `stats.wins` on the next hourly recount. Answers 503 `not_migrated` until the platform's table is in place.

Body (application/json):

- `reported_at` (string, required)
- `counts` (object[], required)
  - `handle` (string, required)
  - `comparisons` (integer, required)
  - `wins` (integer, required)

Responses:

- `200` — OK
  - `handles` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/catalog/comparison_counts \
  -H "Authorization: Bearer ast_..."
```

### GET /catalog/categories

The category vocabulary (scope: public)

Responses:

- `200` — OK
  - `categories` (object[], required)
    - `id` (enum<string>, required) — "websites" · "content" · "video" · "code" · "research" · "general"
    - `label` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/categories' \
  -H "Authorization: Bearer ast_..."
```

### GET /catalog/environments

List environment listings on the shelf (scope: public)

Approved environment listings, plus the caller's own workspace's listings. With the shelf open to every workspace it needs no credentials; with it open to some workspaces only, readers signed in to one of them. Answers 404 when the shelf is not enabled. Answers 503 `not_migrated` until the shelf migration is applied.

Query parameters:

- `q` (string) — Matches handle, name, tagline and description
- `category` (string)
- `sort` (string)

Responses:

- `200` — OK
  - `environments` (object[], required)
    - `id` (string, required) — The listing id (lst_…)
    - `handle` (string, required) — Globally unique within environment listings; lower-case letters, digits and underscores
    - `name` (string, required)
    - `tagline` (string, required) — One line, at most 140 characters
    - `description` (string, required)
    - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
    - `packages` (object | null, required) — The listed environment's package configuration, or null when it has none
    - `tools` (object | null, required) — The listed environment's tool policy, or null when it has none
    - `networking` (object | null, required) — The listed environment's networking configuration, or null when it has none
    - `installs` (integer, required) — How many workspaces have installed this listing
    - `seller` (object | null, required) — Who published it to other workspaces, by the name they chose; null while it is visible only to its own workspace
    - `visibility` (enum<string>, required) — workspace = visible only to the owning workspace; public = approved, and visible to every workspace the shelf is open to. Other workspaces read and install the approved version; the owner's later edits wait for a new approval — "workspace" · "public"
    - `conformance` (object | null, required) — The smoke run the approved version passed; null for a listing that is not public
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/environments' \
  -H "Authorization: Bearer ast_..."
```

### GET /catalog/environments/{handle}

One environment listing by handle (scope: public)

Answers 404 when the shelf is not enabled for the reader, the handle is not found, or the listing belongs to a different workspace and is not approved.

Path parameters:

- `handle` (string, required) — The listing handle

Responses:

- `200` — OK
  - `environment` (object, required)
    - `id` (string, required) — The listing id (lst_…)
    - `handle` (string, required) — Globally unique within environment listings; lower-case letters, digits and underscores
    - `name` (string, required)
    - `tagline` (string, required) — One line, at most 140 characters
    - `description` (string, required)
    - `categories` (enum<string>[], required) — "websites" · "content" · "video" · "code" · "research" · "general"
    - `packages` (object | null, required) — The listed environment's package configuration, or null when it has none
    - `tools` (object | null, required) — The listed environment's tool policy, or null when it has none
    - `networking` (object | null, required) — The listed environment's networking configuration, or null when it has none
    - `installs` (integer, required) — How many workspaces have installed this listing
    - `seller` (object | null, required) — Who published it to other workspaces, by the name they chose; null while it is visible only to its own workspace
    - `visibility` (enum<string>, required) — workspace = visible only to the owning workspace; public = approved, and visible to every workspace the shelf is open to. Other workspaces read and install the approved version; the owner's later edits wait for a new approval — "workspace" · "public"
    - `conformance` (object | null, required) — The smoke run the approved version passed; null for a listing that is not public
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/environments/handle' \
  -H "Authorization: Bearer ast_..."
```

### POST /catalog/environments/{handle}/install

Install an environment listing into your workspace (scope: write)

Creates a copy of the listed environment in the caller's workspace that `extends` the original, so composition (packages, tool policy, networking) is applied at write time; another workspace's listing is composed from its approved version. A second install of the same listing by the same workspace is idempotent and returns the existing copy. Answers 404 when the shelf is not enabled or the listing is not found. Answers 503 `not_migrated` until the shelf migration is applied.

Path parameters:

- `handle` (string, required) — The listing handle

Responses:

- `201` — Created
  - `environment` (object, required)
    - `id` (string, required) — env_…
    - `name` (string, required)
    - `config` (object, required) — `packages` are installed into the image at build time — an environment is built when it is created and rebuilt when its config changes, so a session starting from it pays no install cost. `networking` is the egress policy its sessions run under; `limited` needs `allow_package_managers` when packages are declared, or the install could never succeed.
      - `type` ("cloud") — default: "cloud"
      - `packages` (object)
        - `apt` (string[]) — default: [] — max length 512
        - `pip` (string[]) — default: [] — max length 512
        - `npm` (string[]) — default: [] — max length 512
      - `networking` (object)
        - type: "unrestricted" (object)
          - `type` ("unrestricted", required)
        - type: "limited" (object)
          - `type` ("limited", required)
          - `allowed_hosts` (string[]) — default: [] — max length 253 — pattern ^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$
          - `allow_mcp_servers` (boolean) — default: false
          - `allow_package_managers` (boolean) — default: false
    - `is_default` (boolean, required) — Whether a new session that names no environment uses this one. At most one per workspace; setting it on one clears it on the others.
    - `extends` (string | null, required) — The env_… id of the parent environment this one extends, or null. Immutable after create. Child packages, tools.disabled and networking compose on the parent's at write time.
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/catalog/environments/handle/install \
  -H "Authorization: Bearer ast_..."
```

### GET /catalog/listings/{handle}/hosting

Where one of the workspace's listings runs (scope: read)

The secret is never returned here. Answers 404 until running an agent on your own server is open for the workspace.

Path parameters:

- `handle` (string, required) — The handle of one of the workspace's own listings.

Responses:

- `200` — OK
  - `hosting` (enum<string>, required) — `platform`: in a sandbox. `seller`: on the maker's own server. — "platform" · "seller"
  - `endpoint_url` (string) — The address tasks are sent to. Present when `hosting` is `seller`.
  - `secret` (string) — The secret requests are signed with. Present only in the response that made or replaced it.
  - `created_at` (string)
  - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/catalog/listings/handle/hosting' \
  -H "Authorization: Bearer ast_..."
```

### PUT /catalog/listings/{handle}/hosting

Run a listing on your own server (scope: write)

Each task given to the listing is then sent to this address instead of a sandbox, as one POST per turn: `{id, type: "task.turn", created_at, task: {id, session_id, agent}, message: {id, text}, pass: {token, expires_at}, api_base, callback_url}`. The request is signed like a webhook: `x-asteroids-timestamp`, and `x-asteroids-signature` = `v1=` + HMAC-SHA256 of `<timestamp>.<body>` with the listing's secret; check it before trusting the body. Answer 2xx within 10 seconds, then do the work and report to `callback_url`. The request is made once and is not retried; an address that does not answer 2xx in time ends the turn with an error the person reads. `pass.token` is a Bearer credential for that one turn of that one task. It reads the task (`GET /tasks/{id}`), reports to it (`POST /tasks/{id}/callback`), and reads and writes its files (`/tasks/{id}/files`); every other route refuses it with 403. It stops working when the turn ends, when the person stops the turn or archives the task, or after 15 minutes, whichever is first; a turn still open then is ended with an error. A later message from the person, or their answer to a question, is a new turn with a new pass. The address must be https on the public internet. The first call answers 201 with the signing secret, shown once; a later call changes the address and keeps the secret. A listing that is already public keeps running where its approved version said until a new submission is approved. Answers 404 until running an agent on your own server is open for the workspace. 503 `not_migrated` until its tables are in place.

Path parameters:

- `handle` (string, required) — The handle of one of the workspace's own listings.

Body (application/json):

- `endpoint_url` (string, required) — The https address tasks are sent to.

Responses:

- `200` — Address changed
  - `hosting` (enum<string>, required) — `platform`: in a sandbox. `seller`: on the maker's own server. — "platform" · "seller"
  - `endpoint_url` (string) — The address tasks are sent to. Present when `hosting` is `seller`.
  - `secret` (string) — The secret requests are signed with. Present only in the response that made or replaced it.
  - `created_at` (string)
  - `updated_at` (string)
- `201` — Now runs on your server; carries the secret
  - `hosting` (enum<string>, required) — `platform`: in a sandbox. `seller`: on the maker's own server. — "platform" · "seller"
  - `endpoint_url` (string) — The address tasks are sent to. Present when `hosting` is `seller`.
  - `secret` (string) — The secret requests are signed with. Present only in the response that made or replaced it.
  - `created_at` (string)
  - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/catalog/listings/handle/hosting \
  -H "Authorization: Bearer ast_..."
```

### DELETE /catalog/listings/{handle}/hosting

Run a listing in a sandbox again (scope: write)

Tasks already started on your server can no longer be sent to it: their next turn ends with an error. Answers 404 until running an agent on your own server is open for the workspace.

Path parameters:

- `handle` (string, required) — The handle of one of the workspace's own listings.

Responses:

- `200` — OK
  - `hosting` (enum<string>, required) — `platform`: in a sandbox. `seller`: on the maker's own server. — "platform" · "seller"
  - `endpoint_url` (string) — The address tasks are sent to. Present when `hosting` is `seller`.
  - `secret` (string) — The secret requests are signed with. Present only in the response that made or replaced it.
  - `created_at` (string)
  - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/catalog/listings/handle/hosting \
  -H "Authorization: Bearer ast_..."
```

### POST /catalog/listings/{handle}/hosting/secret

Replace the secret a listing's requests are signed with (scope: write)

Answers the new secret, shown once. The next request is signed with it; the old one is no longer used. Answers 404 until running an agent on your own server is open for the workspace.

Path parameters:

- `handle` (string, required) — The handle of one of the workspace's own listings.

Responses:

- `201` — Replaced; carries the new secret
  - `hosting` (enum<string>, required) — `platform`: in a sandbox. `seller`: on the maker's own server. — "platform" · "seller"
  - `endpoint_url` (string) — The address tasks are sent to. Present when `hosting` is `seller`.
  - `secret` (string) — The secret requests are signed with. Present only in the response that made or replaced it.
  - `created_at` (string)
  - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/catalog/listings/handle/hosting/secret \
  -H "Authorization: Bearer ast_..."
```

## Artifacts

### GET /artifacts/{id}/policy/{requestId}/projection

Read exact immutable policy routing projection

After-commit/replay routing-cache proof. Requires original immutable operation actor, write scope and its current exact full/selected-alias management ceiling. Dedicated session callback accepts only this GET/UUID path with source_epoch and purpose=consumer_artifact_policy_projection, runtime sessionToken cookie header and exact purpose header; it reauthenticates the actual Better Auth session. Bearer presence never falls back to cookies. Current returns the caller-authorized scoped receipt. For alias recovery, the internal proof may select full current projection (selected_alias_id:null) only after the same principal passes and rechecks the existing full management ceiling; otherwise it stays selected-only. The external policy POST response remains narrow. superseded returns receipt:null with no obsolete raw tokens. No independent user action, content grant or global identity endpoint.

Path parameters:

- `id` (string, required)
- `requestId` (string, required)

Query parameters:

- `source_epoch` (integer)
- `purpose` (string)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_policy_projection", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `source_epoch` (integer, required)
  - `request_id` (string, required)
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — max length 200
  - `policy_version` (integer, required)
  - `selected_alias_id` (string | null, required) — max length 200
  - `state` (enum<string>, required) — "current" · "superseded"
  - `receipt` (object | null, required)
    - `id` (string, required) — max length 200
    - `request_id` (string | null, required)
    - `policy_version` (integer, required)
    - `name` (string, required)
    - `version` (integer, required)
    - `policy` (object, required)
      - `version` (1, required)
      - `placement` (object | null, required)
        - `slug` (string, required)
        - `created_at` (string, required)
      - `aliases` (object[], required)
        - `id` (string, required) — max length 200
        - `workspace` (object | null, required)
          - `slug` (string, required)
          - `created_at` (string, required)
        - `workspace_access` (enum<string>, required) — "none" · "view" · "edit"
        - `members` (object[], required)
          - `user_id` (string, required) — max length 200
          - `access` (enum<string>, required) — "view" · "edit"
        - `revision` (integer, required)
        - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
        - `shared_token_hash` (string) — pattern ^[a-f0-9]{64}$
      - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
      - `public_version` (integer | null, required)
    - `tokens` (object, required) — Only exact newly issued/revoked public and alias token receipts; private to the owner
    - `archived_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/policy/requestId/projection' \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts/{id}/reclamation

Read exact retired-file reclamation progress (scope: write)

Actual retired owner's current unrestricted write bearer required even for this read. Durable progress only; missing responses never imply released capacity.

Path parameters:

- `id` (string, required)

Query parameters:

- `request_id` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_reclamation", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `owner_user_id` (string, required) — max length 200
  - `actor_user_id` (string, required) — max length 200
  - `phase` (enum<string>, required) — "pending" · "reclaimed"
  - `revision_ids` (string[], required) — max length 200
  - `pending_requests_closed` (boolean, required)
  - `bytes_reclaimed_revision_ids` (string[], required) — max length 200
  - `source_closed_revision_ids` (string[], required) — max length 200
  - `complete` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/reclamation?request_id=ask-7f3c2a' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/{id}/reclamation

Reclaim actual stored bytes of an explicitly retired file (scope: write)

Retire first through the owner policy. Resume one exact UUID: close pending operations, delete and verify actual canonical generations, then close original source admissions. Failed/unknown deletion keeps capacity charged. Retired identity and request tombstones remain; no resurrection.

Path parameters:

- `id` (string, required)

Body (application/json):

- `request_id` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_reclamation", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `owner_user_id` (string, required) — max length 200
  - `actor_user_id` (string, required) — max length 200
  - `phase` (enum<string>, required) — "pending" · "reclaimed"
  - `revision_ids` (string[], required) — max length 200
  - `pending_requests_closed` (boolean, required)
  - `bytes_reclaimed_revision_ids` (string[], required) — max length 200
  - `source_closed_revision_ids` (string[], required) — max length 200
  - `complete` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/reclamation \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"request_id":"b73682d8-9745-4f09-ae19-dbf83baed1f3"}'
```

### GET /artifacts/adoptions/{targetId}/activation

Read exact legacy activation (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback.

Path parameters:

- `targetId` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_activation", required)
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `adoption_request_id` (string, required) — max length 120
  - `binding_epoch` (integer, required)
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
  - `phase` (enum<string>, required) — "preparing" · "imported" · "active" · "cancelled"
  - `import_receipt` (object | null, required)
    - `target_id` (string, required) — max length 200
    - `request_id` (string, required) — max length 120
    - `source_id` (string, required) — max length 200
    - `binding_epoch` (integer, required)
    - `history_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `policy_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `current_version` (integer, required)
  - `imported_version` (integer)
  - `more` (true)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/adoptions/targetId/activation' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/adoptions/{targetId}/activation

Fence a verified legacy source for activation (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback. Current source history, policy and epoch must still match the verified snapshot. Late legacy writers fail their final fence check.

Path parameters:

- `targetId` (string, required)

Body (application/json):

- `request_id` (string, required) — max length 120

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_activation", required)
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `adoption_request_id` (string, required) — max length 120
  - `binding_epoch` (integer, required)
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
  - `phase` (enum<string>, required) — "preparing" · "imported" · "active" · "cancelled"
  - `import_receipt` (object | null, required)
    - `target_id` (string, required) — max length 200
    - `request_id` (string, required) — max length 120
    - `source_id` (string, required) — max length 200
    - `binding_epoch` (integer, required)
    - `history_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `policy_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `current_version` (integer, required)
  - `imported_version` (integer)
  - `more` (true)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/adoptions/targetId/activation \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"request_id":"legacy-activation-request-001"}'
```

### POST /artifacts/adoptions/{targetId}/activation/import

import exact legacy activation (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback. Imports at most one retained raw revision per call. Repeat the same request while phase=preparing and more=true until phase=imported. Retained versions/raw bytes/manifests and common public pin are preserved; staging stays invisible.

Path parameters:

- `targetId` (string, required)

Body (application/json):

- `request_id` (string, required) — max length 120

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_activation", required)
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `adoption_request_id` (string, required) — max length 120
  - `binding_epoch` (integer, required)
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
  - `phase` (enum<string>, required) — "preparing" · "imported" · "active" · "cancelled"
  - `import_receipt` (object | null, required)
    - `target_id` (string, required) — max length 200
    - `request_id` (string, required) — max length 120
    - `source_id` (string, required) — max length 200
    - `binding_epoch` (integer, required)
    - `history_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `policy_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `current_version` (integer, required)
  - `imported_version` (integer)
  - `more` (true)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/adoptions/targetId/activation/import \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"request_id":"legacy-activation-request-001"}'
```

### POST /artifacts/adoptions/{targetId}/activation/activate

activate exact legacy activation (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback. Verifies exact durable source forwarding before exposing canonical history/current/discussion.

Path parameters:

- `targetId` (string, required)

Body (application/json):

- `request_id` (string, required) — max length 120

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_activation", required)
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `adoption_request_id` (string, required) — max length 120
  - `binding_epoch` (integer, required)
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
  - `phase` (enum<string>, required) — "preparing" · "imported" · "active" · "cancelled"
  - `import_receipt` (object | null, required)
    - `target_id` (string, required) — max length 200
    - `request_id` (string, required) — max length 120
    - `source_id` (string, required) — max length 200
    - `binding_epoch` (integer, required)
    - `history_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `policy_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `current_version` (integer, required)
  - `imported_version` (integer)
  - `more` (true)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/adoptions/targetId/activation/activate \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"request_id":"legacy-activation-request-001"}'
```

### POST /artifacts/adoptions/{targetId}/activation/cancel

cancel exact legacy activation (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback. Allowed only before the imported boundary; close canonical first, then release the source fence.

Path parameters:

- `targetId` (string, required)

Body (application/json):

- `request_id` (string, required) — max length 120

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_activation", required)
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `adoption_request_id` (string, required) — max length 120
  - `binding_epoch` (integer, required)
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
  - `phase` (enum<string>, required) — "preparing" · "imported" · "active" · "cancelled"
  - `import_receipt` (object | null, required)
    - `target_id` (string, required) — max length 200
    - `request_id` (string, required) — max length 120
    - `source_id` (string, required) — max length 200
    - `binding_epoch` (integer, required)
    - `history_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `policy_digest` (string, required) — pattern ^[a-f0-9]{64}$
    - `current_version` (integer, required)
  - `imported_version` (integer)
  - `more` (true)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/adoptions/targetId/activation/cancel \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"request_id":"legacy-activation-request-001"}'
```

### GET /artifacts/adoptions/{targetId}/activation/revisions

Page imported activation history (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback.

Path parameters:

- `targetId` (string, required)

Query parameters:

- `after` (integer)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `binding_epoch` (integer, required)
  - `history_digest` (string, required) — pattern ^[a-f0-9]{64}$
  - `entries` (object[], required)
    - `revision_id` (string, required) — max length 200
    - `request_id` (string, required) — max length 200
    - `base_version` (integer, required)
    - `version` (integer, required)
    - `sha256` (string, required) — pattern ^[a-f0-9]{64}$
    - `size_bytes` (integer, required)
    - `media_type` (string, required) — max length 200
    - `site` (boolean, required)
    - `restored_from` (integer | null, required)
    - `created_at` (string, required)
    - `canonical_revision_id` (string, required) — max length 200
  - `next` (integer | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/adoptions/targetId/activation/revisions' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/{id}/mutations

Prepare an adopted file revision (scope: write)

Prepare immutable UUID/base/hash/size/media/site/restore facts under the real editor's current permission. The source owner's original admission aggregate remains the only quota owner. No accepted bytes, new version or capacity release is implied by preparation.

Path parameters:

- `id` (string, required)

Body (application/json):

- `request_id` (string, required)
- `base_version` (integer, required)
- `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
- `raw_size_bytes` (integer, required)
- `media_type` (string, required) — max length 200
- `site` (boolean, required)
- `restored_from` (integer | null, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_content", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_id` (string, required) — max length 200
  - `source_namespace` ("agent-use", required)
  - `owner_user_id` (string, required) — max length 200
  - `actor` (object, required)
    - option 1 (object)
      - `kind` ("user", required)
      - `user_id` (string, required) — max length 200
    - option 2 (object)
      - `kind` ("publisher", required)
      - `publisher_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer" · "publisher"
  - `consumer_client_id` (string | null, required)
  - `source_epoch` (integer, required)
  - `policy_version` (1, required)
  - `base_version` (integer, required)
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
  - `media_type` (string, required)
  - `site` (boolean, required)
  - `restored_from` (integer | null, required)
  - `phase` (enum<string>, required) — "pending" · "claimed" · "committed" · "cancelled" · "reclaimed"
  - `version` (integer | null, required)
  - `revision_id` (string, required) — max length 200
  - `generations_reclaimed` (boolean, required)
  - `eligible_operation` (enum<string>, required) — "status" · "reserve" · "claim" · "settle" · "close"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/mutations \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"request_id":"b73682d8-9745-4f09-ae19-dbf83baed1f3","base_version":3,"raw_sha256":"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad","raw_size_bytes":3,"media_type":"text/plain","site":false,"restored_from":null}'
```

### GET /artifacts/{id}/mutations/{requestId}

Read purpose-bound exact content request

operation defaults to status. reserve/claim/settle/close project only the exact eligible source operation. Recovery after lost commit/settle uses this same UUID, never a new charge or version.

Path parameters:

- `id` (string, required)
- `requestId` (string, required)

Query parameters:

- `operation` (string)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_content", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_id` (string, required) — max length 200
  - `source_namespace` ("agent-use", required)
  - `owner_user_id` (string, required) — max length 200
  - `actor` (object, required)
    - option 1 (object)
      - `kind` ("user", required)
      - `user_id` (string, required) — max length 200
    - option 2 (object)
      - `kind` ("publisher", required)
      - `publisher_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer" · "publisher"
  - `consumer_client_id` (string | null, required)
  - `source_epoch` (integer, required)
  - `policy_version` (1, required)
  - `base_version` (integer, required)
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
  - `media_type` (string, required)
  - `site` (boolean, required)
  - `restored_from` (integer | null, required)
  - `phase` (enum<string>, required) — "pending" · "claimed" · "committed" · "cancelled" · "reclaimed"
  - `version` (integer | null, required)
  - `revision_id` (string, required) — max length 200
  - `generations_reclaimed` (boolean, required)
  - `eligible_operation` (enum<string>, required) — "status" · "reserve" · "claim" · "settle" · "close"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/mutations/requestId' \
  -H "Authorization: Bearer ast_..."
```

### PUT /artifacts/{id}/mutations/{requestId}

Commit exact raw bytes to a prepared revision (scope: write)

Canonical base64 must exactly match prepared hash and size. Current policy/edit permission, base CAS and the exact source claim are rechecked at commit. Revoke-first wins; stale base is 409 without silent rebase.

Path parameters:

- `id` (string, required)
- `requestId` (string, required)

Body (application/json):

- `content_base64` (string, required) — max length 20971520

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_content", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_id` (string, required) — max length 200
  - `source_namespace` ("agent-use", required)
  - `owner_user_id` (string, required) — max length 200
  - `actor` (object, required)
    - option 1 (object)
      - `kind` ("user", required)
      - `user_id` (string, required) — max length 200
    - option 2 (object)
      - `kind` ("publisher", required)
      - `publisher_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer" · "publisher"
  - `consumer_client_id` (string | null, required)
  - `source_epoch` (integer, required)
  - `policy_version` (1, required)
  - `base_version` (integer, required)
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
  - `media_type` (string, required)
  - `site` (boolean, required)
  - `restored_from` (integer | null, required)
  - `phase` (enum<string>, required) — "pending" · "claimed" · "committed" · "cancelled" · "reclaimed"
  - `version` (integer | null, required)
  - `revision_id` (string, required) — max length 200
  - `generations_reclaimed` (boolean, required)
  - `eligible_operation` (enum<string>, required) — "status" · "reserve" · "claim" · "settle" · "close"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/mutations/requestId \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"content_base64":"YWJj"}'
```

### DELETE /artifacts/{id}/mutations/{requestId}

Close and reclaim an uncommitted revision request (scope: write)

Make commit impossible, reclaim actual canonical storage generations, then release original source admission. Unknown transport/deletion retains capacity. Never cancel a committed version.

Path parameters:

- `id` (string, required)
- `requestId` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_content", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_id` (string, required) — max length 200
  - `source_namespace` ("agent-use", required)
  - `owner_user_id` (string, required) — max length 200
  - `actor` (object, required)
    - option 1 (object)
      - `kind` ("user", required)
      - `user_id` (string, required) — max length 200
    - option 2 (object)
      - `kind` ("publisher", required)
      - `publisher_id` (string, required) — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer" · "publisher"
  - `consumer_client_id` (string | null, required)
  - `source_epoch` (integer, required)
  - `policy_version` (1, required)
  - `base_version` (integer, required)
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
  - `media_type` (string, required)
  - `site` (boolean, required)
  - `restored_from` (integer | null, required)
  - `phase` (enum<string>, required) — "pending" · "claimed" · "committed" · "cancelled" · "reclaimed"
  - `version` (integer | null, required)
  - `revision_id` (string, required) — max length 200
  - `generations_reclaimed` (boolean, required)
  - `eligible_operation` (enum<string>, required) — "status" · "reserve" · "claim" · "settle" · "close"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/mutations/requestId \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts/{id}/policy

Read adopted file owner policy (scope: read)

Owner-only current canonical policy under read scope plus the real credential ceiling; ordinary readers cannot inspect policy. Omit alias_id for full owner inspection. With alias_id, only the exact managed alias is returned: no other placement, grants or raw tokens. Exact workspace incarnation, alias grants and common public pin are retained. Receipts can recover raw tokens only when still matching current policy hashes; initial imported source tokens stay source-owned. Private content read grants discussion read; only current edit grants discussion writes. Public links reveal no discussion.

Path parameters:

- `id` (string, required)

Query parameters:

- `alias_id` (string)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `id` (string, required) — max length 200
  - `request_id` (string | null, required)
  - `policy_version` (integer, required)
  - `name` (string, required)
  - `version` (integer, required)
  - `policy` (object, required)
    - `version` (1, required)
    - `placement` (object | null, required)
      - `slug` (string, required)
      - `created_at` (string, required)
    - `aliases` (object[], required)
      - `id` (string, required) — max length 200
      - `workspace` (object | null, required)
        - `slug` (string, required)
        - `created_at` (string, required)
      - `workspace_access` (enum<string>, required) — "none" · "view" · "edit"
      - `members` (object[], required)
        - `user_id` (string, required) — max length 200
        - `access` (enum<string>, required) — "view" · "edit"
      - `revision` (integer, required)
      - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
      - `shared_token_hash` (string) — pattern ^[a-f0-9]{64}$
    - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
    - `public_version` (integer | null, required)
  - `tokens` (object, required) — Only exact newly issued/revoked public and alias token receipts; private to the owner
  - `archived_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/policy' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/{id}/policy

Apply one adopted file owner policy change (scope: write)

Reuse exact UUID/base_policy_version/base_version and change on retry. Owner-only share/place/alias/retire. Public pin changes require from_public_version CAS. Independent alias grants/revisions and workspace incarnation are enforced. Fresh tokens and new alias ids are canonical-server generated. Omit alias.id for creation; a supplied id must already belong to this resource. Raw public_token/shared_token input fields are not supported; strict unknown fields are 400. Existing token slots are retained by default; normal enable/rotation asks the canonical server to mint fresh URLs. Output token receipts and imported historical token identities remain unchanged. One alias per source workspace slug/null; unknown supplied ids, unknown unification and move collisions are 409, while updating the same id is valid. Alias changes with unify_public not true return only that selected alias and its tokens: null placement/public_version describe a narrowed response, never a global policy reset. Global/unify_public=true requires full management and returns a complete receipt. Consumers must not overwrite a full resource mirror with a selected-alias receipt. Revocation/deletion fences later content and discussion commits.

Path parameters:

- `id` (string, required)

Body (application/json):

- `request_id` (string, required)
- `base_policy_version` (integer, required)
- `base_version` (integer, required)
- `change` (object, required)
  - option 1 (object)
    - `kind` ("share", required)
    - `enabled` (boolean, required)
    - `public_version` (integer | null)
    - `from_public_version` (integer | null)
    - `revoke_all` (true)
  - option 2 (object)
    - `kind` ("place", required)
    - `workspace` (object | null, required)
      - `slug` (string, required)
      - `created_at` (string, required)
  - option 3 (object)
    - `kind` ("alias", required)
    - `alias` (object, required)
      - `id` (string) — Existing resource alias only; omit to create a server-generated alias. Unknown supplied ids return 409. — max length 200
      - `workspace` (object | null, required) — One alias per source workspace slug, including null; a move colliding with another alias returns 409. Same-id updates remain valid.
        - `slug` (string, required)
        - `created_at` (string, required)
      - `workspace_access` (enum<string>, required) — "none" · "view" · "edit"
      - `members` (object[], required)
        - `user_id` (string, required) — max length 200
        - `access` (enum<string>, required) — "view" · "edit"
      - `revision` (integer)
    - `expected_alias_revision` (integer, required)
    - `public_enabled` (boolean)
    - `rotate_shared_token` (true)
    - `unify_public` (boolean)
  - option 4 (object)
    - `kind` ("retire", required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `id` (string, required) — max length 200
  - `request_id` (string | null, required)
  - `policy_version` (integer, required)
  - `name` (string, required)
  - `version` (integer, required)
  - `policy` (object, required)
    - `version` (1, required)
    - `placement` (object | null, required)
      - `slug` (string, required)
      - `created_at` (string, required)
    - `aliases` (object[], required)
      - `id` (string, required) — max length 200
      - `workspace` (object | null, required)
        - `slug` (string, required)
        - `created_at` (string, required)
      - `workspace_access` (enum<string>, required) — "none" · "view" · "edit"
      - `members` (object[], required)
        - `user_id` (string, required) — max length 200
        - `access` (enum<string>, required) — "view" · "edit"
      - `revision` (integer, required)
      - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
      - `shared_token_hash` (string) — pattern ^[a-f0-9]{64}$
    - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
    - `public_version` (integer | null, required)
  - `tokens` (object, required) — Only exact newly issued/revoked public and alias token receipts; private to the owner
  - `archived_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/policy \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"request_id":"b73682d8-9745-4f09-ae19-dbf83baed1f3","base_policy_version":2,"base_version":3,"change":{"kind":"share","enabled":false}}'
```

### GET /artifacts/{id}/original

Download exact retained original bytes

Authenticated current private read authority is checked; version defaults to canonical current. Existing asp_ publisher credentials use the exact fixed-source publisher-read selector, never owner metadata/discovery or general account permission. Raw bytes preserve office/site/restore round trips.

Path parameters:

- `id` (string, required)

Query parameters:

- `version` (integer)

Responses:

- `200` — Exact raw bytes; no-store, attachment and nosniff
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/original' \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts/{id}/public-content

Read isolated public bytes or resolve a concrete public pin

resolve=1 accepts only token/resolve and optional exact alias_id, returning narrow current pinned raw facts/name/selected alias; no owner/policy/history/discussion. An alias selector requires its exact token and cannot fall back globally. Otherwise public file bytes remain sandboxed/no-store with per-request revocation. Existing artifact/library token+seal wire is preserved. issuer=render requires existing grant+exact version+original origin, accepts original=1 or a host-relative path, and forbids token: it validates the original short-lived renderer seal through fixed-source proof plus active/not-archived/exact target/source/version/expiry/origin checks. No Principal or new seal is created.

Path parameters:

- `id` (string, required)

Query parameters:

- `token` (string)
- `resolve` (string)
- `alias_id` (string)
- `version` (integer)
- `path` (string)
- `original` (string)
- `grant` (string)
- `issuer` (string)
- `origin` (string)

Responses:

- `200` — Narrow resolve JSON or exact isolated file bytes
  - `target_id` (string, required) — max length 200
  - `source_id` (string, required) — max length 200
  - `name` (string, required)
  - `selected_alias` (object | null, required)
    - `id` (string, required) — max length 200
    - `revision` (integer, required)
  - `version` (integer, required)
  - `canonical_revision_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
  - `media_type` (string, required)
  - `site` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/public-content' \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts/adoptions

Read whether new adoptions can start, and your unfinished ones (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. `new_starts_enabled` is the platform gate: while it is false a new activation returns 503 not_enabled. `open` lists your activations that have started and not finished or been fully cancelled; they remain recoverable with the gate off.

Responses:

- `200` — Gate and unfinished activations
  - `new_starts_enabled` (boolean, required)
  - `open` (object[], required)
    - `target_id` (string, required) — max length 200
    - `source_id` (string, required)
    - `phase` (enum<string>, required) — "preparing" · "imported" · "cancelled"
    - `request_id` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/adoptions' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/adoptions

Request an inactive legacy artifact adoption (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. This immutable intent does not reserve a source identity before source ownership is proven. Reuse request_id for an identical retry; a changed or retired intent returns 409.

Body (application/json):

- `request_id` (string, required) — max length 120
- `source_namespace` ("agent-use", required)
- `source_id` (string, required) — max length 128

Responses:

- `201` — Inactive request
  - `purpose` ("consumer_artifact_inactive_adoption", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — Owner of this inactive canonical request, derived from its bearer. Requested source ownership is not established until source verification. — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 128
  - `phase` ("adoption_pending", required)
  - `retired` (boolean, required)
  - `policy_version` (1, required)
  - `verified` (boolean, required) — Provenance was observed at the source-locked read; this is not activation or a claim of current cross-database freshness.
  - `observed_snapshot` (object | null, required) — Server-measured snapshot at verification; any future activation must revalidate content, sharing and epoch.
    - `source_version` (integer, required)
    - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
    - `binding_epoch` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/adoptions \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts/adoptions/{targetId}

Read your concrete inactive adoption intent (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated.

Path parameters:

- `targetId` (string, required)

Responses:

- `200` — Immutable owner intent
  - `purpose` ("consumer_artifact_inactive_adoption", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — Owner of this inactive canonical request, derived from its bearer. Requested source ownership is not established until source verification. — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 128
  - `phase` ("adoption_pending", required)
  - `retired` (boolean, required)
  - `policy_version` (1, required)
  - `verified` (boolean, required) — Provenance was observed at the source-locked read; this is not activation or a claim of current cross-database freshness.
  - `observed_snapshot` (object | null, required) — Server-measured snapshot at verification; any future activation must revalidate content, sharing and epoch.
    - `source_version` (integer, required)
    - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
    - `binding_epoch` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/adoptions/targetId' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/adoptions/{targetId}/verify

Verify prepared source provenance (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. The source proof must still match its content revision, sharing policy, epoch and pending request; stale, cancelled or conflicting facts return 409.

Path parameters:

- `targetId` (string, required)

Responses:

- `200` — Verified inactive provenance
  - `purpose` ("consumer_artifact_inactive_adoption", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — Owner of this inactive canonical request, derived from its bearer. Requested source ownership is not established until source verification. — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 128
  - `phase` ("adoption_pending", required)
  - `retired` (boolean, required)
  - `policy_version` (1, required)
  - `verified` (boolean, required) — Provenance was observed at the source-locked read; this is not activation or a claim of current cross-database freshness.
  - `observed_snapshot` (object | null, required) — Server-measured snapshot at verification; any future activation must revalidate content, sharing and epoch.
    - `source_version` (integer, required)
    - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
    - `binding_epoch` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/adoptions/targetId/verify \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/adoptions/{targetId}/cancel

Retire an inactive adoption intent (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. Cancel canonical intent first, then cancel its source binding. Retirement preserves immutable history and prevents resurrection. A new attempt needs a new request_id.

Path parameters:

- `targetId` (string, required)

Body (application/json):

- `request_id` (string, required) — max length 120

Responses:

- `200` — Retired intent
  - `purpose` ("consumer_artifact_inactive_adoption", required)
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `actor_user_id` (string, required) — max length 200
  - `owner_user_id` (string, required) — Owner of this inactive canonical request, derived from its bearer. Requested source ownership is not established until source verification. — max length 200
  - `credential_kind` (enum<string>, required) — "personal" · "consumer"
  - `consumer_client_id` (string | null, required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 128
  - `phase` ("adoption_pending", required)
  - `retired` (boolean, required)
  - `policy_version` (1, required)
  - `verified` (boolean, required) — Provenance was observed at the source-locked read; this is not activation or a claim of current cross-database freshness.
  - `observed_snapshot` (object | null, required) — Server-measured snapshot at verification; any future activation must revalidate content, sharing and epoch.
    - `source_version` (integer, required)
    - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
    - `binding_epoch` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/adoptions/targetId/cancel \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts

List the workspace's artifacts (scope: read)

Without origin, the existing task/workspace list and wire shape stay unchanged. Explicit origin=consumer_adopted selects active adopted owner files; origin=execution selects private service-generated meeting notes with can_edit=false. Both use current policy/credential grants and bounded SQL pagination. Sort updated_at/source.id descending; opaque cursor binds actor, ceiling and filters, not limit. Each row cursor supports consuming a prefix. No URL shared-token discovery. Answers 503 not_migrated until the platform artifact tables exist.

Query parameters:

- `task_id` (string)
- `origin` (string)
- `limit` (integer)
- `cursor` (string)
- `q` (string)
- `visibility` (string)
- `scope` (string)
- `folder` (string)
- `kind` (string)
- `include` (string) — todos adds each artifact's to-dos from its entry file, and owned: whether the caller owns its task.

Responses:

- `200` — Unchanged task list, explicitly requested adopted owner list or private execution-note list
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts

Publish task files as an artifact revision (scope: write)

Publishes paths from the task's file space (`/tasks/{id}/files`) as a new revision of the artifact with that name in the task, creating the artifact on first use. A path that names a folder publishes everything under it. The revision records each file's content at this moment; later edits to the task's files do not change it. `entry` defaults to the only file, or to an `index.html`. 400 when a path names nothing; at most 500 files.

Body (application/json):

- `task_id` (string, required)
- `name` (string, required) — max length 120
- `paths` (string[], required)
- `entry` (string)

Responses:

- `201` — Created
  - `artifact` (object, required)
    - `id` (string, required)
    - `task_id` (string, required) — The task it belongs to (sess_…)
    - `name` (string, required) — Unique within the task; publishing under the same name adds a version
    - `kind` (string | null, required) — design_system when the current revision holds project/design-system.json; null otherwise — "design_system" · null
    - `version` (integer, required) — The current revision
    - `entry` (string, required) — The file opened first
    - `files` (object[], required)
      - `path` (string, required)
      - `sha256` (string, required)
      - `size_bytes` (integer, required)
    - `share_url` (string | null, required) — The public link, or null while not shared
    - `imported` (boolean) — A person brought it in through POST /artifacts/imports
    - `export_formats` (object[]) — What the current version can be exported to, the stored shape first. A format whose converter is not running here is left out.
      - `id` (string, required) — The format query value of GET /artifacts/{id}/export: html, pdf, png, docx, markdown, xlsx, csv, tsv, pptx, original or zip
      - `label` (string, required)
      - `media_type` (string | null, required) — The type of the bytes; null for original, which is sent as application/octet-stream
      - `extension` (string | null, required) — The extension of the file; null for original, which keeps its own name
      - `original` (boolean, required) — These are the stored bytes rather than a conversion
      - `loss` (string) — What the conversion gives up
    - `conversions` (object[]) — What it can be converted to as a new version.
      - `to` ("page", required)
      - `loss` (string) — What the conversion gives up
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"task_id":"sess_cmtb7q2j","name":"Launch page","paths":["site/index.html","site/style.css"],"entry":"site/index.html"}'
```

### GET /artifacts/{id}

One artifact with every revision (scope: read)

Task artifacts keep their fields and add what the caller may do, where a member opens it, its public and embed addresses, and provenance: an object when the caller may open the session it came from, else null. Other kinds use origin as a string naming their kind. Private execution notes expose origin=execution, task_id=null, run_id, can_edit=false and independent can_discuss/can_manage controls. Read only currently authorized surviving files and history; no public URL grants execution-note access.

Path parameters:

- `id` (string, required) — The artifact id

Query parameters:

- `shared_token` (string)
- `universe` (string)

Responses:

- `200` — OK
  - `artifact` (any | object, required) — Task resources retain their original complete wire shape. Execution resources declare origin=execution, task_id=null and run_id, are private and generated-body read-only, and separate can_discuss from can_edit. Adopted private owner resources explicitly declare consumer_adopted/null task_id. Existing ASP reads return a narrow resource-only publisher shape without owner/policy/public/share/discussion data; can_edit=false describes generic user editing, not the existing operation-bound publisher protocol.
    - option 1 (any)
    - option 2 (object)
      - `id` (string, required) — max length 200
      - `origin` ("consumer_adopted", required)
      - `task_id` (null, required)
      - `owner_user_id` (string, required) — max length 200
      - `name` (string, required)
      - `kind` (enum<string>, required) — "design_system" · null
      - `version` (integer, required)
      - `entry` (string, required)
      - `files` (object[], required)
        - `path` (string, required)
        - `sha256` (string, required)
        - `size_bytes` (integer, required)
      - `share_url` (null, required)
      - `created_at` (string, required)
      - `updated_at` (string, required)
      - `source` (object, required)
        - `namespace` ("agent-use", required)
        - `id` (string, required) — max length 200
        - `binding_epoch` (integer, required)
      - `policy_version` (integer, required)
      - `access` (enum<string>, required) — "view" · "edit" · "owner"
      - `can_edit` (boolean, required)
      - `can_manage` (boolean, required)
      - `is_public` (boolean, required) — Current direct/alias public-enabled state for private metadata projection; not anonymous discovery authority
      - `selected_alias` (object | null, required)
        - `id` (string, required) — max length 200
        - `revision` (integer, required)
        - `workspace` (object | null, required)
      - `mutation_request_id` (string) — Adopted DS save response only: stable exact mutation recovery identity; ordinary metadata reads omit it
      - `revisions` (any[], required)
    - option 3 (object)
      - `id` (string, required) — max length 200
      - `origin` ("consumer_adopted", required)
      - `name` (string, required)
      - `version` (integer, required)
      - `source` (object, required)
        - `namespace` ("agent-use", required)
        - `id` (string, required) — max length 200
        - `binding_epoch` (integer, required)
      - `access` ("publisher", required)
      - `can_edit` (false, required)
      - `can_manage` (false, required)
      - `revisions` (object[], required)
        - `version` (integer, required)
        - `canonical_revision_id` (string, required) — max length 200
        - `request_id` (string, required)
        - `raw_sha256` (string, required)
        - `raw_size_bytes` (integer, required)
        - `media_type` (string, required)
        - `site` (boolean, required)
        - `restored_from` (integer | null, required)
        - `created_at` (string, required)
    - option 4 (object) — Private service-generated meeting note/facts. task_id is null; run_id identifies the owning execution, and exact workspace grants come from current policy rather than an invented task. Generated content is read-only even when can_discuss permits comments. Current/history/file/export, discussion, policy and deletion reuse their existing artifact endpoints; no public sharing or generic body mutation is available.
      - `id` (string, required) — max length 200
      - `origin` ("execution", required)
      - `task_id` (null, required)
      - `run_id` (string, required)
      - `owner_user_id` (string, required) — max length 200
      - `name` (string, required)
      - `version` (integer, required)
      - `updated_at` (string, required)
      - `source` (object, required)
        - `namespace` ("recall", required)
        - `id` (string, required) — max length 200
      - `policy_version` (integer, required)
      - `access` (enum<string>, required) — "view" · "edit" · "owner"
      - `can_edit` (false, required)
      - `can_manage` (boolean, required)
      - `kind` (enum<string>, required) — "design_system" · null
      - `entry` (string, required)
      - `files` (object[], required)
        - `path` (string, required)
        - `sha256` (string, required)
        - `size_bytes` (integer, required)
      - `share_url` (null, required)
      - `created_at` (string, required)
      - `can_discuss` (boolean, required)
      - `selected_alias` (null, required)
      - `is_public` (false, required)
      - `revisions` (object[], required)
        - `version` (integer, required)
        - `entry` (string, required)
        - `files` (object[], required)
          - `path` (string, required)
          - `sha256` (string, required)
          - `size_bytes` (integer, required)
        - `published_by_session` (null, required)
        - `created_at` (string, required)
        - `canonical_revision_id` (string, required) — max length 200
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /artifacts/{id}

Rename an artifact (scope: write)

Its links, versions and files stay. A task holds one artifact per name: a taken name is 409 name_taken. An artifact stays in its task's workspace; copy it to place it in another.

Path parameters:

- `id` (string, required) — The artifact id

Body (application/json):

- `name` (string, required) — max length 120

Responses:

- `200` — OK
  - `artifact` (object, required)
    - `id` (string, required)
    - `task_id` (string, required) — The task it belongs to (sess_…)
    - `name` (string, required) — Unique within the task; publishing under the same name adds a version
    - `kind` (string | null, required) — design_system when the current revision holds project/design-system.json; null otherwise — "design_system" · null
    - `version` (integer, required) — The current revision
    - `entry` (string, required) — The file opened first
    - `files` (object[], required)
      - `path` (string, required)
      - `sha256` (string, required)
      - `size_bytes` (integer, required)
    - `share_url` (string | null, required) — The public link, or null while not shared
    - `imported` (boolean) — A person brought it in through POST /artifacts/imports
    - `export_formats` (object[]) — What the current version can be exported to, the stored shape first. A format whose converter is not running here is left out.
      - `id` (string, required) — The format query value of GET /artifacts/{id}/export: html, pdf, png, docx, markdown, xlsx, csv, tsv, pptx, original or zip
      - `label` (string, required)
      - `media_type` (string | null, required) — The type of the bytes; null for original, which is sent as application/octet-stream
      - `extension` (string | null, required) — The extension of the file; null for original, which keeps its own name
      - `original` (boolean, required) — These are the stored bytes rather than a conversion
      - `loss` (string) — What the conversion gives up
    - `conversions` (object[]) — What it can be converted to as a new version.
      - `to` ("page", required)
      - `loss` (string) — What the conversion gives up
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5 \
  -H "Authorization: Bearer ast_..."
```

### DELETE /artifacts/{id}

Remove an artifact (scope: write)

It stops being listed and its public link stops working. Publishing under the same name in the task afterwards brings it back with the next version number. Execution-generated notes use the same current management authority, retire their canonical projection and cannot be reopened by late metadata recovery.

Path parameters:

- `id` (string, required) — The artifact id

Responses:

- `200` — OK
  - `ok` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5 \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/{id}/copy

Copy an artifact (scope: write)

Copies one version, by default the current one, into a new artifact with its own files, version 1 and no public link, in the same task or in task_id, a task of any workspace the caller may act in. At most 64 MiB. Counts against the owner's artifact storage limit: 409 artifact_storage_limit. Retrying a request_id answers with the copy it made.

Path parameters:

- `id` (string, required) — The artifact id

Body (application/json):

- `name` (string) — max length 120
- `version` (integer)
- `task_id` (string)
- `request_id` (string) — pattern ^[A-Za-z0-9_-]{8,128}$

Responses:

- `201` — Created
  - `artifact` (object, required)
    - `id` (string, required)
    - `task_id` (string, required) — The task it belongs to (sess_…)
    - `name` (string, required) — Unique within the task; publishing under the same name adds a version
    - `kind` (string | null, required) — design_system when the current revision holds project/design-system.json; null otherwise — "design_system" · null
    - `version` (integer, required) — The current revision
    - `entry` (string, required) — The file opened first
    - `files` (object[], required)
      - `path` (string, required)
      - `sha256` (string, required)
      - `size_bytes` (integer, required)
    - `share_url` (string | null, required) — The public link, or null while not shared
    - `imported` (boolean) — A person brought it in through POST /artifacts/imports
    - `export_formats` (object[]) — What the current version can be exported to, the stored shape first. A format whose converter is not running here is left out.
      - `id` (string, required) — The format query value of GET /artifacts/{id}/export: html, pdf, png, docx, markdown, xlsx, csv, tsv, pptx, original or zip
      - `label` (string, required)
      - `media_type` (string | null, required) — The type of the bytes; null for original, which is sent as application/octet-stream
      - `extension` (string | null, required) — The extension of the file; null for original, which keeps its own name
      - `original` (boolean, required) — These are the stored bytes rather than a conversion
      - `loss` (string) — What the conversion gives up
    - `conversions` (object[]) — What it can be converted to as a new version.
      - `to` ("page", required)
      - `loss` (string) — What the conversion gives up
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/copy \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts/{id}/page-backend

Read what a published page can spend (scope: read)

For a result whose current version has an `agentsky.json`: `spends_owner_credits`, the `notice` a person reads before it goes live, whether the payer has `confirmed` this version, `run_cost`, `spend` and its `collections`.

Path parameters:

- `id` (string, required) — The artifact id

Responses:

- `200` — The page's facts, and `visitor_sessions`: its newest 100 visitor sessions, which the default session and task lists leave out. Each opens by its `session_id`.
  - `spends_owner_credits` (boolean, required)
  - `notice` (string | null)
  - `confirmed` (boolean, required)
  - `run_cost` (object | null)
  - `spend` (object, required)
    - `limit_cents` (integer)
    - `spent_cents` (integer)
    - `paused` (boolean)
  - `collections` (string[], required)
  - `visitor_sessions` (object[])
    - `session_id` (string)
    - `agent` (string)
    - `created_at` (string)
    - `last_used_at` (string)
    - `spent_cents` (integer)
- `404` — No such result, or it has no page backend
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/page-backend' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /artifacts/{id}/page-backend

Change what a published page can spend (scope: write)

`spend_limit_cents` sets the most it may spend; a page at its limit says it is paused and its payer is told once. `confirm_spends_owner_credits` makes the caller the payer for what this version can spend on. A new version that names other agents or APIs pauses the page until this is confirmed again.

Path parameters:

- `id` (string, required) — The artifact id

Body (application/json):

- `spend_limit_cents` (integer)
- `confirm_spends_owner_credits` (enum<boolean>) — true

Responses:

- `200` — The page's facts
  - `spends_owner_credits` (boolean, required)
  - `notice` (string | null)
  - `confirmed` (boolean, required)
  - `run_cost` (object | null)
  - `spend` (object, required)
    - `limit_cents` (integer)
    - `spent_cents` (integer)
    - `paused` (boolean)
  - `collections` (string[], required)
  - `visitor_sessions` (object[])
    - `session_id` (string)
    - `agent` (string)
    - `created_at` (string)
    - `last_used_at` (string)
    - `spent_cents` (integer)
- `400` — Nothing to change, or not a whole number of cents
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — No such result, or it has no page backend
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/page-backend \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"spend_limit_cents":1000}'
```

### POST /artifacts/{id}/share

Turn the artifact's public link on or off (scope: write)

Private execution-generated notes do not support this public-sharing operation. For task artifacts, the link needs no credentials and always serves the current revision. Published pages are served sandboxed: their scripts cannot read the platform's cookies or call its API as the visitor. Turning sharing off makes the link stop working; turning it on again gives a new link.

Path parameters:

- `id` (string, required) — The artifact id

Body (application/json):

- `enabled` (boolean, required)
- `confirm_spends_owner_credits` (boolean) — Required as true to make public a page whose agentsky.json names agents or APIs: anyone who opens the link uses the caller's credits. Without it: 409 spend_confirmation_required.
- `frame_ancestors` (string[]) — The sites that may frame its public pages, as https origins; empty means any. Unsent, it stays as it is.
- `audience` (object) — Records a change to who its Library link grants in the work graph. The grants themselves are owned by /library/links.
  - `workspace_access` (enum<string>, required) — "none" · "view" · "edit"
  - `members` (object[], required)
    - `user_id` (string, required)
    - `access` (enum<string>, required) — "view" · "edit"
  - `guest_count` (integer, required)

Responses:

- `200` — OK
  - `share_url` (string | null, required)
  - `public_url` (string | null)
  - `embed_url` (string | null)
  - `public_generation` (integer)
  - `frame_ancestors` (string[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/share \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"enabled":true}'
```

### POST /artifacts/design-systems

Import a design system (scope: write)

Imports a design system's file table (the shape a Claude Design System artifact keeps: `design-system.json`, `tokens.json`, `README.md`, `components/<Name>/README.md` and `preview.html`, `assets/…`, `fonts/…`, with or without the leading `project/`) into the task's files under `design-systems/<slug>/project/`, then publishes that folder as an artifact named after its title. Binary files are `data:` URIs. 400 lists every refused path: `..`, dot segments, toolchain manifests and `blob:` pointers into another service's store.

Body (application/json):

- `task_id` (string, required)
- `title` (string) — Replaces the index's title; required when the table has none — max length 120
- `files` (map<string, string>, required) — Path → text, or a data: URI for binary files; at most 500

Responses:

- `201` — Created
  - `artifact` (object, required)
    - `id` (string, required)
    - `task_id` (string, required) — The task it belongs to (sess_…)
    - `name` (string, required) — Unique within the task; publishing under the same name adds a version
    - `kind` (string | null, required) — design_system when the current revision holds project/design-system.json; null otherwise — "design_system" · null
    - `version` (integer, required) — The current revision
    - `entry` (string, required) — The file opened first
    - `files` (object[], required)
      - `path` (string, required)
      - `sha256` (string, required)
      - `size_bytes` (integer, required)
    - `share_url` (string | null, required) — The public link, or null while not shared
    - `imported` (boolean) — A person brought it in through POST /artifacts/imports
    - `export_formats` (object[]) — What the current version can be exported to, the stored shape first. A format whose converter is not running here is left out.
      - `id` (string, required) — The format query value of GET /artifacts/{id}/export: html, pdf, png, docx, markdown, xlsx, csv, tsv, pptx, original or zip
      - `label` (string, required)
      - `media_type` (string | null, required) — The type of the bytes; null for original, which is sent as application/octet-stream
      - `extension` (string | null, required) — The extension of the file; null for original, which keeps its own name
      - `original` (boolean, required) — These are the stored bytes rather than a conversion
      - `loss` (string) — What the conversion gives up
    - `conversions` (object[]) — What it can be converted to as a new version.
      - `to` ("page", required)
      - `loss` (string) — What the conversion gives up
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/design-systems \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"task_id":"sess_cmtb7q2j","title":"Acme","files":{"README.md":"Set body copy in `body`; `ink` on `surface-100`.","tokens.json":"{\"color\":{\"themes\":[{\"id\":\"light\",\"name\":\"Light\"}],\"tokens\":[{\"name\":\"ink\",\"value\":\"#2b2118\",\"usage\":\"Text.\"}]}}"}}'
```

### GET /artifacts/{id}/design-system

Read the design system an artifact holds (scope: read)

404 when the artifact is not a design system.

Path parameters:

- `id` (string, required) — The artifact id

Responses:

- `200` — OK
  - `design_system` (object, required) — A design system as its files say: the index, the brand book, tokens with the stylesheet compiled from them, components and asset groups. Paths are relative to `root`.
    - `artifact_id` (string, required)
    - `name` (string, required)
    - `version` (integer, required)
    - `root` (string, required) — The folder that holds project/: empty or ending in /
    - `title` (string, required)
    - `namespace` (string | null)
    - `libraries` (object[])
      - `name` (string)
      - `version` (string)
    - `last_change` (object | null)
    - `editable` (boolean, required)
    - `editable_files` (string[], required) — The text files saved through PUT /artifacts/{id}/design-system/files/{path}, project/README.md first; empty when the system is read-only
    - `readme` (string | null, required) — project/README.md, the brand book: read it first
    - `sections` (object[], required)
      - `path` (string)
      - `title` (string)
      - `markdown` (string)
    - `tokens` (object | null, required) — tokens.json as read, with `dropped` naming every value that could not be read and why
    - `tokens_css` (string, required) — tokens.css compiled from tokens.json, without @font-face
    - `fonts` (object[], required)
      - `family` (string)
      - `path` (string)
      - `weight` (string)
      - `style` (string)
    - `cover` (boolean, required)
    - `components` (object[], required)
      - `name` (string)
      - `group` (string | null)
      - `height` (integer)
      - `width` (integer | null)
      - `subtitle` (string | null)
      - `readme` (string | null)
      - `has_preview` (boolean)
    - `assets` (object[], required)
    - `files` (string[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/design-system' \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts/{id}/comments

Read an artifact's private threaded discussion (scope: read)

Returns entries in append order, with parent_id null for roots (including historical flat entries). Replies reference an entry in the same artifact and viewed revision. Reading does not publish or start an agent. Public share links do not grant discussion access.

Path parameters:

- `id` (string, required) — The artifact id

Responses:

- `200` — OK
  - `comments` (object[])
    - `id` (string, required)
    - `text` (string, required)
    - `target` (string, required)
    - `version` (integer, required)
    - `author_id` (string, required)
    - `author` (string, required)
    - `created_at` (string, required)
    - `parent_id` (string | null, required)
    - `resolution` (object) — Root thread state only; absent means open at resolution version 0. Replies inherit their root's state.
      - `resolved` (boolean, required)
      - `version` (integer, required)
      - `updatedAt` (string, required)
      - `updatedBy` (object, required)
        - `id` (string, required)
        - `name` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/comments' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/{id}/comments

Comment on an artifact or reply to a comment (scope: write)

The server binds the authenticated author, current revision and timestamp. parent_id must name a comment in this artifact at base_version. 409 on stale revision or the 1000-entry limit. Appends do not publish or start an agent. This operation is not idempotent: after an uncertain response, read the discussion before deciding whether to resubmit.

Path parameters:

- `id` (string, required) — The artifact id

Body (application/json):

- `text` (string, required) — max length 4000
- `base_version` (integer, required)
- `parent_id` (string | null) — default: null — max length 200
- `target` (string) — What on the artifact this is about; overview when absent. A note on a page element is element:<CSS selector>, with the words it points at in quotes. — max length 500

Responses:

- `201` — Created
  - `comment` (object)
    - `id` (string, required)
    - `text` (string, required)
    - `target` (string, required)
    - `version` (integer, required)
    - `author_id` (string, required)
    - `author` (string, required)
    - `created_at` (string, required)
    - `parent_id` (string | null, required)
    - `resolution` (object) — Root thread state only; absent means open at resolution version 0. Replies inherit their root's state.
      - `resolved` (boolean, required)
      - `version` (integer, required)
      - `updatedAt` (string, required)
      - `updatedBy` (object, required)
        - `id` (string, required)
        - `name` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/comments \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"text":"The updated result is easier to follow.","base_version":3}'
```

### PUT /artifacts/{id}/comments/{commentId}/resolution

Resolve or reopen an artifact thread (scope: write)

Set a root thread's desired resolved state. base_version must match the current artifact revision, including when the root was written on an earlier revision. A root without resolution metadata is open at resolution version 0. If already in the requested state, returns the current root without changing its actor, time or state version. Otherwise base_resolution_version must match the root's resolution.version, or 409; a stale retry cannot overwrite another member's intervening reopen. Missing artifact/root is 404; a reply id is 400. Does not publish, create a revision or start an agent. Replies keep their existing version contract and never reopen a thread implicitly.

Path parameters:

- `id` (string, required) — The artifact id
- `commentId` (string, required) — The root comment id, never a reply

Body (application/json):

- `resolved` (boolean, required)
- `base_version` (integer, required)
- `base_resolution_version` (integer, required)

Responses:

- `200` — OK
  - `comment` (object, required)
    - `id` (string, required)
    - `text` (string, required)
    - `target` (string, required)
    - `version` (integer, required)
    - `author_id` (string, required)
    - `author` (string, required)
    - `created_at` (string, required)
    - `parent_id` (string | null, required)
    - `resolution` (object) — Root thread state only; absent means open at resolution version 0. Replies inherit their root's state.
      - `resolved` (boolean, required)
      - `version` (integer, required)
      - `updatedAt` (string, required)
      - `updatedBy` (object, required)
        - `id` (string, required)
        - `name` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/comments/commentId/resolution \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"resolved":true,"base_version":3,"base_resolution_version":0}'
```

### GET /artifacts/{id}/design-system/comments

Read design-system discussion (scope: read)

Path parameters:

- `id` (string, required) — The artifact id

Responses:

- `200` — OK
  - `comments` (object[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/design-system/comments' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/{id}/design-system/comments

Comment on a design system, color or component (scope: write)

The server records the authenticated author and version. Comments stay private to workspace members and do not start an agent or create a publication. target is overview, color:<name> or component:<name>. 409 when base_version is stale.

Path parameters:

- `id` (string, required) — The artifact id

Body (application/json):

- `text` (string, required) — max length 4000
- `target` (string) — default: "overview" — max length 200
- `base_version` (integer, required)

Responses:

- `201` — Created
  - `comment` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/design-system/comments \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"text":"Use a darker ink for small text.","target":"color:ink","base_version":3}'
```

### GET /artifacts/{id}/design-system/previews/{component}

One component preview as a document (scope: read)

The preview with tokens.css, fonts, bundle.css, libraries and bundle.js preloaded and `data-theme` set, as JSON for a sandboxed frame (`srcdoc` with no same-origin access). `Cover` is the system's cover.

Path parameters:

- `id` (string, required) — The artifact id
- `component` (string, required)

Query parameters:

- `theme` (string) — A theme id from tokens.json; defaults to the first

Responses:

- `200` — OK
  - `html` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/design-system/previews/component' \
  -H "Authorization: Bearer ast_..."
```

### PUT /artifacts/{id}/design-system/tokens

Save edited design tokens (scope: write)

Writes tokens.json whole, compiles tokens.css from it, sets the index's lastChange and publishes the system's next version. 409 `conflict` when `base_version` is not the current version.

Path parameters:

- `id` (string, required) — The artifact id

Body (application/json):

- `base_version` (integer, required)
- `tokens` (object, required)
- `note` (string) — max length 280

Responses:

- `200` — OK
  - `artifact` (object, required)
    - `id` (string, required)
    - `task_id` (string, required) — The task it belongs to (sess_…)
    - `name` (string, required) — Unique within the task; publishing under the same name adds a version
    - `kind` (string | null, required) — design_system when the current revision holds project/design-system.json; null otherwise — "design_system" · null
    - `version` (integer, required) — The current revision
    - `entry` (string, required) — The file opened first
    - `files` (object[], required)
      - `path` (string, required)
      - `sha256` (string, required)
      - `size_bytes` (integer, required)
    - `share_url` (string | null, required) — The public link, or null while not shared
    - `imported` (boolean) — A person brought it in through POST /artifacts/imports
    - `export_formats` (object[]) — What the current version can be exported to, the stored shape first. A format whose converter is not running here is left out.
      - `id` (string, required) — The format query value of GET /artifacts/{id}/export: html, pdf, png, docx, markdown, xlsx, csv, tsv, pptx, original or zip
      - `label` (string, required)
      - `media_type` (string | null, required) — The type of the bytes; null for original, which is sent as application/octet-stream
      - `extension` (string | null, required) — The extension of the file; null for original, which keeps its own name
      - `original` (boolean, required) — These are the stored bytes rather than a conversion
      - `loss` (string) — What the conversion gives up
    - `conversions` (object[]) — What it can be converted to as a new version.
      - `to` ("page", required)
      - `loss` (string) — What the conversion gives up
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/design-system/tokens \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"base_version":3,"tokens":{"color":{"themes":[{"id":"light","name":"Light"}],"tokens":[{"name":"ink","value":"#1d1712","usage":"Text."}]}},"note":"Darker ink"}'
```

### PUT /artifacts/{id}/design-system/files/{path}

Save or restore one design-system file (scope: write)

Saves one of the system's `editable_files` (path relative to `root`, such as `project/README.md`) as the system's next version: `content` replaces it, or `restore_version` puts back the file as it was in that version. tokens.json is saved as tokens are, recompiling tokens.css. Sets the index's lastChange. 409 `conflict` when `base_version` is not the current version; 400 on a read-only system or a file that is not editable; 404 when the file is not in the system or in the restored version.

Path parameters:

- `id` (string, required) — The artifact id
- `path` (string, required)

Body (application/json):

- `base_version` (integer, required)
- `content` (string) — The file's new text; send this or restore_version
- `restore_version` (integer) — An earlier version whose copy of the file becomes the next version
- `note` (string) — max length 280

Responses:

- `200` — OK
  - `artifact` (object, required)
    - `id` (string, required)
    - `task_id` (string, required) — The task it belongs to (sess_…)
    - `name` (string, required) — Unique within the task; publishing under the same name adds a version
    - `kind` (string | null, required) — design_system when the current revision holds project/design-system.json; null otherwise — "design_system" · null
    - `version` (integer, required) — The current revision
    - `entry` (string, required) — The file opened first
    - `files` (object[], required)
      - `path` (string, required)
      - `sha256` (string, required)
      - `size_bytes` (integer, required)
    - `share_url` (string | null, required) — The public link, or null while not shared
    - `imported` (boolean) — A person brought it in through POST /artifacts/imports
    - `export_formats` (object[]) — What the current version can be exported to, the stored shape first. A format whose converter is not running here is left out.
      - `id` (string, required) — The format query value of GET /artifacts/{id}/export: html, pdf, png, docx, markdown, xlsx, csv, tsv, pptx, original or zip
      - `label` (string, required)
      - `media_type` (string | null, required) — The type of the bytes; null for original, which is sent as application/octet-stream
      - `extension` (string | null, required) — The extension of the file; null for original, which keeps its own name
      - `original` (boolean, required) — These are the stored bytes rather than a conversion
      - `loss` (string) — What the conversion gives up
    - `conversions` (object[]) — What it can be converted to as a new version.
      - `to` ("page", required)
      - `loss` (string) — What the conversion gives up
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/design-system/files/report.md \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"base_version":3,"content":"# Acme\n\nSet body copy in `body`.","note":"Brand book voice"}'
```

### GET /artifacts/{id}/export

Download an artifact in a format, or as one archive (scope: read)

With no `format`, or `format=zip`, a zip archive of every file of the current revision, or of `version=N`, each at its published path; 413 `export_too_large` when the files are more than 64 MiB together. With a `format` the artifact's `export_formats` lists, the file it opens to in that format, always as a download. A Markdown, Word, spreadsheet, PDF or page file converts as the matrix says; a page's PDF and PNG are drawn in the render browser and are not offered where none is running. 400 `format_not_applicable` for a format not offered; 413 `artifact_too_large` for a source over 8 MiB or a page over 32 MiB; 422 `conversion_failed` when the stored file cannot be parsed; 503 `render_unavailable` when the render browser fails. PowerPoint to PDF is not offered.

Path parameters:

- `id` (string, required) — The artifact id

Query parameters:

- `format` (string)
- `version` (integer)

Responses:

- `200` — The file
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/export' \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/imports

Import a file or a public page as an artifact (scope: write)

A new artifact whose version 1 holds the original in a task's folder, where agents read it. Multipart `file`, or JSON with `file_name` and `content_base64`, up to 16 MiB; or JSON with `url` for a snapshot of a public https page, fetched from our network with no redirect followed and no script run, private and link-local addresses refused (400 `address_not_allowed`, `url_redirected`). The bytes are checked against the name: 422 `invalid_document` for a damaged Office file, a PDF or picture that is not one, or an unsafe zip. A zip holding a web page (`index.html` at its root or under one folder) is unpacked with every path checked, its original kept beside it; any other zip stays a file. With no `task_id` it goes in the person's own imports folder; a workspace key must name a task. A name in use gets a number. Retrying a `request_id` answers with the artifact it made.

Body (application/json):

- `url` (string) — max length 2048
- `file_name` (string) — max length 1024
- `content_base64` (string)
- `name` (string) — max length 120
- `task_id` (string)
- `request_id` (string) — max length 128

Responses:

- `201` — The new artifact
  - `artifact` (object, required)
    - `id` (string, required)
    - `task_id` (string, required) — The task it belongs to (sess_…)
    - `name` (string, required) — Unique within the task; publishing under the same name adds a version
    - `kind` (string | null, required) — design_system when the current revision holds project/design-system.json; null otherwise — "design_system" · null
    - `version` (integer, required) — The current revision
    - `entry` (string, required) — The file opened first
    - `files` (object[], required)
      - `path` (string, required)
      - `sha256` (string, required)
      - `size_bytes` (integer, required)
    - `share_url` (string | null, required) — The public link, or null while not shared
    - `imported` (boolean) — A person brought it in through POST /artifacts/imports
    - `export_formats` (object[]) — What the current version can be exported to, the stored shape first. A format whose converter is not running here is left out.
      - `id` (string, required) — The format query value of GET /artifacts/{id}/export: html, pdf, png, docx, markdown, xlsx, csv, tsv, pptx, original or zip
      - `label` (string, required)
      - `media_type` (string | null, required) — The type of the bytes; null for original, which is sent as application/octet-stream
      - `extension` (string | null, required) — The extension of the file; null for original, which keeps its own name
      - `original` (boolean, required) — These are the stored bytes rather than a conversion
      - `loss` (string) — What the conversion gives up
    - `conversions` (object[]) — What it can be converted to as a new version.
      - `to` ("page", required)
      - `loss` (string) — What the conversion gives up
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/imports \
  -H "Authorization: Bearer ast_..."
```

### POST /artifacts/{id}/conversions

Convert an artifact to a page, as its next version (scope: write)

Makes a Markdown, Word or PDF artifact into a page: a new version that opens to an HTML file, with the source beside it. `loss` says what it gave up (a PDF loses its layout). Restoring the earlier version with PUT /artifacts/{id}/files/{path}?restore_version=N undoes it. 409 `conflict` when `base_version` is no longer current; 400 `not_convertible` for any other file; 422 `conversion_failed` when the stored file cannot be parsed.

Path parameters:

- `id` (string, required) — The artifact id

Body (application/json):

- `to` ("page", required)
- `base_version` (integer, required)
- `request_id` (string) — max length 128

Responses:

- `201` — The new version
  - `artifact` (object, required)
    - `id` (string, required)
    - `task_id` (string, required) — The task it belongs to (sess_…)
    - `name` (string, required) — Unique within the task; publishing under the same name adds a version
    - `kind` (string | null, required) — design_system when the current revision holds project/design-system.json; null otherwise — "design_system" · null
    - `version` (integer, required) — The current revision
    - `entry` (string, required) — The file opened first
    - `files` (object[], required)
      - `path` (string, required)
      - `sha256` (string, required)
      - `size_bytes` (integer, required)
    - `share_url` (string | null, required) — The public link, or null while not shared
    - `imported` (boolean) — A person brought it in through POST /artifacts/imports
    - `export_formats` (object[]) — What the current version can be exported to, the stored shape first. A format whose converter is not running here is left out.
      - `id` (string, required) — The format query value of GET /artifacts/{id}/export: html, pdf, png, docx, markdown, xlsx, csv, tsv, pptx, original or zip
      - `label` (string, required)
      - `media_type` (string | null, required) — The type of the bytes; null for original, which is sent as application/octet-stream
      - `extension` (string | null, required) — The extension of the file; null for original, which keeps its own name
      - `original` (boolean, required) — These are the stored bytes rather than a conversion
      - `loss` (string) — What the conversion gives up
    - `conversions` (object[]) — What it can be converted to as a new version.
      - `to` ("page", required)
      - `loss` (string) — What the conversion gives up
    - `created_at` (string, required)
    - `updated_at` (string, required)
  - `loss` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/conversions \
  -H "Authorization: Bearer ast_..."
```

### PUT /artifacts/{id}/files/{path}

Save one file of an artifact as its next version (scope: write)

The request body is the file's new raw bytes, or send `restore_version` with no body to put back the file as it was in that version. Every other file stays as the current version holds it, and the task's copy of the file is updated. `base_version` is the version you read: when it is no longer current the save is refused with 409 `conflict`, so read the artifact again and redo the edit. Saving identical bytes makes no version. Retrying with the same `request_id` answers with the version that request made. A design system saves through its own operations.

Path parameters:

- `id` (string, required) — The artifact id
- `path` (string, required)

Query parameters:

- `base_version` (integer, required)
- `restore_version` (integer)
- `request_id` (string)

Responses:

- `200` — The artifact at its new version.
- `400` — Missing `base_version`, a design system, or a tracking board file.
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Unknown artifact, or a restored version without this file.
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — `conflict`: a newer version exists. `request_conflict`: this `request_id` made a different save.
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `413` — `file_too_large`: one save holds at most 30 MiB.
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — `invalid_document`: the bytes are not a valid file of this Office format.
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/files/report.md \
  -H "Authorization: Bearer ast_..."
```

### GET /artifacts/{id}/files/{path}

Download one file of an artifact (scope: read)

The current revision's file, or `version=N`. Always sent as a download.

Path parameters:

- `id` (string, required) — The artifact id
- `path` (string, required)

Query parameters:

- `version` (integer)

Responses:

- `200` — The bytes
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/artifacts/cmtb6a1r9t4f2c01s6x8y3z5/files/report.md' \
  -H "Authorization: Bearer ast_..."
```

## Browser

### GET /sessions/{id}/browser

Read the session browser and live snapshots (scope: read)

Uses the session's existing universe and token restrictions. Viewing reconnects without restarting execution. Expired browsers are finalized; final screenshots and action history remain readable.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — Authorized browser state, or null when the session has no browser. Provider credentials, interactive viewer links and browser connection URLs are never returned.
  - `browser` (object | null, required)
    - `id` (string, required)
    - `status` (enum<string>, required) — "preparing" · "running" · "completed" · "blocked" · "failed" · "stopped"
    - `viewerUrl` (null, required) — Always null. Observation uses screenshots; interactive provider viewer links are never exposed.
    - `url` (string, required)
    - `startedAt` (string, required)
    - `expiresAt` (string, required)
    - `endedAt` (string | null, required)
    - `elapsedMs` (number, required)
    - `actionCount` (integer, required)
    - `progress` (string)
    - `claim` (string) — The agent's completion claim, separate from task verification.
    - `resolvedModel` (string) — Resolved Jev model reported by OpenRouter.
    - `error` (string)
    - `actions` (object[], required)
      - `id` (string, required)
      - `verb` (string, required)
      - `detail` (string, required)
      - `timestamp` (string, required)
      - `status` (string, required)
    - `verification` (object, required)
      - `status` (enum<string>, required) — "passed" · "failed" · "unverified"
      - `checks` (object[], required)
        - `label` (string, required)
        - `status` (enum<string>, required) — "passed" · "failed" · "unverified"
        - `detail` (string, required)
    - `lastScreenshot` (string | null, required) — Latest observed or final JPEG as a data URL when capture succeeded.
    - `lastScreenshotAt` (string | null) — Time the latest screenshot was captured successfully.
    - `cleanupPending` (boolean, required) — A terminal browser may still be releasing provider resources; cleanup is retried durably.
    - `costs` (object, required) — Recorded billed USD, including the fixed Mercury text-entry helper. Receipts can arrive after completion.
      - `coveredBy` (enum<string>) — Model coverage from stored receipts, including native subscription measurements. Arena requires every zero-charge ledger receipt to record that waiver and no native measurements. Unknown or mixed model coverage is null; subscription coverage does not waive runtime or tools. — "subscription" · "arena" · null
      - `pricingComplete` (boolean) — False when model prices are unknown, including native reports whose process-cumulative cost cannot establish a turn price.
      - `unpricedModelCalls` (integer)
      - `unpricedModels` (string[])
      - `decisionUsd` (number, required)
      - `helperUsd` (number, required)
      - `browserUsd` (number, required)
      - `runtimeUsd` (number, required)
      - `totalUsd` (number, required) — Known metered cost including waived usage; only a lower bound when pricingComplete is false.
      - `chargedUsd` (number, required) — Actual amount charged after billing waivers.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/browser' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/browser

Prepare an isolated browser for a session (scope: write)

Prepare before sending the task's first turn. Requires an active session, positive credit balance and remaining session budget. An identical repeated request reuses the browser; a different configuration or an ended browser returns 409. The browser has a 15-minute lifetime, fixed viewport and bounded actions. Structured Google Flights verification checks visible route, dates, passengers, cabin and results; tasks without verification remain unverified. Browser usage is billed separately from model and runtime usage.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `task` (string, required) — max length 16000
- `startUrl` (string, required)
- `viewport` (object, required)
  - `width` (integer, required)
  - `height` (integer, required)
- `verification` (object)
  - `kind` ("google-flights", required)
  - `origin` (string, required) — max length 120
  - `destination` (string, required) — max length 120
  - `departureDate` (string, required) — pattern ^\d{4}-\d{2}-\d{2}$
  - `returnDate` (string) — pattern ^\d{4}-\d{2}-\d{2}$
  - `passengers` (integer, required)
  - `cabin` (enum<string>, required) — "economy" · "premium-economy" · "business" · "first"

Responses:

- `201` — Authorized browser state, or null when the session has no browser. Provider credentials, interactive viewer links and browser connection URLs are never returned.
  - `browser` (object | null, required)
    - `id` (string, required)
    - `status` (enum<string>, required) — "preparing" · "running" · "completed" · "blocked" · "failed" · "stopped"
    - `viewerUrl` (null, required) — Always null. Observation uses screenshots; interactive provider viewer links are never exposed.
    - `url` (string, required)
    - `startedAt` (string, required)
    - `expiresAt` (string, required)
    - `endedAt` (string | null, required)
    - `elapsedMs` (number, required)
    - `actionCount` (integer, required)
    - `progress` (string)
    - `claim` (string) — The agent's completion claim, separate from task verification.
    - `resolvedModel` (string) — Resolved Jev model reported by OpenRouter.
    - `error` (string)
    - `actions` (object[], required)
      - `id` (string, required)
      - `verb` (string, required)
      - `detail` (string, required)
      - `timestamp` (string, required)
      - `status` (string, required)
    - `verification` (object, required)
      - `status` (enum<string>, required) — "passed" · "failed" · "unverified"
      - `checks` (object[], required)
        - `label` (string, required)
        - `status` (enum<string>, required) — "passed" · "failed" · "unverified"
        - `detail` (string, required)
    - `lastScreenshot` (string | null, required) — Latest observed or final JPEG as a data URL when capture succeeded.
    - `lastScreenshotAt` (string | null) — Time the latest screenshot was captured successfully.
    - `cleanupPending` (boolean, required) — A terminal browser may still be releasing provider resources; cleanup is retried durably.
    - `costs` (object, required) — Recorded billed USD, including the fixed Mercury text-entry helper. Receipts can arrive after completion.
      - `coveredBy` (enum<string>) — Model coverage from stored receipts, including native subscription measurements. Arena requires every zero-charge ledger receipt to record that waiver and no native measurements. Unknown or mixed model coverage is null; subscription coverage does not waive runtime or tools. — "subscription" · "arena" · null
      - `pricingComplete` (boolean) — False when model prices are unknown, including native reports whose process-cumulative cost cannot establish a turn price.
      - `unpricedModelCalls` (integer)
      - `unpricedModels` (string[])
      - `decisionUsd` (number, required)
      - `helperUsd` (number, required)
      - `browserUsd` (number, required)
      - `runtimeUsd` (number, required)
      - `totalUsd` (number, required) — Known metered cost including waived usage; only a lower bound when pricingComplete is false.
      - `chargedUsd` (number, required) — Actual amount charged after billing waivers.
- `400` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `402` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `502` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/browser \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"task":"Find the Example Domain heading and stop when it is visible.","startUrl":"https://example.com","viewport":{"width":1120,"height":780}}'
```

### DELETE /sessions/{id}/browser

Stop the session browser and release its resources (scope: write)

Fences new browser actions before capturing the final page and releasing the browser. Repeated requests retry unfinished cleanup; a session without a browser returns null. This operation stops browser access; use POST /sessions/{id}/interrupt to also interrupt the agent's turn.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — Authorized browser state, or null when the session has no browser. Provider credentials, interactive viewer links and browser connection URLs are never returned.
  - `browser` (object | null, required)
    - `id` (string, required)
    - `status` (enum<string>, required) — "preparing" · "running" · "completed" · "blocked" · "failed" · "stopped"
    - `viewerUrl` (null, required) — Always null. Observation uses screenshots; interactive provider viewer links are never exposed.
    - `url` (string, required)
    - `startedAt` (string, required)
    - `expiresAt` (string, required)
    - `endedAt` (string | null, required)
    - `elapsedMs` (number, required)
    - `actionCount` (integer, required)
    - `progress` (string)
    - `claim` (string) — The agent's completion claim, separate from task verification.
    - `resolvedModel` (string) — Resolved Jev model reported by OpenRouter.
    - `error` (string)
    - `actions` (object[], required)
      - `id` (string, required)
      - `verb` (string, required)
      - `detail` (string, required)
      - `timestamp` (string, required)
      - `status` (string, required)
    - `verification` (object, required)
      - `status` (enum<string>, required) — "passed" · "failed" · "unverified"
      - `checks` (object[], required)
        - `label` (string, required)
        - `status` (enum<string>, required) — "passed" · "failed" · "unverified"
        - `detail` (string, required)
    - `lastScreenshot` (string | null, required) — Latest observed or final JPEG as a data URL when capture succeeded.
    - `lastScreenshotAt` (string | null) — Time the latest screenshot was captured successfully.
    - `cleanupPending` (boolean, required) — A terminal browser may still be releasing provider resources; cleanup is retried durably.
    - `costs` (object, required) — Recorded billed USD, including the fixed Mercury text-entry helper. Receipts can arrive after completion.
      - `coveredBy` (enum<string>) — Model coverage from stored receipts, including native subscription measurements. Arena requires every zero-charge ledger receipt to record that waiver and no native measurements. Unknown or mixed model coverage is null; subscription coverage does not waive runtime or tools. — "subscription" · "arena" · null
      - `pricingComplete` (boolean) — False when model prices are unknown, including native reports whose process-cumulative cost cannot establish a turn price.
      - `unpricedModelCalls` (integer)
      - `unpricedModels` (string[])
      - `decisionUsd` (number, required)
      - `helperUsd` (number, required)
      - `browserUsd` (number, required)
      - `runtimeUsd` (number, required)
      - `totalUsd` (number, required) — Known metered cost including waived usage; only a lower bound when pricingComplete is false.
      - `chargedUsd` (number, required) — Actual amount charged after billing waivers.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/browser \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/browser-tabs

Open pages in a session's browser (scope: write)

Opens `urls` (at most 20 http or https addresses) in the browser of a session you own, as tabs the agent finds there: at once when its pod holds your browser (`opened`), else at the session's next start or wake (`pending`), for up to an hour. A page already open is not opened again. Answers 404 where `BROWSER_TWO_WAY_SYNC` is off for the workspace, 403 for anyone but the session's owner, and 409 for a session that cannot use your browser, such as a shared or Fresh one.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `urls` (string[], required) — max length 2048

Responses:

- `200` — How many pages opened now, and whether they wait for the session's next start.
  - `opened` (integer, required)
  - `pending` (boolean, required)
- `400` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/browser-tabs \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/browser-handoff

See the agent's browser during a hand-off (scope: read)

While a `browser_handoff` request in this session is open and addressed to the caller, answers the page the agent's own browser is on. 404 `no_handoff` when none is open, 403 `not_addressed` when it is for someone else, 503 `browser_unavailable` when the browser cannot be reached. Answer the request (`done` or `skip`) to hand the browser back.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — The agent's browser: `open: false` when none is running, else the page as a JPEG (base64) with its CSS width and height, address and title.
  - `browser` (object)
    - `open` (boolean)
    - `url` (string)
    - `title` (string)
    - `width` (integer)
    - `height` (integer)
    - `jpeg` (string) — Base64 JPEG of the visible page.
- `403` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/browser-handoff' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/browser-handoff

Act in the agent's browser during a hand-off (scope: write)

One action by the caller in the agent's browser, under the same conditions as reading it: `{type: "click", x, y}` (CSS pixels of the frame), `{type: "text", text}` (at most 2,000 characters, typed where the focus is), `{type: "key", key}` (Enter, Tab, Backspace, Escape, the arrows or Space) or `{type: "scroll", x, y, deltaY}`. Answers the page afterwards.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `type` (enum<string>, required) — "click" · "text" · "key" · "scroll"
- `x` (number)
- `y` (number)
- `text` (string)
- `key` (enum<string>) — "Enter" · "Tab" · "Backspace" · "Escape" · "ArrowUp" · "ArrowDown" · "ArrowLeft" · "ArrowRight" · "Space"
- `deltaY` (number)

Responses:

- `200` — The agent's browser: `open: false` when none is running, else the page as a JPEG (base64) with its CSS width and height, address and title.
  - `browser` (object)
    - `open` (boolean)
    - `url` (string)
    - `title` (string)
    - `width` (integer)
    - `height` (integer)
    - `jpeg` (string) — Base64 JPEG of the visible page.
- `400` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/browser-handoff \
  -H "Authorization: Bearer ast_..."
```

## Workspace

### GET /sessions/{id}/workspace/files

List a directory in the session's workspace (scope: read)

Returns up to 200 entries (name, type, size, mtime) for a directory under /data/workspace. Dotfiles are excluded by default; pass ?hidden=true to include them. Only regular files and directories are listed: symlinks, FIFOs, sockets and devices never are. Paths are confined to the workspace root; '..' and absolute paths outside the root return 400 invalid_path. A parked or suspended pod returns 409 session_parked — send a message to wake it.

Path parameters:

- `id` (string, required) — The session id

Query parameters:

- `path` (string) — Relative or absolute path under workspace root; defaults to root
- `hidden` (boolean) — Include dotfiles (default false)

Responses:

- `200` — OK
  - `path` (string)
  - `entries` (object[])
    - `name` (string)
    - `type` (enum<string>) — "file" · "directory"
    - `size` (integer)
    - `mtime` (string)
  - `truncated` (boolean)
  - `limit` (integer)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/files' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/workspace/files/content

Download a file from the session's workspace (scope: read)

Returns the raw file bytes as an attachment. Limited to 1 MB. Binary files are supported. Content-Type is inferred from the file extension. Returns 400 not_a_file for directories, 413 file_too_large when over the cap, 403 path_escape for symlink escapes, 409 session_parked when the pod is not running.

Path parameters:

- `id` (string, required) — The session id

Query parameters:

- `path` (string, required) — Relative or absolute path to the file under workspace root

Responses:

- `200` — File contents
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/files/content?path=report.md' \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/workspace/changes

Git status and diff summary for each repo in the session's workspace (scope: read)

Finds up to 10 git repositories within three levels of the workspace root and, for each, runs `git status --porcelain=v1` and `git diff --stat HEAD` inside the pod as the workspace owner, with fsmonitor, hooks, external diff drivers and textconv disabled. Each output is bounded to 200 lines. `repos` is empty when the workspace has no repository. Never wakes the pod: 409 session_parked when it is not running, 409 workspace_unsupported when its runtime has no exec or resumes a parked sandbox on contact (E2B), 503 workspace_unavailable when the read cannot run as the workspace owner.

Path parameters:

- `id` (string, required) — The session id

Responses:

- `200` — OK
  - `root` (string)
  - `repos` (object[])
    - `path` (string) — repo directory relative to root; "." for the root itself
    - `status` (string | null) — git status --porcelain=v1 output; null when clean
    - `stat` (string | null) — git diff --stat HEAD output; null when no diff or no commit yet
  - `limit` (integer) — most repos reported
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/changes' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/workspace/import

Copy a folder from the caller's machine into the workspace (scope: write)

The body is the folder as a gzipped tar (up to 25 MB). It is unpacked at <workspace root>/<name> as the workspace owner and made a git repository whose first commit is that copy, so /workspace/patch later answers the work done on it. Wakes a parked pod. 400 invalid_name, 409 already_exists, 413 archive_too_large, 422 invalid_archive.

Path parameters:

- `id` (string, required) — The session id

Query parameters:

- `name` (string, required) — the folder's name in the workspace: 1–80 letters, digits, spaces, dots, dashes or underscores

Responses:

- `200` — OK
  - `path` (string)
  - `files` (integer)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/import \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/workspace/imports

Start a resumable folder upload into the workspace (scope: write)

For folders over the single-request import's 25 MB: declare the folder's name, the gzipped tar's size (up to 2 GiB) and sha256, then send it in parts and complete. Answers the upload; its parts are numbered from 0. Or send {name, file_id}: a gzipped tar already stored as one of your files, which needs no parts and answers state verified, so complete unpacks it straight away (404 for a file you cannot see, 400 not_downloadable). 404 when resumable imports are not enabled for the workspace, 400 invalid_name or invalid_request (size, sha256 or part_size out of range).

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- option 1 (object)
  - `name` (string, required) — the folder's name in the workspace, as for /workspace/import
  - `size` (integer, required) — bytes of the gzipped tar, at most 2 GiB
  - `sha256` (string, required) — hex sha256 of the whole tar
  - `part_size` (integer) — bytes per part, 1–16 MiB; default 8 MiB
- option 2 (object)
  - `name` (string, required) — the folder's name in the workspace, as for /workspace/import
  - `file_id` (string, required) — one of your files holding the gzipped tar, at most 2 GiB

Responses:

- `201` — Created
  - `id` (string)
  - `name` (string)
  - `size` (integer)
  - `sha256` (string)
  - `part_size` (integer)
  - `parts` (integer) — how many parts the upload has
  - `received` (integer[]) — part numbers already stored
  - `state` (enum<string>) — "uploading" · "verified" · "importing" · "imported" · "failed"
  - `path` (string) — where the folder landed, once imported
  - `files` (integer) — files unpacked, once imported
  - `error` (object)
    - `code` (string)
    - `message` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/imports \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/workspace/imports/{upload_id}

Read a resumable folder upload: which parts arrived and its state (scope: read)

`received` lists the part numbers already stored, so an interrupted upload sends only the rest.

Path parameters:

- `id` (string, required) — The session id
- `upload_id` (string, required)

Responses:

- `200` — OK
  - `id` (string)
  - `name` (string)
  - `size` (integer)
  - `sha256` (string)
  - `part_size` (integer)
  - `parts` (integer) — how many parts the upload has
  - `received` (integer[]) — part numbers already stored
  - `state` (enum<string>) — "uploading" · "verified" · "importing" · "imported" · "failed"
  - `path` (string) — where the folder landed, once imported
  - `files` (integer) — files unpacked, once imported
  - `error` (object)
    - `code` (string)
    - `message` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/imports/upload_id' \
  -H "Authorization: Bearer ast_..."
```

### PUT /sessions/{id}/workspace/imports/{upload_id}/parts/{part}

Store one part of a resumable folder upload (scope: write)

The body is the part's bytes; every part but the last is exactly part_size long. Sending a part again replaces it. An optional X-Part-Sha256 header is checked. 400 invalid_part or part_size_mismatch, 422 part_checksum_mismatch.

Path parameters:

- `id` (string, required) — The session id
- `upload_id` (string, required)
- `part` (integer, required) — the part number, from 0

Responses:

- `200` — OK
  - `part` (integer)
  - `size` (integer)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/imports/upload_id/parts/part \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/workspace/imports/{upload_id}/complete

Finish a resumable folder upload and unpack it into the workspace (scope: write)

Checks the parts' total size and sha256 against the declaration, then has the pod pull and unpack the folder in the background, exactly as /workspace/import would; poll the upload until its state is imported or failed. Calling it again is safe. 202 while importing. 409 parts_missing, 422 size_mismatch or checksum_mismatch, 409 import_unsupported when the session's runtime predates resumable imports (use /workspace/import).

Path parameters:

- `id` (string, required) — The session id
- `upload_id` (string, required)

Responses:

- `200` — OK
  - `id` (string)
  - `name` (string)
  - `size` (integer)
  - `sha256` (string)
  - `part_size` (integer)
  - `parts` (integer) — how many parts the upload has
  - `received` (integer[]) — part numbers already stored
  - `state` (enum<string>) — "uploading" · "verified" · "importing" · "imported" · "failed"
  - `path` (string) — where the folder landed, once imported
  - `files` (integer) — files unpacked, once imported
  - `error` (object)
    - `code` (string)
    - `message` (string)
- `202` — Importing
  - `id` (string)
  - `name` (string)
  - `size` (integer)
  - `sha256` (string)
  - `part_size` (integer)
  - `parts` (integer) — how many parts the upload has
  - `received` (integer[]) — part numbers already stored
  - `state` (enum<string>) — "uploading" · "verified" · "importing" · "imported" · "failed"
  - `path` (string) — where the folder landed, once imported
  - `files` (integer) — files unpacked, once imported
  - `error` (object)
    - `code` (string)
    - `message` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/imports/upload_id/complete \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/workspace/patch

The work in one workspace repo since its base branch, as a git patch (scope: write)

Runs inside the pod as the workspace owner and returns one binary-safe `git diff --binary` from the merge base of HEAD with the branch's upstream (or the remote's default branch, or else the base an imported folder recorded, with base_branch "") to the working tree: commits, uncommitted edits and new files that are not ignored. The repository's own index is left as it was. Wakes a parked pod. 400 not_a_repository, 409 no_base when there is no remote branch to compare against, 413 patch_too_large over 5 MB.

Path parameters:

- `id` (string, required) — The session id

Body (application/json):

- `repo` (string, required) — repo directory relative to the workspace root, as /workspace/changes lists it; "." for the root

Responses:

- `200` — OK
  - `repo` (string)
  - `base_branch` (string) — the branch the work started from, as the remote names it
  - `base_commit` (string) — the commit the patch applies to
  - `commits` (string[]) — subjects of the commits since the base, oldest first
  - `patch` (string) — base64 of the patch; empty when nothing changed
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/workspace/patch \
  -H "Authorization: Bearer ast_..."
```

## Routines

### GET /routines

List routines (scope: read)

Query parameters:

- `cursor` (string)
- `limit` (integer) — 1–500, default 50
- `session_id` (string) — only routines whose next run posts into this session: those that target it, and the reuse_session routine whose runs continue it

Responses:

- `200` — OK
  - `items` (object[], required)
    - `id` (string) — rtn_… identifier
    - `name` (string)
    - `description` (string | null)
    - `metadata` (object)
    - `target` (object) — {type:"new_session", agent, environment_id?, vault_ids?, reuse_session?} — a fresh session per fire (CMA parity); with reuse_session: true the first fire starts the session and every later fire posts into it (a new one only once it is archived or deleted; a fire while it is working or waiting on a person is skipped) · {type:"session", session_id} — a turn into the existing session every fire (busy target skips with session_busy_error)
    - `initial_events` (object[])
    - `schedule` (object | null) — 5-field POSIX cron + IANA timezone, wall-clock matching, minute granularity; null = manual-run only
    - `budget` (object | null) — Per-run cap (RFC-0080 shape): copied onto each new session (mode new_session) or granted as a per-fire delta allowance consumed+budget (mode session). Clearable.
    - `status` (enum<string>) — "active" · "paused"
    - `paused_reason` (object | null) — {type:"manual"} | {type:"error", error:{type}, consecutive_failures, message?} — non-null exactly when paused. A routine pauses itself after 3 runs in a row fail with an error that the next run would repeat, insufficient_credits_error included (the wallet that pays for it is empty); add credit, then unpause.
    - `archived_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
  - `cursor` (string | null)
  - `hasMore` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routines' \
  -H "Authorization: Bearer ast_..."
```

### POST /routines

Create a routine — scheduled agent execution (scope: write)

initial_events (1–50 user.message events) are delivered on every fire. target picks the mode: new_session creates a fresh session per run, or with reuse_session: true one session that every run continues; session sends the turn into an existing session (busy target → failed run session_busy_error). schedule is a 5-field POSIX cron with an IANA timezone; omit it for a manual-run-only routine. budget bounds each run separately. The answer carries effective_deliver_to: where each run's result goes (metadata created_in_session names the conversation the routine was made in, which receives results by default).

Body (application/json):

- `name` (string, required) — max length 256
- `description` (string) — max length 2048
- `metadata` (map<string, string>) — max length 512
- `target` (object, required)
  - type: "new_session" (object)
    - `type` ("new_session", required)
    - `agent` (string, required)
    - `environment_id` (string)
    - `vault_ids` (string[])
    - `reuse_session` (boolean)
  - type: "session" (object)
    - `type` ("session", required)
    - `session_id` (string, required)
- `initial_events` (object[], required)
  - `type` ("user.message", required)
  - `content` (object[], required)
    - type: "text" (object)
      - `type` ("text", required)
      - `text` (string, required)
    - type: "image" (object)
      - `type` ("image", required)
      - `source` (object, required)
        - type: "base64" (object)
          - `type` ("base64", required)
          - `media_type` (string, required)
          - `data` (string, required)
        - type: "url" (object)
          - `type` ("url", required)
          - `url` (string, required)
        - type: "file" (object)
          - `type` ("file", required)
          - `file_id` (string, required)
    - type: "document" (object)
      - `type` ("document", required)
      - `source` (object, required)
        - type: "base64" (object)
          - `type` ("base64", required)
          - `media_type` (string, required)
          - `data` (string, required)
        - type: "text" (object)
          - `type` ("text", required)
          - `media_type` ("text/plain") — default: "text/plain"
          - `data` (string, required)
        - type: "url" (object)
          - `type` ("url", required)
          - `url` (string, required)
        - type: "file" (object)
          - `type` ("file", required)
          - `file_id` (string, required)
      - `title` (string | null)
      - `context` (string | null)
  - `interaction_mode` (enum<string> | null) — "plan" · "build"
- `schedule` (object | null)
  - `type` ("cron", required)
  - `expression` (string, required) — max length 256
  - `timezone` (string, required)
- `budget` (object | null)
  - `type` ("limit", required)
  - `max_list_cost` (object, required)
    - `amount` (string, required) — Whole US cents as an integer decimal string, e.g. "125" for $1.25 — max length 15
    - `currency` ("USD", required)

Responses:

- `201` — Created
  - `routine` (object, required) — Scheduled agent execution: initial_events + a target (new_session per fire, or an existing session) bound to a cron schedule. Fires record routine runs.
    - `id` (string) — rtn_… identifier
    - `name` (string)
    - `description` (string | null)
    - `metadata` (object)
    - `target` (object) — {type:"new_session", agent, environment_id?, vault_ids?, reuse_session?} — a fresh session per fire (CMA parity); with reuse_session: true the first fire starts the session and every later fire posts into it (a new one only once it is archived or deleted; a fire while it is working or waiting on a person is skipped) · {type:"session", session_id} — a turn into the existing session every fire (busy target skips with session_busy_error)
    - `initial_events` (object[])
    - `schedule` (object | null) — 5-field POSIX cron + IANA timezone, wall-clock matching, minute granularity; null = manual-run only
    - `budget` (object | null) — Per-run cap (RFC-0080 shape): copied onto each new session (mode new_session) or granted as a per-fire delta allowance consumed+budget (mode session). Clearable.
    - `status` (enum<string>) — "active" · "paused"
    - `paused_reason` (object | null) — {type:"manual"} | {type:"error", error:{type}, consecutive_failures, message?} — non-null exactly when paused. A routine pauses itself after 3 runs in a row fail with an error that the next run would repeat, insufficient_credits_error included (the wallet that pays for it is empty); add credit, then unpause.
    - `archived_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
  - `effective_deliver_to` (object) — Where each run's result goes in effect. channel_thread: the chosen chat. session: a conversation — the one the routine runs in (source target) or the one it was made in (source origin, from metadata created_in_session or proposed_by_session). notification: no conversation. The owner is notified in every case.
    - `type` (enum<string>, required) — "channel_thread" · "session" · "notification"
    - `connection_id` (string)
    - `thread_id` (string)
    - `session_id` (string)
    - `source` (enum<string>) — "target" · "origin"
    - `notify_owner` (enum<boolean>, required) — true
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/routines \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"name":"Weekly compliance scan","target":{"type":"new_session","agent":"agent_cmtb2f0a8m9k7x51q4ez6r0d"},"initial_events":[{"type":"user.message","content":[{"type":"text","text":"Run the weekly compliance scan."}]}],"schedule":{"type":"cron","expression":"0 20 * * 5","timezone":"America/New_York"}}'
```

### GET /routines/{id}

Routine detail (scope: read)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `routine` (object, required) — Scheduled agent execution: initial_events + a target (new_session per fire, or an existing session) bound to a cron schedule. Fires record routine runs.
    - `id` (string) — rtn_… identifier
    - `name` (string)
    - `description` (string | null)
    - `metadata` (object)
    - `target` (object) — {type:"new_session", agent, environment_id?, vault_ids?, reuse_session?} — a fresh session per fire (CMA parity); with reuse_session: true the first fire starts the session and every later fire posts into it (a new one only once it is archived or deleted; a fire while it is working or waiting on a person is skipped) · {type:"session", session_id} — a turn into the existing session every fire (busy target skips with session_busy_error)
    - `initial_events` (object[])
    - `schedule` (object | null) — 5-field POSIX cron + IANA timezone, wall-clock matching, minute granularity; null = manual-run only
    - `budget` (object | null) — Per-run cap (RFC-0080 shape): copied onto each new session (mode new_session) or granted as a per-fire delta allowance consumed+budget (mode session). Clearable.
    - `status` (enum<string>) — "active" · "paused"
    - `paused_reason` (object | null) — {type:"manual"} | {type:"error", error:{type}, consecutive_failures, message?} — non-null exactly when paused. A routine pauses itself after 3 runs in a row fail with an error that the next run would repeat, insufficient_credits_error included (the wallet that pays for it is empty); add credit, then unpause.
    - `archived_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routines/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /routines/{id}

Update a routine — omit preserves; null clears schedule/budget (scope: write)

initial_events is a full replacement; metadata is key-patched (null deletes a key); name and target cannot be cleared. Archived routines are immutable (409).

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Body (application/json):

- `name` (string) — max length 256
- `description` (string | null) — max length 2048
- `metadata` (map<string, string | null>)
- `target` (object)
  - type: "new_session" (object)
    - `type` ("new_session", required)
    - `agent` (string, required)
    - `environment_id` (string)
    - `vault_ids` (string[])
    - `reuse_session` (boolean)
  - type: "session" (object)
    - `type` ("session", required)
    - `session_id` (string, required)
- `initial_events` (object[])
  - `type` ("user.message", required)
  - `content` (object[], required)
    - type: "text" (object)
      - `type` ("text", required)
      - `text` (string, required)
    - type: "image" (object)
      - `type` ("image", required)
      - `source` (object, required)
        - type: "base64" (object)
          - `type` ("base64", required)
          - `media_type` (string, required)
          - `data` (string, required)
        - type: "url" (object)
          - `type` ("url", required)
          - `url` (string, required)
        - type: "file" (object)
          - `type` ("file", required)
          - `file_id` (string, required)
    - type: "document" (object)
      - `type` ("document", required)
      - `source` (object, required)
        - type: "base64" (object)
          - `type` ("base64", required)
          - `media_type` (string, required)
          - `data` (string, required)
        - type: "text" (object)
          - `type` ("text", required)
          - `media_type` ("text/plain") — default: "text/plain"
          - `data` (string, required)
        - type: "url" (object)
          - `type` ("url", required)
          - `url` (string, required)
        - type: "file" (object)
          - `type` ("file", required)
          - `file_id` (string, required)
      - `title` (string | null)
      - `context` (string | null)
  - `interaction_mode` (enum<string> | null) — "plan" · "build"
- `schedule` (object | null)
  - `type` ("cron", required)
  - `expression` (string, required) — max length 256
  - `timezone` (string, required)
- `budget` (object | null)
  - `type` ("limit", required)
  - `max_list_cost` (object, required)
    - `amount` (string, required) — Whole US cents as an integer decimal string, e.g. "125" for $1.25 — max length 15
    - `currency` ("USD", required)

Responses:

- `200` — OK
  - `routine` (object, required) — Scheduled agent execution: initial_events + a target (new_session per fire, or an existing session) bound to a cron schedule. Fires record routine runs.
    - `id` (string) — rtn_… identifier
    - `name` (string)
    - `description` (string | null)
    - `metadata` (object)
    - `target` (object) — {type:"new_session", agent, environment_id?, vault_ids?, reuse_session?} — a fresh session per fire (CMA parity); with reuse_session: true the first fire starts the session and every later fire posts into it (a new one only once it is archived or deleted; a fire while it is working or waiting on a person is skipped) · {type:"session", session_id} — a turn into the existing session every fire (busy target skips with session_busy_error)
    - `initial_events` (object[])
    - `schedule` (object | null) — 5-field POSIX cron + IANA timezone, wall-clock matching, minute granularity; null = manual-run only
    - `budget` (object | null) — Per-run cap (RFC-0080 shape): copied onto each new session (mode new_session) or granted as a per-fire delta allowance consumed+budget (mode session). Clearable.
    - `status` (enum<string>) — "active" · "paused"
    - `paused_reason` (object | null) — {type:"manual"} | {type:"error", error:{type}, consecutive_failures, message?} — non-null exactly when paused. A routine pauses itself after 3 runs in a row fail with an error that the next run would repeat, insufficient_credits_error included (the wallet that pays for it is empty); add credit, then unpause.
    - `archived_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/routines/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"schedule":{"type":"cron","expression":"0 9 * * 1-5","timezone":"UTC"}}'
```

### DELETE /routines/{id}

Delete a routine — it never fires again and is no longer listed (scope: write)

The routine is archived (no schedule, inbound URL or chat trigger fires it) and every read of it, its runs included, answers 404 from then on, so a second delete is 404 too. The sessions its runs started are kept. To stop a routine and keep it listed, archive it instead.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `204` — Deleted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/routines/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### POST /routines/{id}/pause

Pause — suppress scheduled fires; manual runs still work (scope: write)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `routine` (object, required) — Scheduled agent execution: initial_events + a target (new_session per fire, or an existing session) bound to a cron schedule. Fires record routine runs.
    - `id` (string) — rtn_… identifier
    - `name` (string)
    - `description` (string | null)
    - `metadata` (object)
    - `target` (object) — {type:"new_session", agent, environment_id?, vault_ids?, reuse_session?} — a fresh session per fire (CMA parity); with reuse_session: true the first fire starts the session and every later fire posts into it (a new one only once it is archived or deleted; a fire while it is working or waiting on a person is skipped) · {type:"session", session_id} — a turn into the existing session every fire (busy target skips with session_busy_error)
    - `initial_events` (object[])
    - `schedule` (object | null) — 5-field POSIX cron + IANA timezone, wall-clock matching, minute granularity; null = manual-run only
    - `budget` (object | null) — Per-run cap (RFC-0080 shape): copied onto each new session (mode new_session) or granted as a per-fire delta allowance consumed+budget (mode session). Clearable.
    - `status` (enum<string>) — "active" · "paused"
    - `paused_reason` (object | null) — {type:"manual"} | {type:"error", error:{type}, consecutive_failures, message?} — non-null exactly when paused. A routine pauses itself after 3 runs in a row fail with an error that the next run would repeat, insufficient_credits_error included (the wallet that pays for it is empty); add credit, then unpause.
    - `archived_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/pause \
  -H "Authorization: Bearer ast_..."
```

### POST /routines/{id}/unpause

Unpause — resumes from the NEXT occurrence; missed fires are never backfilled (scope: write)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `routine` (object, required) — Scheduled agent execution: initial_events + a target (new_session per fire, or an existing session) bound to a cron schedule. Fires record routine runs.
    - `id` (string) — rtn_… identifier
    - `name` (string)
    - `description` (string | null)
    - `metadata` (object)
    - `target` (object) — {type:"new_session", agent, environment_id?, vault_ids?, reuse_session?} — a fresh session per fire (CMA parity); with reuse_session: true the first fire starts the session and every later fire posts into it (a new one only once it is archived or deleted; a fire while it is working or waiting on a person is skipped) · {type:"session", session_id} — a turn into the existing session every fire (busy target skips with session_busy_error)
    - `initial_events` (object[])
    - `schedule` (object | null) — 5-field POSIX cron + IANA timezone, wall-clock matching, minute granularity; null = manual-run only
    - `budget` (object | null) — Per-run cap (RFC-0080 shape): copied onto each new session (mode new_session) or granted as a per-fire delta allowance consumed+budget (mode session). Clearable.
    - `status` (enum<string>) — "active" · "paused"
    - `paused_reason` (object | null) — {type:"manual"} | {type:"error", error:{type}, consecutive_failures, message?} — non-null exactly when paused. A routine pauses itself after 3 runs in a row fail with an error that the next run would repeat, insufficient_credits_error included (the wallet that pays for it is empty); add credit, then unpause.
    - `archived_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/unpause \
  -H "Authorization: Bearer ast_..."
```

### POST /routines/{id}/archive

Archive — terminal; the schedule stops and the routine becomes immutable (scope: write)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `routine` (object, required) — Scheduled agent execution: initial_events + a target (new_session per fire, or an existing session) bound to a cron schedule. Fires record routine runs.
    - `id` (string) — rtn_… identifier
    - `name` (string)
    - `description` (string | null)
    - `metadata` (object)
    - `target` (object) — {type:"new_session", agent, environment_id?, vault_ids?, reuse_session?} — a fresh session per fire (CMA parity); with reuse_session: true the first fire starts the session and every later fire posts into it (a new one only once it is archived or deleted; a fire while it is working or waiting on a person is skipped) · {type:"session", session_id} — a turn into the existing session every fire (busy target skips with session_busy_error)
    - `initial_events` (object[])
    - `schedule` (object | null) — 5-field POSIX cron + IANA timezone, wall-clock matching, minute granularity; null = manual-run only
    - `budget` (object | null) — Per-run cap (RFC-0080 shape): copied onto each new session (mode new_session) or granted as a per-fire delta allowance consumed+budget (mode session). Clearable.
    - `status` (enum<string>) — "active" · "paused"
    - `paused_reason` (object | null) — {type:"manual"} | {type:"error", error:{type}, consecutive_failures, message?} — non-null exactly when paused. A routine pauses itself after 3 runs in a row fail with an error that the next run would repeat, insufficient_credits_error included (the wallet that pays for it is empty); add credit, then unpause.
    - `archived_at` (string | null)
    - `created_at` (string)
    - `updated_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/archive \
  -H "Authorization: Bearer ast_..."
```

### POST /routines/{id}/run

Run now, outside the schedule; works while paused (scope: write)

With no body it is a manual run: trigger_context {type:"manual"}. With `input` or `idempotency_key` it is an API-triggered run: trigger_context {type:"api"}; the input is added to the run's first message under the label "Input for this run:", and a repeated idempotency_key on the same routine returns the first run instead of starting another. Neither emits routine_run webhooks.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Body (application/json):

- `input` (string) — What this run should work on, such as an event's payload — max length 50000
- `idempotency_key` (string) — The caller's id for the event; a repeat returns the first run — max length 200

Responses:

- `201` — Created
  - `run` (object, required) — One fire attempt. Exactly one of session_id / error is non-null once the fire ended.
    - `id` (string) — rrun_… identifier
    - `routine_id` (string)
    - `trigger_context` (object) — {type:"schedule", scheduled_at} | {type:"manual"}
    - `session_id` (string | null)
    - `error` (object | null) — {type, message}. Types: agent_archived_error · agent_not_found_error · session_archived_error · session_not_found_error · session_busy_error · environment_archived_error · environment_not_found_error · vault_not_found_error · insufficient_credits_error · rate_limited_error · run_rejected_error · unknown_error. Unrecoverable types auto-pause the routine; transient ones (credits, rate limit, busy) leave it active for the next occurrence. precheck_unchanged is not a failure: the scheduled fire was skipped because the routine's precheck URL returned the same content as at the last run; no session started, the routine stays active and no routine_run webhook is sent. workspace_idle is the same for a workspace's upkeep routine: nothing had happened in the workspace since its last upkeep run.
    - `agent` (object) — Resolved agent reference at fire time
    - `created_at` (string)
    - `status` (enum<string>) — Where the run stands. failed: it did not start (error) or its turn failed (turn_error). unknown: no turn end was recorded and the session is no longer working. — "running" · "succeeded" · "failed" · "unknown"
    - `finished_at` (string | null) — When the run's turn ended, or when it failed to start; null until then
    - `turn_error` (object | null) — {type, message}: why a run that started failed in its turn. error stays the failure to start
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/run \
  -H "Authorization: Bearer ast_..."
```

### GET /routines/{id}/inbound-url

Whether the routine has an inbound URL (scope: read)

`inbound_url` is null when there is none. The URL itself is never returned here, only the start of its secret.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `inbound_url` (object | null, required)
    - `routine_id` (string, required)
    - `prefix` (string, required) — The start of the secret in the URL
    - `created_at` (string, required)
    - `last_used_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/inbound-url' \
  -H "Authorization: Bearer ast_..."
```

### POST /routines/{id}/inbound-url

Make the routine's inbound URL (scope: write)

Returns a URL that starts a run of this routine when posted to, with no API token: for a service that can only call a URL. It replaces any earlier one, which stops working at once. The URL carries its own secret and is returned only in this response.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `201` — Created
  - `inbound_url` (object, required)
    - `routine_id` (string, required)
    - `prefix` (string, required) — The start of the secret in the URL
    - `created_at` (string, required)
    - `last_used_at` (string | null, required)
    - `url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/inbound-url \
  -H "Authorization: Bearer ast_..."
```

### DELETE /routines/{id}/inbound-url

Remove the routine's inbound URL (scope: write)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `removed` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/inbound-url \
  -H "Authorization: Bearer ast_..."
```

### GET /routines/{id}/result-email

Whether the routine emails its result (scope: read)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `result_email` (object, required)
    - `enabled` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/result-email' \
  -H "Authorization: Bearer ast_..."
```

### PUT /routines/{id}/result-email

Email the routine's creator the result of each run (scope: write)

When a run finishes, its creator gets one email with the last thing the agent said and a link to the run. It is sent whatever the person chose for finished-task emails, and every email carries a link that turns this routine's emails off. Only a routine whose target is `new_session` can have it (400 otherwise); an archived routine answers 409.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `result_email` (object, required)
    - `enabled` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/result-email \
  -H "Authorization: Bearer ast_..."
```

### DELETE /routines/{id}/result-email

Stop emailing the routine's result (scope: write)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `result_email` (object, required)
    - `enabled` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/result-email \
  -H "Authorization: Bearer ast_..."
```

### GET /routines/{id}/precheck

The routine's precheck (scope: read)

`precheck` is null when there is none. It carries what the last check before a scheduled fire found.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `precheck` (object | null, required)
    - `routine_id` (string, required)
    - `url` (string, required)
    - `created_at` (string, required)
    - `last_checked_at` (string | null, required) — When the URL was last checked before a scheduled fire
    - `last_result` (string | null, required) — changed: the fire ran. unchanged: the fire was skipped. failed: the check could not be completed and the fire ran anyway. — "changed" · "unchanged" · "failed" · null
    - `last_error` (object | null, required) — {type, message} when last_result is failed. Types: address_not_allowed · dns_failed · redirect · http_status · too_large · timeout · network.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/precheck' \
  -H "Authorization: Bearer ast_..."
```

### PUT /routines/{id}/precheck

Run scheduled fires only when a URL's content changed (scope: write)

Before each scheduled fire the platform GETs `url` and compares its content with the content at the last scheduled fire that ran. The same content skips the fire: it is recorded as a run with error.type `precheck_unchanged` and no session, and nothing is charged. New content, and the first check, run the fire. A check that cannot be completed (a redirect, a status outside 2xx, more than 256 KiB, more than 5 seconds, a host that is not on the public internet) never skips: the fire runs and the reason is kept in `last_error`. Manual runs, API runs and inbound-URL runs never consult it. The URL must be https on the default port, with no user name or password, and must not point at a private, loopback or link-local address (400 otherwise); it is fetched with no credentials. Setting a URL forgets what the earlier check remembered. An archived routine answers 409.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Body (application/json):

- `url` (string, required)

Responses:

- `200` — OK
  - `precheck` (object, required)
    - `routine_id` (string, required)
    - `url` (string, required)
    - `created_at` (string, required)
    - `last_checked_at` (string | null, required) — When the URL was last checked before a scheduled fire
    - `last_result` (string | null, required) — changed: the fire ran. unchanged: the fire was skipped. failed: the check could not be completed and the fire ran anyway. — "changed" · "unchanged" · "failed" · null
    - `last_error` (object | null, required) — {type, message} when last_result is failed. Types: address_not_allowed · dns_failed · redirect · http_status · too_large · timeout · network.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/precheck \
  -H "Authorization: Bearer ast_..."
```

### DELETE /routines/{id}/precheck

Remove the routine's precheck (scope: write)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `removed` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/precheck \
  -H "Authorization: Bearer ast_..."
```

### GET /routines/{id}/channel-trigger

The routine's chat trigger (scope: read)

`channel_trigger` is null when there is none. `available` says whether messages of this workspace's connected chats are offered to routines in this deployment; where it is false a trigger can be stored and will never match.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `channel_trigger` (object | null, required)
    - `routine_id` (string, required)
    - `connection_id` (string, required)
    - `thread_id` (string | null, required) — The one conversation whose messages start a run; null for every conversation on the connection
    - `text_prefix` (string | null, required) — What a message has to start with to start a run; null for every message
    - `created_at` (string, required)
    - `last_matched_at` (string | null, required)
  - `available` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/channel-trigger' \
  -H "Authorization: Bearer ast_..."
```

### PUT /routines/{id}/channel-trigger

Start the routine from a message in a connected chat (scope: write)

A message starts a run when it is on the connection, in `thread_id` when one is given, and starts with `text_prefix` when one is given (leading mentions of the bot and letter case are ignored). Only messages from the person the routine belongs to start a run: the person who connected the chat, or a chat identity they linked to the same account. Anyone else's message is routed as if there were no trigger. The text after the prefix is added to the run's first message under the label "Input for this run:". The run is a task of the routine's creator (trigger_context {type:"channel", connection_id, thread_id}), and when its turn ends its last message is posted, once, in the conversation the message came from, with a link to the run. A message that started a run is sent nowhere else. One message starts at most one run; when several routines match, the one naming a thread and then the longest prefix wins. A paused or archived routine starts nothing, and more than 30 runs of one routine in a minute are dropped. Only the routine's creator can set the trigger (403 otherwise), on a connected chat of their own in this workspace (404 otherwise). `thread_id` must be a conversation on that connection and `text_prefix` 1 to 200 characters (400 otherwise). Setting a trigger replaces the earlier one. An archived routine answers 409.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Body (application/json):

- `connection_id` (string, required)
- `thread_id` (string)
- `text_prefix` (string)

Responses:

- `200` — OK
  - `channel_trigger` (object, required)
    - `routine_id` (string, required)
    - `connection_id` (string, required)
    - `thread_id` (string | null, required) — The one conversation whose messages start a run; null for every conversation on the connection
    - `text_prefix` (string | null, required) — What a message has to start with to start a run; null for every message
    - `created_at` (string, required)
    - `last_matched_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/channel-trigger \
  -H "Authorization: Bearer ast_..."
```

### DELETE /routines/{id}/channel-trigger

Remove the routine's chat trigger (scope: write)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `removed` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/channel-trigger \
  -H "Authorization: Bearer ast_..."
```

### GET /routines/{id}/deliver-to

Where the routine's runs post their answer (scope: read)

`deliver_to` is the chat the owner chose, or null. `effective_deliver_to` is where results go in effect: the chosen chat, else the conversation the routine runs in or was made in, else the owner notification alone.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `deliver_to` (object | null, required)
    - `routine_id` (string, required)
    - `type` (enum<string>, required) — "channel_thread"
    - `connection_id` (string, required)
    - `thread_id` (string, required)
    - `created_at` (string, required)
  - `effective_deliver_to` (object, required) — Where each run's result goes in effect. channel_thread: the chosen chat. session: a conversation — the one the routine runs in (source target) or the one it was made in (source origin, from metadata created_in_session or proposed_by_session). notification: no conversation. The owner is notified in every case.
    - `type` (enum<string>, required) — "channel_thread" · "session" · "notification"
    - `connection_id` (string)
    - `thread_id` (string)
    - `session_id` (string)
    - `source` (enum<string>) — "target" · "origin"
    - `notify_owner` (enum<boolean>, required) — true
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/deliver-to' \
  -H "Authorization: Bearer ast_..."
```

### PUT /routines/{id}/deliver-to

Post each run's answer to a conversation in a connected chat (scope: write)

When a turn of a run's session ends and the run is not waiting on its owner, the last thing the agent said (at most 3,000 characters) is posted in the conversation with a link to the run, once per run. `thread_id` defaults to the chat itself. A run a chat message started answers where that message was instead. Only the routine's creator can set this (403 otherwise), on a connected chat of their own in this workspace (404 otherwise). An archived routine answers 409.

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Body (application/json):

- `type` (enum<string>, required) — "channel_thread"
- `connection_id` (string, required)
- `thread_id` (string)

Responses:

- `200` — OK
  - `deliver_to` (object, required)
    - `routine_id` (string, required)
    - `type` (enum<string>, required) — "channel_thread"
    - `connection_id` (string, required)
    - `thread_id` (string, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/deliver-to \
  -H "Authorization: Bearer ast_..."
```

### DELETE /routines/{id}/deliver-to

Stop posting the routine's answers to a conversation (scope: write)

Path parameters:

- `id` (string, required) — The routine id (rtn_…)

Responses:

- `200` — OK
  - `removed` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/routines/sess_cmtb7q2j/deliver-to \
  -H "Authorization: Bearer ast_..."
```

### POST /routines/inbound/{token}

Start a run through the routine's inbound URL

No Authorization header: the secret in the path is the credential. The request body, in any format and up to 50,000 characters, is added to the run's first message under the label "Input for this run:"; an empty body starts a run with no input. An `Idempotency-Key` header makes a repeated delivery return the first run. A paused routine answers 409 and starts nothing, an unknown URL or an archived routine answers 404, and more than 30 runs of one routine in a minute answers 429. The run is a task of the routine's owner (trigger_context {type:"api"}).

Path parameters:

- `token` (string, required) — The secret part of the inbound URL (rin_…)

Responses:

- `202` — Accepted
  - `run` (object, required)
    - `id` (string, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/routines/inbound/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0 \
  -H "Authorization: Bearer ast_..."
```

### GET /routine-runs

List routine runs — every fire attempt (scope: read)

Query parameters:

- `routine` (string) — Filter to one routine (rtn_…)
- `has_error` (boolean) — true = failed runs, false = runs with a session
- `trigger_type` (string)
- `created_at[gte]` (string) — Also gt / lt / lte
- `cursor` (string)
- `limit` (integer)

Responses:

- `200` — OK
  - `items` (object[], required)
    - `id` (string) — rrun_… identifier
    - `routine_id` (string)
    - `trigger_context` (object) — {type:"schedule", scheduled_at} | {type:"manual"}
    - `session_id` (string | null)
    - `error` (object | null) — {type, message}. Types: agent_archived_error · agent_not_found_error · session_archived_error · session_not_found_error · session_busy_error · environment_archived_error · environment_not_found_error · vault_not_found_error · insufficient_credits_error · rate_limited_error · run_rejected_error · unknown_error. Unrecoverable types auto-pause the routine; transient ones (credits, rate limit, busy) leave it active for the next occurrence. precheck_unchanged is not a failure: the scheduled fire was skipped because the routine's precheck URL returned the same content as at the last run; no session started, the routine stays active and no routine_run webhook is sent. workspace_idle is the same for a workspace's upkeep routine: nothing had happened in the workspace since its last upkeep run.
    - `agent` (object) — Resolved agent reference at fire time
    - `created_at` (string)
    - `status` (enum<string>) — Where the run stands. failed: it did not start (error) or its turn failed (turn_error). unknown: no turn end was recorded and the session is no longer working. — "running" · "succeeded" · "failed" · "unknown"
    - `finished_at` (string | null) — When the run's turn ended, or when it failed to start; null until then
    - `turn_error` (object | null) — {type, message}: why a run that started failed in its turn. error stays the failure to start
  - `cursor` (string | null)
  - `hasMore` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routine-runs' \
  -H "Authorization: Bearer ast_..."
```

### GET /routine-runs/{id}

Routine run detail (scope: read)

Path parameters:

- `id` (string, required) — The run id (rrun_…)

Responses:

- `200` — OK
  - `run` (object, required) — One fire attempt. Exactly one of session_id / error is non-null once the fire ended.
    - `id` (string) — rrun_… identifier
    - `routine_id` (string)
    - `trigger_context` (object) — {type:"schedule", scheduled_at} | {type:"manual"}
    - `session_id` (string | null)
    - `error` (object | null) — {type, message}. Types: agent_archived_error · agent_not_found_error · session_archived_error · session_not_found_error · session_busy_error · environment_archived_error · environment_not_found_error · vault_not_found_error · insufficient_credits_error · rate_limited_error · run_rejected_error · unknown_error. Unrecoverable types auto-pause the routine; transient ones (credits, rate limit, busy) leave it active for the next occurrence. precheck_unchanged is not a failure: the scheduled fire was skipped because the routine's precheck URL returned the same content as at the last run; no session started, the routine stays active and no routine_run webhook is sent. workspace_idle is the same for a workspace's upkeep routine: nothing had happened in the workspace since its last upkeep run.
    - `agent` (object) — Resolved agent reference at fire time
    - `created_at` (string)
    - `status` (enum<string>) — Where the run stands. failed: it did not start (error) or its turn failed (turn_error). unknown: no turn end was recorded and the session is no longer working. — "running" · "succeeded" · "failed" · "unknown"
    - `finished_at` (string | null) — When the run's turn ended, or when it failed to start; null until then
    - `turn_error` (object | null) — {type, message}: why a run that started failed in its turn. error stays the failure to start
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/routine-runs/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

## Model subscriptions

### GET /model-subscriptions

List connected model subscriptions — metadata only, never credentials (scope: read)

Query parameters:

- `accounts` (string) — Include additional accounts; omitted preserves the legacy provider-only list

Responses:

- `200` — OK
  - `modelSubscriptions` (object[], required)
    - `provider` (enum<string>) — "anthropic" · "openai" · "cursor" · "xai" · "meta"
    - `accountId` (string) — Additional account identifier; omitted for the legacy provider account
    - `label` (string)
    - `status` (enum<string>) — connected runs agents; needs_reconnect lost its credential; org_disabled is signed in to an organization that turned off plan access for this harness, so nothing runs on it until it is reconnected — "connected" · "needs_reconnect" · "org_disabled"
    - `expiresAt` (string | null)
    - `lastUsedAt` (string | null)
    - `useForNewAgents` (boolean)
    - `createdAt` (string)
    - `agents` (object[]) — Agents in this universe running on the subscription
      - `id` (string)
      - `agentId` (string | null)
      - `name` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/model-subscriptions' \
  -H "Authorization: Bearer ast_..."
```

### POST /model-subscriptions

Add a separate subscription account (scope: write)

ChatGPT connections default to the email in their sign-in metadata. Adding the same native ChatGPT account again refreshes and returns its existing workspace connection instead of creating a duplicate; explicit custom names remain supported.

Body (application/json):

- `credential` (string, required) — max length 100000
- `label` (string) — max length 60
- `provider` (enum<string>, required) — "anthropic" · "openai" · "cursor" · "xai" · "meta"

Responses:

- `201` — Created
  - `modelSubscription` (object, required) — A connected consumer AI subscription (Claude Pro/Max, ChatGPT, Cursor, Grok or Muse plan) powering eligible agents at $0 model usage. The credential itself is write-only.
    - `provider` (enum<string>) — "anthropic" · "openai" · "cursor" · "xai" · "meta"
    - `accountId` (string) — Additional account identifier; omitted for the legacy provider account
    - `label` (string)
    - `status` (enum<string>) — connected runs agents; needs_reconnect lost its credential; org_disabled is signed in to an organization that turned off plan access for this harness, so nothing runs on it until it is reconnected — "connected" · "needs_reconnect" · "org_disabled"
    - `expiresAt` (string | null)
    - `lastUsedAt` (string | null)
    - `useForNewAgents` (boolean)
    - `createdAt` (string)
    - `agents` (object[]) — Agents in this universe running on the subscription
      - `id` (string)
      - `agentId` (string | null)
      - `name` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/model-subscriptions \
  -H "Authorization: Bearer ast_..."
```

### PUT /model-subscriptions/{provider}

Connect or replace a subscription credential (write-only) (scope: write)

anthropic: the sk-ant-oat… token from `claude setup-token`. openai: the contents of ~/.codex/auth.json from `codex login`. cursor: a Cursor API key, or the sign-in file ~/.config/cursor/auth.json from `cursor-agent login`. xai: the sign-in file ~/.grok/auth.json from `grok login`. meta: the sign-in file ~/.config/muse/auth.json from `muse login`. Eligible agents can then run at $0 model usage; with useForNewAgents (default on), new eligible Claude, ChatGPT, Grok and Muse agents use it automatically. Cursor agents use it only when created or switched with modelBilling `account`. ChatGPT connections default to their sign-in email when no custom label is supplied. Replacing a different connection with a ChatGPT account already connected here returns account_already_connected.

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription

Query parameters:

- `accountId` (string) — Target an additional account; omitted targets the legacy provider account

Body (application/json):

- `credential` (string, required) — max length 100000
- `label` (string) — max length 60

Responses:

- `200` — OK
  - `modelSubscription` (object, required) — A connected consumer AI subscription (Claude Pro/Max, ChatGPT, Cursor, Grok or Muse plan) powering eligible agents at $0 model usage. The credential itself is write-only.
    - `provider` (enum<string>) — "anthropic" · "openai" · "cursor" · "xai" · "meta"
    - `accountId` (string) — Additional account identifier; omitted for the legacy provider account
    - `label` (string)
    - `status` (enum<string>) — connected runs agents; needs_reconnect lost its credential; org_disabled is signed in to an organization that turned off plan access for this harness, so nothing runs on it until it is reconnected — "connected" · "needs_reconnect" · "org_disabled"
    - `expiresAt` (string | null)
    - `lastUsedAt` (string | null)
    - `useForNewAgents` (boolean)
    - `createdAt` (string)
    - `agents` (object[]) — Agents in this universe running on the subscription
      - `id` (string)
      - `agentId` (string | null)
      - `name` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/model-subscriptions/provider \
  -H "Authorization: Bearer ast_..."
```

### PATCH /model-subscriptions/{provider}

Update useForNewAgents / label (scope: write)

useForNewAgents true pins the account as the default; unpinned, new agents use the plan that ends soonest. An empty label restores the account's email.

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription

Query parameters:

- `accountId` (string) — Target an additional account; omitted targets the legacy provider account

Body (application/json):

- `useForNewAgents` (boolean)
- `label` (string) — max length 60

Responses:

- `200` — OK
  - `modelSubscription` (object, required) — A connected consumer AI subscription (Claude Pro/Max, ChatGPT, Cursor, Grok or Muse plan) powering eligible agents at $0 model usage. The credential itself is write-only.
    - `provider` (enum<string>) — "anthropic" · "openai" · "cursor" · "xai" · "meta"
    - `accountId` (string) — Additional account identifier; omitted for the legacy provider account
    - `label` (string)
    - `status` (enum<string>) — connected runs agents; needs_reconnect lost its credential; org_disabled is signed in to an organization that turned off plan access for this harness, so nothing runs on it until it is reconnected — "connected" · "needs_reconnect" · "org_disabled"
    - `expiresAt` (string | null)
    - `lastUsedAt` (string | null)
    - `useForNewAgents` (boolean)
    - `createdAt` (string)
    - `agents` (object[]) — Agents in this universe running on the subscription
      - `id` (string)
      - `agentId` (string | null)
      - `name` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/model-subscriptions/provider \
  -H "Authorization: Bearer ast_..."
```

### DELETE /model-subscriptions/{provider}

Remove — the account is deleted and leaves every list; removing one already gone succeeds with removed: false. Its agents move to the provider's default connected account, else its oldest; with none left they pause until an account of the provider is next connected. They never move to credits on their own (scope: write)

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription

Query parameters:

- `accountId` (string) — Target an additional account; omitted targets the legacy provider account

Responses:

- `200` — OK
  - `removed` (boolean) — false when the account was already gone
  - `affectedAgents` (object[]) — Agents left paused because no other connected account of the provider exists
    - `id` (string)
    - `agentId` (string | null)
    - `name` (string)
  - `movedAgents` (object[]) — Agents moved to movedTo; each takes it at its next wake, so a running turn is not interrupted
    - `id` (string)
    - `agentId` (string | null)
    - `name` (string)
  - `movedTo` (object | null) — The account the agents moved to; null when none moved. accountId null is the provider's original account
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/model-subscriptions/provider \
  -H "Authorization: Bearer ast_..."
```

### POST /model-subscriptions/{provider}/copy

Copy a model account between a platform administrator's own workspaces (scope: admin)

Company platform operators only; ordinary workspace administrators are refused. The source is the request workspace. Both workspaces must belong to the caller and cannot be partner workspaces. Credentials are decrypted and re-encrypted server-side, never returned. Omit sourceAccountId for the legacy account. Omit targetAccountId to create or refresh a stable additional account; set it to an existing id (or null for the existing legacy account) to replace that exact account. Retries do not create duplicates. Implicit ChatGPT copies reuse the same native account already connected in the target; an explicit different target returns account_already_connected. Preserves the source expiry and existing target defaults and session pointers. Does not add provider permissions or quota; copied OAuth refresh grants are not independent logins.

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription

Body (application/json):

- `targetWorkspace` (string, required) — max length 100
- `sourceAccountId` (string)
- `targetAccountId` (string | null)
- `reason` (string, required) — max length 500

Responses:

- `200` — Copied, or already current
  - `accountId` (string | null, required)
  - `provider` (string, required)
  - `targetWorkspace` (string, required)
  - `changed` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/model-subscriptions/provider/copy \
  -H "Authorization: Bearer ast_..."
```

### POST /model-subscriptions/{provider}/logins

Start a browser sign-in to a model plan (scope: write)

The provider's own CLI signs in inside a short-lived sandbox; open the returned `url`, then poll GET …/logins/{loginId} until `connected`. accountId `new` adds a separate account; omitted signs in the legacy provider account. Five starts per member per 10 minutes.

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription

Body (application/json):

- `accountId` (string)
- `label` (string) — max length 60

Responses:

- `201` — Created
  - `login` (object, required) — A browser sign-in in progress. starting: the sandbox is booting, poll again. waiting: open `url` (and, when `acceptsCode`, submit the code the provider's page shows). connected: the subscription is stored. cleanup_pending: stored, but the sandbox has not stopped yet; poll again or DELETE. failed: start again.
    - `state` (enum<string>, required) — "starting" · "waiting" · "connected" · "cleanup_pending" · "failed"
    - `loginId` (string) — Opaque handle bound to the caller, the workspace and the provider; valid for 16 minutes
    - `url` (string) — The provider's sign-in page (waiting)
    - `userCode` (string | null) — A code to confirm on the provider's page, when it shows one
    - `acceptsCode` (boolean) — The provider's page shows a code to submit to /code
    - `subscription` (object) — A connected consumer AI subscription (Claude Pro/Max, ChatGPT, Cursor, Grok or Muse plan) powering eligible agents at $0 model usage. The credential itself is write-only.
      - `provider` (enum<string>) — "anthropic" · "openai" · "cursor" · "xai" · "meta"
      - `accountId` (string) — Additional account identifier; omitted for the legacy provider account
      - `label` (string)
      - `status` (enum<string>) — connected runs agents; needs_reconnect lost its credential; org_disabled is signed in to an organization that turned off plan access for this harness, so nothing runs on it until it is reconnected — "connected" · "needs_reconnect" · "org_disabled"
      - `expiresAt` (string | null)
      - `lastUsedAt` (string | null)
      - `useForNewAgents` (boolean)
      - `createdAt` (string)
      - `agents` (object[]) — Agents in this universe running on the subscription
        - `id` (string)
        - `agentId` (string | null)
        - `name` (string)
    - `reason` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/model-subscriptions/provider/logins \
  -H "Authorization: Bearer ast_..."
```

### GET /model-subscriptions/{provider}/logins/{loginId}

Advance a browser sign-in; stores the subscription when it finishes (scope: write)

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription
- `loginId` (string, required) — The handle a sign-in start returned

Responses:

- `200` — OK
  - `login` (object, required) — A browser sign-in in progress. starting: the sandbox is booting, poll again. waiting: open `url` (and, when `acceptsCode`, submit the code the provider's page shows). connected: the subscription is stored. cleanup_pending: stored, but the sandbox has not stopped yet; poll again or DELETE. failed: start again.
    - `state` (enum<string>, required) — "starting" · "waiting" · "connected" · "cleanup_pending" · "failed"
    - `loginId` (string) — Opaque handle bound to the caller, the workspace and the provider; valid for 16 minutes
    - `url` (string) — The provider's sign-in page (waiting)
    - `userCode` (string | null) — A code to confirm on the provider's page, when it shows one
    - `acceptsCode` (boolean) — The provider's page shows a code to submit to /code
    - `subscription` (object) — A connected consumer AI subscription (Claude Pro/Max, ChatGPT, Cursor, Grok or Muse plan) powering eligible agents at $0 model usage. The credential itself is write-only.
      - `provider` (enum<string>) — "anthropic" · "openai" · "cursor" · "xai" · "meta"
      - `accountId` (string) — Additional account identifier; omitted for the legacy provider account
      - `label` (string)
      - `status` (enum<string>) — connected runs agents; needs_reconnect lost its credential; org_disabled is signed in to an organization that turned off plan access for this harness, so nothing runs on it until it is reconnected — "connected" · "needs_reconnect" · "org_disabled"
      - `expiresAt` (string | null)
      - `lastUsedAt` (string | null)
      - `useForNewAgents` (boolean)
      - `createdAt` (string)
      - `agents` (object[]) — Agents in this universe running on the subscription
        - `id` (string)
        - `agentId` (string | null)
        - `name` (string)
    - `reason` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/model-subscriptions/provider/logins/loginId' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /model-subscriptions/{provider}/logins/{loginId}

Abandon a browser sign-in and free its sandbox (scope: write)

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription
- `loginId` (string, required) — The handle a sign-in start returned

Responses:

- `204` — Abandoned
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/model-subscriptions/provider/logins/loginId \
  -H "Authorization: Bearer ast_..."
```

### POST /model-subscriptions/{provider}/logins/{loginId}/code

Submit the code the provider's sign-in page shows (scope: write)

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription
- `loginId` (string, required) — The handle a sign-in start returned

Body (application/json):

- `code` (string, required) — max length 1024

Responses:

- `204` — Handed to the waiting CLI
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/model-subscriptions/provider/logins/loginId/code \
  -H "Authorization: Bearer ast_..."
```

### GET /model-subscriptions/{provider}/usage

Plan allowance left on a connected account (scope: read)

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription

Query parameters:

- `accountId` (string) — Target an additional account; omitted targets the legacy provider account

Responses:

- `200` — OK
  - `usage` (object, required) — The plan allowance left on a connected account. `unavailable` with a reason when the provider cannot be read.
    - `checkedAt` (string)
    - `status` (enum<string>) — "known" · "unavailable"
    - `reason` (string | null) — "unsupported" · "sign_in" · "token_expired" · "permission" · "temporarily_unavailable" · null
    - `plan` (string | null)
    - `allowed` (boolean | null) — false when a window is used up
    - `windows` (object[])
      - `label` (string)
      - `remainingPercent` (number)
      - `resetsAt` (string | null)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/model-subscriptions/provider/usage' \
  -H "Authorization: Bearer ast_..."
```

### POST /model-subscriptions/{provider}/switch-to-credits

Move the agents on a subscription account onto platform credits (scope: write)

Run before disconnecting an account so its agents keep working. Restarts their running sessions.

Path parameters:

- `provider` (string, required) — anthropic = Claude subscription · openai = ChatGPT plan · cursor = Cursor plan · xai = Grok subscription · meta = Muse subscription

Query parameters:

- `accountId` (string) — Target an additional account; omitted targets the legacy provider account

Responses:

- `200` — OK
  - `switched` (integer)
  - `restartFailures` (string[]) — Agents switched to credits whose running session could not be restarted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/model-subscriptions/provider/switch-to-credits \
  -H "Authorization: Bearer ast_..."
```

## External accounts

### GET /external_accounts

List the workspace's accounts at outside vendors — never credentials (scope: read)

Vendor accounts connected here, and the workspace's model plans (managed under /model-subscriptions; their ids start with `plan:`). `vendors` lists the vendors an account can be connected for and whether connecting takes one `key` or the vendor's full `settings`. 404 where external accounts are not turned on for the workspace.

Responses:

- `200` — OK
  - `external_accounts` (object[], required)
    - `id` (string, required)
    - `kind` (enum<string>, required) — "model_subscription" · "vendor_account"
    - `vendor` (string, required)
    - `vendor_name` (string, required)
    - `label` (string, required)
    - `status` (enum<string>, required) — "active" · "needs_reconnect" · "exhausted"
    - `plan` (string | null, required) — The plan the vendor reported, when it reports one
    - `agents` (object[], required) — The agents that have run on it
      - `id` (string, required)
      - `name` (string, required)
    - `last_used_at` (string | null, required)
    - `created_at` (string, required)
  - `vendors` (object[], required)
    - `id` (string, required)
    - `name` (string, required)
    - `credential` (enum<string>, required) — "key" · "settings"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/external_accounts' \
  -H "Authorization: Bearer ast_..."
```

### POST /external_accounts

Connect a vendor account, or replace the credential of the one with the same vendor and label (scope: write)

The credential is write-only. Every task of the workspace waiting on this vendor's account (an open `connect_account` request) then continues. 422 `invalid_credential` when the vendor does not accept it; 503 `not_migrated` before the store exists. A vendor's own browser sign-in is not offered here.

Body (application/json):

- `vendor` (string, required) — A vendor id from `vendors` — max length 80
- `label` (string) — Defaults to the vendor's name — max length 80
- `credential` (string | map<string, string>, required) — One key, or the vendor's account settings as upper-case names with text values
  - option 1 (string)
  - option 2 (map<string, string>)

Responses:

- `201` — Created
  - `external_account` (object, required)
    - `id` (string, required)
    - `kind` (enum<string>, required) — "model_subscription" · "vendor_account"
    - `vendor` (string, required)
    - `vendor_name` (string, required)
    - `label` (string, required)
    - `status` (enum<string>, required) — "active" · "needs_reconnect" · "exhausted"
    - `plan` (string | null, required) — The plan the vendor reported, when it reports one
    - `agents` (object[], required) — The agents that have run on it
      - `id` (string, required)
      - `name` (string, required)
    - `last_used_at` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/external_accounts \
  -H "Authorization: Bearer ast_..."
```

### DELETE /external_accounts/{id}

Disconnect an account; a later task that needs it asks for it again (scope: write)

Path parameters:

- `id` (string, required) — The account's id from the list

Responses:

- `204` — Disconnected
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/external_accounts/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /external_accounts/{id}/usage

Which agents and tasks ran on a vendor account (scope: read)

Path parameters:

- `id` (string, required) — The account's id from the list

Responses:

- `200` — OK
  - `usage` (object, required)
    - `agents` (object[], required)
      - `id` (string, required)
      - `name` (string, required)
    - `tasks` (object[], required)
      - `session_id` (string, required)
      - `agent_id` (string | null, required)
      - `title` (string | null, required)
      - `first_used_at` (string, required)
      - `last_used_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/external_accounts/sess_cmtb7q2j/usage' \
  -H "Authorization: Bearer ast_..."
```

## Connectors

### GET /shared-connections

Deprecated: use GET /plugins?view=yours&source=app&include=shared. Everything you share with a workspace, and the calls made through each (scope: read)

Deprecated: use `GET /plugins?view=yours&source=app&include=shared`. Still served exactly as before; every answer carries a `Deprecation` header.

Responses:

- `200` — OK
  - `shared` (object[], required)
    - `connection_id` (string)
    - `app` (string)
    - `app_name` (string)
    - `label` (string)
    - `workspace` (object)
      - `slug` (string)
      - `name` (string)
    - `shared_at` (string)
    - `use_count` (integer)
    - `uses` (object[])
      - `session_id` (string)
      - `started_by` (object)
        - `user_id` (string)
        - `name` (string)
      - `key` (object) — The workspace key that started the session, when one did.
        - `id` (string)
        - `name` (string)
      - `method` (string)
      - `host` (string)
      - `status` (integer)
      - `at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/shared-connections' \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/apps

Deprecated: use GET /plugins?view=discover&source=app. Deprecated: use GET /plugins?view=discover&source=app. Deprecated: use GET /plugins?view=discover&source=app. List the apps a person can connect (scope: read)

Deprecated: use `GET /plugins?view=discover&source=app`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins?view=discover&source=app`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins?view=discover&source=app`. Still served exactly as before; every answer carries a `Deprecation` header. One page of the catalog. With neither `q` nor `cursor` the page leads with the widely used apps. Pages vary in size: continue with `next_cursor` until it is null. Answers 502 `catalog_error` when the catalog cannot be read.

Query parameters:

- `q` (string) — Search by name
- `cursor` (string) — A page's `next_cursor`

Responses:

- `200` — OK
  - `apps` (object[], required)
    - `slug` (string, required) — The app's id, used wherever an app is named.
    - `name` (string, required)
    - `description` (string, required)
  - `next_cursor` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/apps' \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/apps/{slug}/logo

An app's mark (scope: public)

The catalog's logo for one app, as an image AgentSky serves and caches for a day, so a page never loads it from the connector service's own hosts. Plugin cards name this address as `provider.logo`. 404 `not_found` when the app has no logo; 502 `catalog_error` when the catalog cannot be read.

Path parameters:

- `slug` (string, required)

Responses:

- `200` — The image
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/apps/acme/logo' \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/connections

Deprecated: use GET /plugins?view=yours&source=app&include=connections (include=granted for granted=true). Deprecated: use GET /plugins?view=yours&source=app&include=connections (include=granted for granted=true). Deprecated: use GET /plugins?view=yours&source=app&include=connections (include=granted for granted=true). List the caller's connections (scope: read)

Deprecated: use `GET /plugins?view=yours&source=app&include=connections (include=granted for granted=true)`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins?view=yours&source=app&include=connections (include=granted for granted=true)`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins?view=yours&source=app&include=connections (include=granted for granted=true)`. Still served exactly as before; every answer carries a `Deprecation` header. The accounts the caller connected, by app and then oldest first. Connections belong to the person, not to a workspace. `credit` is what the caller has earned by connecting apps and the most they can earn that way. With `granted=true` the answer is instead `{connections: GrantedConnection[]}`: the connections other people let this credential call through with POST /connectors/proxy — those granted to the selected workspace as a whole, plus those granted to this very key.

Query parameters:

- `granted` (string) — List what this credential may call through instead of the caller's own connections.

Responses:

- `200` — OK
  - `connections` (object[], required)
    - `id` (string, required)
    - `app` (string, required) — The app's slug.
    - `app_name` (string, required)
    - `when_to_use` (string) — Optional owner-provided guidance for choosing this account; does not grant access.
    - `label` (string, required) — The account's name at the app, usually an email address.
    - `created_at` (string, required)
  - `credit` (object, required)
    - `earned_usd` (number, required)
    - `cap_usd` (number, required)
    - `granted_apps` (string[], required) — Slugs of the apps that earned credit.
    - `eligible_apps` (string[], required) — Slugs of the apps whose connection can earn credit.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/connections' \
  -H "Authorization: Bearer ast_..."
```

### POST /connectors/connections

Deprecated: use POST /plugins/app:{app}/add. Deprecated: use POST /plugins/app:{app}/add. Deprecated: use POST /plugins/app:{app}/add. Start connecting an app (scope: write)

Deprecated: use `POST /plugins/app:{app}/add`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `POST /plugins/app:{app}/add`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `POST /plugins/app:{app}/add`. Still served exactly as before; every answer carries a `Deprecation` header. Answers the address the person's browser opens to sign in to the app and allow access. Afterwards the browser is sent to `success_url`, with `account_id` added to its query, or to `error_url`; the caller then records the result with `POST /connectors/connections/complete`. Both addresses must be https (http is accepted for localhost) and on one origin. Answers 400 `unknown_app` for an app that cannot be connected and 502 `connect_error` when the authorization cannot be started.

Body (application/json):

- `app` (string, required) — The app's slug.
- `success_url` (string, required)
- `error_url` (string, required)

Responses:

- `200` — OK
  - `url` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/connectors/connections \
  -H "Authorization: Bearer ast_..."
```

### POST /connectors/connections/complete

Record a finished authorization (scope: write)

Call this when the browser arrives at `success_url`. The account is checked against the caller's own accounts at the app's provider, so an account somebody else authorized is refused; without `account_id` the caller's newest account for the app is used. Preserve the optional `account_source` returned in the callback to select the same provider when an account id is absent; every account remains bound to the authenticated caller and app. Every task of the caller that was waiting on the app continues. Answers 404 when the caller has no such account and 502 `connect_error` when the provider cannot be read.

Body (application/json):

- `app` (string, required)
- `account_id` (string)
- `account_source` (enum<string>) — "google_native" · "pipedream"

Responses:

- `200` — OK
  - `connection` (object, required)
    - `app` (string, required)
    - `app_name` (string, required)
    - `label` (string, required)
    - `credit_grant` (object, required) — Credit given for this connection, when connecting apps earns credit. `status` is granted, already_granted, cap_reached or ineligible.
      - `status` (string, required)
      - `amount_usd` (number)
      - `earned_usd` (number)
      - `cap_usd` (number)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/connectors/connections/complete \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/connections/{id}

Deprecated: use GET /plugins/app:{app}. Deprecated: use GET /plugins/app:{app}. Deprecated: use GET /plugins/app:{app}. Get one of the caller's connections (scope: read)

Deprecated: use `GET /plugins/app:{app}`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins/app:{app}`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins/app:{app}`. Still served exactly as before; every answer carries a `Deprecation` header. Returns the connection by id. Use this to confirm a connection is still live after OAuth completes, or to poll for it after POST /connectors/connections/complete returns its id. To wait for an OAuth flow to complete, poll GET /connectors/connections (the list) until the target app appears; the {id} endpoint is for confirming a known connection id.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `connection` (object, required)
    - `id` (string, required)
    - `appSlug` (string, required)
    - `appName` (string, required)
    - `label` (string, required)
    - `imgSrc` (string)
    - `createdAt` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/connections/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /connectors/connections/{id}

Deprecated: use DELETE /plugins/app:{app}?connection_id={id}&disconnect=true. Deprecated: use DELETE /plugins/app:{app}?connection_id={id}&disconnect=true. Deprecated: use DELETE /plugins/app:{app}?connection_id={id}&disconnect=true. Disconnect one of the caller's connections (scope: write)

Deprecated: use `DELETE /plugins/app:{app}?connection_id={id}&disconnect=true`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `DELETE /plugins/app:{app}?connection_id={id}&disconnect=true`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `DELETE /plugins/app:{app}?connection_id={id}&disconnect=true`. Still served exactly as before; every answer carries a `Deprecation` header. Agents stop being able to use the account at once. Answers 404 for a connection that is not the caller's.

Path parameters:

- `id` (string, required)

Responses:

- `204` — Disconnected
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/connectors/connections/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/connections/{id}/grants

Deprecated: use GET /plugins/app:{app}/share?connection_id={id}. Deprecated: use GET /plugins/app:{app}/share?connection_id={id}. Deprecated: use GET /plugins/app:{app}/share?connection_id={id}. List who may call through one of the caller's connections with a key (scope: read)

Deprecated: use `GET /plugins/app:{app}/share?connection_id={id}`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins/app:{app}/share?connection_id={id}`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins/app:{app}/share?connection_id={id}`. Still served exactly as before; every answer carries a `Deprecation` header. Every grant on the connection, workspace by workspace, with the calls made under each. 404 for a connection that is not the caller's.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `grants` (object[], required)
    - `id` (string, required)
    - `connection_id` (string, required)
    - `workspace` (object, required)
      - `slug` (string, required)
      - `name` (string, required)
    - `key` (object, required) — The one key the grant is for; null when every key of the workspace may use it.
      - `id` (string, required)
      - `name` (string, required)
    - `created_at` (string, required)
    - `use_count` (integer, required) — Calls made under this grant so far.
    - `uses` (object[], required) — The newest calls, at most 20.
      - `key_id` (string, required)
      - `method` (string, required)
      - `host` (string, required)
      - `status` (integer, required)
      - `at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/connections/sess_cmtb7q2j/grants' \
  -H "Authorization: Bearer ast_..."
```

### POST /connectors/connections/{id}/grants

Deprecated: use POST /plugins/app:{app}/share {workspace, api_key | all_api_keys: true}. Deprecated: use POST /plugins/app:{app}/share {workspace, api_key | all_api_keys: true}. Deprecated: use POST /plugins/app:{app}/share {workspace, api_key | all_api_keys: true}. Let a workspace's keys call through one of the caller's connections (scope: write)

Deprecated: use `POST /plugins/app:{app}/share {workspace, api_key | all_api_keys: true}`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `POST /plugins/app:{app}/share {workspace, api_key | all_api_keys: true}`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `POST /plugins/app:{app}/share {workspace, api_key | all_api_keys: true}`. Still served exactly as before; every answer carries a `Deprecation` header. The workspace is the one the request selected (X-Universe, or the credential's own). With `key_id`, only that one live key of the workspace. Granting again changes nothing. Only the connection's owner acting as themselves may grant: a workspace key, an app credential or a task pass answers 403, so no key can grant itself access. 404 for a connection that is not the caller's, or a key that is not a live key of the workspace. Sends `connector.granted` to the workspace's webhooks. Sessions in the workspace do not gain the connection: this is the service path, separate from sharing (POST /universes/{slug}/connections).

Path parameters:

- `id` (string, required)

Body (application/json):

- `key_id` (string) — One key of the workspace (its id from GET /universes/{slug}/keys or GET /api_keys). Omitted: every key of the workspace.

Responses:

- `201` — Created
  - `grant` (object, required) — Permission for a workspace's API keys, or one of them, to call through a connection with POST /connectors/proxy. Made and taken back only by the connection's owner.
    - `id` (string, required)
    - `connection_id` (string, required)
    - `workspace` (object, required)
      - `slug` (string, required)
      - `name` (string, required)
    - `key` (object, required) — The one key the grant is for; null when every key of the workspace may use it.
      - `id` (string, required)
      - `name` (string, required)
    - `created_at` (string, required)
    - `use_count` (integer, required) — Calls made under this grant so far.
    - `uses` (object[], required) — The newest calls, at most 20.
      - `key_id` (string, required)
      - `method` (string, required)
      - `host` (string, required)
      - `status` (integer, required)
      - `at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/connectors/connections/sess_cmtb7q2j/grants \
  -H "Authorization: Bearer ast_..."
```

### DELETE /connectors/connections/{id}/grants

Deprecated: use DELETE /plugins/app:{app}/share?workspace=&api_key= (or all_api_keys=true). Deprecated: use DELETE /plugins/app:{app}/share?workspace=&api_key= (or all_api_keys=true). Deprecated: use DELETE /plugins/app:{app}/share?workspace=&api_key= (or all_api_keys=true). Take a grant back (scope: write)

Deprecated: use `DELETE /plugins/app:{app}/share?workspace=&api_key= (or all_api_keys=true)`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `DELETE /plugins/app:{app}/share?workspace=&api_key= (or all_api_keys=true)`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `DELETE /plugins/app:{app}/share?workspace=&api_key= (or all_api_keys=true)`. Still served exactly as before; every answer carries a `Deprecation` header. Same body as granting names the grant: the selected workspace and, with `key_id`, one key. The service loses the connection at once. 404 when there is no such grant. Sends `connector.revoked`.

Path parameters:

- `id` (string, required)

Body (application/json):

- `key_id` (string) — One key of the workspace (its id from GET /universes/{slug}/keys or GET /api_keys). Omitted: every key of the workspace.

Responses:

- `204` — Revoked
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/connectors/connections/sess_cmtb7q2j/grants \
  -H "Authorization: Bearer ast_..."
```

### POST /connectors/proxy

Deprecated: use POST /plugins/app:{app}/call. Deprecated: use POST /plugins/app:{app}/call. Deprecated: use POST /plugins/app:{app}/call. Call a third-party API through a granted connection (scope: write)

Deprecated: use `POST /plugins/app:{app}/call`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `POST /plugins/app:{app}/call`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `POST /plugins/app:{app}/call`. Still served exactly as before; every answer carries a `Deprecation` header. For services holding an API key: the same gateway sessions use through `actl connector call`. An unrestricted personal key may use its owner's connections directly. Other credentials need an explicit grant to the key or workspace; otherwise 404 `not_granted`. `url` must be https (400 `https_required`); `method` defaults to GET; `headers` and `body` are passed to the third party. The answer carries the third party's `status`, `ok` and `body` as text. The workspace's tool-call rules decide first: a block rule, a require_approval rule or a model_review rule (a service call has no thread to be approved in and no person's words to review against), answers 403 `capability_denied`; rules that cannot be read answer 503 `policy_unavailable`. Native GitHub uses https://api.github.com directly, with no per-call connector charge or funded-wallet requirement. GitHub credentials and redirects cannot be overridden; legacy managed GitHub handles require native reconnection (409 github_reconnect_required). Other managed connectors book one CONNECTOR_CALL on a 2xx; other statuses are not billed. Calls made under a sharing grant are recorded for the connection's owner (host, method, status). 403 `key_required` for a browser session or a task pass; 502 `proxy_error` when the third party could not be reached.

Body (application/json):

- `connection_id` (string, required)
- `url` (string, required) — The third-party API address, https.
- `method` (string)
- `headers` (map<string, string>)
- `body` (string)

Responses:

- `200` — The third party's answer
  - `status` (integer, required)
  - `ok` (boolean, required)
  - `body` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/connectors/proxy \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/github/repos

List the repositories the caller's GitHub connection can reach (scope: read)

Most recently pushed first, at most 100. Answers 404 `github_not_connected` when the caller has no GitHub connection and 409 `github_reconnect_required` when none of their connections can be used.

Responses:

- `200` — OK
  - `repos` (object[], required)
    - `full_name` (string, required)
    - `default_branch` (string, required)
    - `private` (boolean, required)
    - `pushed_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/github/repos' \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/github/pulls

Find the open pull request for a branch through the caller's GitHub connection (scope: read)

For a client that pushed `branch` to `repo` and opened the PR in a browser, without a signed-in GitHub CLI. Answers `{ pull: null }` when no PR from that branch of the repository itself is open, 404 `github_not_connected` and 409 `github_reconnect_required` as `GET /connectors/github/repos`. The token never leaves the platform.

Query parameters:

- `repo` (string, required) — owner/name
- `branch` (string, required)

Responses:

- `200` — OK
  - `pull` (object, required)
    - `url` (string, required)
    - `number` (integer, required)
    - `title` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/github/pulls?repo=repo&branch=branch' \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/github/pulls/status

Read one pull request's state, checks and review through the caller's GitHub connection (scope: read)

`status` is running, failing, passing, merged, closed, draft or unknown; a failure outranks running checks, and passing needs every check read and at least one finished. Answers `{ pull: null }` when the connection cannot read the pull request, 404 `github_not_connected` with no GitHub connection and 409 `github_reconnect_required` when it must be reconnected.

Query parameters:

- `repo` (string, required) — owner/name
- `number` (integer, required)

Responses:

- `200` — OK
  - `pull` (object, required)
    - `repo` (string, required)
    - `number` (integer, required)
    - `url` (string, required)
    - `title` (string, required)
    - `author` (string, required)
    - `state` (enum<string>, required) — "open" · "draft" · "merged" · "closed"
    - `status` (enum<string>, required) — "running" · "failing" · "passing" · "merged" · "closed" · "draft" · "unknown"
    - `final` (boolean, required)
    - `checks` (object, required)
      - `state` (enum<string>, required) — "running" · "failing" · "passing" · "unknown"
      - `passed` (integer, required)
      - `failed` (integer, required)
      - `running` (integer, required)
      - `failed_names` (string[], required)
    - `review` (enum<string>, required) — "approved" · "changes_requested" · "review_required"
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/github/pulls/status?repo=repo&number=number' \
  -H "Authorization: Bearer ast_..."
```

### POST /connectors/links

Deprecated: use POST /plugins/app:{app}/add {task_id, request_id}. Deprecated: use POST /plugins/app:{app}/add {task_id, request_id}. Deprecated: use POST /plugins/app:{app}/add {task_id, request_id}. Make a link to connect the app a task is waiting on (scope: write)

Deprecated: use `POST /plugins/app:{app}/add {task_id, request_id}`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `POST /plugins/app:{app}/add {task_id, request_id}`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `POST /plugins/app:{app}/add {task_id, request_id}`. Still served exactly as before; every answer carries a `Deprecation` header. For a task with an open `connect_app` request (see `GET /tasks/{id}`): a link the person the request is addressed to can open in any browser to connect the app. Native GitHub additionally requires that person to sign in to AgentSky before consent. Only that person can make it. The link can be used once, within fifteen minutes, and this is the only response that carries it; making another replaces one that was not used. When the app is connected the task continues by itself. Answers 404 when the task has no such open request, 403 `request_not_yours` when it is addressed to somebody else, and 503 `not_migrated` until the platform's link table is in place.

Body (application/json):

- `task_id` (string, required) — The task (sess_…)
- `request_id` (string, required)

Responses:

- `201` — Created
  - `link` (object, required)
    - `url` (string, required)
    - `expires_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/connectors/links \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/links/{token}

The page a connect link opens

No Authorization header: the secret in the path is the credential. Answers a page that says what is asked, with a button to continue; looking uses nothing up. A link that is unknown, expired, already used, or whose request is no longer waiting answers the same 404 page. More than 10 requests for one link in a minute answers 429.

Path parameters:

- `token` (string, required) — The secret part of the link (cnl_…)

Responses:

- `200` — The page
- `404` — The link cannot be used
- `429` — Too many requests for this link
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/links/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0' \
  -H "Authorization: Bearer ast_..."
```

### POST /connectors/links/{token}

Continue from a connect link to the app's authorization

What the page's button sends. Uses the link up and redirects the browser to the app's sign-in. Refused exactly as the page is.

Path parameters:

- `token` (string, required)

Responses:

- `303` — Redirect to the app's authorization
- `404` — The link cannot be used
- `429` — Too many requests for this link
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/connectors/links/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0 \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/links/{token}/done

Where the app's authorization returns for a connect link

The browser arrives here after the person allows access. The connection is recorded for the person the link was made for, once, and the waiting task continues. Only a link that was used, within the last hour, is accepted; anything else answers the 404 page.

Path parameters:

- `token` (string, required)

Query parameters:

- `account_id` (string)

Responses:

- `200` — Connected
- `404` — The link cannot be used
- `502` — The app was not connected
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/links/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0/done' \
  -H "Authorization: Bearer ast_..."
```

### GET /connectors/return

Where an app's authorization returns when the client named no address

The default `success_url` (and, with `error=1`, `error_url`) of `POST /plugins/app:{app}/add` when the caller names neither. `t` is signed for the person who started connecting and that app, for an hour, so the connection is recorded for that person without a signed-in browser; the provider still checks the account is theirs. A token for another app, forged or expired answers the 404 page.

Query parameters:

- `app` (string, required)
- `t` (string, required)
- `account_id` (string)
- `account_source` (string)
- `error` (string)

Responses:

- `200` — Connected, or the authorization was declined
- `404` — The page has expired
- `502` — The app was not connected
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/connectors/return?app=app&t=t' \
  -H "Authorization: Bearer ast_..."
```

## Workspace identity

### GET /workspace-identity

What the identity in the Authorization header stands for (scope: identity)

Only a session's workspace identity (Bearer wid_…, delivered to the pod beside each turn) may ask: its session, workspace, role, expiry, the route groups a token from the exchange may call, and the installed connectors with whether its role is granted each.

Responses:

- `200` — OK
  - `identity` (object, required)
    - `session_id` (string, required)
    - `agent_id` (string | null, required)
    - `workspace` (object, required)
      - `id` (string)
      - `slug` (string)
      - `name` (string)
    - `role` (enum<string>, required) — "owner" · "admin" · "member"
    - `expires_at` (string, required)
    - `api_route_groups` (string[], required) — The /v1 route groups a token from the exchange may call
    - `connectors` (object[], required)
      - `kind` (string)
      - `name` (string)
      - `origin` (string)
      - `granted` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-identity' \
  -H "Authorization: Bearer ast_..."
```

### POST /workspace-identity/exchange

Exchange a workspace identity for an API token or a connector credential (scope: identity)

Bearer wid_…. {for: agentsky_api} mints a workspace-fixed ast_ token for the session's owner (read+write, one hour, never past the identity) that reaches the route groups the identity lists and nothing else. {for: connector, kind} attaches the vault the connector names for the identity's role to the session and pushes its network policy, then answers placeholders by environment variable name: export them and send requests to origin; the real credential is set at the network edge and never reaches the pod. Every exchange is recorded and revoked with the session. 404 connector_not_installed, 403 role_not_granted, 409 connector_misconfigured, 400 egress refusals, 503 connector_attach_failed.

Body (application/json):

- option 1 (object)
  - `for` ("agentsky_api", required)
- option 2 (object)
  - `for` ("sky", required)
- option 3 (object)
  - `for` ("connector", required)
  - `kind` (string, required) — A short lowercase name for the service, e.g. crm — pattern ^[a-z][a-z0-9_-]{1,31}$
  - `name` (string) — max length 80

Responses:

- `201` — Created
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/workspace-identity/exchange \
  -H "Authorization: Bearer ast_..."
```

### GET /workspace-identity/exchanges

The workspace's identity exchanges, newest first (scope: admin, owner or admin)

Query parameters:

- `limit` (integer) — 1–500, default 100

Responses:

- `200` — OK
  - `exchanges` (object[], required)
    - `id` (string, required)
    - `session_id` (string, required)
    - `kind` (enum<string>, required) — "agentsky_api" · "connector"
    - `role` (string, required)
    - `connector_id` (string | null, required)
    - `vault_id` (string | null, required)
    - `created_at` (string, required)
    - `revoked_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-identity/exchanges' \
  -H "Authorization: Bearer ast_..."
```

### GET /workspace-connectors

Deprecated: use GET /plugins?view=yours&source=app&include=services. Deprecated: use GET /plugins?view=yours&source=app&include=services. Deprecated: use GET /plugins?view=yours&source=app&include=services. The services the workspace installed for its agents (scope: read)

Deprecated: use `GET /plugins?view=yours&source=app&include=services`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins?view=yours&source=app&include=services`. Still served exactly as before; every answer carries a `Deprecation` header. Deprecated: use `GET /plugins?view=yours&source=app&include=services`. Still served exactly as before; every answer carries a `Deprecation` header.

Responses:

- `200` — OK
  - `connectors` (object[], required)
    - `id` (string, required)
    - `kind` (string, required)
    - `name` (string, required)
    - `origin` (string, required)
    - `role_vaults` (map<string, string>, required) — Public vault ids by workspace role; never a value
    - `tools` (object[], required)
      - `name` (string, required)
      - `description` (string, required)
      - `example` (string | null, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-connectors' \
  -H "Authorization: Bearer ast_..."
```

### POST /workspace-connectors

Install a connector: its origin, the vault per workspace role, and its tools (scope: admin, owner or admin)

The credentials live in the named vaults as environment_variable secrets bound to the origin's host; nothing here stores or returns a value. At most 20 connectors per workspace; 409 on a repeated kind and name; 422 for a vault outside the workspace.

Body (application/json):

- `kind` (string, required) — A short lowercase name for the service, e.g. crm — pattern ^[a-z][a-z0-9_-]{1,31}$
- `name` (string) — Defaults to kind — max length 80
- `origin` (string, required) — https, public host; the host the connector's credentials are sent to
- `role_vaults` (object, required) — The vault (vlt_…) each workspace role exchanges its identity for; at least one role
  - `owner` (string)
  - `admin` (string)
  - `member` (string)
- `tools` (object[]) — What the service offers, shown to agents that ask what the workspace has
  - `name` (string, required) — max length 80
  - `description` (string) — max length 400
  - `example` (string) — max length 400

Responses:

- `201` — Created
  - `connector` (object, required)
    - `id` (string, required)
    - `kind` (string, required)
    - `name` (string, required)
    - `origin` (string, required)
    - `role_vaults` (map<string, string>, required) — Public vault ids by workspace role; never a value
    - `tools` (object[], required)
      - `name` (string, required)
      - `description` (string, required)
      - `example` (string | null, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/workspace-connectors \
  -H "Authorization: Bearer ast_..."
```

### GET /workspace-connectors/{id}

One installed connector (scope: read)

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `connector` (object, required)
    - `id` (string, required)
    - `kind` (string, required)
    - `name` (string, required)
    - `origin` (string, required)
    - `role_vaults` (map<string, string>, required) — Public vault ids by workspace role; never a value
    - `tools` (object[], required)
      - `name` (string, required)
      - `description` (string, required)
      - `example` (string | null, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-connectors/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /workspace-connectors/{id}

Uninstall a connector (scope: admin, owner or admin)

Sessions that already exchanged for it keep what they were given until they end.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `removed` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/workspace-connectors/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### POST /workspace-connectors/{id}/provision

Mint one key per workspace role at the service and vault each (scope: admin, owner or admin)

Through the service's own key route (POST {origin}/v1/keys) with the workspace's admin key, read from the named vault by the platform alone. Each key goes into a vault <kind>-<role> as <KIND>_API_KEY bound to the connector's host, which the connector then names for that role; a role that already had a key gets a new one, its secret is rotated in place so attached sessions follow, and the old key is revoked at the service. Behind CONNECTOR_KEY_MINTING (403 not_enabled otherwise). 404 unknown connector or admin vault, 422 admin_key_missing, 424 service_refused (the service could not be reached, or refused the admin key or the request).

Path parameters:

- `id` (string, required)

Body (application/json):

- `admin_vault` (string, required) — The vault (vlt_…) holding the service's admin key; read by the platform alone
- `admin_secret_name` (string) — The secret that is the admin key: an environment_variable secret by variable name, or a static_bearer secret by display name; default CRM_ADMIN_KEY
- `roles` (object, required) — Per workspace role: the role the service gives the key, in the service's own vocabulary
  - `owner` (object)
    - `role` (string, required)
    - `see_money` (boolean)
    - `tools` (string[])
  - `admin` (object)
    - `role` (string, required)
    - `see_money` (boolean)
    - `tools` (string[])
  - `member` (object)
    - `role` (string, required)
    - `see_money` (boolean)
    - `tools` (string[])
- `deliver_as` (enum<string>) — env (default): <KIND>_API_KEY bound to the origin's host; mcp_bearer: a bearer for the service's MCP server at origin + mcp_path — "env" · "mcp_bearer"
- `mcp_path` (string) — Default /mcp

Responses:

- `201` — Created
  - `connector_id` (string, required)
  - `minted` (map<string, object>, required) — Per workspace role: the key's id and prefix at the service, when it was minted, and the vault and secret name that carry it; never the key
  - `not_revoked` (object[], required) — Earlier keys the service would not revoke; revoke them by hand
    - `role` (string)
    - `key_id` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/workspace-connectors/sess_cmtb7q2j/provision \
  -H "Authorization: Bearer ast_..."
```

### POST /workspace-connectors/{id}/ingest/messages

Relay a message envelope to the connector's service as the signed-in person (scope: write)

{id} is a connector id or a kind (the oldest connector of that kind answers). The person's workspace role picks the connector's vault; the vault's credential (a <KIND>_API_KEY environment secret, or a bearer secret for the service's host) goes on a POST to {origin}/v1/ingest/messages and never reaches the caller. The body is the service's message envelope, or an array of them, and passes through unchanged (JSON, at most 1 MiB); Idempotency-Key passes through, defaulting to the envelope's external_message_id or id, or for an array to a digest of its envelopes' ids. ?sync=true passes through (the CRM then ingests inline for at most 100 envelopes); otherwise the service may answer 202 {data:{inbox_id,count,status}} and ingest later, which GET ../ingest/inbox/{inbox_id} follows. The answer is the service's status and body as they were, with x-agentsky-relay naming the audit record, except that a service answering 502, 503 or 504 answers 424 service_unreachable. 404 connector_not_installed, 403 role_not_granted, 409 connector_misconfigured, 424 service_unreachable. A workspace identity cannot call this; it exchanges itself instead.

Path parameters:

- `id` (string, required)

Query parameters:

- `sync` (string) — Forwarded to the service: ingest inline and answer the counts

Body (application/json):

- option 1 (object)
- option 2 (object[])

Responses:

- `202` — The service's answer, as it was
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/workspace-connectors/sess_cmtb7q2j/ingest/messages \
  -H "Authorization: Bearer ast_..."
```

### POST /workspace-connectors/{id}/ingest/meeting-notes

Relay one finished meeting note to the connector's service as the signed-in person (scope: write)

The Mac app's meeting-note.v1 facts for a recorded call (source, app, start and end, the matched calendar event's id and attendees, what each side said, the workspace file ids of the note), or the platform's for a settled cloud recording (source recall). Relayed exactly like ../ingest/messages — the person's workspace role picks the connector's vault, whose credential goes on POST {origin}/v1/ingest/meeting-notes and never reaches the caller — and the service decides what the note becomes (the CRM keeps only notes with a counterpart it knows and stores the transcript as a file). The body is one JSON object of at most 1 MiB; Idempotency-Key passes through, defaulting to meeting-note:<shared file id>, else the start time and app. The answer is the service's status and body as they were, with x-agentsky-relay naming the audit record. The same refusals as ../ingest/messages.

Path parameters:

- `id` (string, required)

Body (application/json):


Responses:

- `200` — The service's answer, as it was
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/workspace-connectors/sess_cmtb7q2j/ingest/meeting-notes \
  -H "Authorization: Bearer ast_..."
```

### GET /workspace-connectors/{id}/ingest/inbox/{inbox}

Where a batch the connector's service queued (a 202 from ../ingest/messages) has got to (scope: read)

Relayed as the signed-in person with the same vault credential to GET {origin}/v1/ingest/inbox/{inbox}; the service's status and body come back as they were: {data:{status: queued|processing|done|failed, created, existing, errors, last_error}}. The same refusals as the POST; 400 invalid_request for an inbox id that is not 1–120 letters, digits, '_' or '-'.

Path parameters:

- `id` (string, required)
- `inbox` (string, required) — The inbox_id the service answered with

Responses:

- `200` — The service's answer, as it was
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-connectors/sess_cmtb7q2j/ingest/inbox/inbox' \
  -H "Authorization: Bearer ast_..."
```

### GET /workspace-connectors/{id}/relays

Requests the platform relayed to this connector's service, newest first (scope: admin, owner or admin)

Path parameters:

- `id` (string, required)

Query parameters:

- `limit` (integer) — 1–500, default 100

Responses:

- `200` — OK
  - `relays` (object[], required)
    - `id` (string, required)
    - `connector_id` (string, required)
    - `vault_id` (string, required)
    - `user_id` (string, required)
    - `role` (string, required)
    - `path` (string, required)
    - `idempotency_key` (string | null, required)
    - `upstream_status` (integer | null, required) — The service's status; null when it could not be reached
    - `error` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-connectors/sess_cmtb7q2j/relays' \
  -H "Authorization: Bearer ast_..."
```

## Discovery

### GET /workspace-describe

What this workspace has and what you may do here, with a usage line per item (scope: read)

Agents, company skills, routines with their triggers, installed connectors with their tools, hook rules (policies), policy rules such as spend caps (policy_rules), remaining budget, and the caller's role, credential and route groups, read live. A workspace identity may ask before it exchanges itself.

Responses:

- `200` — OK
  - `workspace` (object, required) — What the caller's workspace has and what the caller may do there, each item with a one-line usage example
    - `workspace` (object, required)
      - `id` (string)
      - `slug` (string)
      - `name` (string)
    - `you` (object, required)
      - `role` (string | null)
      - `scopes` (string[])
      - `credential` (string)
      - `route_groups` (array | null)
      - `example` (string)
    - `agents` (object[], required)
      - `id` (string)
      - `name` (string)
      - `display_name` (string)
      - `harness` (string)
      - `model` (string)
      - `example` (string)
    - `skills` (object[], required)
      - `id` (string)
      - `name` (string)
      - `attach_by_default` (boolean)
      - `example` (string)
    - `routines` (object[], required)
      - `id` (string)
      - `name` (string)
      - `status` (enum<string>) — "active" · "paused"
      - `schedule` (string | null)
      - `triggers` (string[])
      - `example` (string)
    - `connectors` (object[], required)
      - `id` (string)
      - `kind` (string)
      - `name` (string)
      - `origin` (string)
      - `granted_roles` (string[])
      - `granted` (boolean | null)
      - `tools` (object[])
        - `name` (string, required)
        - `description` (string, required)
        - `example` (string | null, required)
      - `example` (string)
    - `policies` (object[], required) — The workspace's hook rules (/universes/{slug}/hooks)
      - `point` (string)
      - `action` (string)
      - `enabled` (boolean)
      - `match` (object)
    - `policy_rules` (any[], required) — The workspace's policy rules (/universes/{slug}/policies): spend caps, tool-call and call-count limits and capability rules, disabled ones included
    - `budget` (object, required)
      - `credit_usd` (number | null)
      - `session_budget_usd` (number | null)
      - `session_spent_usd` (number | null)
    - `help` (object, required)
      - `example` (string)
      - `topics` (string[])
    - `unavailable` (string[], required) — Sections that could not be read
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/workspace-describe' \
  -H "Authorization: Bearer ast_..."
```

### GET /help

Help on a topic, generated from this API document (scope: read)

Without topic: the topics (the first segment of every path, plus connectors/<kind> and workflow). With one: its operations, each body's required fields and a skeleton, and one usage line. Aliases: start_session, trigger, identity, singular forms. 404 unknown_topic; 404 connector_not_installed for connectors/<kind> the workspace lacks.

Query parameters:

- `topic` (string)

Responses:

- `200` — OK
  - `help` (object, required)
    - `topic` (string, required)
    - `usage` (string, required) — One request to adapt
    - `operations` (object[], required)
      - `method` (string)
      - `path` (string)
      - `summary` (string)
      - `description` (string | null)
      - `body` (object | null)
    - `connector` (object)
      - `kind` (string)
      - `name` (string)
      - `origin` (string)
      - `granted` (boolean | null)
      - `tools` (object[])
        - `name` (string, required)
        - `description` (string, required)
        - `example` (string | null, required)
    - `notes` (string[], required)
    - `topics` (string[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/help' \
  -H "Authorization: Bearer ast_..."
```

## Sky

### GET /sky

Your Sky: its session, model, billing and open matters (scope: read)

404 no_home before the first message. A workspace key has no person and answers 403 person_required.

Responses:

- `200` — OK
  - `sky` (object, required)
    - `session_id` (string, required) — Sky's current session. It moves when Sky rotates; the home does not
    - `harness` (string, required)
    - `model` (string, required)
    - `chosen_model` (string | null, required) — The model the person chose; null follows their plans
    - `billing` (enum<string>, required) — "plan" · "wallet"
    - `open_matters` (integer, required) — Tickets Sky is watching
    - `created_at` (string, required)
    - `rotated_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sky' \
  -H "Authorization: Bearer ast_..."
```

### POST /sky

Open your Sky without sending anything (scope: write)

Makes the home on first use and answers it; repeats answer the same home. Naming a channel answers 409 channel_not_routed where that chat does not route to Sky. A workspace key has no person and answers 403 person_required.

Body (application/json):

- `channel` (string) — A chat platform such as lark

Responses:

- `200` — OK
  - `sky` (object, required)
    - `session_id` (string, required) — Sky's current session. It moves when Sky rotates; the home does not
    - `harness` (string, required)
    - `model` (string, required)
    - `chosen_model` (string | null, required) — The model the person chose; null follows their plans
    - `billing` (enum<string>, required) — "plan" · "wallet"
    - `open_matters` (integer, required) — Tickets Sky is watching
    - `created_at` (string, required)
    - `rotated_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sky \
  -H "Authorization: Bearer ast_..."
```

### PATCH /sky

Change Sky's model (scope: write)

Sky stays in the same conversation. null goes back to following your plans. 422 model_unavailable for a model Sky cannot run on. A workspace key has no person and answers 403 person_required.

Body (application/json):

- `model` (string | null, required)

Responses:

- `200` — OK
  - `sky` (object, required)
    - `session_id` (string, required) — Sky's current session. It moves when Sky rotates; the home does not
    - `harness` (string, required)
    - `model` (string, required)
    - `chosen_model` (string | null, required) — The model the person chose; null follows their plans
    - `billing` (enum<string>, required) — "plan" · "wallet"
    - `open_matters` (integer, required) — Tickets Sky is watching
    - `created_at` (string, required)
    - `rotated_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/sky \
  -H "Authorization: Bearer ast_..."
```

### POST /sky/messages

Send your Sky a message (scope: write)

Makes the home first if needed. An Idempotency-Key makes a retry send it once. The answer arrives in Sky's session. A workspace key has no person and answers 403 person_required.

Body (application/json):

- `text` (string, required) — max length 100000

Responses:

- `202` — Delivered
  - `session_id` (string, required)
  - `message_id` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sky/messages \
  -H "Authorization: Bearer ast_..."
```

### GET /sky/follow-ups

Every open matter your Sky is watching (scope: read)

Each with who holds the next move and when Sky looks next. A workspace key has no person and answers 403 person_required.

Responses:

- `200` — OK
  - `follow_ups` (object[], required)
    - `task_id` (string, required)
    - `state` (enum<string>, required) — "watching" · "after_delivery"
    - `origin` (enum<string>, required) — "sky" · "person"
    - `title` (string | null, required)
    - `needs_you` (boolean, required) — The task has an open request, or the person owns the next move.
    - `next_follow_up_at` (string | null, required)
    - `reason` (string | null, required)
    - `next_move` (object, required)
      - `kind` (string | null)
      - `owner` (string | null)
    - `held` (boolean, required) — The person said to stop or wait
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sky/follow-ups' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /sky/follow-ups/{task}

Stop following a matter (scope: write)

Closes it for good; it does not come back. reason records why, such as "already handled". A workspace key has no person and answers 403 person_required.

Path parameters:

- `task` (string, required)

Query parameters:

- `reason` (string)

Responses:

- `204` — Stopped
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sky/follow-ups/task \
  -H "Authorization: Bearer ast_..."
```

### GET /sky/tracking

Your boards and the workspace's team boards (scope: read)

Each board with its counts, and method: how a writer states an item. Another person's personal board is never listed. A workspace key has no person and answers 403 person_required.

Responses:

- `200` — OK
  - `boards` (object[], required)
    - `id` (string, required)
    - `scope` (string, required) — What the board covers, in the person's words
    - `routine_id` (string | null, required) — The routine that checks the board every half hour. Null until a default board is first opened: until then it only collects reports, for free
    - `visibility` (enum<string>, required) — personal: only its owner can read it, paid from their credits. team: every member can read and write it, paid from the workspace's wallet — "personal" · "team"
    - `mine` (boolean, required) — Whether the caller started it and can stop it
    - `artifact_id` (string, required) — The published page, read live on each open. A personal board's page opens only for its person
    - `last_run` (object | null) — The latest scheduled check. no_credits means the wallet paying for it is empty
    - `status` (enum<string>, required) — "tracking" · "stopped"
    - `task_id` (string, required)
    - `counts` (object, required)
      - `open` (integer, required)
      - `needs_you` (integer, required)
      - `stuck` (integer, required)
      - `closed` (integer, required)
    - `created_at` (string, required)
    - `updated_at` (string | null, required)
  - `method` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sky/tracking' \
  -H "Authorization: Bearer ast_..."
```

### POST /sky/tracking

Start tracking (scope: write)

One call creates the board and the routine that checks it every half hour on your balance, and teaches your new sessions to write to it. personal is the default: only you can read it and your credits pay. team is open to the workspace and its wallet pays, and the same scope there answers a teammate's board. The same scope answers the same board and resumes it if stopped. 409 too_many_boards past five running. A workspace key has no person and answers 403 person_required.

Body (application/json):

- `scope` (string) — max length 200
- `visibility` (enum<string>) — "personal" · "team"

Responses:

- `201` — Tracking
  - `board` (object, required)
    - `id` (string, required)
    - `scope` (string, required) — What the board covers, in the person's words
    - `routine_id` (string | null, required) — The routine that checks the board every half hour. Null until a default board is first opened: until then it only collects reports, for free
    - `visibility` (enum<string>, required) — personal: only its owner can read it, paid from their credits. team: every member can read and write it, paid from the workspace's wallet — "personal" · "team"
    - `mine` (boolean, required) — Whether the caller started it and can stop it
    - `artifact_id` (string, required) — The published page, read live on each open. A personal board's page opens only for its person
    - `last_run` (object | null) — The latest scheduled check. no_credits means the wallet paying for it is empty
    - `status` (enum<string>, required) — "tracking" · "stopped"
    - `task_id` (string, required)
    - `counts` (object, required)
      - `open` (integer, required)
      - `needs_you` (integer, required)
      - `stuck` (integer, required)
      - `closed` (integer, required)
    - `created_at` (string, required)
    - `updated_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sky/tracking \
  -H "Authorization: Bearer ast_..."
```

### POST /sky/tracking/default

Open your board or the team board (scope: write)

Answers the default board for this visibility, creating it if needed. It needs no scope and is outside the limit of five. Opening your personal board starts its paid check; until then it only collects reports. Creating a board starts no run. A workspace key has no person and answers 403 person_required.

Body (application/json):

- `visibility` (enum<string>) — "personal" · "team" — default: "personal"

Responses:

- `200` — OK
  - `board` (object, required)
    - `id` (string, required)
    - `scope` (string, required) — What the board covers, in the person's words
    - `routine_id` (string | null, required) — The routine that checks the board every half hour. Null until a default board is first opened: until then it only collects reports, for free
    - `visibility` (enum<string>, required) — personal: only its owner can read it, paid from their credits. team: every member can read and write it, paid from the workspace's wallet — "personal" · "team"
    - `mine` (boolean, required) — Whether the caller started it and can stop it
    - `artifact_id` (string, required) — The published page, read live on each open. A personal board's page opens only for its person
    - `last_run` (object | null) — The latest scheduled check. no_credits means the wallet paying for it is empty
    - `status` (enum<string>, required) — "tracking" · "stopped"
    - `task_id` (string, required)
    - `counts` (object, required)
      - `open` (integer, required)
      - `needs_you` (integer, required)
      - `stuck` (integer, required)
      - `closed` (integer, required)
    - `created_at` (string, required)
    - `updated_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sky/tracking/default \
  -H "Authorization: Bearer ast_..."
```

### POST /sky/tracking/report

Report a local session (scope: write)

For a session on a computer with no cloud task: puts it on your personal board, as stated, at no charge. source_id stays the same for one session, so reporting again updates its item. It never reaches a team board. reported is false when you have no Sky here or have stopped your boards. A workspace key has no person and answers 403 person_required.

Body (application/json):

- `source_id` (string, required) — max length 300
- `title` (string, required) — max length 200
- `now` (string | null) — max length 1000
- `links` (object[])
  - `label` (string, required) — max length 100
  - `url` (string, required) — max length 2000

Responses:

- `200` — OK
  - `reported` (boolean, required)
  - `item_id` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sky/tracking/report \
  -H "Authorization: Bearer ast_..."
```

### GET /sky/tracking/{board}

One board with its items (scope: read)

Your own board or a team board of the workspace; anyone else's personal board answers 404. A workspace key has no person and answers 403 person_required.

Path parameters:

- `board` (string, required)

Responses:

- `200` — OK
  - `board` (object, required)
    - `id` (string, required)
    - `scope` (string, required) — What the board covers, in the person's words
    - `routine_id` (string | null, required) — The routine that checks the board every half hour. Null until a default board is first opened: until then it only collects reports, for free
    - `visibility` (enum<string>, required) — personal: only its owner can read it, paid from their credits. team: every member can read and write it, paid from the workspace's wallet — "personal" · "team"
    - `mine` (boolean, required) — Whether the caller started it and can stop it
    - `artifact_id` (string, required) — The published page, read live on each open. A personal board's page opens only for its person
    - `last_run` (object | null) — The latest scheduled check. no_credits means the wallet paying for it is empty
    - `status` (enum<string>, required) — "tracking" · "stopped"
    - `task_id` (string, required)
    - `counts` (object, required)
      - `open` (integer, required)
      - `needs_you` (integer, required)
      - `stuck` (integer, required)
      - `closed` (integer, required)
    - `created_at` (string, required)
    - `updated_at` (string | null, required)
  - `items` (object[], required)
    - `id` (string, required)
    - `title` (string, required)
    - `lane` (string, required)
    - `stage` (enum<string>, required) — "planned" · "in_progress" · "awaiting_merge" · "merged" · "live" · "closed"
    - `needs_you` (boolean, required)
    - `ask` (string | null)
    - `stuck` (boolean, required)
    - `now` (string | null)
    - `gap` (string | null)
    - `owner` (string | null)
    - `links` (object[])
      - `label` (string, required)
      - `url` (string, required)
    - `task_ids` (string[])
    - `evidence` (enum<string>, required) — verified only when the board's routine checked it — "verified" · "stated"
    - `proof` (string | null)
    - `checked_at` (string | null)
    - `updated_at` (string, required)
    - `updated_by` (string, required)
    - `source` (enum<string>) — Set when the platform reported this item: a cloud task whose turn ended, or a session on a computer — "task" · "local"
    - `reported_at` (string) — When the platform last reported it. A report is not evidence: the item reads as stated
    - `shared_by` (string) — Who moved it to this team board
  - `log` (object[], required)
    - `at` (string, required)
    - `text` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sky/tracking/board' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /sky/tracking/{board}

Stop tracking (scope: write)

Pauses the check. The board stays; starting the same scope resumes it. 403 board_owner_only for anyone but the person who started it or the workspace's owner. A workspace key has no person and answers 403 person_required.

Path parameters:

- `board` (string, required)

Responses:

- `200` — OK
  - `board` (object, required)
    - `id` (string, required)
    - `scope` (string, required) — What the board covers, in the person's words
    - `routine_id` (string | null, required) — The routine that checks the board every half hour. Null until a default board is first opened: until then it only collects reports, for free
    - `visibility` (enum<string>, required) — personal: only its owner can read it, paid from their credits. team: every member can read and write it, paid from the workspace's wallet — "personal" · "team"
    - `mine` (boolean, required) — Whether the caller started it and can stop it
    - `artifact_id` (string, required) — The published page, read live on each open. A personal board's page opens only for its person
    - `last_run` (object | null) — The latest scheduled check. no_credits means the wallet paying for it is empty
    - `status` (enum<string>, required) — "tracking" · "stopped"
    - `task_id` (string, required)
    - `counts` (object, required)
      - `open` (integer, required)
      - `needs_you` (integer, required)
      - `stuck` (integer, required)
      - `closed` (integer, required)
    - `created_at` (string, required)
    - `updated_at` (string | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sky/tracking/board \
  -H "Authorization: Bearer ast_..."
```

### PUT /sky/tracking/{board}/items/{item}

State where an item stands (scope: write)

Fields left out stay. What you state reads as stated until the board's routine checks it: only the routine verifies (403 verified_by_routine_only) or closes (409 closed_needs_evidence). A new item needs title and stage. A workspace key has no person and answers 403 person_required.

Path parameters:

- `board` (string, required)
- `item` (string, required)

Body (application/json):

- `title` (string) — max length 200
- `lane` (string) — max length 60
- `stage` (enum<string>) — "planned" · "in_progress" · "awaiting_merge" · "merged" · "live" · "closed"
- `needs_you` (boolean)
- `ask` (string | null) — max length 500
- `stuck` (boolean)
- `now` (string | null) — max length 1000
- `gap` (string | null) — max length 1000
- `owner` (string | null) — max length 200
- `links` (object[])
  - `label` (string, required) — max length 100
  - `url` (string, required) — max length 2000

Responses:

- `200` — OK
  - `item` (object, required)
    - `id` (string, required)
    - `title` (string, required)
    - `lane` (string, required)
    - `stage` (enum<string>, required) — "planned" · "in_progress" · "awaiting_merge" · "merged" · "live" · "closed"
    - `needs_you` (boolean, required)
    - `ask` (string | null)
    - `stuck` (boolean, required)
    - `now` (string | null)
    - `gap` (string | null)
    - `owner` (string | null)
    - `links` (object[])
      - `label` (string, required)
      - `url` (string, required)
    - `task_ids` (string[])
    - `evidence` (enum<string>, required) — verified only when the board's routine checked it — "verified" · "stated"
    - `proof` (string | null)
    - `checked_at` (string | null)
    - `updated_at` (string, required)
    - `updated_by` (string, required)
    - `source` (enum<string>) — Set when the platform reported this item: a cloud task whose turn ended, or a session on a computer — "task" · "local"
    - `reported_at` (string) — When the platform last reported it. A report is not evidence: the item reads as stated
    - `shared_by` (string) — Who moved it to this team board
  - `changed` (boolean, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/sky/tracking/board/items/item \
  -H "Authorization: Bearer ast_..."
```

### DELETE /sky/tracking/{board}/items/{item}

Take an item off the board (scope: write)

A workspace key has no person and answers 403 person_required.

Path parameters:

- `board` (string, required)
- `item` (string, required)

Responses:

- `204` — Removed
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sky/tracking/board/items/item \
  -H "Authorization: Bearer ast_..."
```

### POST /sky/tracking/{board}/items/{item}/move

Move an item between your board and a team board (scope: write)

For a person's own decision, not an agent's: it moves, it does not copy. The item reads as stated where it lands, a team item shows who shared it, and a later report of the same work does not bring it back. 400 unless one board is personal and the other team; 409 item_exists. A workspace key has no person and answers 403 person_required.

Path parameters:

- `board` (string, required)
- `item` (string, required)

Body (application/json):

- `to` (string, required)

Responses:

- `200` — OK
  - `item` (object, required)
    - `id` (string, required)
    - `title` (string, required)
    - `lane` (string, required)
    - `stage` (enum<string>, required) — "planned" · "in_progress" · "awaiting_merge" · "merged" · "live" · "closed"
    - `needs_you` (boolean, required)
    - `ask` (string | null)
    - `stuck` (boolean, required)
    - `now` (string | null)
    - `gap` (string | null)
    - `owner` (string | null)
    - `links` (object[])
      - `label` (string, required)
      - `url` (string, required)
    - `task_ids` (string[])
    - `evidence` (enum<string>, required) — verified only when the board's routine checked it — "verified" · "stated"
    - `proof` (string | null)
    - `checked_at` (string | null)
    - `updated_at` (string, required)
    - `updated_by` (string, required)
    - `source` (enum<string>) — Set when the platform reported this item: a cloud task whose turn ended, or a session on a computer — "task" · "local"
    - `reported_at` (string) — When the platform last reported it. A report is not evidence: the item reads as stated
    - `shared_by` (string) — Who moved it to this team board
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sky/tracking/board/items/item/move \
  -H "Authorization: Bearer ast_..."
```

### GET /sky/rules

Your rules for every agent of yours (scope: read)

Each answers enforcement: enforced (the platform stops it) or guidance (Sky carries it). 404 no_home before the first message. A workspace key has no person and answers 403 person_required.

Responses:

- `200` — OK
  - `rules` (object[], required)
    - `effect` (enum<string>, required) — "allow" · "ask" · "deny"
    - `capability_id` (string)
    - `connector_app` (string)
    - `writes_only` (boolean) — With connector_app: stop what the app would change or send, and leave reading it alone
    - `spend_over_cents` (integer) — With effect ask: a job budgeted over this needs the person's word first
    - `text` (string) — max length 500
    - `enforcement` (enum<string>) — "enforced" · "guidance"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sky/rules' \
  -H "Authorization: Bearer ast_..."
```

### PUT /sky/rules

Replace your rules (scope: write)

The whole ordered list. Each rule names one of capability_id, connector_app or text. A rule tightens and never loosens a workspace rule. A workspace key has no person and answers 403 person_required.

Body (application/json):

- `rules` (object[], required)
  - `effect` (enum<string>, required) — "allow" · "ask" · "deny"
  - `capability_id` (string)
  - `connector_app` (string)
  - `writes_only` (boolean) — With connector_app: stop what the app would change or send, and leave reading it alone
  - `spend_over_cents` (integer) — With effect ask: a job budgeted over this needs the person's word first
  - `text` (string) — max length 500
  - `enforcement` (enum<string>) — "enforced" · "guidance"

Responses:

- `200` — OK
  - `rules` (object[], required)
    - `effect` (enum<string>, required) — "allow" · "ask" · "deny"
    - `capability_id` (string)
    - `connector_app` (string)
    - `writes_only` (boolean) — With connector_app: stop what the app would change or send, and leave reading it alone
    - `spend_over_cents` (integer) — With effect ask: a job budgeted over this needs the person's word first
    - `text` (string) — max length 500
    - `enforcement` (enum<string>) — "enforced" · "guidance"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/sky/rules \
  -H "Authorization: Bearer ast_..."
```

### GET /sky/profile

What Sky knows about you (scope: read)

The files beside Sky's ledger. A file Sky has not written yet is an empty string. 404 no_home before the first message. A workspace key has no person and answers 403 person_required.

Responses:

- `200` — OK
  - `profile` (object, required)
    - `profile` (string, required) — Who the person is and which agents and models they prefer
    - `attention` (string, required) — What they want to hear unasked, what never, when and how
    - `style` (string, required) — How they work with Sky
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sky/profile' \
  -H "Authorization: Bearer ast_..."
```

### PUT /sky/profile

Edit what Sky knows about you (scope: write)

Replaces the files named and leaves the rest. A workspace key has no person and answers 403 person_required.

Body (application/json):

- `profile` (string)
- `attention` (string)
- `style` (string)

Responses:

- `200` — OK
  - `profile` (object, required)
    - `profile` (string, required) — Who the person is and which agents and models they prefer
    - `attention` (string, required) — What they want to hear unasked, what never, when and how
    - `style` (string, required) — How they work with Sky
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/sky/profile \
  -H "Authorization: Bearer ast_..."
```

## Webhooks

### GET /hook_rules

The workspace's hook rules, in evaluation order (scope: read)

`enabled` says whether hook rules are turned on for the workspace; where they are not the list is empty and nothing is evaluated.

Responses:

- `200` — OK
  - `enabled` (boolean, required) — Whether hook rules are turned on for the workspace.
  - `can_edit` (boolean, required) — Whether the caller may replace the rules: they are turned on and the caller owns the workspace.
  - `hook_rules` (object[], required)
    - `id` (string, required) — hkr_…
    - `point` (enum<string>, required) — "session.start" · "tool.call" · "spend" · "turn.end"
    - `match` (map<string, string>, required)
    - `action` (enum<string>, required) — "notify" · "block" · "require_approval" · "model_review"
    - `webhook_id` (string | null, required)
    - `enabled` (boolean, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/hook_rules' \
  -H "Authorization: Bearer ast_..."
```

### PUT /hook_rules

Replace the workspace's hook rules (owner only) (scope: write)

The body is the whole ordered list (at most 20); the order is the order of evaluation. A rule sent with the `id` of an existing rule keeps it. Points: `session.start` (a session is about to be created), `tool.call` (a capability call, a call to a connected app, or a tool the gateway runs for a session reached the platform), `spend` (a session's consumed cost reached `match.amount`, whole US cents; read when a turn ends and at a capability call, once per session), `turn.end` (a turn ended). Actions: `notify` delivers a signed event (`hook.session_start`, `hook.tool_call`, `hook.spend`, `hook.turn_end`) to `webhook_id`, one of the workspace's webhook endpoints, whatever events that endpoint subscribed to; never a URL. `block` at `session.start` refuses the session with 403 `blocked_by_hook_rule`; at `tool.call` it refuses the call with `capability_denied` (`reason: hook_rule`). `require_approval` at `tool.call` asks the session's owner exactly as an `ask` capability policy does, and an answer covers one call. `require_approval` at `session.start` creates the session waiting: it has no sandbox and takes no turn (409 `start_not_approved`), and its task carries an `approval` request for the person who created it, answered `confirm` or `decline` through `POST /tasks/{id}/requests/{request_id}/answer`. Approved, it starts with what it was created with; declined, it is archived, never runs and is charged nothing. A session started in a way that cannot wait (a helper, a product run, a handoff) is refused with 403 `blocked_by_hook_rule`. `model_review` at `tool.call`, where nothing else asks: one model call through the model gateway, booked to the session, reads only the person's own messages and the pending call and either lets the call run or raises the same approval question with its one-sentence reason; it never refuses on its own, and when it cannot review (no gateway, an error, a malformed answer) the person is asked. Once that question exists, the person's answer decides. The most restrictive of the matching rules and the capability policies wins (deny over ask over review over allow). Refused with 400 and the reason: `block` and `require_approval` at `spend` and at `turn.end`; `model_review` anywhere but `tool.call`. `match` narrows a rule: `{agent_id}` at `session.start` and `turn.end`, `{capability_id}` or `{connector_app}` (the slug of a connected app), not both, at `tool.call`; omitted, the rule applies to all. A notify rule that cannot be delivered never affects the session. 403 `not_enabled` where hook rules are not turned on; 503 `not_migrated` before the tables exist.

Body (application/json):

- `rules` (object[], required)
  - `id` (string) — An existing rule's id, to keep it.
  - `point` (enum<string>, required) — "session.start" · "tool.call" · "spend" · "turn.end"
  - `action` (enum<string>, required) — "notify" · "block" · "require_approval" · "model_review"
  - `match` (object)
    - `agent_id` (string)
    - `capability_id` (string)
    - `connector_app` (string) — The slug of a connected app, e.g. "slack".
    - `amount` (string) — Whole US cents, e.g. "125" for $1.25. Required at spend.
  - `webhook_id` (string) — Required for notify (whep_…); not allowed otherwise.
  - `enabled` (boolean) — Default true.

Responses:

- `200` — OK
  - `enabled` (boolean, required) — Whether hook rules are turned on for the workspace.
  - `can_edit` (boolean, required) — Whether the caller may replace the rules: they are turned on and the caller owns the workspace.
  - `hook_rules` (object[], required)
    - `id` (string, required) — hkr_…
    - `point` (enum<string>, required) — "session.start" · "tool.call" · "spend" · "turn.end"
    - `match` (map<string, string>, required)
    - `action` (enum<string>, required) — "notify" · "block" · "require_approval" · "model_review"
    - `webhook_id` (string | null, required)
    - `enabled` (boolean, required)
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/hook_rules \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"rules":[{"point":"turn.end","action":"notify","webhook_id":"whep_cmtb2f0a8m9k7x51q4ez6r0d"},{"point":"tool.call","action":"require_approval","match":{"capability_id":"exa.search"}}]}'
```

### GET /webhooks

List webhook endpoints (scope: read)

Responses:

- `200` — OK
  - `webhooks` (object[], required)
    - `id` (string) — whep_… identifier
    - `url` (string)
    - `events` (string[])
    - `status` (enum<string>) — "active" · "disabled"
    - `failure_count` (integer)
    - `created_at` (string)
    - `secret` (string) — whsec_… — present ONLY in the create response
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/webhooks' \
  -H "Authorization: Bearer ast_..."
```

### POST /webhooks

Register a webhook endpoint — the whsec_ secret appears only in this response (scope: write)

The URL must be https, with no user name or password, and must not point at a private, loopback or link-local address (400 otherwise). At delivery the host is resolved again: a host that resolves to such an address, and a redirect, are failed attempts.

Body (application/json):

- `url` (string, required) — max length 2048
- `events` (string[], required)

Responses:

- `201` — Created
  - `webhook` (object, required) — Outbound webhook endpoint. Deliveries carry x-asteroids-event/-delivery/-timestamp/-signature (v1=hmac-sha256(secret, "<ts>.<body>")), retry 3× (0s/5s/30s), and sustained failure disables (PATCH status:active re-enables). Payloads are thin {id, type, created_at, data:{type, id}} — fetch the resource, dedupe on the event id.
    - `id` (string) — whep_… identifier
    - `url` (string)
    - `events` (string[])
    - `status` (enum<string>) — "active" · "disabled"
    - `failure_count` (integer)
    - `created_at` (string)
    - `secret` (string) — whsec_… — present ONLY in the create response
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/webhooks \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/hooks/agentsky","events":["routine_run.failed","routine.paused"]}'
```

### GET /webhooks/{id}

Webhook endpoint detail (scope: read)

Path parameters:

- `id` (string, required) — The webhook endpoint id (whep_…)

Responses:

- `200` — OK
  - `webhook` (object, required) — Outbound webhook endpoint. Deliveries carry x-asteroids-event/-delivery/-timestamp/-signature (v1=hmac-sha256(secret, "<ts>.<body>")), retry 3× (0s/5s/30s), and sustained failure disables (PATCH status:active re-enables). Payloads are thin {id, type, created_at, data:{type, id}} — fetch the resource, dedupe on the event id.
    - `id` (string) — whep_… identifier
    - `url` (string)
    - `events` (string[])
    - `status` (enum<string>) — "active" · "disabled"
    - `failure_count` (integer)
    - `created_at` (string)
    - `secret` (string) — whsec_… — present ONLY in the create response
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/webhooks/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /webhooks/{id}

Update url/events, or status:active to re-enable a disabled endpoint (scope: write)

Path parameters:

- `id` (string, required) — The webhook endpoint id (whep_…)

Body (application/json):

- `url` (string) — max length 2048
- `events` (string[])
- `status` (enum<string>) — "active" · "disabled"

Responses:

- `200` — OK
  - `webhook` (object, required) — Outbound webhook endpoint. Deliveries carry x-asteroids-event/-delivery/-timestamp/-signature (v1=hmac-sha256(secret, "<ts>.<body>")), retry 3× (0s/5s/30s), and sustained failure disables (PATCH status:active re-enables). Payloads are thin {id, type, created_at, data:{type, id}} — fetch the resource, dedupe on the event id.
    - `id` (string) — whep_… identifier
    - `url` (string)
    - `events` (string[])
    - `status` (enum<string>) — "active" · "disabled"
    - `failure_count` (integer)
    - `created_at` (string)
    - `secret` (string) — whsec_… — present ONLY in the create response
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/webhooks/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### DELETE /webhooks/{id}

Delete a webhook endpoint (scope: write)

Path parameters:

- `id` (string, required) — The webhook endpoint id (whep_…)

Responses:

- `200` — OK
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/webhooks/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

## Apps with sign-in

### GET /oauth_clients

The apps the caller registered (scope: read)

Answers 404 until apps with sign-in are open on the platform.

Responses:

- `200` — OK
  - `oauth_clients` (object[], required)
    - `id` (string, required) — The client id the app presents when it sends a person to sign in.
    - `name` (string, required) — Shown to people when they are asked to allow the app. — max length 80
    - `redirect_uris` (string[], required) — Where the app may send people back after they decide. Matched exactly: no wildcards, no fragments. Must be https; `http://localhost` and `http://127.0.0.1` are accepted while the app is not reviewed.
    - `scopes` (enum<string>[], required) — What the app may ask a person for. `read` sees their tasks, agents and sessions; `write` also starts and changes them. — "read" · "write"
    - `test_users` (string[], required) — People besides you who may use the app before it is reviewed, by the email address of their account.
    - `review_status` (enum<string>, required) — An unreviewed app works only for its owner and its test users, and people are told it has not been reviewed. — "unreviewed" · "approved"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/oauth_clients' \
  -H "Authorization: Bearer ast_..."
```

### POST /oauth_clients

Register an app that signs people in (scope: write)

The app signs a person in with the authorization-code flow and PKCE (S256) at the sign-in service, asking for `openid` plus the scopes registered here and naming this API as the `resource`. The access token it receives is sent as `Authorization: Bearer` to this API. It acts as that person in one workspace: a person who belongs to several chooses it when they allow the app, and the app is refused everywhere else (`universe_mismatch` for another workspace named in `X-Universe`, `not_found` for a session outside it). It holds only the scopes they allowed and reaches tasks, sessions, agents, the catalog and whoami. On a session in that workspace it can also send messages and interrupts (`POST /sessions/{id}/events`, `POST /sessions/{id}/interrupt`, both `write`) and follow the live stream (`GET /sessions/{id}/stream`, `read`). It stops working as soon as the person removes the app from their account page: the next request is refused, and a stream that is open ends within a few seconds. To move the app to another workspace the person removes its access and allows it again. A new app is unreviewed. A caller may register up to 10 apps. Answers 404 until apps with sign-in are open on the platform, and 503 `not_migrated` until its tables are in place.

Body (application/json):

- `name` (string, required) — Shown to people when they are asked to allow the app. — max length 80
- `redirect_uris` (string[], required) — Where the app may send people back after they decide. Matched exactly: no wildcards, no fragments. Must be https; `http://localhost` and `http://127.0.0.1` are accepted while the app is not reviewed.
- `scopes` (enum<string>[], required) — What the app may ask a person for. `read` sees their tasks, agents and sessions; `write` also starts and changes them. — "read" · "write"
- `test_users` (string[]) — People besides you who may use the app before it is reviewed, by the email address of their account.

Responses:

- `201` — Created
  - `oauth_client` (object, required) — An app registered to sign people in with their account.
    - `id` (string, required) — The client id the app presents when it sends a person to sign in.
    - `name` (string, required) — Shown to people when they are asked to allow the app. — max length 80
    - `redirect_uris` (string[], required) — Where the app may send people back after they decide. Matched exactly: no wildcards, no fragments. Must be https; `http://localhost` and `http://127.0.0.1` are accepted while the app is not reviewed.
    - `scopes` (enum<string>[], required) — What the app may ask a person for. `read` sees their tasks, agents and sessions; `write` also starts and changes them. — "read" · "write"
    - `test_users` (string[], required) — People besides you who may use the app before it is reviewed, by the email address of their account.
    - `review_status` (enum<string>, required) — An unreviewed app works only for its owner and its test users, and people are told it has not been reviewed. — "unreviewed" · "approved"
    - `created_at` (string, required)
    - `updated_at` (string, required)
  - `client_secret` (string, required) — Shown in this response only. Keep it on your server.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/oauth_clients \
  -H "Authorization: Bearer ast_..."
```

### GET /oauth_clients/{id}

One of the caller's apps (scope: read)

Path parameters:

- `id` (string, required) — The app's client id.

Responses:

- `200` — OK
  - `oauth_client` (object, required) — An app registered to sign people in with their account.
    - `id` (string, required) — The client id the app presents when it sends a person to sign in.
    - `name` (string, required) — Shown to people when they are asked to allow the app. — max length 80
    - `redirect_uris` (string[], required) — Where the app may send people back after they decide. Matched exactly: no wildcards, no fragments. Must be https; `http://localhost` and `http://127.0.0.1` are accepted while the app is not reviewed.
    - `scopes` (enum<string>[], required) — What the app may ask a person for. `read` sees their tasks, agents and sessions; `write` also starts and changes them. — "read" · "write"
    - `test_users` (string[], required) — People besides you who may use the app before it is reviewed, by the email address of their account.
    - `review_status` (enum<string>, required) — An unreviewed app works only for its owner and its test users, and people are told it has not been reviewed. — "unreviewed" · "approved"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/oauth_clients/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /oauth_clients/{id}

Change one of the caller's apps (scope: write)

Send only the fields to change. Changing the name, the redirect URLs or the scopes of an approved app returns it to unreviewed; changing its test users does not.

Path parameters:

- `id` (string, required) — The app's client id.

Body (application/json):

- `name` (string) — Shown to people when they are asked to allow the app. — max length 80
- `redirect_uris` (string[]) — Where the app may send people back after they decide. Matched exactly: no wildcards, no fragments. Must be https; `http://localhost` and `http://127.0.0.1` are accepted while the app is not reviewed.
- `scopes` (enum<string>[]) — What the app may ask a person for. `read` sees their tasks, agents and sessions; `write` also starts and changes them. — "read" · "write"
- `test_users` (string[]) — People besides you who may use the app before it is reviewed, by the email address of their account.

Responses:

- `200` — OK
  - `oauth_client` (object, required) — An app registered to sign people in with their account.
    - `id` (string, required) — The client id the app presents when it sends a person to sign in.
    - `name` (string, required) — Shown to people when they are asked to allow the app. — max length 80
    - `redirect_uris` (string[], required) — Where the app may send people back after they decide. Matched exactly: no wildcards, no fragments. Must be https; `http://localhost` and `http://127.0.0.1` are accepted while the app is not reviewed.
    - `scopes` (enum<string>[], required) — What the app may ask a person for. `read` sees their tasks, agents and sessions; `write` also starts and changes them. — "read" · "write"
    - `test_users` (string[], required) — People besides you who may use the app before it is reviewed, by the email address of their account.
    - `review_status` (enum<string>, required) — An unreviewed app works only for its owner and its test users, and people are told it has not been reviewed. — "unreviewed" · "approved"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/oauth_clients/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### DELETE /oauth_clients/{id}

Delete one of the caller's apps (scope: write)

Everyone's access through the app ends with it.

Path parameters:

- `id` (string, required) — The app's client id.

Responses:

- `200` — Deleted
  - `deleted` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/oauth_clients/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### POST /oauth_clients/{id}/rotate_secret

Replace an app's client secret (scope: write)

The previous secret stops working at once. People who already allowed the app keep their access.

Path parameters:

- `id` (string, required) — The app's client id.

Responses:

- `200` — OK
  - `oauth_client` (object, required) — An app registered to sign people in with their account.
    - `id` (string, required) — The client id the app presents when it sends a person to sign in.
    - `name` (string, required) — Shown to people when they are asked to allow the app. — max length 80
    - `redirect_uris` (string[], required) — Where the app may send people back after they decide. Matched exactly: no wildcards, no fragments. Must be https; `http://localhost` and `http://127.0.0.1` are accepted while the app is not reviewed.
    - `scopes` (enum<string>[], required) — What the app may ask a person for. `read` sees their tasks, agents and sessions; `write` also starts and changes them. — "read" · "write"
    - `test_users` (string[], required) — People besides you who may use the app before it is reviewed, by the email address of their account.
    - `review_status` (enum<string>, required) — An unreviewed app works only for its owner and its test users, and people are told it has not been reviewed. — "unreviewed" · "approved"
    - `created_at` (string, required)
    - `updated_at` (string, required)
  - `client_secret` (string, required) — Shown in this response only. Keep it on your server.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/oauth_clients/sess_cmtb7q2j/rotate_secret \
  -H "Authorization: Bearer ast_..."
```

## Apps with access

### GET /oauth_grants

The registered apps the caller allowed into their own account (scope: read)

The account page's apps with access: each app the person allowed, the scopes they allowed it, and when. Only a credential for the whole account may read this; a workspace key, an app acting for the person and other restricted credentials are 403 `restricted_token`. 404 while apps with sign-in are switched off.

Responses:

- `200` — OK
  - `oauth_grants` (object[], required)
    - `client_id` (string, required)
    - `name` (string, required)
    - `scopes` (string[], required)
    - `review_status` (enum<string>, required) — "unreviewed" · "approved"
    - `allowed_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/oauth_grants' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /oauth_grants/{client_id}

Remove an app's access to the caller's own account (scope: admin)

The same Remove as the account page: the consent is forgotten and every token the app holds for this person stops working at once. The grant removed is always the caller's own; 404 `not_found` when that app had no access. Restricted credentials are 403 `restricted_token`.

Path parameters:

- `client_id` (string, required)

Responses:

- `200` — Revoked
  - `revoked` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/oauth_grants/client_id \
  -H "Authorization: Bearer ast_..."
```

## API keys

### GET /api_keys

The caller's own API keys (scope: admin)

Only the person's own sign-in or a personal key that is not fixed to one workspace may call this; a workspace key, an app acting for the person, a task pass, a key limited to one job and a key fixed to one workspace are refused with 403 `restricted_token`. Workspace keys are listed on the workspace, not here.

Responses:

- `200` — OK
  - `api_keys` (object[], required)
    - `id` (string, required)
    - `name` (string, required)
    - `token_prefix` (string, required) — The first characters of the secret, to tell keys apart.
    - `scopes` (enum<string>[], required) — "read" · "write" · "admin"
    - `universe` (string | null, required) — The workspace the key is fixed to; null for a key that works in any of the person's workspaces.
    - `status` (enum<string>, required) — "active" · "revoked" · "expired"
    - `can_reveal` (boolean, required) — Whether `reveal` can read the secret back. Keys made before secrets were kept encrypted cannot.
    - `can_restore` (boolean, required) — Whether `restore` can make the key work again once revoked.
    - `access` (enum<string>) — Present when the key is limited to GPT inference through the platform pool. — "gpt-pool"
    - `current` (boolean, required) — True for the key this request was made with.
    - `last_used_at` (string | null, required)
    - `expires_at` (string | null, required)
    - `revoked_at` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/api_keys' \
  -H "Authorization: Bearer ast_..."
```

### POST /api_keys

Create an API key (scope: admin)

Only the person's own sign-in or a personal key that is not fixed to one workspace may call this; a workspace key, an app acting for the person, a task pass, a key limited to one job and a key fixed to one workspace are refused with 403 `restricted_token`. A key never holds a scope the caller lacks (403 `insufficient_scope`). The secret is in this response; `reveal` reads it back later.

Body (application/json):

- `name` (string, required) — max length 60
- `scopes` (enum<string>[], required) — "read" · "write" · "admin"
- `universe` (string | null) — Fix the key to this workspace, which the person must belong to.
- `expires_at` (string | null) — When the key stops working; must be in the future. Omit for a key that does not expire.
- `access` (enum<string>) — Limit this key to GPT inference through the platform pool. It cannot use other models, agents, tools or account-management APIs. — "gpt-pool"

Responses:

- `201` — Created
  - `api_key` (object, required) — One of the person's own API keys. Its secret is never part of it.
    - `id` (string, required)
    - `name` (string, required)
    - `token_prefix` (string, required) — The first characters of the secret, to tell keys apart.
    - `scopes` (enum<string>[], required) — "read" · "write" · "admin"
    - `universe` (string | null, required) — The workspace the key is fixed to; null for a key that works in any of the person's workspaces.
    - `status` (enum<string>, required) — "active" · "revoked" · "expired"
    - `can_reveal` (boolean, required) — Whether `reveal` can read the secret back. Keys made before secrets were kept encrypted cannot.
    - `can_restore` (boolean, required) — Whether `restore` can make the key work again once revoked.
    - `access` (enum<string>) — Present when the key is limited to GPT inference through the platform pool. — "gpt-pool"
    - `current` (boolean, required) — True for the key this request was made with.
    - `last_used_at` (string | null, required)
    - `expires_at` (string | null, required)
    - `revoked_at` (string | null, required)
    - `created_at` (string, required)
  - `secret` (string, required) — The key itself. Keep it like a password.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/api_keys \
  -H "Authorization: Bearer ast_..."
```

### GET /api_keys/{id}

One of the caller's API keys (scope: admin)

Path parameters:

- `id` (string, required) — The key's id.

Responses:

- `200` — OK
  - `api_key` (object, required) — One of the person's own API keys. Its secret is never part of it.
    - `id` (string, required)
    - `name` (string, required)
    - `token_prefix` (string, required) — The first characters of the secret, to tell keys apart.
    - `scopes` (enum<string>[], required) — "read" · "write" · "admin"
    - `universe` (string | null, required) — The workspace the key is fixed to; null for a key that works in any of the person's workspaces.
    - `status` (enum<string>, required) — "active" · "revoked" · "expired"
    - `can_reveal` (boolean, required) — Whether `reveal` can read the secret back. Keys made before secrets were kept encrypted cannot.
    - `can_restore` (boolean, required) — Whether `restore` can make the key work again once revoked.
    - `access` (enum<string>) — Present when the key is limited to GPT inference through the platform pool. — "gpt-pool"
    - `current` (boolean, required) — True for the key this request was made with.
    - `last_used_at` (string | null, required)
    - `expires_at` (string | null, required)
    - `revoked_at` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/api_keys/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### POST /api_keys/{id}/revoke

Revoke an API key (scope: admin)

The key stops working at once. Revoking the key the request was made with ends that credential too. Revoking a revoked key changes nothing.

Path parameters:

- `id` (string, required) — The key's id.

Responses:

- `200` — OK
  - `api_key` (object, required) — One of the person's own API keys. Its secret is never part of it.
    - `id` (string, required)
    - `name` (string, required)
    - `token_prefix` (string, required) — The first characters of the secret, to tell keys apart.
    - `scopes` (enum<string>[], required) — "read" · "write" · "admin"
    - `universe` (string | null, required) — The workspace the key is fixed to; null for a key that works in any of the person's workspaces.
    - `status` (enum<string>, required) — "active" · "revoked" · "expired"
    - `can_reveal` (boolean, required) — Whether `reveal` can read the secret back. Keys made before secrets were kept encrypted cannot.
    - `can_restore` (boolean, required) — Whether `restore` can make the key work again once revoked.
    - `access` (enum<string>) — Present when the key is limited to GPT inference through the platform pool. — "gpt-pool"
    - `current` (boolean, required) — True for the key this request was made with.
    - `last_used_at` (string | null, required)
    - `expires_at` (string | null, required)
    - `revoked_at` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/api_keys/sess_cmtb7q2j/revoke \
  -H "Authorization: Bearer ast_..."
```

### POST /api_keys/{id}/restore

Restore a revoked API key (scope: admin)

The same secret works again. An expired key cannot be restored (409 `expired`).

Path parameters:

- `id` (string, required) — The key's id.

Responses:

- `200` — OK
  - `api_key` (object, required) — One of the person's own API keys. Its secret is never part of it.
    - `id` (string, required)
    - `name` (string, required)
    - `token_prefix` (string, required) — The first characters of the secret, to tell keys apart.
    - `scopes` (enum<string>[], required) — "read" · "write" · "admin"
    - `universe` (string | null, required) — The workspace the key is fixed to; null for a key that works in any of the person's workspaces.
    - `status` (enum<string>, required) — "active" · "revoked" · "expired"
    - `can_reveal` (boolean, required) — Whether `reveal` can read the secret back. Keys made before secrets were kept encrypted cannot.
    - `can_restore` (boolean, required) — Whether `restore` can make the key work again once revoked.
    - `access` (enum<string>) — Present when the key is limited to GPT inference through the platform pool. — "gpt-pool"
    - `current` (boolean, required) — True for the key this request was made with.
    - `last_used_at` (string | null, required)
    - `expires_at` (string | null, required)
    - `revoked_at` (string | null, required)
    - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/api_keys/sess_cmtb7q2j/restore \
  -H "Authorization: Bearer ast_..."
```

### POST /api_keys/{id}/reveal

Read an API key's secret again (scope: admin)

Refused during a support impersonation (403 `impersonating`), and for keys made before secrets were kept encrypted (409 `not_retrievable`).

Path parameters:

- `id` (string, required) — The key's id.

Responses:

- `200` — OK
  - `secret` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/api_keys/sess_cmtb7q2j/reveal \
  -H "Authorization: Bearer ast_..."
```

## Branding

### GET /branding

The branding of the caller's shared session pages (scope: read)

Only the person's own sign-in or a personal key that is not fixed to one workspace may call this; a workspace key, an app acting for the person, a task pass, a key limited to one job and a key fixed to one workspace are refused with 403 `restricted_token`. `branding` is null when nothing is set.

Responses:

- `200` — OK
  - `branding` (object | null, required)
    - `brand_name` (string | null, required) — Shown in place of AgentSky on the shared pages. — max length 40
    - `logo_url` (string | null, required) — An uploaded logo, as a path on the developer console's origin.
    - `brand_color` (string | null, required) — Header color. — pattern ^#[0-9a-fA-F]{6}$
    - `accent_color` (string | null, required) — Buttons and links; text on it is chosen for contrast. — pattern ^#[0-9a-fA-F]{6}$
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/branding' \
  -H "Authorization: Bearer ast_..."
```

### PUT /branding

Replace the branding of the caller's shared session pages (scope: write)

Only the person's own sign-in or a personal key that is not fixed to one workspace may call this; a workspace key, an app acting for the person, a task pass, a key limited to one job and a key fixed to one workspace are refused with 403 `restricted_token`. Replaces every field: a field left out, null or empty is cleared. Send JSON, or `multipart/form-data` with the same fields plus a `logo` part (PNG, JPEG or WebP, up to 512 KB) to upload a new logo. To keep the current logo, send its `logo_url` back.

Body (application/json):

- `brand_name` (string | null) — Shown in place of AgentSky on the shared pages. — max length 40
- `logo_url` (string | null) — The logo already in use, to keep it. A new logo is uploaded as the `logo` part of a multipart request, never by address.
- `brand_color` (string | null) — Header color. — pattern ^#[0-9a-fA-F]{6}$
- `accent_color` (string | null) — Buttons and links; text on it is chosen for contrast. — pattern ^#[0-9a-fA-F]{6}$

Responses:

- `200` — OK
  - `branding` (object | null, required)
    - `brand_name` (string | null, required) — Shown in place of AgentSky on the shared pages. — max length 40
    - `logo_url` (string | null, required) — An uploaded logo, as a path on the developer console's origin.
    - `brand_color` (string | null, required) — Header color. — pattern ^#[0-9a-fA-F]{6}$
    - `accent_color` (string | null, required) — Buttons and links; text on it is chosen for contrast. — pattern ^#[0-9a-fA-F]{6}$
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/branding \
  -H "Authorization: Bearer ast_..."
```

### DELETE /branding

Return the shared session pages to the default look (scope: write)

Responses:

- `200` — OK
  - `branding` (object | null, required)
    - `brand_name` (string | null, required) — Shown in place of AgentSky on the shared pages. — max length 40
    - `logo_url` (string | null, required) — An uploaded logo, as a path on the developer console's origin.
    - `brand_color` (string | null, required) — Header color. — pattern ^#[0-9a-fA-F]{6}$
    - `accent_color` (string | null, required) — Buttons and links; text on it is chosen for contrast. — pattern ^#[0-9a-fA-F]{6}$
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/branding \
  -H "Authorization: Bearer ast_..."
```

## Channels

### GET /channels/apps

List BYO channel apps — credentials masked (scope: read)

Responses:

- `200` — OK
  - `apps` (object[], required)
    - `verification_error` (string) — Non-secret explanation when X verification remains pending
    - `verification_retryable` (boolean) — Present for pending X verification. False means the saved refresh attempt cannot be replayed; replace credentials with a fresh OAuth grant.
    - `id` (string)
    - `platform` (enum<string>) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
    - `label` (string)
    - `status` (string)
    - `credential_keys` (string[]) — Key names only — values are write-only
    - `created_at` (string)
    - `setup` (map<string, string>) — Steps the platform cannot automate (per-app webhook_url / verify_token / events_url / invite_url)
  - `registered_platforms` (string[], required) — Platforms with a registered-app writer enabled in this service deployment. Does not prove customer credentials or provider delivery.
  - `shared_platforms` (string[], required) — Shared bot choices supported by app selection in this deployment; does not inventory the legacy shared channel flows.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/apps' \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/apps

Register your own bot/number as a channel app (scope: write)

Credentials are proven against the platform where an API exists, stored encrypted, and write-only from then on. The response's setup object carries the steps the platform cannot automate (webhook URLs to paste, invite links).

Body (application/json):

- `platform` (enum<string>, required) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
- `label` (string, required) — max length 120
- `credentials` (map<string, string>, required) — Write-only. Required keys per platform — telegram: bot_token · discord: bot_token · slack: bot_token, signing_secret · whatsapp: access_token, phone_number_id, app_secret · email (requires EMAIL_CHANNEL_ENABLED): region, access_key, secret_key, from_address, sns_topic_arn; optional from_name, inbound_address, allow_subaddressing, reply_to_sender_only (string true/false); optional s3_bucket, s3_prefix (nonempty, ends /), s3_bucket_owner (12 digits), all three together for S3 receiving with the same region/key pair · teams (when enabled; app creation and credential rotation return 501 coming_soon when disabled): app_id (Azure Application client ID), app_password (client secret); optional app_tenant_id (Directory ID for single-tenant bots, omit for multi-tenant). Credentials are validated against Azure AD on creation. The API returns a webhook_url to paste into Azure Bot Configuration → Messaging Endpoint. Connection returns PENDING and a LINK code to send to the bot. Each conversation can bind to its own session. · imessage (coming soon — answers 501 coming_soon today): api_key, phone_number, webhook_secret · x: consumer_secret + either user_access_token (Group A, OAuth 2.0 Bearer) or client_id + refresh_token (Group B, OAuth 2.0 managed refresh). Exactly one group must be supplied. · lark: app_id, app_secret, verification_token (optional encrypt_key, domain: lark|feishu, app_mode: self-built|store, app_ticket for migration) · buzz: private_key, auth_tag · gchat: service_account_json, project_number · line: channel_access_token, channel_secret (requires LINE_CHANNEL_ENABLED; setup returns manual webhook instructions)

Responses:

- `201` — Created
  - `verification_error` (string) — Non-secret explanation when X verification remains pending
  - `verification_retryable` (boolean) — Present for pending X verification. False means the saved refresh attempt cannot be replayed; replace credentials with a fresh OAuth grant.
  - `id` (string)
  - `platform` (enum<string>) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
  - `label` (string)
  - `status` (string)
  - `credential_keys` (string[]) — Key names only — values are write-only
  - `created_at` (string)
  - `setup` (map<string, string>) — Steps the platform cannot automate (per-app webhook_url / verify_token / events_url / invite_url)
- `202` — Verification pending
  - `verification_error` (string) — Non-secret explanation when X verification remains pending
  - `verification_retryable` (boolean) — Present for pending X verification. False means the saved refresh attempt cannot be replayed; replace credentials with a fresh OAuth grant.
  - `id` (string)
  - `platform` (enum<string>) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
  - `label` (string)
  - `status` (string)
  - `credential_keys` (string[]) — Key names only — values are write-only
  - `created_at` (string)
  - `setup` (map<string, string>) — Steps the platform cannot automate (per-app webhook_url / verify_token / events_url / invite_url)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/apps \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/apps/{id}

Channel app detail — credentials masked (scope: read)

Path parameters:

- `id` (string, required) — The channel app id

Responses:

- `200` — OK
  - `verification_error` (string) — Non-secret explanation when X verification remains pending
  - `verification_retryable` (boolean) — Present for pending X verification. False means the saved refresh attempt cannot be replayed; replace credentials with a fresh OAuth grant.
  - `id` (string)
  - `platform` (enum<string>) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
  - `label` (string)
  - `status` (string)
  - `credential_keys` (string[]) — Key names only — values are write-only
  - `created_at` (string)
  - `setup` (map<string, string>) — Steps the platform cannot automate (per-app webhook_url / verify_token / events_url / invite_url)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/apps/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /channels/apps/{id}

Rename or rotate credentials (rotation re-runs registration) (scope: write)

Path parameters:

- `id` (string, required) — The channel app id

Body (application/json):

- `retry_registration` (boolean) — Retry saved X verification without resubmitting credentials; mutually exclusive with credentials
- `label` (string) — max length 120
- `credentials` (map<string, string>) — Full replacement bag; rotation re-runs the platform registration

Responses:

- `200` — OK
  - `verification_error` (string) — Non-secret explanation when X verification remains pending
  - `verification_retryable` (boolean) — Present for pending X verification. False means the saved refresh attempt cannot be replayed; replace credentials with a fresh OAuth grant.
  - `id` (string)
  - `platform` (enum<string>) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
  - `label` (string)
  - `status` (string)
  - `credential_keys` (string[]) — Key names only — values are write-only
  - `created_at` (string)
  - `setup` (map<string, string>) — Steps the platform cannot automate (per-app webhook_url / verify_token / events_url / invite_url)
- `202` — Verification pending
  - `verification_error` (string) — Non-secret explanation when X verification remains pending
  - `verification_retryable` (boolean) — Present for pending X verification. False means the saved refresh attempt cannot be replayed; replace credentials with a fresh OAuth grant.
  - `id` (string)
  - `platform` (enum<string>) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
  - `label` (string)
  - `status` (string)
  - `credential_keys` (string[]) — Key names only — values are write-only
  - `created_at` (string)
  - `setup` (map<string, string>) — Steps the platform cannot automate (per-app webhook_url / verify_token / events_url / invite_url)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/channels/apps/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### DELETE /channels/apps/{id}

Delete the channel app (scope: write)

Path parameters:

- `id` (string, required) — The channel app id

Responses:

- `204` — Deleted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/channels/apps/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/connections

List connections with their bound session (scope: read)

Responses:

- `200` — OK
  - `connections` (object[], required)
    - `id` (string)
    - `platform` (string)
    - `channel_id` (string)
    - `thread_id` (string) — Present after administrative adoption; the existing app-scoped reply address
    - `label` (string)
    - `status` (enum<string>) — "PENDING" · "CONNECTED" · "DISCONNECTED"
    - `bound_session` (object)
      - `id` (string)
      - `label` (string)
    - `created_at` (string)
    - `connect` (object) — PENDING only: open url; X and webhook-based Slack/Discord use a hosted page, phone-based flows include phone + code, and Lark includes app_id and a code to send to the bot.
      - `url` (string)
      - `phone` (string)
      - `app_id` (string) — Lark app ID used to open the bot
      - `code` (string)
      - `expires_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/connections' \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/connections

Connect a surface — link-flow platforms return a pending connect ceremony (scope: write)

telegram/imessage/whatsapp/x/lark/gchat mint a connect ceremony (hosted page or deep link + code) the end user claims in-platform. Slack/Discord with destination.webhook return a LINK ceremony; other Slack/Discord flows create a channel synchronously. Pass app for BYO; callback_url (link flows) redirects the hosted connect page to you after the claim.

Body (application/json):

- `platform` (enum<string>, required) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line" · "loopback"
- `label` (string) — max length 120
- `metadata` (object) — Echoed on channel.connected and the callback redirect
- `destination` (object) — Pre-bind to exactly one owned session or webhook endpoint when the surface is claimed
  - `session` (string)
  - `webhook` (string)
- `app` (string) — BYO ChannelApp id — the connect ceremony runs on your bot/number
- `adopt` (object) — Admin-scope migration of the app owner's previously verified conversation. Requires an owned active app, an app-scoped thread ID and destination. The caller attests the existing sender binding and consent; no LINK ceremony or provider message is performed. Exact replay reuses the connection; changed sender, metadata, destination or a disconnected record returns 409. Cannot combine with callback_url or invite_user.
  - `thread_id` (string, required) — max length 8192
  - `author_id` (string, required) — max length 1024
  - `tenant_key` (string) — Required only for Lark Store adoption; provider app and chat state must confirm this organization. — max length 256
- `invite_user` (string) — Slack only: user id to invite into the created channel
- `callback_url` (string) — Link-flow platforms only: the hosted connect page redirects here after the claim with connection_id, status, and metadata query params

Responses:

- `201` — Created
  - `id` (string)
  - `platform` (string)
  - `channel_id` (string)
  - `thread_id` (string) — Present after administrative adoption; the existing app-scoped reply address
  - `label` (string)
  - `status` (enum<string>) — "PENDING" · "CONNECTED" · "DISCONNECTED"
  - `bound_session` (object)
    - `id` (string)
    - `label` (string)
  - `created_at` (string)
  - `connect` (object) — PENDING only: open url; X and webhook-based Slack/Discord use a hosted page, phone-based flows include phone + code, and Lark includes app_id and a code to send to the bot.
    - `url` (string)
    - `phone` (string)
    - `app_id` (string) — Lark app ID used to open the bot
    - `code` (string)
    - `expires_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/connections \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/connections/status

Read your connection claim's current status (scope: read)

Look up a link-flow ceremony by its 32-character token, scoped to the authenticated owner and universe. Reconnecting an existing conversation can replace the pending connection ID; this returns the effective ID. It does not confirm downstream webhook processing. Responses are not cached. Normal API rate limits apply; back off on 429.

Query parameters:

- `token` (string, required) — The token after LINK: or in the Telegram start parameter

Responses:

- `200` — OK
  - `status` (enum<string>, required) — "pending" · "connected" · "expired" · "disconnected"
  - `connection_id` (string, required)
  - `platform` (string, required)
  - `metadata` (object, required) — The caller's original connection metadata
  - `expires_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/connections/status?token=Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /channels/connections/{id}

Disconnect the surface (scope: write)

Path parameters:

- `id` (string, required) — The connection id

Responses:

- `204` — Disconnected
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/channels/connections/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### DELETE /channels/connections/{id}/pending

Cancel an unclaimed chat setup (scope: write)

Revokes only an owned, unbound PENDING connection with a pending link. Serializes with claims and bindings; returns 409 connection_not_pending if already claimed or bound. Repeating an already canceled pending setup returns 204. Does not disconnect connected chats or emit a channel.disconnected webhook.

Path parameters:

- `id` (string, required) — The exact connection id returned by setup

Responses:

- `204` — Pending setup canceled
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/channels/connections/sess_cmtb7q2j/pending \
  -H "Authorization: Bearer ast_..."
```

### PUT /channels/connections/{id}/binding

Set where the surface routes — a session or your webhook endpoint (single active binding) (scope: write)

Path parameters:

- `id` (string, required) — The connection id

Body (application/json):

- `destination` (object, required) — Exactly one of webhook (endpoint id) or session (session id)
  - `webhook` (string)
  - `session` (string)

Responses:

- `200` — OK
  - `connection_id` (string)
  - `binding_id` (string)
  - `session` (string)
  - `webhook` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/channels/connections/sess_cmtb7q2j/binding \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/connections/{id}/capabilities

Declared platform capabilities — branch on these instead of guessing (scope: read)

Path parameters:

- `id` (string, required) — The connection id

Responses:

- `200` — OK
  - `connection_id` (string)
  - `platform` (string)
  - `history_source` (enum<string>) — History origin; unavailable returns 501 rather than an empty history. — "provider" · "sdk_cache" · "unavailable"
  - `capabilities` (map<string, boolean>) — threads · reactions · markers · proactive · markdown · modals · ephemeral · streaming · files
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/connections/sess_cmtb7q2j/capabilities' \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/connections/{id}/dev/inbound

Inject a message into a loopback connection (scope: write)

Local development without a real platform: the message goes through the same webhook pipeline a Telegram or Slack event would. Only loopback connections accept it — anything else answers 400.

Path parameters:

- `id` (string, required) — The connection id

Body (application/json):

- `text` (string, required)
- `thread` (string) — Thread key within the connection; default "main"
- `id` (string) — Message id to attribute it to; default a generated one
- `author` (object)
  - `user_id` (string, required)
  - `user_name` (string)
- `mention` (boolean) — Whether it reads as a mention of the bot

Responses:

- `202` — Accepted
  - `thread_id` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/connections/sess_cmtb7q2j/dev/inbound \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/connections/{id}/dev/outbound

Everything the agent has sent on a loopback connection (scope: read)

The counterpart to dev/inbound: what a real platform would have received.

Path parameters:

- `id` (string, required) — The connection id

Responses:

- `200` — OK
  - `outbound` (object[], required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/connections/sess_cmtb7q2j/dev/outbound' \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/bindings

List bindings, optionally by connection (scope: read)

Query parameters:

- `connection_id` (string)

Responses:

- `200` — OK
  - `bindings` (object[], required)
    - `id` (string)
    - `connection_id` (string)
    - `thread_id` (string)
    - `destination` (object) — Exactly one of webhook (endpoint id) or session (session id)
      - `webhook` (string)
      - `session` (string)
    - `is_default` (boolean)
    - `status` (string)
    - `route_key` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/bindings' \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/bindings

Route one thread of a connection to a session or your webhook (scope: write)

Body (application/json):

- `connection_id` (string, required)
- `thread_id` (string, required) — The one thread this rule routes. Connection-level routing is a single slot — set it via PUT /connections/{id}/binding
- `destination` (object, required) — Exactly one of webhook (endpoint id) or session (session id)
  - `webhook` (string)
  - `session` (string)
- `route_key` (string) — max length 60

Responses:

- `201` — Created
  - `id` (string)
  - `connection_id` (string)
  - `thread_id` (string)
  - `destination` (object) — Exactly one of webhook (endpoint id) or session (session id)
    - `webhook` (string)
    - `session` (string)
  - `is_default` (boolean)
  - `status` (string)
  - `route_key` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/bindings \
  -H "Authorization: Bearer ast_..."
```

### DELETE /channels/bindings/{id}

Delete the binding (scope: write)

Path parameters:

- `id` (string, required) — The binding id

Responses:

- `204` — Deleted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/channels/bindings/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/identities

List the chat identities linked to your account (scope: read)

Responses:

- `200` — OK
  - `identities` (object[], required)
    - `id` (string)
    - `platform` (enum<string>) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
    - `external_user_id` (string) — The person's id on that platform
    - `display_name` (string)
    - `linked_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/identities' \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/identities

Complete a link offered to a person in a connected chat, as the caller (scope: write)

From then on that person's messages in conversations on the same bot or workspace run as the caller's account. The token is the one posted in the chat; it works once and for 30 minutes. 404 when it was used or has expired, 503 `not_migrated` until the platform's tables are in place.

Body (application/json):

- `token` (string, required)

Responses:

- `201` — Linked
  - `identity` (object, required) — A person in a connected chat, linked to the account their messages there run as.
    - `id` (string)
    - `platform` (enum<string>) — "telegram" · "slack" · "discord" · "whatsapp" · "imessage" · "email" · "teams" · "x" · "lark" · "buzz" · "gchat" · "line"
    - `external_user_id` (string) — The person's id on that platform
    - `display_name` (string)
    - `linked_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/identities \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/identities/links/{token}

Read who a link would connect, before completing it (scope: read)

Path parameters:

- `token` (string, required) — The link token posted in the chat

Responses:

- `200` — OK
  - `link` (any, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/identities/links/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /channels/identities/{id}

Unlink a chat identity; that person's messages stop running as you (scope: write)

Path parameters:

- `id` (string, required) — The identity id

Responses:

- `204` — Unlinked
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/channels/identities/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/webhooks

List webhook endpoints (scope: read)

Responses:

- `200` — OK
  - `webhooks` (object[], required)
    - `id` (string)
    - `url` (string)
    - `events` (string[])
    - `status` (string)
    - `secret` (string) — whsec_ HMAC secret — returned on create only
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/webhooks' \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/webhooks

Create a webhook endpoint — HMAC-signed deliveries, 0/5/30s retries (scope: write)

Deliveries carry X-Asteroids-{Event,Delivery,Timestamp,Signature}; ~20 consecutive failures disable the endpoint. Consumers must be idempotent by delivery id. The message.received payload is described by ChannelMessageReceived, including its optional service-owned claim.

Body (application/json):

- `url` (string, required) — https (http allowed for localhost only)
- `events` (string[]) — Default ["message.received"]

Responses:

- `201` — Created
  - `id` (string)
  - `url` (string)
  - `events` (string[])
  - `status` (string)
  - `secret` (string) — whsec_ HMAC secret — returned on create only
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/webhooks \
  -H "Authorization: Bearer ast_..."
```

### PATCH /channels/webhooks/{id}

Re-enable a disabled endpoint (resets failures, keeps the secret) and/or re-pick events (scope: write)

Path parameters:

- `id` (string, required) — The webhook endpoint id

Body (application/json):

- `status` (enum<string>) — "ACTIVE"
- `events` (string[])

Responses:

- `200` — OK
  - `id` (string)
  - `url` (string)
  - `events` (string[])
  - `status` (string)
  - `secret` (string) — whsec_ HMAC secret — returned on create only
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/channels/webhooks/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### DELETE /channels/webhooks/{id}

Delete the webhook endpoint (scope: write)

Path parameters:

- `id` (string, required) — The webhook endpoint id

Responses:

- `204` — Deleted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/channels/webhooks/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/threads/{id}/messages

Read one authorized conversation history page (scope: read)

Provider-authorized history or retained SDK cache only. Does not send a turn, persist files, or mark messages seen. An unsupported adapter returns history_unavailable, not an empty success. Reuse next_cursor with the same thread and limit; same-page retries are allowed. Cursors are encrypted and bound to the current caller, installation and thread. Files are metadata only.

Path parameters:

- `id` (string, required) — The exact thread id

Query parameters:

- `limit` (integer)
- `cursor` (string)

Responses:

- `200` — One chronological page; next_cursor continues to older messages
  - `thread_id` (string)
  - `history_source` (enum<string>) — "provider" · "sdk_cache"
  - `coverage` (string)
  - `messages` (object[])
  - `next_cursor` (string | null)
  - `truncated` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/threads/sess_cmtb7q2j/messages' \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/threads/{id}/messages

Post into a thread — markdown renders natively per platform (scope: write)

File parts use owned Files API assets and require capabilities.files. Long replies are split into complete platform-sized messages. Supply idempotency_key to avoid duplicate sends on retry; an uncertain or partial send must be inspected before choosing a new key. done and failed are mutually exclusive.

Path parameters:

- `id` (string, required) — The thread id (from message.received or channel events)

Body (application/json):

- `parts` (object[], required)
  - type: "file" (object)
    - `type` ("file", required)
    - `file_id` (string, required) — A visible, unexpired Files API upload or session output; requires capabilities.files. — pattern ^file_[A-Za-z0-9_-]{1,128}$
  - type: "text" (object)
    - `type` ("text", required)
    - `text` (string, required)
  - type: "markdown" (object)
    - `type` ("markdown", required)
    - `text` (string, required)
  - type: "raw" (object)
    - `type` ("raw", required)
    - `platform` (string, required)
    - `payload` (string, required) — Platform-native payload, JSON-encoded
- `email` (object) — SES-only headers. The authorized thread owns the recipient; this object cannot change To.
  - `subject` (string) — max length 200 — pattern ^[^\r\n]+$
  - `reply_to` (string)
- `idempotency_key` (string) — Durable replay key scoped to the persisted owner, connection and thread, independent of bearer token scope. Same-content replays return the accepted receipt even after disconnect; changed content or an unconfirmed send returns 409 without resending. — max length 200
- `done` (boolean) — Resolves the working marker as successful; cannot be true with failed
- `failed` (boolean) — Resolves the working marker as failed; cannot be true with done

Responses:

- `201` — Created
  - `message_id` (string)
  - `thread_id` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/threads/sess_cmtb7q2j/messages \
  -H "Authorization: Bearer ast_..."
```

### PUT /channels/threads/{id}/messages/{mid}/reactions/{emoji}

Add a reaction (platform-neutral emoji names) (scope: write)

Path parameters:

- `id` (string, required) — The thread id
- `mid` (string, required)
- `emoji` (string, required)

Responses:

- `204` — Reacted
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/channels/threads/sess_cmtb7q2j/messages/mid/reactions/emoji \
  -H "Authorization: Bearer ast_..."
```

### DELETE /channels/threads/{id}/messages/{mid}/reactions/{emoji}

Remove a reaction (scope: write)

Path parameters:

- `id` (string, required) — The thread id
- `mid` (string, required)
- `emoji` (string, required)

Responses:

- `204` — Removed
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/channels/threads/sess_cmtb7q2j/messages/mid/reactions/emoji \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/deliveries

Proactive fan-out: post to every thread bound to a destination (scope: write)

Body (application/json):

- `destination` (object, required) — Exactly one of webhook (endpoint id) or session (session id)
  - `webhook` (string)
  - `session` (string)
- `parts` (object[], required)
  - type: "file" (object)
    - `type` ("file", required)
    - `file_id` (string, required) — A visible, unexpired Files API upload or session output; requires capabilities.files. — pattern ^file_[A-Za-z0-9_-]{1,128}$
  - type: "text" (object)
    - `type` ("text", required)
    - `text` (string, required)
  - type: "markdown" (object)
    - `type` ("markdown", required)
    - `text` (string, required)
  - type: "raw" (object)
    - `type` ("raw", required)
    - `platform` (string, required)
    - `payload` (string, required) — Platform-native payload, JSON-encoded
- `done` (boolean) — Resolves each working marker as successful; cannot be true with failed
- `failed` (boolean) — Resolves each working marker as failed; cannot be true with done

Responses:

- `200` — OK — per-thread results
  - `results` (object[])
    - `thread_id` (string)
    - `status` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/deliveries \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/events/stream

SSE mirror of your webhook events — for local development (scope: read)

Responses:

- `200` — SSE stream
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -N 'https://api.agentsky.dev/v1/channels/events/stream' \
  -H "Authorization: Bearer ast_..."
```

### POST /channels/whatsapp/pairing

Start personal WhatsApp QR pairing (scope: write)

Requires an unrestricted personal key not fixed to a workspace and a session owned by that person. Uses the same durable pairing store and worker as the web. Poll GET for the QR, which the account owner scans with WhatsApp on their phone. This does not send messages. Worker unavailability returns 502 or 503.

Body (application/json):

- `session` (string, required)

Responses:

- `200` — OK
  - `state` (enum<string>, required) — "pending_qr" · "connected" · "disconnected"
  - `qr` (string | null, required)
- `400` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `502` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/channels/whatsapp/pairing \
  -H "Authorization: Bearer ast_..."
```

### GET /channels/whatsapp/pairing

Read personal WhatsApp pairing state and QR (scope: read)

Requires an unrestricted personal key not fixed to a workspace. Reads only the caller's pairing. 404 means no pairing has started. Responses are private and not cached.

Responses:

- `200` — OK
  - `state` (enum<string>, required) — "pending_qr" · "connected" · "disconnected"
  - `qr` (string | null, required)
- `401` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/channels/whatsapp/pairing' \
  -H "Authorization: Bearer ast_..."
```

## White label

### GET /partner/onboarding

The onboarding instruction for this account (scope: read)

Markdown by default (the reader is a language model); `?format=json` returns the same state as fields. It describes the step this account is actually on, so an agent can fetch it, make the call it names, and fetch it again until it reports the account is live. This is the entry point for white-label onboarding — there is no form.

Query parameters:

- `format` (string)

Responses:

- `200` — The instruction
  - `state` (enum<string>) — "unapplied" · "waiting" · "rejected" · "setting_up" · "live" · "suspended"
  - `next_action` (string) — The one call that advances onboarding; null when nothing does.
  - `outstanding` (string[])
  - `partner` (any)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/partner/onboarding' \
  -H "Authorization: Bearer ast_..."
```

### GET /partner

Where this account stands (scope: read)

Responses:

- `200` — OK
  - `state` (enum<string>) — "unapplied" · "waiting" · "rejected" · "setting_up" · "live" · "suspended"
  - `next_action` (string) — The one call that advances onboarding; null when nothing does.
  - `outstanding` (string[])
  - `partner` (any)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/partner' \
  -H "Authorization: Bearer ast_..."
```

### POST /partner/application

Ask to become a white-label partner (scope: write)

A request, not a switch: a person here reads it and decides, and no call advances it in the meantime. One open application per account.

Body (application/json):

- `productName` (string, required) — What this partner's customers will call the product.
- `intendedHost` (string, required) — Advisory at this stage; hostnames are claimed later.
- `notes` (string)

Responses:

- `201` — Accepted for a decision
  - `application_id` (string)
  - `state` (string)
  - `next_action` (string)
  - `message` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/partner/application \
  -H "Authorization: Bearer ast_..."
```

### GET /partner/earnings

Read this partner's workspaces, earnings, payouts and funded trial (scope: read)

What the White label page shows of the money: how many workspaces came from the partner's hostnames, what it earned by month and source, its payouts, and the starting credit it funds. People are counted, never named. 409 not_a_partner until the account is a partner. A workspace key or a restricted credential cannot read it.

Responses:

- `200` — OK
  - `live` (boolean, required) — Counting has started: the account is live and its domain switched on.
  - `workspaces` (integer, required) — Workspaces created by people who signed up on this partner's hostnames.
  - `active_workspaces` (integer, required) — Of those, how many ran a task in the last 30 days.
  - `tasks` (integer, required) — Tasks started in those workspaces.
  - `earned_total` (string, required) — US dollars with two decimals, rounded down to the cent.
  - `months` (object[], required) — What was earned by month and source, newest first.
    - `month` (string) — YYYY-MM.
    - `source` (enum<string>) — "gateway" · "session" · "agent_fee"
    - `charges` (integer)
    - `earned` (string) — US dollars with two decimals.
  - `payouts` (object, required) — Null where partner domains are not set up.
    - `paid` (string) — Written out, such as $12.50, as are the other amounts here.
    - `owed` (string)
    - `waiting` (string) — Earned but in no payout yet. Can be negative after a refund.
    - `items` (object[]) — Newest first.
      - `month` (string)
      - `amount` (string)
      - `paid_on` (string) — YYYY-MM-DD; null while owed.
  - `trial` (object, required) — The starting credit this partner funds; null when it funds none.
    - `per_workspace` (string)
    - `deposited` (string)
    - `spent` (string)
    - `balance` (string) — Can be negative.
    - `workspaces` (integer) — How many workspaces were given it.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/partner/earnings' \
  -H "Authorization: Bearer ast_..."
```

### POST /partner/key-prefix

Claim the prefix this partner's API keys carry (scope: admin)

The visible half of every key their customers hold: `acme_…` rather than `ast_…`. Changeable only while no keys exist under it — after that, changing it would strand them.

Body (application/json):

- `prefix` (string, required) — 2–8 lowercase letters or digits, starting with a letter.

Responses:

- `200` — Claimed
  - `partner` (object)
    - `id` (string)
    - `slug` (string)
    - `name` (string)
    - `status` (enum<string>) — "pending" · "active" · "suspended"
    - `key_prefix` (string) — Null until claimed.
    - `brand` (map<string, string>)
    - `brand_missing` (string[]) — Brand fields still falling back to ours.
    - `rate_limit_per_min` (integer)
    - `hostname_quota` (integer)
    - `hostnames` (object[])
      - `hostname` (string)
      - `plane` (enum<string>) — "API" · "GATEWAY" · "APP" · "ACCOUNTS" · "STUDIO_POOL" · "STUDIO_WILDCARD"
      - `ssl_status` (string)
      - `serving` (boolean) — Only a serving hostname counts toward going live.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/partner/key-prefix \
  -H "Authorization: Bearer ast_..."
```

### POST /partner/domains

Claim a hostname for one plane (scope: admin)

The response leads with the CNAME a person must add at the partner's own registrar — the one step of onboarding nobody on our side can do. Adding the row is not ownership: nothing routes until domain-control validation issues a certificate.

Body (application/json):

- `hostname` (string, required)
- `plane` (enum<string>, required) — "API" · "GATEWAY" · "APP" · "ACCOUNTS" · "STUDIO_POOL"

Responses:

- `201` — Claimed, pending DNS
  - `dns_record` (string)
  - `next_action` (string)
  - `partner` (object)
    - `id` (string)
    - `slug` (string)
    - `name` (string)
    - `status` (enum<string>) — "pending" · "active" · "suspended"
    - `key_prefix` (string) — Null until claimed.
    - `brand` (map<string, string>)
    - `brand_missing` (string[]) — Brand fields still falling back to ours.
    - `rate_limit_per_min` (integer)
    - `hostname_quota` (integer)
    - `hostnames` (object[])
      - `hostname` (string)
      - `plane` (enum<string>) — "API" · "GATEWAY" · "APP" · "ACCOUNTS" · "STUDIO_POOL" · "STUDIO_WILDCARD"
      - `ssl_status` (string)
      - `serving` (boolean) — Only a serving hostname counts toward going live.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/partner/domains \
  -H "Authorization: Bearer ast_..."
```

### PUT /partner/brand

Set the names and copy this partner's customers see (scope: admin)

All fields together. A partial brand is refused rather than half-applied: every field left unset falls back to a platform value carrying our name, which would reach their customer.

Body (application/json):

- `productName` (string, required)
- `requestIdHeader` (string, required) — Written into responses verbatim; must look like x-something.
- `spendGateHeader` (string, required) — Must look like x-something.
- `spendGateMessage` (string, required) — What this partner's customer reads when their balance is empty.
- `billingUrl` (string, required)
- `docsUrl` (string, required)
- `supportUrl` (string, required)
- `frameAncestors` (string, required) — A bare https origin naming one of this partner's own hostnames — it becomes the CSP on their customers' session pages.

Responses:

- `200` — Saved
  - `partner` (object)
    - `id` (string)
    - `slug` (string)
    - `name` (string)
    - `status` (enum<string>) — "pending" · "active" · "suspended"
    - `key_prefix` (string) — Null until claimed.
    - `brand` (map<string, string>)
    - `brand_missing` (string[]) — Brand fields still falling back to ours.
    - `rate_limit_per_min` (integer)
    - `hostname_quota` (integer)
    - `hostnames` (object[])
      - `hostname` (string)
      - `plane` (enum<string>) — "API" · "GATEWAY" · "APP" · "ACCOUNTS" · "STUDIO_POOL" · "STUDIO_WILDCARD"
      - `ssl_status` (string)
      - `serving` (boolean) — Only a serving hostname counts toward going live.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/partner/brand \
  -H "Authorization: Bearer ast_..."
```

### GET /partner/site

What this partner has set for its own hostnames (scope: read)

Responses:

- `200` — OK
  - `site` (object)
    - `brand` (any)
    - `helpers` (enum<string> | string[]) — "all", or the handles agents in this partner's workspaces may hire. — "all"
    - `agents` (string[]) — The handles of this partner's own agents: the only ones its hostnames list.
    - `only_here` (string[]) — Those of `agents` that are listed on this partner's hostnames and nowhere else. The rest also appear in the general catalog once approved.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/partner/site' \
  -H "Authorization: Bearer ast_..."
```

### PUT /partner/site

Set how the product looks, which helpers may be hired, and which agents are this partner's (scope: admin)

Send any of `brand`, `helpers` and `agents`; a part left out is left as it is. `brand` is replaced whole, or cleared with null. A person who signs up on one of this partner's hostnames gets a workspace that counts as the partner's: those hostnames list only the agents named in `agents`, and agents in those workspaces may hire only the helpers `helpers` allows (a refused hire answers 403 `helper_not_allowed`). 422 `refused` says in words what was wrong.

Body (application/json):

- `brand` (any)
- `helpers` (enum<string> | string[]) — "all"
- `agents` (string[]) — Each must be a listing in a workspace this partner's owner owns.
- `only_here` (string[]) — Replaces the list whole. Each must be one of `agents`. Refused 422 while this partner's hostnames are not switched on.

Responses:

- `200` — Saved
  - `site` (object)
    - `brand` (any)
    - `helpers` (enum<string> | string[]) — "all", or the handles agents in this partner's workspaces may hire. — "all"
    - `agents` (string[]) — The handles of this partner's own agents: the only ones its hostnames list.
    - `only_here` (string[]) — Those of `agents` that are listed on this partner's hostnames and nowhere else. The rest also appear in the general catalog once approved.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/partner/site \
  -H "Authorization: Bearer ast_..."
```

## Invites

### GET /invites/{token}

What an invitation link offers the signed-in person (scope: read)

status is open (this account may join), joined, wrong_email (sent to a different address) or closed (used, withdrawn or expired).

Path parameters:

- `token` (string, required) — The token from the invitation link

Responses:

- `200` — OK
  - `workspace` (object)
    - `slug` (string)
    - `name` (string)
  - `invited_by` (string)
  - `role` (enum<string>) — "admin" · "member"
  - `email` (string)
  - `status` (enum<string>) — "open" · "joined" · "wrong_email" · "closed"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/invites/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0' \
  -H "Authorization: Bearer ast_..."
```

### POST /invites/{token}

Join the workspace through an invitation link (scope: write)

Only an account signed in with the invited, verified email may join; a credential limited to one workspace cannot.

Path parameters:

- `token` (string, required)

Responses:

- `200` — OK
  - `workspace` (object)
    - `slug` (string)
    - `name` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/invites/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0 \
  -H "Authorization: Bearer ast_..."
```

### GET /invites/{token}/public

Public preview of an invitation — workspace name and inviter, no auth required

Returns the workspace name, the inviter's display name and email, and the email address the invite was sent to. Returns 404 for an expired, accepted or revoked invite. The raw token is never logged or forwarded; it is hashed before any DB lookup.

Path parameters:

- `token` (string, required) — The token from the invitation link

Responses:

- `200` — OK
  - `workspace` (object)
    - `name` (string)
  - `invited_by` (object)
    - `name` (string)
    - `email` (string)
  - `email` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/invites/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0/public' \
  -H "Authorization: Bearer ast_..."
```

## Workspace harnesses

### GET /sessions/{id}/harness

Remote-harness relay WebSocket (scope: write)

WebSocket (Upgrade: websocket) served by the chat-proxy. The maker's ACP process connects with `Authorization: Bearer hct_…` (the per-harness connect token minted via `POST /harnesses/{id}/connect-token`). The relay validates the token, then opens a parallel WebSocket to the session's pod and splices both connections together, forwarding newline-delimited JSON-RPC frames in both directions. One live connection per session; a second attempt while one is open returns 409. The session must be ACTIVE and the pod RUNNING. Gated by the `REMOTE_HARNESSES` platform switch (off → 404).

Path parameters:

- `id` (string, required) — The session id

Responses:

- `101` — Switching Protocols — WebSocket relay open
- `401` — Missing or invalid connect token
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Token does not belong to this session's harness
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Session not found or REMOTE_HARNESSES gate is off
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Session not active, pod not ready, or relay already connected
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/harness' \
  -H "Authorization: Bearer ast_..."
```

### GET /harnesses

List workspace harnesses, oldest first (scope: read)

Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Responses:

- `200` — OK
  - `harnesses` (object[], required)
    - `id` (string, required) — hrn_… — the public id
    - `handle` (string, required) — Short slug within the workspace (e.g. my-harness)
    - `name` (string, required)
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `model_billing` (enum<string>, required) — gateway: model calls are billed through the platform wallet. external: the harness manages billing itself. — "gateway" · "external"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/harnesses' \
  -H "Authorization: Bearer ast_..."
```

### POST /harnesses

Create a harness (scope: write)

Creates a workspace harness with the given handle, name and profile. After creating, add a version with POST /harnesses/{id}/versions, then promote it with POST /harnesses/{id}/versions/{v}/current before creating agents that reference it. Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Body (application/json):

- `handle` (string, required) — pattern ^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$
- `name` (string, required) — max length 200
- `profile` (object, required)
  - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
  - `name` (string, required) — max length 200
  - `version` (string, required) — max length 128
  - `distribution` (map<string, any> | object)
    - option 1 (map<string, any>)
    - option 2 (object)
      - `oci` (object, required)
        - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
  - `auth_command` (string[])
  - `bundled_mcp_servers` (map<string, any>[])
  - `configuration_files` (map<string, any>[])
  - `credential_args` (map<string, any>)
  - `graceful_exit_timeout_seconds` (number)
  - `home_directories` (string[])
  - `managed_model_id_template` (string)
  - `native_provider_setup` (map<string, any>)
  - `pipeline` (string)
  - `prerequisites` (map<string, any>)
  - `request_timeout_seconds` (number)
  - `requirements` (string[])
  - `session_close_before_exit` (boolean)
  - `session_config_options` (map<string, any>)
  - `session_load_supported` (boolean)
  - `session_parameters` (map<string, any>)
  - `subscription_files` (boolean)
  - `docker_target` (string)
  - `tools` (object[])
    - `id` (string, required)
    - `kind` (string, required)
    - `title` (string)
    - `requires` (map<string, any>)
  - `features` (string[])
  - `placement` (enum<string>) — "in_sandbox" · "remote"
- `model_billing` (enum<string>) — "gateway" · "external" — default: "external"

Responses:

- `201` — Created
  - `harness` (object, required)
    - `id` (string, required) — hrn_… — the public id
    - `handle` (string, required) — Short slug within the workspace (e.g. my-harness)
    - `name` (string, required)
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `model_billing` (enum<string>, required) — gateway: model calls are billed through the platform wallet. external: the harness manages billing itself. — "gateway" · "external"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/harnesses \
  -H "Authorization: Bearer ast_..."
```

### GET /harnesses/{id}

One harness (scope: read)

Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)

Responses:

- `200` — OK
  - `harness` (object, required)
    - `id` (string, required) — hrn_… — the public id
    - `handle` (string, required) — Short slug within the workspace (e.g. my-harness)
    - `name` (string, required)
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `model_billing` (enum<string>, required) — gateway: model calls are billed through the platform wallet. external: the harness manages billing itself. — "gateway" · "external"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /harnesses/{id}

Rename a harness or change its model_billing (scope: write)

Omitted fields are left unchanged. Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)

Body (application/json):

- `name` (string) — max length 200
- `model_billing` (enum<string>) — "gateway" · "external"

Responses:

- `200` — OK
  - `harness` (object, required)
    - `id` (string, required) — hrn_… — the public id
    - `handle` (string, required) — Short slug within the workspace (e.g. my-harness)
    - `name` (string, required)
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `model_billing` (enum<string>, required) — gateway: model calls are billed through the platform wallet. external: the harness manages billing itself. — "gateway" · "external"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### DELETE /harnesses/{id}

Delete a harness (scope: write)

Deletes the harness and all its versions. Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)

Responses:

- `204` — Deleted — no body
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /harnesses/{id}/versions

List versions for a harness, oldest first (scope: read)

Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)

Responses:

- `200` — OK
  - `versions` (object[], required)
    - `id` (string, required) — hrnv_… — internal version row id
    - `harness_id` (string, required) — hrn_… — the parent harness
    - `version` (string, required) — Version string, e.g. v1-4096m
    - `status` (enum<string>, required) — pending: registered, build not started. building: E2B template build in progress. ready: build succeeded; can be promoted. current: the version agents are created against; at most one per harness. revoked: explicitly withdrawn; cannot be promoted or used for new sessions. — "pending" · "building" · "ready" · "current" · "revoked"
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j/versions' \
  -H "Authorization: Bearer ast_..."
```

### POST /harnesses/{id}/versions

Register a new harness version (scope: write)

Registers the version string and triggers an E2B template build. Poll the version's status until it reaches ready, then promote with POST /harnesses/{id}/versions/{v}/current. If profile is omitted, the parent harness's profile is used. A workspace may create 20 versions in 24 hours; beyond that the answer is 429 rate_limited. Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)

Body (application/json):

- `version` (string, required) — max length 128
- `profile` (object)
  - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
  - `name` (string, required) — max length 200
  - `version` (string, required) — max length 128
  - `distribution` (map<string, any> | object)
    - option 1 (map<string, any>)
    - option 2 (object)
      - `oci` (object, required)
        - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
  - `auth_command` (string[])
  - `bundled_mcp_servers` (map<string, any>[])
  - `configuration_files` (map<string, any>[])
  - `credential_args` (map<string, any>)
  - `graceful_exit_timeout_seconds` (number)
  - `home_directories` (string[])
  - `managed_model_id_template` (string)
  - `native_provider_setup` (map<string, any>)
  - `pipeline` (string)
  - `prerequisites` (map<string, any>)
  - `request_timeout_seconds` (number)
  - `requirements` (string[])
  - `session_close_before_exit` (boolean)
  - `session_config_options` (map<string, any>)
  - `session_load_supported` (boolean)
  - `session_parameters` (map<string, any>)
  - `subscription_files` (boolean)
  - `docker_target` (string)
  - `tools` (object[])
    - `id` (string, required)
    - `kind` (string, required)
    - `title` (string)
    - `requires` (map<string, any>)
  - `features` (string[])
  - `placement` (enum<string>) — "in_sandbox" · "remote"

Responses:

- `201` — Created
  - `version` (object, required)
    - `id` (string, required) — hrnv_… — internal version row id
    - `harness_id` (string, required) — hrn_… — the parent harness
    - `version` (string, required) — Version string, e.g. v1-4096m
    - `status` (enum<string>, required) — pending: registered, build not started. building: E2B template build in progress. ready: build succeeded; can be promoted. current: the version agents are created against; at most one per harness. revoked: explicitly withdrawn; cannot be promoted or used for new sessions. — "pending" · "building" · "ready" · "current" · "revoked"
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j/versions \
  -H "Authorization: Bearer ast_..."
```

### GET /harnesses/{id}/versions/{v}

One harness version (scope: read)

Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)
- `v` (string, required) — The harness version string, e.g. v1-4096m

Responses:

- `200` — OK
  - `version` (object, required)
    - `id` (string, required) — hrnv_… — internal version row id
    - `harness_id` (string, required) — hrn_… — the parent harness
    - `version` (string, required) — Version string, e.g. v1-4096m
    - `status` (enum<string>, required) — pending: registered, build not started. building: E2B template build in progress. ready: build succeeded; can be promoted. current: the version agents are created against; at most one per harness. revoked: explicitly withdrawn; cannot be promoted or used for new sessions. — "pending" · "building" · "ready" · "current" · "revoked"
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j/versions/v' \
  -H "Authorization: Bearer ast_..."
```

### POST /harnesses/{id}/versions/{v}/current

Promote a version to current (scope: write)

Marks this version as the current one for the harness. The previous current version moves back to ready. New agents created against this harness will pin this version. The version must be in ready or current status; a revoked version cannot be promoted. Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)
- `v` (string, required) — The harness version string, e.g. v1-4096m

Responses:

- `200` — OK
  - `version` (object, required)
    - `id` (string, required) — hrnv_… — internal version row id
    - `harness_id` (string, required) — hrn_… — the parent harness
    - `version` (string, required) — Version string, e.g. v1-4096m
    - `status` (enum<string>, required) — pending: registered, build not started. building: E2B template build in progress. ready: build succeeded; can be promoted. current: the version agents are created against; at most one per harness. revoked: explicitly withdrawn; cannot be promoted or used for new sessions. — "pending" · "building" · "ready" · "current" · "revoked"
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j/versions/v/current \
  -H "Authorization: Bearer ast_..."
```

### POST /harnesses/{id}/versions/{v}/revoke

Revoke a harness version (scope: write)

Permanently withdraws a version; it cannot be promoted or used for new sessions. Sessions already running on this version continue until they terminate. Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)
- `v` (string, required) — The harness version string, e.g. v1-4096m

Responses:

- `200` — OK
  - `version` (object, required)
    - `id` (string, required) — hrnv_… — internal version row id
    - `harness_id` (string, required) — hrn_… — the parent harness
    - `version` (string, required) — Version string, e.g. v1-4096m
    - `status` (enum<string>, required) — pending: registered, build not started. building: E2B template build in progress. ready: build succeeded; can be promoted. current: the version agents are created against; at most one per harness. revoked: explicitly withdrawn; cannot be promoted or used for new sessions. — "pending" · "building" · "ready" · "current" · "revoked"
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j/versions/v/revoke \
  -H "Authorization: Bearer ast_..."
```

### POST /harnesses/{id}/versions/{v}/verify

Record the E2B template listing for a version (scope: write)

Stores the E2B sandbox listing string for the built template. Called by the build pipeline after a successful build; advances the version status to ready. Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)
- `v` (string, required) — The harness version string, e.g. v1-4096m

Body (application/json):

- `listing` (string, required)

Responses:

- `200` — OK
  - `version` (object, required)
    - `id` (string, required) — hrnv_… — internal version row id
    - `harness_id` (string, required) — hrn_… — the parent harness
    - `version` (string, required) — Version string, e.g. v1-4096m
    - `status` (enum<string>, required) — pending: registered, build not started. building: E2B template build in progress. ready: build succeeded; can be promoted. current: the version agents are created against; at most one per harness. revoked: explicitly withdrawn; cannot be promoted or used for new sessions. — "pending" · "building" · "ready" · "current" · "revoked"
    - `profile` (object, required) — The runtime description of a workspace harness: the distribution spec (npx, uvx or binary), optional auth command, bundled MCP servers, tools, features and other catalog fields the installer reads when it builds the template image.
      - `id` (string, required) — pattern ^[a-z0-9][a-z0-9_-]{1,39}$
      - `name` (string, required) — max length 200
      - `version` (string, required) — max length 128
      - `distribution` (map<string, any> | object)
        - option 1 (map<string, any>)
        - option 2 (object)
          - `oci` (object, required)
            - `image` (string, required) — pattern ^[^@]+@sha256:[0-9a-f]{64}$
      - `auth_command` (string[])
      - `bundled_mcp_servers` (map<string, any>[])
      - `configuration_files` (map<string, any>[])
      - `credential_args` (map<string, any>)
      - `graceful_exit_timeout_seconds` (number)
      - `home_directories` (string[])
      - `managed_model_id_template` (string)
      - `native_provider_setup` (map<string, any>)
      - `pipeline` (string)
      - `prerequisites` (map<string, any>)
      - `request_timeout_seconds` (number)
      - `requirements` (string[])
      - `session_close_before_exit` (boolean)
      - `session_config_options` (map<string, any>)
      - `session_load_supported` (boolean)
      - `session_parameters` (map<string, any>)
      - `subscription_files` (boolean)
      - `docker_target` (string)
      - `tools` (object[])
        - `id` (string, required)
        - `kind` (string, required)
        - `title` (string)
        - `requires` (map<string, any>)
      - `features` (string[])
      - `placement` (enum<string>) — "in_sandbox" · "remote"
    - `created_at` (string, required)
    - `updated_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j/versions/v/verify \
  -H "Authorization: Bearer ast_..."
```

### POST /harnesses/{id}/connect-token

Mint a connect token for a remote harness (shown once) (scope: write)

Issues a hct_… bearer token the maker's process uses to authenticate to the relay at WS /api/v1/sessions/{id}/harness. Minting revokes any existing token for this harness. The token value is returned exactly once — it cannot be retrieved again. Gated by the REMOTE_HARNESSES platform switch (off → 404). Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)

Responses:

- `201` — Created — one-time token
  - `connect_token` (string, required) — hct_… — store immediately; not retrievable after this response
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j/connect-token \
  -H "Authorization: Bearer ast_..."
```

### DELETE /harnesses/{id}/connect-token

Revoke the current connect token for a remote harness (scope: write)

Revokes the active hct_… token. Any maker process currently connected will be dropped on its next frame. Gated by the REMOTE_HARNESSES platform switch. Returns 404 when the WORKSPACE_HARNESSES feature switch is off for this workspace. Returns 503 not_migrated when the backing tables are not yet present.

Path parameters:

- `id` (string, required) — The harness id (hrn_…)

Responses:

- `200` — OK
  - `ok` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/harnesses/sess_cmtb7q2j/connect-token \
  -H "Authorization: Bearer ast_..."
```

## Meeting recording

### GET /meeting-auto-join

Read your meeting auto-join setting and recorders (scope: read)

Whether a recorder joins the video meetings on your calendar, and your recorders from a day ago to two days ahead.

Responses:

- `200` — OK
  - `enabled` (boolean)
  - `available` (boolean) — False where the recorder service is not configured
  - `workspace` (string) — Slug of the workspace notes and videos go to
  - `bot_name` (string) — The name everyone in the meeting sees
  - `last_checked_at` (string)
  - `next_check_at` (string)
  - `last_error` (string) — Why the last calendar read failed, in plain words
  - `bookings` (object[])
    - `id` (string)
    - `calendar_event_id` (string)
    - `title` (string)
    - `start` (string)
    - `join_at` (string)
    - `meeting_url` (string)
    - `state` (enum<string>) — "pending" · "booked" · "cancelled" · "left" · "failed" · "skipped"
    - `reason` (string) — Why it was skipped, withdrawn or failed, in plain words
    - `bot_id` (string)
    - `booking_run_id` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/meeting-auto-join' \
  -H "Authorization: Bearer ast_..."
```

### PUT /meeting-auto-join

Turn meeting auto-join on or off (scope: write)

On: a recorder joins every timed, undeclined video meeting on your connected calendars that none of your devices is recording. It records video, audio and a transcript, appears to everyone in the call and says so in the meeting chat. Notes and videos go to the workspace this call is made in; its wallet pays. Off withdraws every recorder not yet in its meeting. 409 calendar_not_connected without a calendar; 503 recorder_unavailable where no recorder is configured.

Body (application/json):

- `enabled` (boolean, required)

Responses:

- `200` — The setting as saved
  - `enabled` (boolean)
  - `available` (boolean) — False where the recorder service is not configured
  - `workspace` (string) — Slug of the workspace notes and videos go to
  - `bot_name` (string) — The name everyone in the meeting sees
  - `last_checked_at` (string)
  - `next_check_at` (string)
  - `last_error` (string) — Why the last calendar read failed, in plain words
  - `bookings` (object[])
    - `id` (string)
    - `calendar_event_id` (string)
    - `title` (string)
    - `start` (string)
    - `join_at` (string)
    - `meeting_url` (string)
    - `state` (enum<string>) — "pending" · "booked" · "cancelled" · "left" · "failed" · "skipped"
    - `reason` (string) — Why it was skipped, withdrawn or failed, in plain words
    - `bot_id` (string)
    - `booking_run_id` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/meeting-auto-join \
  -H "Authorization: Bearer ast_..."
```

### POST /meeting-auto-join/bookings/{id}/cancel

Withdraw one recorder (scope: write)

Deletes a recorder that has not joined and tells one that may have joined to leave. 404 when it is not yours; 409 when it is already closed.

Path parameters:

- `id` (string, required)

Responses:

- `200` — The recorder as it now stands
  - `booking` (object)
    - `id` (string)
    - `calendar_event_id` (string)
    - `title` (string)
    - `start` (string)
    - `join_at` (string)
    - `meeting_url` (string)
    - `state` (enum<string>) — "pending" · "booked" · "cancelled" · "left" · "failed" · "skipped"
    - `reason` (string) — Why it was skipped, withdrawn or failed, in plain words
    - `bot_id` (string)
    - `booking_run_id` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/meeting-auto-join/bookings/sess_cmtb7q2j/cancel \
  -H "Authorization: Bearer ast_..."
```

### POST /meeting-auto-join/live

Say a device is recording a calendar event (scope: write)

No recorder joins that event while this stands, and a booked one is withdrawn or told to leave. The Mac app calls this when it starts recording a call it matched to your calendar. A signal with no end stops counting after six hours.

Body (application/json):

- `calendar_event_id` (string, required) — max length 1024
- `event_start` (string | null) — pattern ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|([+-](?:[01]\d|2[0-3]):[0-5]\d)))$
- `app` (string | null) — max length 100
- `device` (string, required) — max length 100

Responses:

- `200` — The live signal and any recorders withdrawn
  - `live` (object)
    - `calendar_event_id` (string)
    - `started_at` (string)
  - `withdrawn` (object[])
    - `id` (string)
    - `calendar_event_id` (string)
    - `title` (string)
    - `start` (string)
    - `join_at` (string)
    - `meeting_url` (string)
    - `state` (enum<string>) — "pending" · "booked" · "cancelled" · "left" · "failed" · "skipped"
    - `reason` (string) — Why it was skipped, withdrawn or failed, in plain words
    - `bot_id` (string)
    - `booking_run_id` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/meeting-auto-join/live \
  -H "Authorization: Bearer ast_..."
```

### POST /meeting-auto-join/live/end

Say a device stopped recording a calendar event (scope: write)

Ends the live signal for that event.

Body (application/json):

- `calendar_event_id` (string, required) — max length 1024

Responses:

- `200` — Whether a signal was open
  - `ended` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/meeting-auto-join/live/end \
  -H "Authorization: Bearer ast_..."
```

### GET /meeting-recordings

List the caller's meeting recordings (scope: read)

All recordings charged to the caller's account, newest first. Paginate with after (a created_at ISO string from the last row).

Query parameters:

- `limit` (integer) — Default 50
- `after` (string) — Cursor: created_at of the last row from the previous page

Responses:

- `200` — OK
  - `recordings` (object[])
    - `id` (string) — Internal ledger entry id
    - `meeting_id` (string)
    - `bot_id` (string)
    - `idempotency_key` (string) — meeting:<meeting_id>:<bot_id>
    - `session_id` (string) — The session this recording was attributed to, if any
    - `billed_bot_seconds` (number)
    - `billed_recorded_seconds` (number)
    - `cost_usd` (number)
    - `error_code` (string)
    - `created_at` (string)
  - `has_more` (boolean)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/meeting-recordings' \
  -H "Authorization: Bearer ast_..."
```

### POST /meeting-recordings

Report a finished meeting recording for metering (scope: write)

Books one charge for one recording, on the two bases the supplier charges us on. bot_seconds is how long the recorder held a seat — first to last status change, including time spent waiting to be admitted — billed at $1.00 per hour. recorded_seconds is what was actually captured, capture start to capture end, billed at $0.30 per hour; it is not a bot lifetime and not a running total for the meeting. Neither basis is derived from the other and both are required. The 60-second minimum applies to each basis separately, not to their sum. A report naming error_code zeroes the transcription basis but still owes the seat, because the supplier still charged for it; only a booking where neither basis ran costs nothing. The reporting account is the account charged. A recording is identified by meeting_id and bot_id together: reporting it again returns the booked terms with 200 and charges nothing further.

Body (application/json):

- `meeting_id` (string, required) — The meeting, in the reporter's own namespace — max length 200
- `bot_id` (string, required) — The recorder instance that produced this recording — max length 200
- `bot_seconds` (number, required) — Seconds the recorder held a seat, the wait included — the basis the seat charge bills on. 0 means it never ran. Over 86400 is refused rather than truncated
- `recorded_seconds` (number, required) — Seconds actually captured — the only basis transcription bills on. Not a bot lifetime; bot_seconds is that. Over 86400 is refused rather than truncated
- `error_code` (string) — Why this recording is not billable. Its presence alone forces a $0 receipt — max length 100
- `session_id` (string) — A session to attribute the charge to; omit when the reporter has no session — max length 200

Responses:

- `200` — Already reported; the booked terms, unchanged
  - `recording` (object, required)
    - `meeting_id` (string, required)
    - `bot_id` (string, required)
    - `idempotency_key` (string, required) — meeting:<meeting_id>:<bot_id>
    - `recorded` (boolean, required) — False when this recording was already booked
    - `billed_bot_seconds` (number, required) — Seat seconds the price was computed on, after that basis's own 60s minimum
    - `billed_recorded_seconds` (number, required) — Recorded seconds the price was computed on, after that basis's own 60s minimum
    - `cost_usd` (number, required)
    - `error_code` (string, required)
- `201` — Booked
  - `recording` (object, required)
    - `meeting_id` (string, required)
    - `bot_id` (string, required)
    - `idempotency_key` (string, required) — meeting:<meeting_id>:<bot_id>
    - `recorded` (boolean, required) — False when this recording was already booked
    - `billed_bot_seconds` (number, required) — Seat seconds the price was computed on, after that basis's own 60s minimum
    - `billed_recorded_seconds` (number, required) — Recorded seconds the price was computed on, after that basis's own 60s minimum
    - `cost_usd` (number, required)
    - `error_code` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/meeting-recordings \
  -H "Authorization: Bearer ast_..."
```

### GET /meeting-recordings/{id}

Get one meeting recording (scope: read)

One recording by its internal ledger entry id. 404 when the id names no recording charged to the caller's account.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `recording` (object)
    - `id` (string) — Internal ledger entry id
    - `meeting_id` (string)
    - `bot_id` (string)
    - `idempotency_key` (string) — meeting:<meeting_id>:<bot_id>
    - `session_id` (string) — The session this recording was attributed to, if any
    - `billed_bot_seconds` (number)
    - `billed_recorded_seconds` (number)
    - `cost_usd` (number)
    - `error_code` (string)
    - `created_at` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/meeting-recordings/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

## Preferences

### GET /preferences

The caller's platform preferences (scope: read)

Per-person platform settings: the default session budget applied to new sessions when no budget_cents is passed, and model-improvement consent. These are owned by the platform and reachable via any API key.

Responses:

- `200` — OK
  - `preferences` (object)
    - `default_budget_usd` (string) — Default budget as a USD string (e.g. '5.00') or null for no limit
    - `model_improvement` (boolean) — Whether conversations may be used for model improvement
    - `language` (enum<string>) — The language every AgentSky surface shows: the web app, the public pages and the Mac app. Null follows the browser or the Mac. — "en" · "zh"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/preferences' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /preferences

Update the caller's platform preferences (scope: write)

Change default_budget_usd (a dollar string like '5.00', or null to clear), model_improvement (boolean), language ('en', 'zh', or null to follow the browser or the Mac), or any of them together. Returns all preferences after the update.

Body (application/json):

- `default_budget_usd` (string) — New default budget as a USD string or null to clear
- `model_improvement` (boolean)
- `language` (enum<string>) — "en" · "zh"

Responses:

- `200` — OK
  - `preferences` (object)
    - `default_budget_usd` (string)
    - `model_improvement` (boolean)
    - `language` (enum<string>) — "en" · "zh"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/preferences \
  -H "Authorization: Bearer ast_..."
```

## This Mac

### GET /desktop/machines

The person's Macs connected through the Mac app (scope: read)

Responses:

- `200` — OK
  - `machines` (object[], required)
    - `id` (string, required) — mac_…
    - `name` (string, required)
    - `online` (boolean, required) — The Mac app polled within the last minute
    - `last_seen_at` (string, required)
    - `created_at` (string, required)
    - `reach` (object) — What the Mac app says it can lend now, from its last poll; null when the app is too old to say (it answers no reach requests)
      - `kinds` (enum<string>[], required) — What a reach request may ask this Mac for now. host: the Mac app's own local Claude Code and Codex chats, call notes, uploads to workspace files, saves to Downloads, local git (apply a session's changes, open a pull request), WeChat reader and local sync; every change through it is confirmed on the Mac per call — "folder" · "browser" · "chrome" · "screen" · "host"
      - `screen` (enum<string>, required) — off: the person has not turned on lending the screen; needs_permission: macOS has not granted AgentSky Screen Recording or Accessibility (only the person can, in System Settings) — "ready" · "off" · "needs_permission" · "unavailable"
    - `mounts` (object[]) — The live folders, browser windows, screens and host reaches (the Mac's apps and files) lent from this Mac. Personal keys only: a workspace key never sees what a person lent. Capability URLs are never listed.
      - `id` (string, required) — dmt_…
      - `kind` (enum<string>, required) — "folder" · "browser" · "chrome" · "screen" · "host"
      - `label` (string, required)
      - `root` (string) — The folder's absolute path on the Mac (folders only)
      - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/desktop/machines' \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines

Register this Mac (scope: write)

The Mac app registers the Mac it runs on and is handed its connect token once. The token is what the app polls the relay with; the person's own token never reaches the app. Edge-routed to the chat-proxy like the ports routes.

Body (application/json):

- `name` (string, required) — What the person calls this Mac
- `replaces` (string) — The id this Mac held before it lost its sign-in; that registration is retired

Responses:

- `201` — Registered
  - `machine` (object, required)
    - `id` (string, required) — mac_…
    - `name` (string, required)
    - `online` (boolean, required) — The Mac app polled within the last minute
    - `last_seen_at` (string, required)
    - `created_at` (string, required)
    - `reach` (object) — What the Mac app says it can lend now, from its last poll; null when the app is too old to say (it answers no reach requests)
      - `kinds` (enum<string>[], required) — What a reach request may ask this Mac for now. host: the Mac app's own local Claude Code and Codex chats, call notes, uploads to workspace files, saves to Downloads, local git (apply a session's changes, open a pull request), WeChat reader and local sync; every change through it is confirmed on the Mac per call — "folder" · "browser" · "chrome" · "screen" · "host"
      - `screen` (enum<string>, required) — off: the person has not turned on lending the screen; needs_permission: macOS has not granted AgentSky Screen Recording or Accessibility (only the person can, in System Settings) — "ready" · "off" · "needs_permission" · "unavailable"
    - `mounts` (object[]) — The live folders, browser windows, screens and host reaches (the Mac's apps and files) lent from this Mac. Personal keys only: a workspace key never sees what a person lent. Capability URLs are never listed.
      - `id` (string, required) — dmt_…
      - `kind` (enum<string>, required) — "folder" · "browser" · "chrome" · "screen" · "host"
      - `label` (string, required)
      - `root` (string) — The folder's absolute path on the Mac (folders only)
      - `created_at` (string, required)
  - `connect_token` (string, required) — dmc_… — shown once; the Mac app's only credential, stored hashed
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/reach-requests

Ask one of your Macs to lend a folder, a browser window, its screen or its apps and files (scope: write)

The person's own key only (a workspace key answers 403). The ask reaches the Mac app on its next poll; the person answers there — the folder picker (they choose the folder; Cancel refuses) or Allow / Deny for the browser, the screen and `host` (the Mac app's local chats, call notes, uploads, saves to Downloads and local git; once granted its reads answer at once and each change asks the person again). An agent can ask; only the person grants. The optional workspace query fixes the reach's destination without changing the Mac's registration. The caller must still belong to that workspace; a workspace-scoped key cannot choose another. Caller and membership are checked again before granting and serving the reach. A workspace teammate may ask a Mac from `GET /desktop/lent-machines` with their own key and that workspace; the Mac's owner decides by their tier for that teammate, a Mac that does not name them answers 404, and the screen is refused with 403. Answers 202 with the request and the capability URL the mount will carry; poll `GET /desktop/reach-requests/{id}` for the answer. Refused at once with 409: machine_offline (the app is not polling), reach_unsupported (the app is too old, or cannot lend that kind), screen_reach_off, screen_permissions_missing (only the person can grant Screen Recording and Accessibility in System Settings), reach_request_open (one ask per Mac at a time).

Path parameters:

- `id` (string, required)

Query parameters:

- `workspace` (string) — Destination workspace slug; an empty value explicitly selects your default workspace. Omitted uses the credential's fixed workspace or the Mac's registration.

Body (application/json):

- `kind` (enum<string>, required) — "folder" · "browser" · "chrome" · "screen" · "host"
- `reason` (string, required) — Why, in one sentence; shown to the person on the Mac, quoted as the agent's words — max length 280

Responses:

- `202` — Asked
  - `reach_request` (object, required)
    - `id` (string, required) — drr_…
    - `machine_id` (string, required)
    - `kind` (enum<string>, required) — "folder" · "browser" · "chrome" · "screen" · "host"
    - `reason` (string, required)
    - `status` (enum<string>, required) — pending: waiting for the Mac's next poll; asking: the person is being asked; granted: the mount below is live — "pending" · "asking" · "granted" · "denied" · "unavailable" · "expired"
    - `mount` (object, required) — The granted mount while it is live
      - `id` (string, required) — dmt_…
      - `kind` (enum<string>, required) — "folder" · "browser" · "chrome" · "screen" · "host"
      - `label` (string, required)
      - `root` (string) — The folder's absolute path on the Mac (folders only)
      - `created_at` (string, required)
    - `error` (object, required)
      - `code` (enum<string>, required) — "reach_denied" · "screen_reach_off" · "screen_permissions_missing" · "reach_unavailable" · "reach_timeout"
      - `message` (string, required)
    - `created_at` (string, required)
    - `deadline_at` (string, required) — When an unanswered ask expires: a minute for the Mac to pick it up, then 150 seconds for the person
  - `mcp_url` (string, required) — https://mac-<token>.agentsky.dev/mcp — shown once, stored hashed. Answers nothing until the person grants the ask; then attach it as a url MCP server (POST /sessions mcp_servers, MCP start_session sources, or PATCH /sessions/{id} mcp_servers)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/reach-requests \
  -H "Authorization: Bearer ast_..."
```

### GET /desktop/reach-requests/{id}

Where an ask for reach stands (scope: read)

With `wait` (seconds, at most 25) the call returns as soon as the person answers. Another person's or a workspace key's read answers 404 or 403.

Path parameters:

- `id` (string, required)

Query parameters:

- `wait` (integer)

Responses:

- `200` — OK
  - `reach_request` (object, required)
    - `id` (string, required) — drr_…
    - `machine_id` (string, required)
    - `kind` (enum<string>, required) — "folder" · "browser" · "chrome" · "screen" · "host"
    - `reason` (string, required)
    - `status` (enum<string>, required) — pending: waiting for the Mac's next poll; asking: the person is being asked; granted: the mount below is live — "pending" · "asking" · "granted" · "denied" · "unavailable" · "expired"
    - `mount` (object, required) — The granted mount while it is live
      - `id` (string, required) — dmt_…
      - `kind` (enum<string>, required) — "folder" · "browser" · "chrome" · "screen" · "host"
      - `label` (string, required)
      - `root` (string) — The folder's absolute path on the Mac (folders only)
      - `created_at` (string, required)
    - `error` (object, required)
      - `code` (enum<string>, required) — "reach_denied" · "screen_reach_off" · "screen_permissions_missing" · "reach_unavailable" · "reach_timeout"
      - `message` (string, required)
    - `created_at` (string, required)
    - `deadline_at` (string, required) — When an unanswered ask expires: a minute for the Mac to pick it up, then 150 seconds for the person
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/desktop/reach-requests/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/reach-requests/{id}/response

The Mac answers an ask it did not grant (scope: machine connect token)

Sent by the Mac app with outcome denied, screen_reach_off, screen_permissions_missing or reach_unavailable. A grant is not answered here: the Mac creates the mount with `reach_request_id`.

Path parameters:

- `id` (string, required)

Body (application/json):

- `outcome` (enum<string>, required) — "denied" · "screen_reach_off" · "screen_permissions_missing" · "reach_unavailable"
- `detail` (string) — max length 300

Responses:

- `204` — Answered
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/reach-requests/sess_cmtb7q2j/response \
  -H "Authorization: Bearer ast_..."
```

### DELETE /desktop/machines/{id}

Revoke a Mac (scope: write)

The app's connect token stops working and every folder it handed over answers 404 from then on.

Path parameters:

- `id` (string, required)

Responses:

- `204` — Revoked
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/mounts

Hand a locally selected folder on that Mac to agents (scope: machine connect token)

Answers the address a spec's `mcp_servers` entry carries (`{type: "url", name: "this-mac", url: mcp_url}`): a pod's MCP calls on it are relayed to the Mac app, which answers them with file tools rooted at the folder and holds every change for the person's confirmation. This route accepts only that Mac's connect token after its native picker returns a normalized absolute path; an account token cannot create a mount. A Mac that is not polling answers 503 machine_offline to the pod.

Path parameters:

- `id` (string, required)

Body (application/json):

- `root` (string, required) — The folder's absolute path on that Mac, "browser:" for the Mac app's browser window, "screen:" for that Mac's screen, or "host:" for the Mac app's own apps and files, each lent to one task
- `label` (string, required) — What the thread shows for it
- `reach_request_id` (string) — drr_… — the Mac grants that reach request: the mount carries the capability its caller was handed, and this answer's mcp_url is null

Responses:

- `201` — Mounted
  - `id` (string, required) — dmt_…
  - `machine_id` (string, required)
  - `root` (string, required)
  - `label` (string, required)
  - `mcp_url` (string, required) — https://mac-<token>.agentsky.dev/mcp — put it in a spec's mcp_servers as a url server; the token is the credential. Null when the mount grants a reach request (its caller already holds it)
  - `created_at` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/mounts \
  -H "Authorization: Bearer ast_..."
```

### DELETE /desktop/mounts/{id}

Take a folder back (scope: write)

Its address answers 404 from then on; a running session keeps its spec entry but every call to it fails.

Path parameters:

- `id` (string, required)

Responses:

- `204` — Revoked
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/desktop/mounts/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/mounts/{id}/verify

Verify a live folder mount before starting agents (scope: read)

Confirms that the mount id and capability URL still name the same live folder owned by this account in the token's universe, or the account's personal universe when the token is unscoped. A stale, revoked, foreign-universe or mismatched mount answers 404.

Path parameters:

- `id` (string, required)

Body (application/json):

- `mcp_url` (string, required) — The mount capability URL returned when the folder was selected

Responses:

- `204` — The mount is live and owned by this account
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/mounts/sess_cmtb7q2j/verify \
  -H "Authorization: Bearer ast_..."
```

### GET /desktop/machines/{id}/teammates

Read who may act on this Mac, and what they did (scope: admin)

Requires the owner's unrestricted account-wide personal admin key, including for reads. Team/workspace-fixed, task, app, system and restricted credentials are refused. This goes through a dedicated owner-administration path, not ordinary task or mount grants. The Mac must be online and updated. Answers each teammate above Never and the activity record. 404 while teammate access is off on the platform.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
  - `available` (boolean, required)
  - `identityReady` (boolean)
  - `revision` (integer, required)
  - `teammates` (object[], required) — Everyone above Never. Anyone not listed is at Never.
    - `user_id` (string, required)
    - `workspace` (string | null, required) — Workspace slug; null is the owner's default workspace.
    - `name` (string)
    - `tier` (enum<string>, required) — "ask" · "allowed"
    - `scope` (object)
      - `hostTools` (string[]) — Tools from the fixed teammate list, inside the owner's own approval. — pattern ^[a-z][a-z0-9_]{0,99}$
      - `folderRoots` (string[])
      - `browserOrigins` (string[]) — max length 2048
  - `offered` (object) — What may be named in a scope: the fixed teammate tools inside the owner's own approval.
  - `activity` (object[], required) — Newest first: who, what and when for every teammate action on this Mac, allowed or not. Never contains call contents.
    - `at` (string, required)
    - `decision` (enum<string>, required) — "allowed" · "denied" · "no_answer" · "removed"
    - `teammateId` (string | null)
    - `teammate` (string | null)
    - `email` (string | null)
    - `workspace` (string | null)
    - `tool` (string | null)
    - `target` (string | null)
    - `action` (string | null)
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/teammates' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /desktop/machines/{id}/teammates

Set one teammate's access to this Mac (scope: admin)

Requires the owner's unrestricted account-wide personal admin key, including for reads. Team/workspace-fixed, task, app, system and restricted credentials are refused. This goes through a dedicated owner-administration path, not ordinary task or mount grants. The Mac must be online and updated. tier never removes them, ask puts each action to the owner, allowed needs an explicit scope no wider than the owner's own. Any change ends that teammate's running work. The screen, device controls, local agents, Google sign-in, passwords and keychain are never available.

Path parameters:

- `id` (string, required)

Body (application/json):

- `expectedRevision` (integer, required)
- `request_id` (string, required) — pattern ^[a-zA-Z0-9_-]{16,200}$
- `user_id` (string, required)
- `workspace` (string | null, required)
- `name` (string) — max length 120
- `tier` (enum<string>, required) — "never" · "ask" · "allowed"
- `scope` (object)
  - `hostTools` (string[]) — Tools from the fixed teammate list, inside the owner's own approval. — pattern ^[a-z][a-z0-9_]{0,99}$
  - `folderRoots` (string[])
  - `browserOrigins` (string[]) — max length 2048

Responses:

- `200` — OK
  - `available` (boolean, required)
  - `identityReady` (boolean)
  - `revision` (integer, required)
  - `teammates` (object[], required) — Everyone above Never. Anyone not listed is at Never.
    - `user_id` (string, required)
    - `workspace` (string | null, required) — Workspace slug; null is the owner's default workspace.
    - `name` (string)
    - `tier` (enum<string>, required) — "ask" · "allowed"
    - `scope` (object)
      - `hostTools` (string[]) — Tools from the fixed teammate list, inside the owner's own approval. — pattern ^[a-z][a-z0-9_]{0,99}$
      - `folderRoots` (string[])
      - `browserOrigins` (string[]) — max length 2048
  - `offered` (object) — What may be named in a scope: the fixed teammate tools inside the owner's own approval.
  - `activity` (object[], required) — Newest first: who, what and when for every teammate action on this Mac, allowed or not. Never contains call contents.
    - `at` (string, required)
    - `decision` (enum<string>, required) — "allowed" · "denied" · "no_answer" · "removed"
    - `teammateId` (string | null)
    - `teammate` (string | null)
    - `email` (string | null)
    - `workspace` (string | null)
    - `tool` (string | null)
    - `target` (string | null)
    - `action` (string | null)
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/teammates \
  -H "Authorization: Bearer ast_..."
```

### PUT /desktop/teammates

Publish who may ask this Mac (scope: connect token)

Sent by the Mac app with its connect token. Replaces the list of teammates above Never. The list only narrows who may ask: a teammate it leaves out is refused by the platform, and naming one grants nothing, because identity, membership and the Mac's own choice are still checked. 404 while teammate access is off on the platform.

Body (application/json):

- `teammates` (object[], required)
  - `user_id` (string, required)
  - `workspace` (string | null, required)

Responses:

- `204` — Published
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/desktop/teammates \
  -H "Authorization: Bearer ast_..."
```

### GET /desktop/lent-machines

List Macs teammates lend to you (scope: read)

The Macs in one workspace whose owner set you above Never, for asking with POST /desktop/machines/{id}/reach-requests and the same workspace. Requires your own unrestricted key. A Mac that does not name you is not listed. 404 while teammate access is off on the platform.

Query parameters:

- `workspace` (string, required) — The workspace slug you share with the Mac's owner.

Responses:

- `200` — OK
  - `machines` (object[], required)
    - `id` (string, required)
    - `name` (string, required)
    - `online` (boolean, required)
    - `owner` (string, required)
    - `reach` (object | null)
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/desktop/lent-machines?workspace=workspace' \
  -H "Authorization: Bearer ast_..."
```

### GET /desktop/machines/{id}/automation

Read persistent Mac authorization (scope: admin)

Requires the owner's unrestricted account-wide personal admin key, including for reads. Team/workspace-fixed, task, app, system and restricted credentials are refused. This goes through a dedicated owner-administration path, not ordinary task or mount grants. The Mac must be online and updated. Read the current revision and supported authorization choices. Workspaces containing null name the caller's default workspace.

Path parameters:

- `id` (string, required) — Owned Mac machine id, mac_…

Responses:

- `200` — OK
  - `mode` (enum<string>) — This Mac's default permission mode. bypass never asks about the owner's own agents; auto asks only about what leaves the Mac or is hard to undo; manual asks each time. A teammate's agent is always asked about. — "bypass" · "auto" · "manual"
  - `enabled` (boolean)
  - `workspaces` ((string | null)[]) — Use an array containing * for all current and future workspace memberships; null selects the default workspace. Other action scopes remain unchanged. — pattern ^(?:[*]|[A-Za-z0-9_-]{1,200})$
  - `reachKinds` (enum<string>[]) — "folder" · "host" · "browser" · "screen"
  - `hostTools` (string[]) — pattern ^[a-z][a-z0-9_]{0,99}$
  - `folderRoots` (string[])
  - `browserOrigins` (string[]) — max length 2048
  - `deviceAuthorities` (string[]) — pattern ^[a-z][a-z0-9_]{0,99}$
  - `revision` (integer)
  - `identityReady` (boolean)
  - `supportedHostTools` (string[])
  - `supportedDeviceAuthorities` (string[])
  - `supportedReachKinds` (string[])
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/automation' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /desktop/machines/{id}/automation

Configure persistent Mac authorization (scope: admin)

Requires the owner's unrestricted account-wide personal admin key, including for reads. Team/workspace-fixed, task, app, system and restricted credentials are refused. This goes through a dedicated owner-administration path, not ordinary task or mount grants. The Mac must be online and updated. Pass only fields to change, the expectedRevision from a fresh read and a stable request_id reused on retries. Revision conflicts require re-reading; no blind overwrites. Host tools, destinations, folder roots and device authorities are validated by the same native Settings owner. OS grants remain separate.

Path parameters:

- `id` (string, required) — Owned Mac machine id, mac_…

Body (application/json):

- `expectedRevision` (integer, required)
- `request_id` (string, required) — pattern ^[a-zA-Z0-9_-]{16,200}$
- `mode` (enum<string>) — This Mac's default permission mode. bypass never asks about the owner's own agents; auto asks only about what leaves the Mac or is hard to undo; manual asks each time. A teammate's agent is always asked about. — "bypass" · "auto" · "manual"
- `enabled` (boolean)
- `workspaces` ((string | null)[]) — Use an array containing * for all current and future workspace memberships; null selects the default workspace. Other action scopes remain unchanged. — pattern ^(?:[*]|[A-Za-z0-9_-]{1,200})$
- `reachKinds` (enum<string>[]) — "folder" · "host" · "browser" · "screen"
- `hostTools` (string[]) — pattern ^[a-z][a-z0-9_]{0,99}$
- `folderRoots` (string[])
- `browserOrigins` (string[]) — max length 2048
- `deviceAuthorities` (string[]) — pattern ^[a-z][a-z0-9_]{0,99}$

Responses:

- `200` — OK
  - `mode` (enum<string>) — This Mac's default permission mode. bypass never asks about the owner's own agents; auto asks only about what leaves the Mac or is hard to undo; manual asks each time. A teammate's agent is always asked about. — "bypass" · "auto" · "manual"
  - `enabled` (boolean)
  - `workspaces` ((string | null)[]) — Use an array containing * for all current and future workspace memberships; null selects the default workspace. Other action scopes remain unchanged. — pattern ^(?:[*]|[A-Za-z0-9_-]{1,200})$
  - `reachKinds` (enum<string>[]) — "folder" · "host" · "browser" · "screen"
  - `hostTools` (string[]) — pattern ^[a-z][a-z0-9_]{0,99}$
  - `folderRoots` (string[])
  - `browserOrigins` (string[]) — max length 2048
  - `deviceAuthorities` (string[]) — pattern ^[a-z][a-z0-9_]{0,99}$
  - `revision` (integer)
  - `identityReady` (boolean)
  - `supportedHostTools` (string[])
  - `supportedDeviceAuthorities` (string[])
  - `supportedReachKinds` (string[])
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/automation \
  -H "Authorization: Bearer ast_..."
```

### DELETE /desktop/machines/{id}/automation

Disable persistent Mac authorization (scope: admin)

Requires the owner's unrestricted account-wide personal admin key, including for reads. Team/workspace-fixed, task, app, system and restricted credentials are refused. This goes through a dedicated owner-administration path, not ordinary task or mount grants. The Mac must be online and updated. Disables automation and invalidates active permits immediately, retaining configured choices. Requires the current revision and stable retry identity.

Path parameters:

- `id` (string, required) — Owned Mac machine id, mac_…

Body (application/json):

- `expectedRevision` (integer, required)
- `request_id` (string, required) — pattern ^[a-zA-Z0-9_-]{16,200}$

Responses:

- `200` — OK
  - `mode` (enum<string>) — This Mac's default permission mode. bypass never asks about the owner's own agents; auto asks only about what leaves the Mac or is hard to undo; manual asks each time. A teammate's agent is always asked about. — "bypass" · "auto" · "manual"
  - `enabled` (boolean)
  - `workspaces` ((string | null)[]) — Use an array containing * for all current and future workspace memberships; null selects the default workspace. Other action scopes remain unchanged. — pattern ^(?:[*]|[A-Za-z0-9_-]{1,200})$
  - `reachKinds` (enum<string>[]) — "folder" · "host" · "browser" · "screen"
  - `hostTools` (string[]) — pattern ^[a-z][a-z0-9_]{0,99}$
  - `folderRoots` (string[])
  - `browserOrigins` (string[]) — max length 2048
  - `deviceAuthorities` (string[]) — pattern ^[a-z][a-z0-9_]{0,99}$
  - `revision` (integer)
  - `identityReady` (boolean)
  - `supportedHostTools` (string[])
  - `supportedDeviceAuthorities` (string[])
  - `supportedReachKinds` (string[])
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/automation \
  -H "Authorization: Bearer ast_..."
```

### GET /desktop/mounts/{mount}/tools

Read authorized Mac host/device or browser download controls (scope: read)

Lists exact advertised host and device_* names and input schemas from an owned online host mount. A browser mount lists only download, downloads, download_status and cancel_download, matching the REST allowlist; its complete browser MCP catalog remains unchanged. Does not expose a host token or raw IPC. Each operation retains its own authorization; device administration is separately authorized for device_* controls. Offline and revoked mounts fail.

Path parameters:

- `mount` (string, required)

Query parameters:

- `workspace` (string) — Operation workspace slug; empty explicitly selects the owner's default workspace. Omit for the key-fixed workspace, otherwise the Mac enrollment workspace. The server checks key scope, ownership and workspace membership, and bound task workspace. Tool arguments cannot choose authorization scope.

Responses:

- `200` — OK
  - `tools` (object[], required)
    - `name` (string)
    - `description` (string)
    - `inputSchema` (object)
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/desktop/mounts/mount/tools' \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/mounts/{mount}/tools/{tool}

Operate an authorized Mac host/device control (scope: write)

Calls an exact host/device operation, or download, downloads, download_status, cancel_download on an owned browser mount. Browser download arguments are {ref,file_path,replace_existing?}; ref is the current read_page AX ref of an actual download anchor, never a URL. Status/cancel use {download_id}, list uses {}. Download requires current workspace, site and output-folder authorization. Status completion includes output.file_path, size_bytes and sha256. Human downloads are not agent-owned and cannot be cancelled. Cancel returns saving while an admitted native commit awaits its receipt; read download_status for the final receipt. All POST operations, including downloads and download_status, require a personal write key; the GET tools directory requires read scope. Each operation's host, device administration, destination, path and OS permissions remain enforced. A required_action response identifies a permission that needs setup. Reuse the stable request_id when retrying to avoid duplicate writes. Raw IPC names are refused. A tool-level error remains content/isError rather than a claimed success. The whole relay request envelope is limited to 1 MiB, including JSON and base64 expansion.

Path parameters:

- `mount` (string, required)
- `tool` (string, required)

Query parameters:

- `workspace` (string) — Operation workspace slug; empty explicitly selects the owner's default workspace. Omit for the key-fixed workspace, otherwise the Mac enrollment workspace. The server checks key scope, ownership and workspace membership, and bound task workspace. Tool arguments cannot choose authorization scope.

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[a-zA-Z0-9_-]{16,200}$

Responses:

- `200` — OK
  - `content` (object[], required)
  - `isError` (boolean)
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/mounts/mount/tools/tool \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_configure_app_access

Configure Mac app data access (scope: admin)

Change an existing Mac app blocked/unblocked setting. Unblocking does not supply a missing macOS permission. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `app` (enum<string>, required) — "mail" · "notes" · "calendar" · "reminders" · "contacts"
  - `blocked` (boolean, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_configure_app_access \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_configure_blocked_folder

Configure a custom blocked folder (scope: admin)

Add or remove a custom blocked folder. Built-in protected stores remain protected. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `path` (string, required) — max length 4096
  - `blocked` (boolean, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_configure_blocked_folder \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_configure_screen_reach

Configure Mac screen reach (scope: admin)

Enable or disable the existing screen-control setting; separately granted scope and macOS permission still apply. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `allowed` (boolean, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_configure_screen_reach \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_forget_screen_app

Revoke a remembered screen-app decision (scope: admin)

Remove the remembered decision for the exact app bundle id and end current screen reaches using that app. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `bundleId` (string, required) — max length 300
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_forget_screen_app \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_forget_chrome_site

Revoke a remembered Chrome-site decision (scope: admin)

Remove the remembered HTTP or HTTPS origin, end current Chrome reaches using it and wait for their downloads to settle. Browser logins and unrelated reaches remain. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `origin` (string, required) — max length 4096
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_forget_chrome_site \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_configure_setup_files

Configure local setup Files consent (scope: admin)

Set local setup Files consent. This cannot enlarge an ordinary task folder grant. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `allow` (boolean, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_configure_setup_files \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_setup_state

Read Mac environment preparation (scope: admin)

Read setup consent and local CLI preparation state. Each engine reports installed separately from progress. This response does not establish model availability or vendor sign-in. Use a new request_id for each refresh. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace, task, app and restricted credentials are refused. Device account changes stop further installation admission. Remote API-key revocation prevents new requests; an already admitted preparation retains its local account and device lifetime.

Path parameters:

- `id` (string, required)

Query parameters:

- `workspace` (string)

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Current preparation snapshot; completion is reported in status
  - `files` (string)
  - `available` (any)
  - `home` (string)
  - `preparation` (object)
    - `status` (enum<string>, required) — "idle" · "checking" · "installing" · "completed" · "failed" · "cancelled"
    - `engines` (object[], required)
      - `engine` (enum<string>, required) — "claude_code" · "codex"
      - `name` (string, required)
      - `status` (enum<string>, required) — "unknown" · "missing" · "installing" · "installed" · "failed" · "cancelled"
      - `installed` (boolean | null, required) — Last observed installation state. Does not certify model routing or vendor login.
      - `message` (string) — The same installation failure message shown in the Mac interface. — max length 4000
- `400` — Invalid request
- `401` — Authentication required
- `403` — Owner administration required
- `409` — Retry conflict or preparation unavailable
- `503` — Mac offline
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_setup_state \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_prepare_local_agents

Prepare local agent CLIs (scope: admin)

Start or join preparation of the default local agent CLIs. Without model subscriptions, prepare Codex for AgentSky Gateway. Returns progress immediately; poll device_setup_state with fresh request IDs. Reuse this request_id only for a retry. Existing installations are preserved. Model access and billing are checked when starting work. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace, task, app and restricted credentials are refused. Device account changes stop further installation admission. Remote API-key revocation prevents new requests; an already admitted preparation retains its local account and device lifetime.

Path parameters:

- `id` (string, required)

Query parameters:

- `workspace` (string)

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Current preparation snapshot; completion is reported in status
  - `status` (enum<string>, required) — "idle" · "checking" · "installing" · "completed" · "failed" · "cancelled"
  - `engines` (object[], required)
    - `engine` (enum<string>, required) — "claude_code" · "codex"
    - `name` (string, required)
    - `status` (enum<string>, required) — "unknown" · "missing" · "installing" · "installed" · "failed" · "cancelled"
    - `installed` (boolean | null, required) — Last observed installation state. Does not certify model routing or vendor login.
    - `message` (string) — The same installation failure message shown in the Mac interface. — max length 4000
- `400` — Invalid request
- `401` — Authentication required
- `403` — Owner administration required
- `409` — Retry conflict or preparation unavailable
- `503` — Mac offline
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_prepare_local_agents \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_auth_state

Read native Mac sign-in state (scope: admin)

Read native sign-in state without returning credentials or secret login material. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_auth_state \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_cancel_sign_in

Cancel native Mac sign-in (scope: admin)

Cancel the existing pending native sign-in attempt without supplying a new identity. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_cancel_sign_in \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_sign_out

Request native Mac sign-out (scope: admin)

Returns 202 admission with completion pending; sign-out executes only after the acknowledgement. This response does not prove sign-out completed. Reuse the request identity on retry. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `202` — Admitted only; native action runs after acknowledgement, completion is not proven
  - `requested` (true, required)
  - `action` (enum<string>, required) — "sign_out" · "relaunch" · "restart_to_update"
  - `completion` ("pending", required)
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_sign_out \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_available_plans

Read available local subscription providers (scope: admin)

Read providers this Mac can sign in to without starting sign-in or returning credentials. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_available_plans \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_cancel_plan_sign_in

Cancel local subscription sign-in (scope: admin)

Cancel an existing local provider sign-in attempt without accepting credentials. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `provider` (enum<string>, required) — "anthropic" · "openai"
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_cancel_plan_sign_in \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_capture_arena_chart

Export a complete Mac Result or capture a rectangle (scope: admin)

Use target {kind: 'thread-result', threadId} to export every Result row and column through the same DOM-to-PNG owner as Mac Share. The checked workspace query authorizes the thread; target cannot override it. Opens a normal visible window without changing the shared workspace preference. Expected fact reads must settle; read failure or unrevealed blind identity refuses capture. Running status and authorized unknown prices remain unchanged. Navigation, revocation or a changed data revision refuses the request; retry with a new request_id after result_changed. Alternatively supply rect for the existing visible-window capture; rect and target are exclusive. Target returns dataUrl, width, height, bytes and sha256. For large images provide filePath to save directly in an authorized writable folder and receive a saved receipt with bytes/SHA-256. An existing fileId never grants thread access. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - option 1 (object)
    - `rect` (object, required)
      - `x` (integer, required)
      - `y` (integer, required)
      - `width` (integer, required)
      - `height` (integer, required)
    - `filePath` (string) — max length 4096
    - `replaceExisting` (boolean)
  - option 2 (object)
    - `target` (object, required)
      - `kind` ("thread-result", required)
      - `threadId` (string, required) — pattern ^[a-zA-Z0-9_-]{1,200}$
    - `filePath` (string) — max length 4096
    - `replaceExisting` (boolean)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_capture_arena_chart \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_save_arena_chart

Save an Arena chart PNG (scope: admin)

Save a PNG through the native export owner in an authorized writable folder. Supply dataUrl or a workspace fileId with exact sizeBytes and sha256. Upload large files using the existing Files API; their streamed bytes and SHA-256 must match before native commit. Creates a new file unless replaceExisting explicitly requests regular-file replacement; protected paths and symlinks remain refused. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `dataUrl` (string) — max length 1048576
  - `fileId` (string) — pattern ^file_[A-Za-z0-9_-]{1,160}$
  - `sizeBytes` (integer)
  - `sha256` (string) — pattern ^[a-f0-9]{64}$
  - `filePath` (string, required) — max length 4096
  - `replaceExisting` (boolean)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_save_arena_chart \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_configure_local_sync

Configure global local-session sync (scope: admin)

Configure the existing owner-level local sync settings, including destination and exclusions. Explicit sync destinations are independently checked for workspace membership; task grants cannot enable this global setting. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `workspace` (string) — max length 300
  - `enabled` (boolean)
  - `terminal` (boolean)
  - `cloudFolders` (boolean)
  - `config` (boolean)
  - `terminalWorkspace` (string | null) — max length 300
  - `excludedFolders` (string[]) — max length 4096 — pattern ^\/
  - `excludedChats` (string[]) — max length 4096
  - `backfillDays` (integer)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_configure_local_sync \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_relaunch

Request native Mac relaunch (scope: admin)

Returns 202 admission with completion pending; relaunch executes only after acknowledgement. Does not prove that a new process is running. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `202` — Admitted only; native action runs after acknowledgement, completion is not proven
  - `requested` (true, required)
  - `action` (enum<string>, required) — "sign_out" · "relaunch" · "restart_to_update"
  - `completion` ("pending", required)
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_relaunch \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/device_restart_to_update

Request restart to install a downloaded update (scope: admin)

Returns 202 admission with completion pending; restart executes only after acknowledgement. Does not claim an update exists or that a new version is running. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `202` — Admitted only; native action runs after acknowledgement, completion is not proven
  - `requested` (true, required)
  - `action` (enum<string>, required) — "sign_out" · "relaunch" · "restart_to_update"
  - `completion` ("pending", required)
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/device_restart_to_update \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/legacy_drafts_list

List legacy unsent Mac drafts (scope: admin)

List bounded summaries, opaque ids and source version for legacy unsent drafts. Never sends, adopts or assigns ownership automatically. Reuse the page source version for a consistent subsequent page. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `offset` (integer)
  - `limit` (integer)
  - `version` (string) — pattern ^[a-f0-9]{64}$
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/legacy_drafts_list \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/administration/legacy_drafts_adopt

Adopt an explicitly selected legacy draft (scope: admin)

Adopt only the selected opaque draft id into this account unsent drafts through the canonical renderer store. Never sends the content or switches the sidebar or workspace. Requires the authenticated machine owner's unrestricted account-wide personal admin key. Workspace-fixed, team, task, app, system and restricted credentials are refused. Uses the existing fixed owner-administration transport, not ordinary task grants. Native OS permissions, path protections and destination membership remain enforced. No raw IPC or secret-key ingress. Reuse request_id on retry. The complete request remains subject to the relay envelope size limit.

Path parameters:

- `id` (string, required) — Owned Mac machine id

Query parameters:

- `workspace` (string) — Checked operation context; empty selects the owner's default workspace. Global settings still require account-wide owner authority.

Body (application/json):

- `arguments` (object, required)
  - `id` (string, required) — pattern ^[a-f0-9]{64}$
- `request_id` (string, required) — pattern ^[A-Za-z0-9_-]{16,200}$

Responses:

- `200` — Canonical native-owner result; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `413` — Error — { error: { code, message } }
- `502` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/administration/legacy_drafts_adopt \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/machines/{id}/controllers

Ask to control the agents on your Mac (scope: write)

Asks your Mac to let this device or key stop its local runs, answer their permission prompts and follow up. The Mac shows the ask with the same six-digit code returned here; nothing is allowed until the person presses Allow there. The ask lapses after 3 minutes. A device already paired gets its pairing back. 409 mac_offline when the Mac is not connected, 409 required_action when its app is too old, 429 when three asks already wait. Off unless the platform has Mac remote control on for your account. Only your own signed-in device or unrestricted personal key (workspace, task, app, partner and restricted keys answer 403 personal_key_required). A first-party web app names the signed-in browser or phone with the x-agentsky-controller header (SHA-256 of its sign-in session id); any other caller is the API key itself.

Path parameters:

- `id` (string, required) — Your own Mac, mac_…

Body (application/json):

- `label` (string, required) — How the Mac names this device: iPhone, ci-bot. — max length 80

Responses:

- `202` — Asked
  - `controller` (object, required)
    - `id` (string, required)
    - `label` (string, required) — What the Mac shows for this device.
    - `kind` (enum<string>, required) — "session" · "api_key"
    - `status` (enum<string>, required) — "pending" · "active" · "denied" · "expired"
    - `code` (string) — While pending: the code the Mac shows beside the ask, for the person to match. — pattern ^\d{6}$
    - `expires_at` (string) — While pending: when the ask lapses.
    - `current` (boolean, required) — Whether this is the calling device or key.
    - `created_at` (string, required)
    - `last_used_at` (string | null, required)
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `429` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/controllers \
  -H "Authorization: Bearer ast_..."
```

### GET /desktop/machines/{id}/controllers

List the devices that may control your Mac (scope: read)

Active and pending pairings, newest first. A pairing nobody used for 30 days has ended and is not listed. Off unless the platform has Mac remote control on for your account. Only your own signed-in device or unrestricted personal key (workspace, task, app, partner and restricted keys answer 403 personal_key_required). A first-party web app names the signed-in browser or phone with the x-agentsky-controller header (SHA-256 of its sign-in session id); any other caller is the API key itself.

Path parameters:

- `id` (string, required) — Your own Mac, mac_…

Responses:

- `200` — OK
  - `controllers` (object[], required)
    - `id` (string, required)
    - `label` (string, required) — What the Mac shows for this device.
    - `kind` (enum<string>, required) — "session" · "api_key"
    - `status` (enum<string>, required) — "pending" · "active" · "denied" · "expired"
    - `code` (string) — While pending: the code the Mac shows beside the ask, for the person to match. — pattern ^\d{6}$
    - `expires_at` (string) — While pending: when the ask lapses.
    - `current` (boolean, required) — Whether this is the calling device or key.
    - `created_at` (string, required)
    - `last_used_at` (string | null, required)
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/controllers' \
  -H "Authorization: Bearer ast_..."
```

### GET /desktop/machines/{id}/controllers/{controller}

Where an ask to control your Mac stands (scope: read)

With wait (seconds, at most 25) returns as soon as the person allows or denies it on the Mac. Off unless the platform has Mac remote control on for your account. Only your own signed-in device or unrestricted personal key (workspace, task, app, partner and restricted keys answer 403 personal_key_required). A first-party web app names the signed-in browser or phone with the x-agentsky-controller header (SHA-256 of its sign-in session id); any other caller is the API key itself.

Path parameters:

- `id` (string, required) — Your own Mac, mac_…
- `controller` (string, required) — A device or key paired with that Mac, dctl_…

Query parameters:

- `wait` (integer)

Responses:

- `200` — OK
  - `controller` (object, required)
    - `id` (string, required)
    - `label` (string, required) — What the Mac shows for this device.
    - `kind` (enum<string>, required) — "session" · "api_key"
    - `status` (enum<string>, required) — "pending" · "active" · "denied" · "expired"
    - `code` (string) — While pending: the code the Mac shows beside the ask, for the person to match. — pattern ^\d{6}$
    - `expires_at` (string) — While pending: when the ask lapses.
    - `current` (boolean, required) — Whether this is the calling device or key.
    - `created_at` (string, required)
    - `last_used_at` (string | null, required)
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/controllers/controller' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /desktop/machines/{id}/controllers/{controller}

Stop a device from controlling your Mac (scope: write)

Ends the pairing at once; its next control answers 403 controller_not_paired, and the Mac forgets it. Off unless the platform has Mac remote control on for your account. Only your own signed-in device or unrestricted personal key (workspace, task, app, partner and restricted keys answer 403 personal_key_required). A first-party web app names the signed-in browser or phone with the x-agentsky-controller header (SHA-256 of its sign-in session id); any other caller is the API key itself.

Path parameters:

- `id` (string, required) — Your own Mac, mac_…
- `controller` (string, required) — A device or key paired with that Mac, dctl_…

Responses:

- `204` — Removed
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/desktop/machines/sess_cmtb7q2j/controllers/controller \
  -H "Authorization: Bearer ast_..."
```

### PUT /desktop/prompts

The Mac reports the commands waiting on the person (scope: machine connect token)

Sent by the Mac app with every change. Each prompt of a chat the Mac owner syncs becomes a platform approval request on that chat's synced copy (options allow_once and deny, expiresAt the command's deadline, answerableRemotely false), so the chat reads Needs you everywhere; one the Mac no longer lists is closed. A prompt naming another person's session is skipped. The request is answered on the Mac or through POST /desktop/sessions/{id}/prompts/{prompt}/answer by a paired device, never through the generic task request answer (409 answer_on_paired_device). 404 unless the platform has Mac remote control on for the Mac's owner.

Body (application/json):

- `prompts` (object[], required)
  - `prompt_id` (string, required) — pattern ^prm_[A-Za-z0-9-]{1,80}$
  - `session_id` (string, required)
  - `command` (string, required) — max length 4000
  - `deadline_at` (string, required)
  - `answerable_remotely` (boolean, required) — False for keychain and privacy-grant commands, which only the Mac answers.
- `phone_control` (boolean) — Whether Phone control is on on this Mac. Sent together with chats.
- `chats` (object[]) — The Mac's synced chats and whether each runs now. With phone_control, stored as the Mac's report and read back as localControl on each chat; entries naming another person's session are dropped.
  - `session_id` (string, required)
  - `run` (enum<string>, required) — "running" · "idle"

Responses:

- `200` — Written
  - `open` (integer, required)
  - `closed` (integer, required)
- `401` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/desktop/prompts \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/chats

Start a new chat on your Mac (scope: write)

Starts a new chat on your newest online paired Mac with your own Claude Code or Codex, as if typed there, instead of in a cloud sandbox. The Mac picks the folder from the task and the repository named; no path is taken from the caller. Waits up to 25 seconds; the answer carries the synced copy's ids once it opens. accepted false with controller_not_paired, mac_offline, agent_not_installed, agent_signed_out, mac_busy or mac_did_not_answer means start it elsewhere; mac_still_starting means the Mac took it, so do not start it again. Off unless the platform has Mac remote control on for your account. Only your own signed-in device or unrestricted personal key (workspace, task, app, partner and restricted keys answer 403 personal_key_required). A first-party web app names the signed-in browser or phone with the x-agentsky-controller header (SHA-256 of its sign-in session id); any other caller is the API key itself.

Body (application/json):

- `text` (string, required) — max length 100000
- `request_id` (string, required) — Your id for this chat; a retry with the same id starts it once. — max length 200
- `agent` (enum<string>, required) — "claude_code" · "codex"
- `repository` (string) — GitHub owner/name the task is about; the Mac uses it to find the folder.
- `surface` (enum<string>) — "web" · "phone" · "api"

Responses:

- `200` — Started, or why not
  - `accepted` (boolean, required)
  - `machine` (string)
  - `chat_id` (string)
  - `session_id` (string)
  - `playground_id` (string)
  - `reason` (string)
- `400` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/chats \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/sessions/{id}/stop

Stop a chat running on your Mac (scope: write)

Stops the run on the Mac exactly as its Stop button does. Waits up to 15 seconds for the Mac. 403 controller_not_paired unless this device is paired with one of your Macs. Off unless the platform has Mac remote control on for your account. Only your own signed-in device or unrestricted personal key (workspace, task, app, partner and restricted keys answer 403 personal_key_required). A first-party web app names the signed-in browser or phone with the x-agentsky-controller header (SHA-256 of its sign-in session id); any other caller is the API key itself.

Path parameters:

- `id` (string, required) — The synced copy of a chat on your Mac, sess_…

Body (application/json):

- `request_id` (string, required) — Your id for this control; a retry with the same id is carried out once. — max length 200
- `surface` (enum<string>) — "web" · "phone" · "api"

Responses:

- `200` — Carried out, or why not
  - `accepted` (boolean, required)
  - `machine` (string) — The Mac that carried it out.
  - `reason` (enum<string>) — Why nothing happened. Nothing is queued: an offline Mac answers mac_offline at once. — "mac_offline" · "mac_did_not_answer" · "mac_refused" · "not_running" · "prompt_gone" · "already_answered" · "mac_only" · "not_allowed_to_approve" · "phone_control_off" · "not_a_mac_chat" · "terminal" · "not_here" · "not_synced_here" · "controller_not_paired"
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/sessions/sess_cmtb7q2j/stop \
  -H "Authorization: Bearer ast_..."
```

### POST /desktop/sessions/{id}/prompts/{prompt}/answer

Allow or deny a command a chat on your Mac is waiting on (scope: write)

Answers the Mac's "Let the agent run this command on your Mac?" for that run. The first answer wins, on the Mac or here; a prompt the Mac no longer holds answers prompt_gone. Commands that touch the keychain are answered on the Mac only. Off unless the platform has Mac remote control on for your account. Only your own signed-in device or unrestricted personal key (workspace, task, app, partner and restricted keys answer 403 personal_key_required). A first-party web app names the signed-in browser or phone with the x-agentsky-controller header (SHA-256 of its sign-in session id); any other caller is the API key itself.

Path parameters:

- `id` (string, required) — The synced copy of a chat on your Mac, sess_…
- `prompt` (string, required)

Body (application/json):

- `request_id` (string, required) — Your id for this control; a retry with the same id is carried out once. — max length 200
- `surface` (enum<string>) — "web" · "phone" · "api"
- `decision` (enum<string>, required) — "allow" · "deny"

Responses:

- `200` — Carried out, or why not
  - `accepted` (boolean, required)
  - `machine` (string) — The Mac that carried it out.
  - `reason` (enum<string>) — Why nothing happened. Nothing is queued: an offline Mac answers mac_offline at once. — "mac_offline" · "mac_did_not_answer" · "mac_refused" · "not_running" · "prompt_gone" · "already_answered" · "mac_only" · "not_allowed_to_approve" · "phone_control_off" · "not_a_mac_chat" · "terminal" · "not_here" · "not_synced_here" · "controller_not_paired"
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/desktop/sessions/sess_cmtb7q2j/prompts/prompt/answer \
  -H "Authorization: Bearer ast_..."
```

## Artifact sources

### GET /consumer/artifact-workspace-state

Observe exact source workspace lifecycle

Canonical negative lifecycle/provenance protocol, not a content/edit grant or general user-info API. Same actual write caller and concrete source/request/epoch/placement incarnation are checked. proof=caller accepts only source_id/request_id/source_epoch/proof and returns one purpose-bound callback identity/ceiling; it terminates the callback without acquiring leases. Normal proof is a lifecycle observation with opaque source lease keys, never reusable positive permission. purpose defaults to artifact_workspace_write; workspace_reference_write uses explicit real placement and a stable opaque reference key without a fabricated source identity, protecting incarnation/recreation races. ASP is accepted only for its existing concrete publisher source path. App/general system credentials are refused.

Query parameters:

- `purpose` (string)
- `placement_slug` (string)
- `placement_created_at` (string)
- `extra_placement_slug` (string)
- `extra_placement_created_at` (string)
- `session_id` (string)
- `source_id` (string)
- `request_id` (string)
- `source_epoch` (integer)
- `proof` (string)
- `publisher_id` (string)
- `shared_token` (string)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/consumer/artifact-workspace-state' \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-workspace-proofs/{sourceId}

Attest concrete source workspace provenance

Pure source-owner provenance callback: no lease, content write or new account authority. Same real ast_ caller uses the canonical purpose-bound proof=caller branch; existing asp_ authority must match its concrete publisher/source. Owner mapping, placement/session, proposed placement and optional exact shared alias are measured, not caller-assumed.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `purpose` ("artifact_workspace_write", required)
- `request_id` (string, required)
- `source_epoch` (integer, required)
- `publisher_id` (string) — max length 200
- `proposed_placement` (object | null)
  - `slug` (string, required)
  - `created_at` (string, required)
- `shared_token` (string) — pattern ^[A-Za-z0-9_-]{43}$

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-workspace-proofs/sourceId \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-workspace-deletions/{universeId}/begin

Fence sources for the existing workspace deletion

Callback of the sole canonical workspace deletion coordinator, not a second delete action. Reads its exact immutable owner/request/incarnation proof through the fixed first-party origin. No caller-supplied sources, sessions or substitute owner credential. Dedicated owner-session transport is limited to this protocol; it does not broaden generic bearer-only artifact transport.

Path parameters:

- `universeId` (string, required)

Body (application/json):

- `request_id` (string, required)
- `after` (string) — max length 200

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-workspace-deletions/universeId/begin \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-workspace-deletions/{universeId}/finish

Finish verified workspace source cleanup

Exact coordinator callback after source fences and actual canonical reclamation proofs. Finish confirms references_cleaned:true and source_finish_digest===source_fence_digest before Universe purge. No after-response wide cleanup or unknown deletion success. Retry the same request while retaining fences and charges.

Path parameters:

- `universeId` (string, required)

Body (application/json):

- `request_id` (string, required)
- `after` (string) — max length 200

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-workspace-deletions/universeId/finish \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-policy-projections/{sourceId}

Project exact committed policy URL identities

After-commit source routing projection of one canonical immutable policy operation, same actual owner credential and fixed first-party transport. Bearer is preferred with no cookie fallback; the dedicated session path carries only the runtime sessionToken cookie and exact policy purpose headers, never a general Cookie or session_data/admin fields. The source callback uses only the fixed canonical GET/projection UUID, source_epoch and purpose; it reauthenticates the actual owner. No independent policy writer or user action. Superseded never restores old grants; failed current projection yields 503 artifact_policy_projection_pending and same-UUID recovery. Canonical replay of superseded work yields 409 artifact_policy_projection_superseded.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required)
- `source_epoch` (integer, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_epoch` (integer, required)
  - `policy_version` (integer, required)
  - `state` (enum<string>, required) — "projected" · "superseded"
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-policy-projections/sourceId \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-content/{sourceId}/publisher-read-proof

Attest one existing publisher resource read selector

Existing asp_ issuer only; exact target/source/epoch and metadata-or-original selector digest/deterministic UUID. Read-only provenance, no operation persistence, canonical discovery, owner/policy/public/share/comments or general user edit capability. Not a new end-user action.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required)
- `source_epoch` (integer, required)
- `selector_digest` (string, required) — pattern ^[a-f0-9]{64}$
- `kind` (enum<string>, required) — "metadata" · "original"
- `version` (integer | null, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-content/sourceId/publisher-read-proof \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-content/{sourceId}/render-proof

Validate an already issued original renderer seal

Anonymous fixed-source seal attestation for the original renderer's issued short-lived grant. Exact target/source/version/expiry/origin/path are checked; this never mints a seal or grants a Principal, discovery, policy or discussion capability.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `source_id` (string, required) — max length 200
- `grant` (string, required) — max length 4096
- `version` (integer, required)
- `origin` (string, required) — max length 2048
- `path` (string | null, required) — max length 4096
- `original` (boolean, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-content/sourceId/render-proof \
  -H "Authorization: Bearer ast_..."
```

### GET /consumer/artifact-activations/{sourceId}

Read the exact source activation proof (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback.

Path parameters:

- `sourceId` (string, required)

Query parameters:

- `target_id` (string, required)
- `request_id` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_activation", required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `adoption_request_id` (string, required) — max length 120
  - `owner_user_id` (string, required) — max length 200
  - `phase` (enum<string>, required) — "preparing" · "forwarding"
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
  - `binding_epoch` (integer, required)
  - `allhistory_digest` (string, required) — pattern ^[a-f0-9]{64}$
  - `policy_digest` (string, required) — pattern ^[a-f0-9]{64}$
  - `current_version` (integer, required)
  - `retained_count` (integer, required)
  - `name` (string, required) — max length 200
  - `publisher_id` (string, required) — max length 200
  - `session_id` (string | null, required) — max length 200
  - `policy` (object, required)
    - `version` (1, required)
    - `placement` (object | null, required)
      - `slug` (string, required)
      - `created_at` (string, required)
    - `aliases` (object[], required)
      - `id` (string, required) — max length 200
      - `workspace` (object | null, required)
        - `slug` (string, required)
        - `created_at` (string, required)
      - `workspace_access` (enum<string>, required) — "none" · "view" · "edit"
      - `members` (object[], required)
        - `user_id` (string, required) — max length 200
        - `access` (enum<string>, required) — "view" · "edit"
      - `revision` (integer, required)
      - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
      - `shared_token_hash` (string) — pattern ^[a-f0-9]{64}$
    - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
    - `public_version` (integer | null, required)
  - `import_receipt` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/consumer/artifact-activations/sourceId?target_id=target_id&request_id=ask-7f3c2a' \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-activations/{sourceId}

Fence the exact original source (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required) — max length 120

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `purpose` ("consumer_artifact_activation", required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `adoption_request_id` (string, required) — max length 120
  - `owner_user_id` (string, required) — max length 200
  - `phase` (enum<string>, required) — "preparing" · "forwarding"
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required) — pattern ^[a-f0-9]{64}$
  - `binding_epoch` (integer, required)
  - `allhistory_digest` (string, required) — pattern ^[a-f0-9]{64}$
  - `policy_digest` (string, required) — pattern ^[a-f0-9]{64}$
  - `current_version` (integer, required)
  - `retained_count` (integer, required)
  - `name` (string, required) — max length 200
  - `publisher_id` (string, required) — max length 200
  - `session_id` (string | null, required) — max length 200
  - `policy` (object, required)
    - `version` (1, required)
    - `placement` (object | null, required)
      - `slug` (string, required)
      - `created_at` (string, required)
    - `aliases` (object[], required)
      - `id` (string, required) — max length 200
      - `workspace` (object | null, required)
        - `slug` (string, required)
        - `created_at` (string, required)
      - `workspace_access` (enum<string>, required) — "none" · "view" · "edit"
      - `members` (object[], required)
        - `user_id` (string, required) — max length 200
        - `access` (enum<string>, required) — "view" · "edit"
      - `revision` (integer, required)
      - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
      - `shared_token_hash` (string) — pattern ^[a-f0-9]{64}$
    - `public_token_hash` (string) — pattern ^[a-f0-9]{64}$
    - `public_version` (integer | null, required)
  - `import_receipt` (object)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-activations/sourceId \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"target_id":"artifact_target","request_id":"legacy-activation-request-001"}'
```

### GET /consumer/artifact-activations/{sourceId}/history

Page retained source history (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback.

Path parameters:

- `sourceId` (string, required)

Query parameters:

- `target_id` (string, required)
- `request_id` (string, required)
- `after` (integer)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `history_digest` (string, required) — pattern ^[a-f0-9]{64}$
  - `entries` (object[], required)
    - `revision_id` (string, required) — max length 200
    - `request_id` (string, required) — max length 200
    - `base_version` (integer, required)
    - `version` (integer, required)
    - `sha256` (string, required) — pattern ^[a-f0-9]{64}$
    - `size_bytes` (integer, required)
    - `media_type` (string, required) — max length 200
    - `site` (boolean, required)
    - `restored_from` (integer | null, required)
    - `created_at` (string, required)
  - `next` (integer | null, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/consumer/artifact-activations/sourceId/history?target_id=target_id&request_id=ask-7f3c2a' \
  -H "Authorization: Bearer ast_..."
```

### GET /consumer/artifact-activations/{sourceId}/revisions/{version}

Download exact retained source raw bytes (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback.

Path parameters:

- `sourceId` (string, required)
- `version` (integer, required)

Query parameters:

- `target_id` (string, required)
- `request_id` (string, required)

Responses:

- `200` — Exact raw bytes; no-store, attachment and nosniff
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/consumer/artifact-activations/sourceId/revisions/version?target_id=target_id&request_id=ask-7f3c2a' \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-activations/{sourceId}/forward

forward exact source fence (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback. Requires the exact complete canonical import receipt; permanently fences the old writer.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required) — max length 120

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-activations/sourceId/forward \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"target_id":"artifact_target","request_id":"legacy-activation-request-001"}'
```

### POST /consumer/artifact-activations/{sourceId}/cancel

cancel exact source fence (scope: write)

Requires the actual owner's unrestricted personal write bearer or exact first-party agent-use-web bearer, including reads. Select one existing legacy file explicitly. No bulk adoption or independent taskless creation. Default-off rollout gating applies to starting a request; an existing exact request remains recoverable. Import is a one-way boundary: after import, resume forward/activate rather than cancellation. No source content writer fallback. Requires the canonical cancelled receipt; a forwarded source cannot resume its old writer.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required) — max length 120

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-activations/sourceId/cancel \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"target_id":"artifact_target","request_id":"legacy-activation-request-001"}'
```

### POST /consumer/artifact-content/{sourceId}/reserve

reserve exact source capacity admission (scope: write)

The original source admission owner reads same-caller canonical facts for this exact eligible purpose. No caller owner/byte/policy/generation facts. All publishers share its existing Serializable quota aggregate. Claimed admissions never expire on TTL or missing local bytes.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_epoch` (integer, required)
  - `admission_id` (string | null, required) — max length 200
  - `claim_epoch` (integer, required)
  - `phase` (enum<string>, required) — "absent" · "reserved" · "claimed" · "settled" · "reclaimed"
  - `version` (integer | null, required)
  - `canonical_revision_id` (string | null, required) — max length 200
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-content/sourceId/reserve \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"target_id":"artifact_target","request_id":"b73682d8-9745-4f09-ae19-dbf83baed1f3"}'
```

### POST /consumer/artifact-content/{sourceId}/claim

claim exact source capacity admission (scope: write)

The original source admission owner reads same-caller canonical facts for this exact eligible purpose. No caller owner/byte/policy/generation facts. All publishers share its existing Serializable quota aggregate. Claimed admissions never expire on TTL or missing local bytes.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_epoch` (integer, required)
  - `admission_id` (string | null, required) — max length 200
  - `claim_epoch` (integer, required)
  - `phase` (enum<string>, required) — "absent" · "reserved" · "claimed" · "settled" · "reclaimed"
  - `version` (integer | null, required)
  - `canonical_revision_id` (string | null, required) — max length 200
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-content/sourceId/claim \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"target_id":"artifact_target","request_id":"b73682d8-9745-4f09-ae19-dbf83baed1f3"}'
```

### POST /consumer/artifact-content/{sourceId}/settle

settle exact source capacity admission (scope: write)

The original source admission owner reads same-caller canonical facts for this exact eligible purpose. No caller owner/byte/policy/generation facts. All publishers share its existing Serializable quota aggregate. Claimed admissions never expire on TTL or missing local bytes.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_epoch` (integer, required)
  - `admission_id` (string | null, required) — max length 200
  - `claim_epoch` (integer, required)
  - `phase` (enum<string>, required) — "absent" · "reserved" · "claimed" · "settled" · "reclaimed"
  - `version` (integer | null, required)
  - `canonical_revision_id` (string | null, required) — max length 200
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-content/sourceId/settle \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"target_id":"artifact_target","request_id":"b73682d8-9745-4f09-ae19-dbf83baed1f3"}'
```

### POST /consumer/artifact-content/{sourceId}/close

close exact source capacity admission (scope: write)

The original source admission owner reads same-caller canonical facts for this exact eligible purpose. No caller owner/byte/policy/generation facts. All publishers share its existing Serializable quota aggregate. Claimed admissions never expire on TTL or missing local bytes.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required)
  - `source_epoch` (integer, required)
  - `admission_id` (string | null, required) — max length 200
  - `claim_epoch` (integer, required)
  - `phase` (enum<string>, required) — "absent" · "reserved" · "claimed" · "settled" · "reclaimed"
  - `version` (integer | null, required)
  - `canonical_revision_id` (string | null, required) — max length 200
  - `raw_sha256` (string, required) — pattern ^[a-f0-9]{64}$
  - `raw_size_bytes` (integer, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-content/sourceId/close \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"target_id":"artifact_target","request_id":"b73682d8-9745-4f09-ae19-dbf83baed1f3"}'
```

### POST /consumer/artifact-content/{sourceId}/publisher-proof

Attest one existing publisher's exact content operation

Protocol-only issuer attestation using the existing asp_ publisher credential. Not a personal owner or discussion grant; cannot be used to select another publisher or owner. The canonical mutation owner requests this proof with the same credential.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required)
- `source_epoch` (integer, required)
- `operation_digest` (string, required) — pattern ^[a-f0-9]{64}$

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-content/sourceId/publisher-proof \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-content/{sourceId}/public-proof

Validate an existing sealed original public read

Protocol-only anonymous validation of an already issued, unexpired, exact sealed artifact/library grant. This never mints a seal or identity, sharing or discussion authority. Issuer seal creation stays private; no agent command exposes unsafe grant minting.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `source_id` (string, required) — max length 200
- `token` (string, required) — pattern ^[A-Za-z0-9_-]{43}$
- `grant` (string, required) — max length 4096
- `issuer` (enum<string>, required) — "artifact" · "library"
- `version` (integer, required)
- `origin` (string | null, required) — max length 2048
- `path` (string | null, required) — max length 4096
- `original` (boolean, required)

Responses:

- `200` — Exact lifecycle receipt; private, no-store
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-content/sourceId/public-proof \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-adoptions/{sourceId}

Prepare source provenance for your adoption intent (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. Requires the actual source publisher, not a collaborator. Binds the concrete target/request and current content/sharing snapshot under the existing source writer lock. Existing pending bindings cannot be stolen; retire and cancel first. Normal content and sharing writers remain available and invalidate old proofs.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required) — max length 120

Responses:

- `200` — Prepared inactive source proof
  - `purpose` ("consumer_artifact_inactive_adoption", required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `owner_user_id` (string, required) — max length 200
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required)
  - `binding_epoch` (integer, required)
  - `policy_version` (1, required)
  - `phase` ("adoption_pending", required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-adoptions/sourceId \
  -H "Authorization: Bearer ast_..."
```

### GET /consumer/artifact-adoptions/{sourceId}/proof

Read source proof for a concrete adoption intent (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. No targetless eligibility lookup exists. A changed content revision, policy or binding epoch returns 409.

Path parameters:

- `sourceId` (string, required)

Query parameters:

- `target_id` (string, required)
- `request_id` (string, required)

Responses:

- `200` — Current inactive source proof
  - `purpose` ("consumer_artifact_inactive_adoption", required)
  - `source_namespace` ("agent-use", required)
  - `source_id` (string, required) — max length 200
  - `target_id` (string, required) — max length 200
  - `request_id` (string, required) — max length 120
  - `owner_user_id` (string, required) — max length 200
  - `source_version` (integer, required)
  - `source_policy_revision` (string, required)
  - `binding_epoch` (integer, required)
  - `policy_version` (1, required)
  - `phase` ("adoption_pending", required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/consumer/artifact-adoptions/sourceId/proof?target_id=target_id&request_id=ask-7f3c2a' \
  -H "Authorization: Bearer ast_..."
```

### GET /consumer/artifact-adoptions/{sourceId}/upgrade

Read where one file's upgrade stands (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. Derived from durable source and canonical state, so it answers the same after a lost response or a closed window.

Path parameters:

- `sourceId` (string, required)

Responses:

- `200` — Upgrade state
  - `source_id` (string, required)
  - `name` (string, required)
  - `target_id` (string | null, required)
  - `stage` (enum<string>, required) — "ready" · "bound" · "verified" · "copying" · "imported" · "forwarded" · "active" · "stale" · "cancelling"
  - `new_starts_enabled` (boolean) — Absent from a step that copied one version.
  - `can_cancel` (boolean, required)
  - `needs_acceptance` (boolean, required) — The next step needs accept_one_way: true.
  - `current_version` (integer, required)
  - `imported_version` (integer) — The version this step copied; present only on the answer to a copy step.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/consumer/artifact-adoptions/sourceId/upgrade' \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-adoptions/{sourceId}/upgrade

Run the next step of one file's upgrade (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. Runs one idempotent step of the adoption and activation sequence with request ids derived from durable state; call again until `stage` is `active`. Fencing and copying require `accept_one_way: true` because a complete copy cannot be undone. A disabled gate returns 503 not_enabled before anything starts; a changed file reports `stage: stale`, cancel to start over.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `accept_one_way` (boolean)

Responses:

- `200` — Upgrade state after this step
  - `source_id` (string, required)
  - `name` (string, required)
  - `target_id` (string | null, required)
  - `stage` (enum<string>, required) — "ready" · "bound" · "verified" · "copying" · "imported" · "forwarded" · "active" · "stale" · "cancelling"
  - `new_starts_enabled` (boolean) — Absent from a step that copied one version.
  - `can_cancel` (boolean, required)
  - `needs_acceptance` (boolean, required) — The next step needs accept_one_way: true.
  - `current_version` (integer, required)
  - `imported_version` (integer) — The version this step copied; present only on the answer to a copy step.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-adoptions/sourceId/upgrade \
  -H "Authorization: Bearer ast_..." \
  -H "Content-Type: application/json" \
  -d '{"accept_one_way":true}'
```

### POST /consumer/artifact-adoptions/{sourceId}/upgrade/cancel

Cancel one file's upgrade before copying finishes (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. Closes the activation, retires the intent and releases the source, resuming wherever an earlier cancel stopped. A complete copy returns 409: finish it instead. A later upgrade uses new request ids.

Path parameters:

- `sourceId` (string, required)

Responses:

- `200` — Upgrade state after cancelling
  - `source_id` (string, required)
  - `name` (string, required)
  - `target_id` (string | null, required)
  - `stage` (enum<string>, required) — "ready" · "bound" · "verified" · "copying" · "imported" · "forwarded" · "active" · "stale" · "cancelling"
  - `new_starts_enabled` (boolean) — Absent from a step that copied one version.
  - `can_cancel` (boolean, required)
  - `needs_acceptance` (boolean, required) — The next step needs accept_one_way: true.
  - `current_version` (integer, required)
  - `imported_version` (integer) — The version this step copied; present only on the answer to a copy step.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-adoptions/sourceId/upgrade/cancel \
  -H "Authorization: Bearer ast_..."
```

### POST /consumer/artifact-adoptions/{sourceId}/cancel

Clear a retired intent's source binding (scope: write)

Requires an unrestricted personal owner write bearer or a platform-issued agent-use-web consumer bearer. Read-only, restricted, team, app, task, fixed-workspace and workspace-identity credentials are refused. Read and proof operations also require write scope. Ownership comes from the actual bearer and exactly one consumer identity mapping, never an input owner or email. The target stays inactive: no content is copied, no revision is committed and no writer is activated. First retire the canonical target. This clears only the matching source binding and retains a monotonic epoch tombstone; it never deletes content or sharing history. A stale request cannot clear a newer binding.

Path parameters:

- `sourceId` (string, required)

Body (application/json):

- `target_id` (string, required) — max length 200
- `request_id` (string, required) — max length 120

Responses:

- `200` — Cleared binding
  - `source_id` (string, required) — max length 200
  - `adoption_epoch` (integer, required) — Monotonic source fence, advanced even for unbound cancellation. Retries preserve the cancelled end state but may advance this counter; concurrent stale epochs return 409 and require an explicit re-read.
  - `retired` (true, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/consumer/artifact-adoptions/sourceId/cancel \
  -H "Authorization: Bearer ast_..."
```

## Comparisons

### GET /comparisons

List comparisons

The caller's multi-agent comparison threads for this workspace, most recently updated first. `?archived=true` lists archived ones.

Query parameters:

- `archived` (boolean) — true to list archived comparisons.

Responses:

- `200` — OK
  - `comparisons` (object[], required)
    - `id` (string, required)
    - `title` (string, required)
    - `openerText` (string) — The task text the comparison was started on.
    - `columnCount` (integer, required) — Number of agent columns (always ≥ 2 for a comparison).
    - `agents` (object[], required)
      - `columnId` (string, required)
      - `agentType` (string, required)
      - `llm` (string, required)
      - `sessionId` (string) — The platform session this column runs in.
    - `attention` (enum<string>) — "needs_you" · "working" · "done" · "idle" · null
    - `statusLine` (string)
    - `updatedAt` (string, required)
    - `archived` (boolean, required)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/comparisons' \
  -H "Authorization: Bearer ast_..."
```

### POST /comparisons

Create a comparison

Start a new side-by-side comparison: send one task to the main agent and one or more agents in `compare` simultaneously. `requestId` makes a retry safe.

Body (application/json):

- `requestId` (string, required) — Idempotency key (16–100 alphanumeric/dash/underscore).
- `agentType` (string, required) — The main agent's harness type.
- `llm` (string, required) — The main agent's model.
- `reasoningEffort` (string) — Optional thinking level for the main agent.
- `task` (string, required) — The task text sent to every agent.
- `compare` (object[], required) — One or more additional agents to compare against (each with agentType and llm).
  - `agentType` (string, required)
  - `llm` (string, required)
  - `reasoningEffort` (string)
- `capabilities` (string[]) — Tool ids to grant every agent (all by default).
- `timezone` (string) — IANA timezone for the session.

Responses:

- `201` — Comparison created.
  - `comparisonId` (string, required)
  - `columns` (object[], required)
    - `columnId` (string)
    - `sessionId` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/comparisons \
  -H "Authorization: Bearer ast_..."
```

### GET /comparisons/{comparisonId}

Get a comparison

One comparison: its task, each agent's column and session, status, and the verdict once the person has picked a winner. Columns in a blind Arena match return masked agent/model fields until the pick is recorded.

Path parameters:

- `comparisonId` (string, required)

Responses:

- `200` — OK
  - `id` (string, required)
  - `title` (string)
  - `openerText` (string)
  - `createdAt` (string)
  - `updatedAt` (string)
  - `columns` (object[], required)
    - `columnId` (string)
    - `sessionId` (string)
    - `agentType` (string) — Harness id (e.g. "dsh"), as POST /comparisons takes it; "unknown" while the match hides identities.
    - `llm` (string) — Model id; empty while the match hides identities.
    - `name` (string) — Display label, e.g. "DeepSeek Harness · DeepSeek V4.1 Flash"; null while identities are hidden.
    - `podStatus` (string)
  - `arena` (object) — Present when this comparison has an associated Arena match.
    - `kind` (string) — "comparison" for named side-by-side; other values are blind Arena.
    - `status` (string)
    - `hidden` (boolean) — Identities are hidden while the match is pending.
    - `pending` (boolean)
  - `vote` (object)
    - `outcome` (string)
    - `winnerSessionId` (string)
    - `sealed` (boolean)
    - `why` (string[])
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/comparisons/comparisonId' \
  -H "Authorization: Bearer ast_..."
```

### POST /comparisons/{comparisonId}/pick

Pick a winner

Record the person's winner pick for this comparison. Writes a `human.decision` event to every session's record, as the web UI does.

Blind Arena matches use `POST /arena/personal/{id}/vote`, which preserves owned-workspace checks, blind identity masking, one verdict and billing release. This ordinary comparison-pick route still refuses those matches (`arena.kind !== "comparison"`).

Path parameters:

- `comparisonId` (string, required)

Body (application/json):

- `winnerColumnId` (string) — The columnId of the winning column. Omit to record a tie or "none of these".
- `outcome` (enum<string>) — "tie" or "both_bad" when there is no winner; ignored when winnerColumnId is set. — "tie" · "both_bad"

Responses:

- `200` — Pick recorded.
  - `comparisonId` (string, required)
  - `winnerSessionId` (string)
  - `revealed` (boolean, required)
  - `seats` (object[], required)
    - `sessionId` (string)
    - `agentType` (string)
    - `llm` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/comparisons/comparisonId/pick \
  -H "Authorization: Bearer ast_..."
```

### GET /comparison-shares/{token}

Read a published comparison

The stored comparison a `/c/{token}` page draws: the task and each agent's engine, model, cost, tokens, time, completion and answer. No cookie or API key is required; the token is the only authority. New comparisons can no longer be published, and links already published keep reading.

Path parameters:

- `token` (string, required)

Responses:

- `200` — OK
  - `prompt` (string, required)
  - `createdAt` (string, required)
  - `entries` (object[], required)
    - `engine` (string, required)
    - `llm` (string, required)
    - `costUsd` (number)
    - `tokens` (integer)
    - `durationMs` (integer)
    - `completed` (boolean)
    - `answer` (string)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/comparison-shares/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0' \
  -H "Authorization: Bearer ast_..."
```

### GET /comparison-shares/{token}/card

Download a published comparison's card

The stored PNG a `/c/{token}` page uses as its preview image. No cookie or API key is required.

Path parameters:

- `token` (string, required)

Responses:

- `200` — The card
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/comparison-shares/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0/card' \
  -H "Authorization: Bearer ast_..."
```

## Threads

### GET /threads

List threads

The caller's conversation threads for this workspace (single-agent and multi-agent alike), as the sidebar rail shows them, each with its `status`. `?filter=all` includes archived threads; `?archived=true` lists only archived ones; `?order=status` puts what waits on the caller first.

Query parameters:

- `filter` (string) — Which threads to include. Default: active.
- `archived` (boolean) — Shorthand for filter=archived.
- `order` (string) — `recent` (default): most recently updated first. `status`: what waits on the caller first, by `status` (needs_you, failed, running, done, idle, then unknown), most recently updated first inside each.

Responses:

- `200` — OK
  - `threads` (object[], required)
    - `id` (string, required)
    - `title` (string, required)
    - `openerText` (string)
    - `columnCount` (integer, required)
    - `agents` (object[], required)
      - `columnId` (string, required)
      - `agentType` (string, required)
      - `llm` (string, required)
      - `sessionId` (string)
    - `attention` (enum<string>) — "needs_you" · "working" · "done" · "idle" · null
    - `status` (enum<string>) — Where the thread stands for the caller. `needs_you`: a request, mention, assignment or a reply opening "Needs you:" waits on the caller. `failed`: a run ran out of retries since the caller last looked and nothing else asks them; `statusLine` is its message. `running`: an agent is working, or only someone else is asked. `done`: a result the caller has not seen. `idle`: nothing new. Null when the platform's state could not be read. — "needs_you" · "failed" · "running" · "done" · "idle" · null
    - `statusLine` (string)
    - `working` (boolean, required)
    - `updatedAt` (string, required)
    - `archived` (boolean, required)
    - `pinned` (boolean, required)
    - `deleting` (boolean) — Deletion has started and not finished. While true the thread cannot be changed and a write answers 409.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads' \
  -H "Authorization: Bearer ast_..."
```

### POST /threads

Start a thread

Start a thread and send it its first message, as the web composer does: one agent, or several to compare when `compare` names more. The thread is created in the workspace the key works in (a team workspace key's own, or `X-Universe` for a personal key) unless `workspace` names one; naming a different workspace than the key works in is refused with `workspace_mismatch`. `requestId` makes a retry safe: the same id and body replay the first outcome. `holdOpener` creates the thread without sending anything, so its first `POST /threads/{id}/messages` becomes the opener.

Body (application/json):

- `requestId` (string, required) — Idempotency key (16–100 letters, digits, dashes or underscores).
- `agentType` (string, required) — The agent's harness type.
- `llm` (string) — The model; the harness default when omitted.
- `reasoningEffort` (string) — Thinking level the model supports.
- `text` (string) — The first message. Required unless `files` or `holdOpener` is given.
- `files` (object[]) — Up to 20 uploads (from `POST /files`) sent with the first message.
  - `id` (string, required)
  - `name` (string, required)
  - `mediaType` (string, required)
- `compare` (object[]) — More agents that receive the same first message, side by side.
  - `agentType` (string, required)
  - `llm` (string)
  - `reasoningEffort` (string)
- `capabilities` (string[]) — Tool ids to grant (all available ones when omitted).
- `agentId` (string) — One of the caller's saved agents to run on, with its own tools and skills.
- `project` (object) — A GitHub repository and branch mounted into the session: `{repoFullName, branch}`.
- `machineMount` (object) — A folder a Mac lent through This Mac.
- `browserMount` (object) — A browser window a Mac lent through This Mac.
- `screenMount` (object) — A screen a Mac lent through This Mac.
- `workspace` (string) — Team workspace slug; defaults to the workspace the key works in.
- `interactionMode` (enum<string>) — Send the first message in Plan or Build mode. — "plan" · "build"
- `holdOpener` (boolean) — Create the thread without sending a message yet.
- `importId` (string) — Continue a conversation imported from a local agent.
- `timezone` (string) — IANA timezone for the session.

Responses:

- `201` — Thread started.
  - `playgroundId` (string, required) — The new thread's id.
  - `columns` (object[], required)
    - `columnId` (string)
    - `sessionId` (string)
  - `undelivered` (string[])
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/snapshots/{token}

Read a shared conversation snapshot

The read-only snapshot a `/share/{token}` page draws, by the 43-character token in its URL. No cookie or API key is required, and a key sent adds nothing: the token is the only authority and grants the snapshot alone, not the thread it came from. Answers 404 once the owner revokes the link or deletes the thread. Message text is redacted as on the page. A thread's view link has a shorter token and needs a signed-in reader: read it with `GET /links/{token}/events`.

Path parameters:

- `token` (string, required)

Responses:

- `200` — OK
  - `threadId` (string, required)
  - `sessionId` (string, required)
  - `title` (string, required)
  - `createdAt` (string, required)
  - `messages` (object[], required)
    - `id` (string, required)
    - `role` (enum<string>, required) — "user" · "agent"
    - `text` (string, required)
  - `sourceUrl` (string, required) — The original thread; opening it needs access to that thread.
  - `access` (enum<string>, required) — "read-only snapshot"
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/snapshots/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0' \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/{id}

Read a thread

One thread with every agent: each column's `sessionId` is the platform session its conversation is read from, `universe` the team workspace that session belongs to. While a comparison hides who is who, an agent is only its letter (`blind`). `fork` says where a forked agent's session came from and whether its copy landed; `importId` names the import that opens its conversation.

Path parameters:

- `id` (string, required) — Thread id.

Responses:

- `200` — OK
  - `id` (string, required)
  - `title` (string, required)
  - `openerText` (string)
  - `updatedAt` (string)
  - `comparison` (object) — Set for a thread that compares agents: `{kind, pending, hidden, ended, browser}`.
  - `columns` (object[], required)
    - `id` (string) — Column id.
    - `sessionId` (string)
    - `name` (string)
    - `agentType` (string)
    - `llm` (string)
    - `reasoningEffort` (string)
    - `podStatus` (string)
    - `status` (string)
    - `universe` (string)
    - `blind` (boolean)
    - `fork` (object) — Where this agent's session was forked from, when it was. `pending` while the conversation is still being copied in; `failed` is the platform's reason when the copy did not complete; `continuedFrom` names the Mac chat it continues. Null on an agent a comparison hides.
      - `sourcePlaygroundId` (string)
      - `sourceColumnId` (string)
      - `sourceSessionId` (string)
      - `pending` (boolean)
      - `failed` (string)
      - `continuedFrom` (object)
        - `kind` (enum<string>) — "mac"
        - `folder` (string)
        - `owner` (string)
    - `importId` (string) — The import whose turns open this agent's conversation, shown above its own turns. `GET /imports/{id}` answers `mirror_session_id`, and `GET /sessions/{id}/events` on that session reads those turns.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /threads/{id}

Rename, pin, archive or mark a thread read

Rename, pin, archive, unarchive, or mark a thread read or unread, as the web rail's row menu does. Any of `title`, `pinned`, `archived`, `seen`; the fields given are applied in that order.

Path parameters:

- `id` (string, required) — Thread id.

Body (application/json):

- `title` (string)
- `pinned` (boolean)
- `archived` (boolean)
- `seen` (boolean)

Responses:

- `200` — OK
  - `updated` (boolean)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/threads/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### DELETE /threads/{id}

Delete a thread

Delete the thread with its sessions.

Path parameters:

- `id` (string, required) — Thread id.

Responses:

- `200` — OK
  - `deleted` (boolean)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/threads/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### POST /threads/{id}/messages

Send a message to a thread

Send one message to every agent of the thread, or to the ones `columnIds` names, as the web composer does. `deliveryId` (a UUID) names the send, so a retry reaches the same agents once. The answer says, per agent, whether it took the message.

Path parameters:

- `id` (string, required) — Thread id.

Body (application/json):

- `text` (string)
- `deliveryId` (string, required)
- `columnIds` (string[])
- `files` (object[])
- `interactionMode` (enum<string>) — "plan" · "build"
- `timezone` (string)

Responses:

- `200` — OK
  - `results` (map<string, object>)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/messages \
  -H "Authorization: Bearer ast_..."
```

### POST /threads/{id}/agents

Add an agent to a thread

Add one more agent beside the thread's others, in a session of its own, with no message sent to it. The same `requestId` replays the first outcome.

Path parameters:

- `id` (string, required) — Thread id.

Body (application/json):

- `requestId` (string, required)
- `agentType` (string, required)
- `llm` (string)
- `reasoningEffort` (string)
- `timezone` (string)

Responses:

- `201` — OK
  - `columns` (object[])
    - `columnId` (string)
    - `sessionId` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/agents \
  -H "Authorization: Bearer ast_..."
```

### DELETE /threads/{id}/agents/{columnId}

Remove an agent from a thread

Take one agent out of the thread, as the web's column menu does. Its session is left as it is.

Path parameters:

- `id` (string, required) — Thread id.
- `columnId` (string, required) — The column id of the agent.

Responses:

- `200` — OK
  - `removed` (boolean)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/threads/agent_cmtb2f0a8m9k7x51q4ez6r0d/agents/columnId \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/{id}/tools

Read a thread agent's tools

The tools turned off in one agent's environment.

Path parameters:

- `id` (string, required) — Thread id.

Query parameters:

- `column` (string) — The agent (column id); the first agent of the thread when omitted.

Responses:

- `200` — OK
  - `envId` (string)
  - `disabled` (string[])
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/tools' \
  -H "Authorization: Bearer ast_..."
```

### PUT /threads/{id}/tools

Replace a thread agent's tools

Replace the environment's list of turned-off tools. Only environment-scoped tool ids are accepted; tools the agent itself owns are read-only.

Path parameters:

- `id` (string, required) — Thread id.

Body (application/json):

- `envId` (string, required)
- `disabled` (string[], required)

Responses:

- `200` — OK
  - `disabled` (string[])
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/tools \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/{id}/engine

Read a thread agent's model

What one of the thread's agents runs on now: its model, effective thinking level and mounted repository. Refused while a comparison hides who is who.

Path parameters:

- `id` (string, required) — Thread id.

Query parameters:

- `column` (string) — The agent (column id); the first agent of the thread when omitted.

Responses:

- `200` — OK
  - `agentType` (string)
  - `llm` (string)
  - `reasoningEffort` (string)
  - `project` (object)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/engine' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /threads/{id}/engine

Change a thread agent's model

Change the model (`llm`) or the thinking level (`reasoningEffort`, null for the default of the model) of one agent, as the pickers on the web do. Applies from its next turn.

Path parameters:

- `id` (string, required) — Thread id.

Query parameters:

- `column` (string) — The agent (column id); the first agent of the thread when omitted.

Body (application/json):

- `llm` (string)
- `reasoningEffort` (string)

Responses:

- `200` — OK
  - `llm` (string)
  - `reasoningEffort` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/engine \
  -H "Authorization: Bearer ast_..."
```

### POST /threads/{id}/interrupt

Stop a thread

Stop whatever the thread's agents are doing; `columnId` stops only that agent.

Path parameters:

- `id` (string, required) — Thread id.

Body (application/json):

- `columnId` (string)

Responses:

- `200` — OK
  - `interrupted` (boolean)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/interrupt \
  -H "Authorization: Bearer ast_..."
```

### POST /threads/{id}/fork

Fork a thread

Continue one agent's conversation in a thread of its own, on a computer of its own. `columnId` names the agent (the first when omitted); `target` (`{agentType, llm?, reasoningEffort?}` or `{agentId, llm?}`) moves it to another agent or model; `messageId` stops the carried conversation at that message. Asking again with the same `requestId` after `fork_pending` resumes the fork.

Path parameters:

- `id` (string, required) — Thread id.

Body (application/json):

- `requestId` (string, required)
- `columnId` (string)
- `messageId` (string)
- `target` (object)

Responses:

- `201` — OK
  - `playgroundId` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/fork \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/{id}/artifacts

List a thread's artifacts

The artifacts the thread's agents have saved, oldest first, each at the version it serves today.

Path parameters:

- `id` (string, required) — Thread id.

Responses:

- `200` — OK
  - `artifacts` (object[])
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/artifacts' \
  -H "Authorization: Bearer ast_..."
```

### POST /threads/experiences

Start a catalog experience thread (scope: write)

The same Mac/web experience owner and turn admission. Personal API key with write scope, using its verified workspace or X-Universe. Reuse requestId on retries: a failed admitted turn retains its existing playgroundId rather than minting a second thread. No body workspace override is accepted.

Body (application/json):

- `experience` (string, required)
- `text` (string, required) — max length 20000
- `requestId` (string, required) — pattern ^[a-zA-Z0-9_-]{16,100}$
- `timezone` (string)

Responses:

- `201` — Started thread
  - `playgroundId` (string, required)
  - `sessionId` (string, required)
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Admission failed after a thread was retained; response includes playgroundId for recovery
  - `error` (object, required)
    - `code` (string, required) — Stable machine-readable condition; branch on this, never on message.
    - `message` (string, required) — What went wrong and how to fix it, for people. May change.
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads/experiences \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/search

Search conversations

Search the words of the caller's conversations, as the web's search does. One page covers one agent's conversation; `nextCursor` is null once every conversation has been read.

Query parameters:

- `q` (string) — 3 to 200 characters.
- `threads` (string) — active, archived or all.
- `cursor` (string) — The cursor of the page before.

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `502` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/search' \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/options

Thread start options

What a new thread can start on, as the composer offers it: each agent (with `acp` when it picks its model in its own account), its models with their thinking levels and the plan provider that can run each, the tool groups a person can grant, and the tools a new agent starts with. Use it to fill `POST /threads`.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/options' \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/joinable

List joinable threads

Threads the caller can open but has not: teammates' threads in the workspace `workspace` names (one they belong to), and threads shared with them. A list the platform did not answer for is null rather than empty.

Query parameters:

- `workspace` (string) — A team workspace slug.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/joinable' \
  -H "Authorization: Bearer ast_..."
```

### POST /threads/joinable

Open a teammate's thread

Open a thread someone else started, by the rule the web's session link follows. An owner or a member of its workspace gets a thread of their own on that session (`playgroundId`, `columnId`); someone it was only shared with to read gets `readOnly` with the session to read.

Body (application/json):

- `sessionId` (string, required)

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads/joinable \
  -H "Authorization: Bearer ast_..."
```

### POST /threads/{id}/continue-mirrored

Continue a Mac-synced chat in the cloud

Continue a chat synced from a Mac (the agent `columnId` names, the first when omitted) in the cloud, from the transcript the platform already holds, with `text` (and optional `files`) as the new session's first message, as a send on the web does. It stays the same chat: the new session's history starts with the synced conversation and `playgroundId` is this thread. The chat's owner and any workspace member who may use it can continue it; the new session is the caller's. Works with the Mac offline; calling this route is itself the choice to continue in the cloud. With `askFirst: true`, a caller that can show the person a question gets 409 `continue_needs_answer` (with `reason`, and a `message` naming why) instead of a silent move, and calls again without `askFirst` once the person says yes. 409 `continue_pending` means ask again with the same `requestId`; 422 `not_mirrored` when the chat did not come from a Mac.

Path parameters:

- `id` (string, required) — Thread id.

Body (application/json):

- `requestId` (string, required)
- `text` (string)
- `files` (object[])
- `columnId` (string)
- `timezone` (string)
- `askFirst` (boolean)

Responses:

- `201` — OK
  - `playgroundId` (string)
  - `sessionId` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads/sess_cmtb7q2j/continue-mirrored \
  -H "Authorization: Bearer ast_..."
```

### GET /threads/continue

Can a local chat continue in the cloud

Whether the caller can continue a chat from their computer in the cloud, and the largest session archive the platform takes. 404 while it is off.

Responses:

- `200` — OK
  - `available` (boolean)
  - `maxArchiveBytes` (integer)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/threads/continue' \
  -H "Authorization: Bearer ast_..."
```

### POST /threads/continue

Continue a local chat in the cloud

Continue a chat that ran on the caller's computer (Claude Code or Codex) as a cloud thread of its own. `native.archive` (base64) resumes the same harness's session from its checkpoint; `transcript` (`{path, sha256, bytes}`) starts any agent knowing where the transcript will be put. 409 `continue_pending` means ask again with the same body.

Body (application/json):

- `requestId` (string, required)
- `agentType` (string, required)
- `llm` (string)
- `reasoningEffort` (string)
- `title` (string)
- `requestedAt` (string, required)
- `source` (object, required)
  - `harness` (enum<string>) — "claude_code" · "codex"
  - `nativeSessionId` (string)
  - `harnessVersion` (string)
- `native` (object)
  - `archive` (string)
- `transcript` (object)
  - `path` (string)
  - `sha256` (string)
  - `bytes` (integer)

Responses:

- `201` — OK
  - `playgroundId` (string)
  - `sessionId` (string)
  - `mode` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/threads/continue \
  -H "Authorization: Bearer ast_..."
```

## Library artifacts

### GET /library/links

Read sharing settings for an original Library file (scope: read)

Read-only: an unshared file returns id=null and revision=0. Membership and original source access are checked. All file kinds use the same link settings; bytes are never copied into a new artifact. Fixed-workspace credentials receive only their selected audience link, without cross-workspace artifact sharing metadata.

Query parameters:

- `ref` (string, required) — JSON LibraryFileRef.
- `workspace` (string) — The team audience for this link; omit for private/public-only sharing. The original file stays in place. A workspace-scoped key cannot select another audience.

Responses:

- `200` — Current settings and real workspace members
  - `artifact` (object) — For consumer artifacts: effective sharing across the legacy public link, workspace placement and all original-file grants; public links share one pinned version.
    - `enabled` (boolean)
    - `sharingRevision` (string)
    - `revision` (integer)
    - `publicVersion` (integer)
    - `url` (string)
    - `workspace` (object)
    - `versions` (object[])
    - `grants` (object[])
  - `link` (any, required)
  - `availableMembers` (object[], required)
    - `userId` (string, required)
    - `name` (string, required)
    - `email` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/links?ref=ref' \
  -H "Authorization: Bearer ast_..."
```

### PUT /library/links

Share, publish or update grants on an original Library file (scope: write)

Compare-and-set revision (0 for initial state); stale settings return 409. Public access is view-only. Edit grants require native source editing. Member grants bind current platform member identities. No workspace permits private/public only. Revoking publicEnabled invalidates the URL; publishing again mints a new URL. For unrestricted owners, consumer-artifact public access is shared with the legacy artifact share API; disabling it revokes every public alias while preserving authenticated member grants. Fixed-workspace credentials update only their selected audience link. Public artifact URLs honor the artifact pin; authenticated member URLs follow latest.

Body (application/json):

- `ref` (object, required)
  - option 1 (object)
    - `kind` (enum<string>, required) — "agent_prompt"
    - `agentId` (string, required) — The original agent user instruction file (AGENTS.md); never the combined runtime/system prompt.
  - option 2 (object)
    - `kind` (enum<string>, required) — "file"
    - `fileId` (string, required)
    - `sessionId` (string)
  - option 3 (object)
    - `kind` (enum<string>, required) — "task_file"
    - `taskId` (string, required)
    - `path` (string, required)
  - option 4 (object)
    - `kind` (enum<string>, required) — "memory_note"
    - `storeId` (string, required)
    - `memoryId` (string, required)
  - option 5 (object)
    - `kind` (enum<string>, required) — "skill_file"
    - `skillId` (string, required)
    - `path` (string, required)
  - option 6 (object)
    - `kind` (enum<string>, required) — "artifact"
    - `artifactId` (string, required)
  - option 7 (object)
    - `kind` (enum<string>, required) — "platform_artifact"
    - `artifactId` (string, required)
    - `path` (string) — Exact full path from the native artifact manifest; DesignSystem files use root plus the relative editable_files path. Omit only for the entire artifact entry.
- `workspace` (string)
- `revision` (integer, required)
- `sharingRevision` (string) — For consumer artifacts, the whole sharing revision returned by artifact.sharingRevision. Supply it to reject concurrent changes in another workspace or the legacy share API. — pattern ^[a-f0-9]{64}$
- `workspaceAccess` (enum<string>, required) — "none" · "view" · "edit"
- `publicEnabled` (boolean, required)
- `guests` (object[]) — People outside the workspace, by address. They open the shared link signed in to an AgentSky account verified for it, and only view. Left out, the current guests stay.
  - `email` (string, required)
  - `access` (enum<string>, required) — "view"
- `members` (object[], required)
  - `userId` (string, required)
  - `access` (enum<string>, required) — "view" · "edit"

Responses:

- `200` — Updated settings
  - `artifact` (object) — For consumer artifacts: effective sharing across the legacy public link, workspace placement and all original-file grants; public links share one pinned version.
    - `enabled` (boolean)
    - `sharingRevision` (string)
    - `revision` (integer)
    - `publicVersion` (integer)
    - `url` (string)
    - `workspace` (object)
    - `versions` (object[])
    - `grants` (object[])
  - `link` (any, required)
  - `availableMembers` (object[], required)
    - `userId` (string, required)
    - `name` (string, required)
    - `email` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/library/links \
  -H "Authorization: Bearer ast_..."
```

### DELETE /library/links

Revoke all access granted by a Library link (scope: write)

An unrestricted owner revoking a consumer artifact stops public sharing, all workspace/member links and workspace placement in one transaction. Fixed-workspace credentials remain limited to revoking their own audience grant, including after source access or membership is lost. Supply sharingRevision for whole-artifact compare-and-swap.

Body (application/json):

- `ref` (object, required)
  - option 1 (object)
    - `kind` (enum<string>, required) — "agent_prompt"
    - `agentId` (string, required) — The original agent user instruction file (AGENTS.md); never the combined runtime/system prompt.
  - option 2 (object)
    - `kind` (enum<string>, required) — "file"
    - `fileId` (string, required)
    - `sessionId` (string)
  - option 3 (object)
    - `kind` (enum<string>, required) — "task_file"
    - `taskId` (string, required)
    - `path` (string, required)
  - option 4 (object)
    - `kind` (enum<string>, required) — "memory_note"
    - `storeId` (string, required)
    - `memoryId` (string, required)
  - option 5 (object)
    - `kind` (enum<string>, required) — "skill_file"
    - `skillId` (string, required)
    - `path` (string, required)
  - option 6 (object)
    - `kind` (enum<string>, required) — "artifact"
    - `artifactId` (string, required)
  - option 7 (object)
    - `kind` (enum<string>, required) — "platform_artifact"
    - `artifactId` (string, required)
    - `path` (string) — Exact full path from the native artifact manifest; DesignSystem files use root plus the relative editable_files path. Omit only for the entire artifact entry.
- `workspace` (string)
- `revision` (integer, required)
- `sharingRevision` (string) — pattern ^[a-f0-9]{64}$

Responses:

- `200` — Revoked settings
  - `artifact` (object) — For consumer artifacts: effective sharing across the legacy public link, workspace placement and all original-file grants; public links share one pinned version.
    - `enabled` (boolean)
    - `sharingRevision` (string)
    - `revision` (integer)
    - `publicVersion` (integer)
    - `url` (string)
    - `workspace` (object)
    - `versions` (object[])
    - `grants` (object[])
  - `link` (any, required)
  - `availableMembers` (object[], required)
    - `userId` (string, required)
    - `name` (string, required)
    - `email` (string, required)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/library/links \
  -H "Authorization: Bearer ast_..."
```

### GET /library/public/{token}

Read a publicly shared original Library file

No cookie or API key is required. Returns a view-only document snapshot; raw=1 or download=1 streams the original bytes with Range support. Source-owner permissions and link revocation are rechecked for every request. Transport URLs stay server-side. A path query is rejected: the token reads only the granted original file, not its siblings.

Path parameters:

- `token` (string, required)

Query parameters:

- `raw` (string)
- `download` (string)

Responses:

- `200` — Snapshot or original file bytes
  - `name` (string, required)
  - `format` (enum<string>, required) — "file" · "site"
  - `mediaType` (string, required)
  - `revision` (string, required)
  - `editable` (boolean, required)
  - `url` (string, required) — Same API path with raw=1; the original bytes, never a storage credential.
  - `maxBytes` (integer, required)
  - `text` (string)
  - `html` (string)
  - `office` (string) — Native Office source bytes as base64 when supported.
  - `history` (object[], required)
  - `previewUrl` (string) — Isolated browser preview when the reader has the required browser session, or the link is public.
  - `previewUnavailable` (string)
  - `sizeBytes` (integer)
  - `sharedBy` (string)
  - `libraryRef` (object) — Canonical original file identity when supplied by its native document reader; the link still supplies authorization.
    - option 1 (object)
      - `kind` (enum<string>, required) — "agent_prompt"
      - `agentId` (string, required) — The original agent user instruction file (AGENTS.md); never the combined runtime/system prompt.
    - option 2 (object)
      - `kind` (enum<string>, required) — "file"
      - `fileId` (string, required)
      - `sessionId` (string)
    - option 3 (object)
      - `kind` (enum<string>, required) — "task_file"
      - `taskId` (string, required)
      - `path` (string, required)
    - option 4 (object)
      - `kind` (enum<string>, required) — "memory_note"
      - `storeId` (string, required)
      - `memoryId` (string, required)
    - option 5 (object)
      - `kind` (enum<string>, required) — "skill_file"
      - `skillId` (string, required)
      - `path` (string, required)
    - option 6 (object)
      - `kind` (enum<string>, required) — "artifact"
      - `artifactId` (string, required)
    - option 7 (object)
      - `kind` (enum<string>, required) — "platform_artifact"
      - `artifactId` (string, required)
      - `path` (string) — Exact full path from the native artifact manifest; DesignSystem files use root plus the relative editable_files path. Omit only for the entire artifact entry.
- `206` — Requested original-file byte range
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/public/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0' \
  -H "Authorization: Bearer ast_..."
```

### GET /library/shared/{token}

Read an original Library file shared with the API caller (scope: read)

Uses the caller's personal ast_ key, never a browser cookie. Requires the exact workspace membership and individual grant or workspace access. A workspace-scoped key cannot act in another audience workspace. raw=1 or download=1 streams original bytes. JSON snapshots expose source text or native Office bytes; private isolated browser grants require a browser login. A path query is rejected; choose the exact original file in the link ref.

Path parameters:

- `token` (string, required)

Query parameters:

- `raw` (string)
- `download` (string)

Responses:

- `200` — Snapshot or original file bytes
  - `name` (string, required)
  - `format` (enum<string>, required) — "file" · "site"
  - `mediaType` (string, required)
  - `revision` (string, required)
  - `editable` (boolean, required)
  - `url` (string, required) — Same API path with raw=1; the original bytes, never a storage credential.
  - `maxBytes` (integer, required)
  - `text` (string)
  - `html` (string)
  - `office` (string) — Native Office source bytes as base64 when supported.
  - `history` (object[], required)
  - `previewUrl` (string) — Isolated browser preview when the reader has the required browser session, or the link is public.
  - `previewUnavailable` (string)
  - `sizeBytes` (integer)
  - `sharedBy` (string)
  - `libraryRef` (object) — Canonical original file identity when supplied by its native document reader; the link still supplies authorization.
    - option 1 (object)
      - `kind` (enum<string>, required) — "agent_prompt"
      - `agentId` (string, required) — The original agent user instruction file (AGENTS.md); never the combined runtime/system prompt.
    - option 2 (object)
      - `kind` (enum<string>, required) — "file"
      - `fileId` (string, required)
      - `sessionId` (string)
    - option 3 (object)
      - `kind` (enum<string>, required) — "task_file"
      - `taskId` (string, required)
      - `path` (string, required)
    - option 4 (object)
      - `kind` (enum<string>, required) — "memory_note"
      - `storeId` (string, required)
      - `memoryId` (string, required)
    - option 5 (object)
      - `kind` (enum<string>, required) — "skill_file"
      - `skillId` (string, required)
      - `path` (string, required)
    - option 6 (object)
      - `kind` (enum<string>, required) — "artifact"
      - `artifactId` (string, required)
    - option 7 (object)
      - `kind` (enum<string>, required) — "platform_artifact"
      - `artifactId` (string, required)
      - `path` (string) — Exact full path from the native artifact manifest; DesignSystem files use root plus the relative editable_files path. Omit only for the entire artifact entry.
- `206` — Requested original-file byte range
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/shared/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0' \
  -H "Authorization: Bearer ast_..."
```

### PUT /library/shared/{token}

Save a native editable file through the caller's Library grant (scope: write)

The same original source writer as the web editor. Requires live edit access and a source revision; stale source versions return 409. Grant revocation or downgrade while reading the request also prevents saving. Public links have no writer.

Path parameters:

- `token` (string, required)

Body (application/json):

- `revision` (string, required)
- `text` (string)
- `html` (string)
- `office` (string) — Native Office bytes as base64.
- `docx` (string) — Native Word document bytes as base64.
- `requestId` (string)
- `restoreRevision` (string)

Responses:

- `200` — Native document save receipt
  - `url` (string, required)
  - `revision` (string, required) — The revision acknowledged by this native write, never a later latest read.
  - `publishedAt` (string, required) — Native publication time, or the host's acknowledgement time after the original writer succeeds.
  - `text` (string)
  - `historyRevision` (string)
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/library/shared/Yy5oaLAHSF5t96EAi9FiEk7uTjLMxNWDVHK8UPr1zK0 \
  -H "Authorization: Bearer ast_..."
```

### GET /library/skills

Open Library skills and settle workspace defaults (scope: write)

Personal API key with write scope. Runs the Mac/web Library owner: lists complete skill cards, records previously unseen skills and makes pending workspace skills available to new conversations. Uses the verified key workspace or X-Universe; this GET has settlement side effects. Settlement failures retain pending records for retry while the catalog still returns.

Responses:

- `200` — Skill cards
  - `skills` (object[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/skills' \
  -H "Authorization: Bearer ast_..."
```

### POST /library/skills

Upload a skill through the Library owner (scope: write)

Uploads a skill, updates the consumer workspace fingerprint record and makes it available by default. Same owner as the Mac Library. JSON file paths and decoded bundles pass the existing platform bundle validator; multipart files use their relative paths as filenames. If Library setup fails after platform creation, the successful status and original skill/revision receipt are preserved with warning.code=library_skill_setup_pending and recovery GET /library/skills. Retry only that catalog settlement; do not re-upload the saved skill.

Body (application/json):

- `files` (object[], required)
  - `path` (string, required) — max length 2048
  - `content` (string, required)
  - `encoding` (enum<string>) — "utf8" · "base64" — default: "utf8"
- `displayName` (string) — max length 200
- `expectedLatestRevision` (string) — Optional revision CAS token for a new version.

Responses:

- `201` — Platform skill and revision receipt, with optional warning {code: library_skill_setup_pending, message, recovery: {method: GET, path: /library/skills}} when saved but Library setup is pending
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/library/skills \
  -H "Authorization: Bearer ast_..."
```

### POST /library/skills/{id}/revisions

Save a Library skill version and its fingerprint (scope: write)

Runs the existing consumer saveSkillRevision owner, including fingerprint update. expectedLatestRevision optionally refuses a concurrent version; platform validation and refusals are preserved.

Path parameters:

- `id` (string, required)

Body (application/json):

- `files` (object[], required)
  - `path` (string, required) — max length 2048
  - `content` (string, required)
  - `encoding` (enum<string>) — "utf8" · "base64" — default: "utf8"
- `displayName` (string) — max length 200
- `expectedLatestRevision` (string) — Optional revision CAS token for a new version.

Responses:

- `201` — Platform revision receipt
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/library/skills/sess_cmtb7q2j/revisions \
  -H "Authorization: Bearer ast_..."
```

### DELETE /library/skills/{id}

Remove a skill through the Library owner (scope: write)

Runs the Mac/web removeSkill owner: retries skill_in_use only after releasing this consumer app's legacy stamped references, never user-attached references, then removes its consumer record after platform deletion succeeds. Other failures preserve the record.

Path parameters:

- `id` (string, required)

Responses:

- `200` — Platform deletion receipt
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/library/skills/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /library/artifacts

List Library artifacts

The caller's artifact Library, as the web Library lists it, newest first; each of their own rows names the thread (`threadId`) whose agent saved it.

Query parameters:

- `q` (string) — Search the names.
- `visibility` (string)
- `scope` (string)
- `cursor` (string)

Responses:

- `200` — OK
  - `artifacts` (object[])
  - `nextCursor` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/artifacts' \
  -H "Authorization: Bearer ast_..."
```

### POST /library/artifacts

Upload a Library artifact

Save a file as a new artifact, as the web Library's upload does. Multipart form: `file`, `requestId` (a retry with the same id saves once) and optional `workspace` (a workspace key to place it in).

Responses:

- `201` — OK
  - `artifact` (object)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `413` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/library/artifacts \
  -H "Authorization: Bearer ast_..."
```

### GET /library/artifacts/{id}

Read a Library artifact

What an artifact the caller can read is, and its saved versions, newest first.

Path parameters:

- `id` (string, required) — Artifact id.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /library/artifacts/{id}

Delete a Library artifact

Delete the caller's own artifact with all its versions. `revision` names the version they were looking at, so a stale delete is refused.

Path parameters:

- `id` (string, required) — Artifact id.

Body (application/json):

- `revision` (integer, required)

Responses:

- `200` — OK
  - `deleted` (boolean)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /library/artifacts/{id}/share

Read a Library artifact's sharing

Whether the artifact's public link is on, the link, and the version it serves.

Path parameters:

- `id` (string, required) — Artifact id.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j/share' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /library/artifacts/{id}/share

Share or unshare a Library artifact

Turn the public link on or off, as the web share dialog does. `revision` is the current version; `publicVersion` pins the version every public alias serves. Disabling revokes every public alias but keeps authenticated grants. Optional sharingRevision compares the whole access state; revokeAll=true with enabled=false also stops workspace/member grants and placement atomically. A fixed-workspace credential cannot read or change whole-artifact sharing if any audience grant is outside its credential ceiling.

Path parameters:

- `id` (string, required) — Artifact id.

Body (application/json):

- `enabled` (boolean, required)
- `revision` (integer, required)
- `publicVersion` (integer)
- `fromPublicVersion` (integer)
- `sharingRevision` (string) — pattern ^[a-f0-9]{64}$
- `revokeAll` (enum<boolean>) — true

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j/share \
  -H "Authorization: Bearer ast_..."
```

### GET /library/artifacts/{id}/source

Read a Library artifact's source

What the web editor reads of one version: its HTML, text or Word bytes, whether it can be edited, and the last 20 versions.

Path parameters:

- `id` (string, required) — Artifact id.

Query parameters:

- `version` (integer) — A saved version; the current one when omitted.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j/source' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /library/artifacts/{id}/source

Save a new version of a Library artifact

Save a new version as the web editor does: `revision` (the current version; 409 when it is no longer current), `requestId`, and one of `html`, `text`, `docx` (base64) or `restoreRevision`.

Path parameters:

- `id` (string, required) — Artifact id.

Body (application/json):

- `revision` (integer, required)
- `requestId` (string, required)
- `html` (string)
- `text` (string)
- `docx` (string)
- `restoreRevision` (integer)

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `413` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j/source \
  -H "Authorization: Bearer ast_..."
```

### PATCH /library/artifacts/{id}/workspace

Place a Library artifact in a workspace

Place the caller's own artifact in a workspace they belong to (by its key), or with null take it back to them alone.

Path parameters:

- `id` (string, required) — Artifact id.

Body (application/json):

- `workspace` (string, required)
- `sharingRevision` (string) — pattern ^[a-f0-9]{64}$

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j/workspace \
  -H "Authorization: Bearer ast_..."
```

### GET /library/todos

List to-dos from documents

Every checklist item (`- [ ] text @who YYYY-MM-DD`) in the Markdown documents of the caller's Library: their own and those shared into their workspaces. Reads never persist an index. Follow next_cursor with the same caller, credential scope, source and filters, including today, even after an empty filtered page. Each page inspects at most 100 candidates, reads at most 25 Markdown documents and 8 MiB of saved bytes and returns at most 1,000 matching items. A document exceeding the byte budget is unavailable (413 for an exact source). The documents are the record; this list is derived from their saved versions. `mine` is what is assigned to one of the caller's handles, plus what is unassigned in their own documents. `@agent` marks an item for an agent (`forAgent`).

Query parameters:

- `cursor` (string) — The previous next_cursor with identical filters. 409 todo_page_changed means restart without a cursor.
- `scope` (string)
- `status` (string)
- `due` (string)
- `source` (string) — Only this document's items (artifact id).
- `today` (string) — The caller's date, for overdue/today/week; UTC today when omitted.

Responses:

- `200` — `todos` (id, text, done, assignee, forAgent, mine, due, overdue, line, source {id, name, owned, workspace}), `sources` (id, name, open, total), `today`, `truncated`, `next_cursor` (null when exhausted), `sources_partial`, `unavailable_sources` (currently authorized id/code), `unavailable_source_count` (also includes anonymous authority transport failures; revoked/unauthorized sources are omitted). Source counts are complete for each document read on this page within the requested mine/workspace scope; sources_partial means these are not full Library totals. A to-do id may be an opaque source/key locator; it grants no access and the same PATCH reauthorizes the current source.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `413` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/todos' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /library/todos/{id}

Tick or untick a to-do

Edits the to-do's document: only the item's checkbox changes, saved as a new version of the document (in its version history), by the same rules as the editor (its owner or a member of its workspace). 409 `todo_changed` when the item is no longer in the document.

Path parameters:

- `id` (string, required) — To-do id from the list.

Body (application/json):

- `done` (boolean, required)

Responses:

- `200` — `todo` as listed, and `revision`, the document's new version.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/library/todos/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### GET /library/artifacts/{id}/download

Download a Library artifact

The saved bytes of one version: the original file, or a site as `.tar.gz`. `x-artifact-format` and `x-artifact-version` name what was sent.

Path parameters:

- `id` (string, required) — Artifact id.

Query parameters:

- `version` (integer) — A saved version; the current one when omitted.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j/download' \
  -H "Authorization: Bearer ast_..."
```

### GET /library/artifacts/{id}/export

Export a Library artifact

The current version converted to `format`, one of the formats its share state lists; the filename is in `x-artifact-filename`, percent-encoded.

Path parameters:

- `id` (string, required) — Artifact id.

Query parameters:

- `format` (string, required)

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/library/artifacts/sess_cmtb7q2j/export?format=format' \
  -H "Authorization: Bearer ast_..."
```

## Projects and imports

### GET /projects

List projects

The GitHub repositories a new thread can start on, as the project picker lists them, with the caller's remembered choice (`last`). Without a list, `unavailable` says why.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/projects' \
  -H "Authorization: Bearer ast_..."
```

### PUT /projects

Remember a project

Remember the repository (`project`: `{{repoFullName, branch}}`, or null for none) for the caller's next new thread, on the web as well.

Body (application/json):

- `project` (object)

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PUT https://api.agentsky.dev/v1/projects \
  -H "Authorization: Bearer ast_..."
```

### GET /imports

List imports

Imports of local agent conversations waiting for the caller to continue or discard.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/imports' \
  -H "Authorization: Bearer ast_..."
```

### POST /imports

Start an import

Mint a one-time import prompt to paste into a local agent (`harness`, default `claude_code`); answers `{{traceId, script, expiresAt}}`. Continue the import with `POST /threads` and `importId`.

Body (application/json):

- `harness` (string)

Responses:

- `201` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `429` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/imports \
  -H "Authorization: Bearer ast_..."
```

### GET /imports/move-in

Read the move from your computer

What the composer's move-in card shows: `{moveIn}`. Null when the card shows nothing; `kind: invite` while nothing has ever been imported; `kind: moving` with the `grantId` to cancel and the `harnessLabel` it runs from while a move is claimed and unfinished; `kind: done` with `landed` (skills that arrived), `instructions` and any `instructionError` or `instructionRetryError` for a week after a move finishes, until it has been seen.

Responses:

- `200` — OK
  - `moveIn` (object, required)
    - `kind` (enum<string>, required) — "invite" · "moving" · "done"
    - `grantId` (string)
    - `harnessLabel` (string)
    - `landed` (integer)
    - `instructions` (enum<string>) — "applied" · "cleared" · "failed" · null
    - `instructionError` (string)
    - `instructionRetryError` (string)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/imports/move-in' \
  -H "Authorization: Bearer ast_..."
```

### POST /imports/move-in/{id}/cancel

Cancel a move from your computer

Stops a move you own: its key stops working and nothing already sent is undone. A repeat answers `replayed: true`. Answers 404 for a move that is not yours, 409 `finished` once it has finished and 410 `expired` once its key has run out, as the local agent's own cancel does.

Path parameters:

- `id` (string, required) — The move's `grantId`.

Responses:

- `200` — OK
  - `status` (enum<string>) — "cancelled"
  - `replayed` (boolean)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `410` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/imports/move-in/sess_cmtb7q2j/cancel \
  -H "Authorization: Bearer ast_..."
```

### POST /imports/setup/skip

Skip setup

Skips setup as the setup page's Skip does. `grant_id` names the setup key to stop; without one a key is minted and stopped, which records the skip. `skipped` is false when the key had already finished or run out, which is left as it is. Answers 404 for a key that is not one of your setup keys.

Body (application/json):

- `grant_id` (string)

Responses:

- `200` — OK
  - `skipped` (boolean)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/imports/setup/skip \
  -H "Authorization: Bearer ast_..."
```

### GET /imports/{id}

Read an import

Where an import stands: `{status, environment, error, mirror_session_id, continuation}`. `mirror_session_id` is the session this import was mirrored into once it completed: `GET /sessions/{id}/events` on it reads the imported person and agent turns, tool calls inside the agent's parts, under the event ids `import:<seq>`. It is null until the mirror lands, and stays null if the mirror was refused or local session sync is off; the page then still draws the turns and no read serves them.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/imports/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /imports/{id}

Discard an import

Permanently discard an import that has not been continued.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/imports/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

### POST /imports/{id}/rerun

Redo an imported session's task

Put an imported session beside other agents redoing its task: the person's own run is the first column, visible and sent nothing, and each seat joins a blind comparison and receives the task the import recorded. The same `requestId` replays the first outcome.

Path parameters:

- `id` (string, required)

Body (application/json):

- `requestId` (string, required)
- `seats` (object[], required)
  - `agentType` (string, required)
  - `llm` (string)
  - `reasoningEffort` (string)
- `timezone` (string)

Responses:

- `201` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/imports/sess_cmtb7q2j/rerun \
  -H "Authorization: Bearer ast_..."
```

## Action items

### GET /action-items

List action items

What stands and what the caller must do in this workspace, from every source, in one shape: open requests, running and finished tasks, document to-dos and proposals, a plan to reconnect, credits. `needs_you` first, then `working`, `proposed`, `done`, newest first within each. A task's state is its `attention`. A source that could not be read is left out and named in `partial`; it does not mean that source is empty. Served by the consumer app. Items true of one Mac are added by that Mac and are not listed here.

Query parameters:

- `state` (array) — Repeat for several. Ticked to-dos are listed only when this includes `done`.
- `kind` (array) — Repeat for several: question, approval, spend, connect, browser_handoff, mention, failure, task, todo, document_proposal, reconnect, credits.
- `source_id` (string) — Only items of this session or document.
- `limit` (integer)
- `cursor` (string) — The previous next_cursor with identical filters; 400 `invalid_cursor` otherwise.

Responses:

- `200` — `data`: items (id, kind, title, detail, source {type, id, url}, state, primary_action {type, label, requires_person, input, url} or null, created_at, updated_at). `next_cursor`, null at the end. `partial`, only when a source could not be read.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/action-items' \
  -H "Authorization: Bearer ast_..."
```

### POST /action-items

Propose work on a document

Offers work on a document the caller can read. It waits, `proposed`, until someone runs its Start. `Idempotency-Key` makes a retry return the first proposal; the same key with a different body is 409 `idempotency_conflict`. 503 `not_migrated` until the feature's table exists.

Body (application/json):

- `kind` (enum<string>, required) — "document_proposal"
- `document_id` (string, required)
- `title` (string, required) — max length 300
- `detail` (string) — max length 4000

Responses:

- `201` — `item`, as listed.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/action-items \
  -H "Authorization: Bearer ast_..."
```

### POST /action-items/{id}/act

Run an action item's primary action

`answer` takes `option_id`, `text`, or `file_ids` with `expected_question`. `start` starts an agent with the document and the item in its first message; `agent_type` and `llm` choose who, and a price or workspace rule stops it as it stops any start. `see` marks the result seen and answers its `url`. `complete` ticks a to-do. An action with `requires_person` true sends something or spends money, so this route does not run it: 409 `person_required` with `url`, and the item keeps waiting for the person. 409 `stale` when the item moved on.

Path parameters:

- `id` (string, required) — Item id from the list.

Body (application/json):

- `option_id` (string)
- `text` (string)
- `file_ids` (string[])
- `expected_question` (object)
- `agent_type` (string)
- `llm` (string)

Responses:

- `200` — `acted`, the action that ran, and what it produced: `session_id`, `message_id`, `thread_id`, `url` or `revision`.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/action-items/sess_cmtb7q2j/act \
  -H "Authorization: Bearer ast_..."
```

## Signing requests

### GET /signing-requests

List signing requests

This workspace's signing requests, newest first: their status and, once signed, their signature record.

Query parameters:

- `status` (string)
- `limit` (integer)
- `cursor` (string) — The previous next_cursor.
- `link` (string) — Only the requests people made by opening this link: who has signed it.

Responses:

- `200` — `data`: requests, as `GET /signing-requests/{id}` without `block_html`. `next_cursor`, null at the end.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/signing-requests' \
  -H "Authorization: Bearer ast_..."
```

### POST /signing-requests

Ask someone to sign a document

Stores the document and answers `signing_url` and `block_html`. Send the person the link, or embed `block_html` in an artifact page. They need no account. With `access` named (the default) one person signs; with `access` link anyone holding the address gives a name and email and signs their own copy, listed with `?link=`. A one-time code to the address proves them, or with `proof` account only a login does. `mark` typed (the default) signs with a typed name, drawn with a drawing. A person's key or a workspace's own key may ask; the signer is told the workspace or person behind it. Nothing here signs: no key, token, MCP call or `sky` command can complete a signature, only the signer in their own browser. `replaces` makes a new version of a document: an unsigned request stops being signable, and a signature on the old version stays on the old version. `Idempotency-Key` makes a retry return the first request.

Body (application/json):

- `title` (string, required) — max length 300
- `document` (string) — The document in Markdown, exactly as the signer reads it. Raw HTML is shown as text. Send this or `source`. — max length 200000
- `source` (object) — Sign one version of an artifact: a page or Markdown result. Its text is frozen now, so later versions never alter what is signed.
  - `artifact_id` (string, required)
  - `version` (integer, required)
- `signer` (object) — Who signs. Required unless `access` is link.
  - `name` (string, required)
  - `email` (string, required)
  - `legal_name` (string) — The organization they sign for.
- `access` (enum<string>) — "named" · "link" — default: "named"
- `mark` (enum<string>) — "typed" · "drawn" — default: "typed"
- `proof` (enum<string>) — A link always uses email_code. — "email_code" · "account" — default: "email_code"
- `legal_name` (string) — On a link, the organization its signers sign for.
- `replaces` (string) — The request this is a new version of.
- `expires_in_days` (integer) — default: 30

Responses:

- `201` — The request, as `GET /signing-requests/{id}`.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `429` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/signing-requests \
  -H "Authorization: Bearer ast_..."
```

### GET /signing-requests/{id}

Read a signing request

`id`, `title`, `status` (pending, signed, cancelled, replaced, expired), `access`, `mark`, `proof`, `requester` (who the signer is told is asking), `link_id`, `signer` {name, email, legal_name} or null on a link, `document` {version, hash}, `signing_url`, `replaces`, `replaced_by`, `created_at`, `expires_at`, `signature` and `block_html`. `signature` is null until signed, then the record, which never changes: `signature_id`, `printed_name`, `typed_name` (null on a drawn signature), `signature_image` (the SVG path the signer drew, in a 400 by 150 box, null on a typed one), `proof` (email_code or account), `read_proof` (scrolled, or none on older signatures), `email`, `legal_name`, `accepted_at`, `time_zone`, `ip`, `version`, `read_version`, `doc_hash`, `consent`. `document.hash` is the SHA-256 of the document's UTF-8 text. `block_html` is inert HTML for an artifact page: read it again after signing to embed the stamp.

Path parameters:

- `id` (string, required)

Responses:

- `200` — The request.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/signing-requests/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### GET /signing-requests/{id}/copy

Download a signed document as a PDF

The document exactly as signed, with its signature and record. The signer is emailed the same PDF when they sign. `409` until it is signed.

Path parameters:

- `id` (string, required)

Responses:

- `200` — The PDF.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/signing-requests/sess_cmtb7q2j/copy' \
  -H "Authorization: Bearer ast_..."
```

### GET /signing-requests/{id}/document

Read the document of a signing request

`title`, `body`, `version` and `hash`: the text exactly as it is to be signed or was signed.

Path parameters:

- `id` (string, required)

Responses:

- `200` — The document.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/signing-requests/sess_cmtb7q2j/document' \
  -H "Authorization: Bearer ast_..."
```

### POST /signing-requests/{id}/cancel

Cancel a signing request

Withdraws a request nobody has signed. 409 `not_pending` for anything else: a signature stands.

Path parameters:

- `id` (string, required)

Responses:

- `200` — The request, as `GET /signing-requests/{id}`.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `503` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/signing-requests/sess_cmtb7q2j/cancel \
  -H "Authorization: Bearer ast_..."
```

## Saved agents

### GET /saved-agents

List saved agents

The caller's saved agents as My Agents lists them. `?for=composer` lists the agents the composer offers (saved ones, then the ones listed in the workspace); `?for=form` adds what the New agent form needs: the caller's skills, the channels an agent may allow, the longest name, and the provider account forms.

Query parameters:

- `for` (string)

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/saved-agents' \
  -H "Authorization: Bearer ast_..."
```

### POST /saved-agents

Save an agent

Save a new agent, as the New agent form does. An agent on its own provider account carries `accountSetup` (`{mode, values}`), stored write-only. The same `requestId` replays the first outcome.

Body (application/json):

- `requestId` (string, required)
- `name` (string, required)
- `agentType` (string, required)
- `llm` (string)
- `reasoningEffort` (string)
- `capabilities` (string[], required)
- `skillIds` (string[])
- `connectionSupport` (object)
- `accountSetup` (object)

Responses:

- `201` — OK
  - `agentId` (string)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/saved-agents \
  -H "Authorization: Bearer ast_..."
```

### GET /saved-agents/{id}

Read a saved agent

One saved agent with its tools, skills, and which channels and connectors it allows.

Path parameters:

- `id` (string, required)

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/saved-agents/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /saved-agents/{id}

Change a saved agent's channels, connectors or account setup

`connectionSupport` changes which channels and whether connectors the agent allows, as the My Agents card does; `accountSetup` (`{mode, values}`) replaces the setup of an agent on its own provider account, write-only.

Path parameters:

- `id` (string, required)

Body (application/json):

- `connectionSupport` (object)
- `accountSetup` (object)

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/saved-agents/sess_cmtb7q2j \
  -H "Authorization: Bearer ast_..."
```

## Settings

### GET /settings

Read settings

What the web's Settings page shows: profile (name, email, picture), default session budget, whether chats may improve models, the chosen language, and task emails (`needs_you`, `done`; null when they could not be read). Budget, model improvement and language are the same values as `/preferences`; task emails live only here.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/settings' \
  -H "Authorization: Bearer ast_..."
```

### PATCH /settings

Change the default budget, language, emails and model improvement settings

Change any of `defaultBudgetUsd` (a dollar amount as text, or null for none), `modelImprovement`, `language` and `emails` (`{needs_you?, done?}`); answers with all settings.

Body (application/json):

- `defaultBudgetUsd` (string)
- `modelImprovement` (boolean)
- `language` (string)
- `emails` (object)
  - `needs_you` (boolean)
  - `done` (boolean)

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X PATCH https://api.agentsky.dev/v1/settings \
  -H "Authorization: Bearer ast_..."
```

## Arena

### GET /arena

Arena standings

Read-only community Arena stats: current standings, recent verdicts, the active lineup, and the vote-reason vocabulary. Starting Arena matches and casting Arena votes require the web UI — scripted API votes would skew the blind, human-judged community leaderboard.

Responses:

- `200` — OK
  - `open` (boolean)
  - `contestants` (integer)
  - `verdicts` (integer)
  - `ties` (integer)
  - `bothBad` (integer)
  - `standings` (object[])
    - `agentType` (string, required)
    - `label` (string, required)
    - `model` (string, required)
    - `wins` (integer, required)
    - `losses` (integer, required)
    - `matches` (integer, required)
    - `winRate` (number, required)
  - `recent` (object[])
  - `reasons` (string[])
  - `failureTags` (string[])
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/arena' \
  -H "Authorization: Bearer ast_..."
```

### GET /arena/personal/boards

Read runnable presets and harness boards (scope: read)

The same normally billed preset slugs, public quotes, same-model records, cost efficiency and failure profiles as the Mac. This read starts nothing. All current presets are unsponsored and use normal usage pricing.

Responses:

- `200` — OK; private, no-store
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/arena/personal/boards' \
  -H "Authorization: Bearer ast_..."
```

### GET /arena/personal

Read your Arena state (scope: read)

Read standings, reasons/failure tags, and your unfinished match restricted to the selected workspace. This is distinct from anonymous GET /arena. Free Arena starts are retired (open false).

Responses:

- `200` — OK; private, no-store
  - `open` (false)
  - `activeMatchId` (string | null)
  - `taskMinLength` (integer)
  - `contestants` (integer)
  - `standings` (object[])
  - `reasons` (string[])
  - `failureTags` (string[])
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/arena/personal' \
  -H "Authorization: Bearer ast_..."
```

### POST /arena/personal

Start a normally billed preset comparison (scope: write)

Uses the Mac's existing runnable-preset owner. Set billing normal to acknowledge normal usage pricing; no free credit, waiver or quota bypass is created. Reuse requestId when retrying. Missing/formerly sponsored presets remain retired (410). A rejected admitted start can carry playgroundId: inspect it before starting another.

Body (application/json):

- `task` (string, required) — max length 4000
- `preset` (string, required)
- `requestId` (string, required) — pattern ^[a-zA-Z0-9_-]{16,100}$
- `billing` ("normal", required)
- `timezone` (string)

Responses:

- `201` — OK; private, no-store
  - `playgroundId` (string)
  - `columns` (object[])
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `410` — Error — { error: { code, message } }
- `422` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/arena/personal \
  -H "Authorization: Bearer ast_..."
```

### GET /arena/personal/{id}

Read your match (scope: read)

Own account and selected workspace only. Blind agent/model identities stay masked until a verdict. Coverage expiry is not a reveal. vote.sealed means waiver release needs recovery before continuation; the same existing owner retries release. This read grants no free usage.

Path parameters:

- `id` (string, required) — Your match/playground id in the selected workspace.

Responses:

- `200` — OK; private, no-store
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/arena/personal/sess_cmtb7q2j' \
  -H "Authorization: Bearer ast_..."
```

### POST /arena/personal/{id}/vote

Record your verdict (scope: write)

Same atomic castArenaVote writer as the Mac. Choose winnerColumnId or tie/both_bad. Optional ranking uses column ids best first. One verdict per owned pending match; 409 requires reading the match instead of recasting. Identity reveal, usage accounting and waiver release remain unchanged. A public inline comment additionally requires commentConsent true.

Path parameters:

- `id` (string, required) — Your match/playground id in the selected workspace.

Body (application/json):

- `winnerColumnId` (string)
- `outcome` (enum<string>) — "win" · "tie" · "both_bad"
- `why` (string[])
- `failures` (map<string, string[]>)
- `ranking` (string[])
- `comment` (string) — max length 280
- `commentConsent` (true)

Responses:

- `200` — OK; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `422` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/arena/personal/sess_cmtb7q2j/vote \
  -H "Authorization: Bearer ast_..."
```

### GET /arena/personal/{id}/comment

Read match comments (scope: read)

Your match's own credited comment and decided-lineup public quotes. Public quotes expose neither another voter's account nor task.

Path parameters:

- `id` (string, required) — Your match/playground id in the selected workspace.

Responses:

- `200` — OK; private, no-store
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/arena/personal/sess_cmtb7q2j/comment' \
  -H "Authorization: Bearer ast_..."
```

### POST /arena/personal/{id}/comment

Publish your comment (scope: write)

One comment on your decided match. consent true explicitly permits public display under your credited name. Link, length and moderation rules are unchanged. On 409 read comments before retrying.

Path parameters:

- `id` (string, required) — Your match/playground id in the selected workspace.

Body (application/json):

- `body` (string, required) — max length 280
- `consent` (true, required)

Responses:

- `201` — OK; private, no-store
- `400` — Error — { error: { code, message } }
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `409` — Error — { error: { code, message } }
- `422` — Error — { error: { code, message } }
- `503` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/arena/personal/sess_cmtb7q2j/comment \
  -H "Authorization: Bearer ast_..."
```

### DELETE /arena/personal/{id}/comment

Remove your comment (scope: write)

Only your own visible comment is removed. Staff-hidden comments remain hidden to prevent moderation evasion. This does not reset a vote or its usage.

Path parameters:

- `id` (string, required) — Your match/playground id in the selected workspace.

Responses:

- `200` — OK; private, no-store
  - `removed` (boolean)
- `401` — Error — { error: { code, message } }
- `403` — Error — { error: { code, message } }
- `404` — Error — { error: { code, message } }
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/arena/personal/sess_cmtb7q2j/comment \
  -H "Authorization: Bearer ast_..."
```

## Session insights

### GET /sessions/{id}/started-with

What a conversation started with

The files and context the conversation started with, as the web's Shared files tab shows them.

Path parameters:

- `id` (string, required) — Session id.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/started-with' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/spend-answer

Answer a price request

Confirm or decline a paid agent's price for this conversation, as the web's card does: `requestId` names the request and `optionId` the chosen option.

Path parameters:

- `id` (string, required) — Session id.

Body (application/json):

- `requestId` (string, required)
- `optionId` (string, required)

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `409` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/spend-answer \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/secrets

Conversation secrets

Whether this conversation has a vault a pasted credential can be saved in, and the names it holds. Never the values.

Path parameters:

- `id` (string, required) — Session id.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/secrets' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/secrets

Save a conversation secret

Save a pasted credential in the conversation's vault, as the composer's guard does (`name`, `host`, `header`, `valueTemplate`, `value`); answers the reference to put in the message instead of the value.

Path parameters:

- `id` (string, required) — Session id.

Body (application/json):

- `name` (string, required)
- `host` (string)
- `header` (string)
- `valueTemplate` (string)
- `value` (string, required)

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/secrets \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/helpers

Task helpers

The helpers this session hired into its task, as the Background tasks panel lists them: session id, title, agent, state, status line and cost, plus the whole task's cost.

Path parameters:

- `id` (string, required) — Session id.

Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `502` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/helpers' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/annotations

Send annotations

Send marked-up elements of a page or artifact to the agent as one message, as the web's and the Mac's Annotate do: each selection with its label, selector, nearby text and box, an optional comment per selection, and optional screenshots as uploaded files.

Path parameters:

- `id` (string, required) — Session id.

Body (application/json):

- `selections` (object[])
- `files` (object[])

Responses:

- `200` — OK
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/annotations \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/feedback

Read message feedback

The feedback the person left on this session's messages, keyed by message id, and the available vote reasons.

Path parameters:

- `id` (string, required) — Session id.

Responses:

- `200` — OK
  - `reports` (map<string, object>, required) — Feedback keyed by message id.
  - `reasons` (string[], required)
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/feedback' \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/feedback

Record message feedback

Record a thumb on one agent message: `"up"`, `"down"`, a report object, or `null` to take it back.

Path parameters:

- `id` (string, required)

Body (application/json):

- `messageId` (string, required)
- `feedback` (enum<string> | object | null, required) — "up", "down", a report object, or null to remove.
  - option 1 (enum<string>) — "up" · "down"
  - option 2 (object) — A thumb and optional reasons on one agent message.
    - `vote` (enum<string>, required) — "up" · "down"
    - `reasons` (string[])
    - `details` (string)
  - option 3 (null)

Responses:

- `200` — OK
  - `saved` (boolean)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/feedback \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/side-chat

Side chat

Ask one question about this session's conversation, as the web's Side chat does: answered beside the session, never sent to the agent.

Path parameters:

- `id` (string, required)

Body (application/json):

- `transcript` (string, required) — The session's conversation text the question refers to.
- `history` (object[]) — Prior side-chat exchanges in this panel, as {role, text}[].
- `question` (string, required)
- `quote` (string) — A specific passage the question targets.

Responses:

- `200` — OK
  - `answer` (string, required)
  - `looked` (string[], required) — Sources the side model consulted.
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/side-chat \
  -H "Authorization: Bearer ast_..."
```

### POST /sessions/{id}/code-review

Code review

Run a Code Review request for this session via the platform's code-review plane (read, open, or review a GitHub pull request). Refused on a blind Arena comparison session.

Path parameters:

- `id` (string, required)

Body (application/json):


Responses:

- `200` — OK
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `422` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X POST https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/code-review \
  -H "Authorization: Bearer ast_..."
```

### GET /sessions/{id}/snapshot

Get snapshot link

The public read-only snapshot link of this session, if one exists. `?thread={id}` is required. Owner only.

Path parameters:

- `id` (string, required)

Query parameters:

- `thread` (string, required) — The thread (comparison/playground) id that owns this session.

Responses:

- `200` — OK
  - `url` (string, required)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `404` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl 'https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/snapshot?thread=thread' \
  -H "Authorization: Bearer ast_..."
```

### DELETE /sessions/{id}/snapshot

Revoke snapshot link

Permanently revokes the public snapshot link for this session. Owner only.

Path parameters:

- `id` (string, required)

Query parameters:

- `thread` (string, required)

Responses:

- `200` — OK
  - `url` (null)
- `400` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `401` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `403` — Error — { error: { code, message } }
  - `error` (object)
    - `code` (string)
    - `message` (string)
    - `request_id` (string) — This request's id (req_…), the same value as the Request-Id header. Quote it when asking for support.
- `4xx` — `{ "error": { "code", "message" } }` (see the error table)

Example request:

```bash
curl -X DELETE https://api.agentsky.dev/v1/sessions/sess_cmtb7q2j/snapshot \
  -H "Authorization: Bearer ast_..."
```

## Stream events

Send and listen are decoupled: POST `…/events`, then read `…/stream` until `session.status_idle` — there is no non-streaming reply mode. Frames are `id:` + `event:` + one `data:` JSON object `{ id, type, sessionId, agent, at, …payload }` (the `id` is the dedupe key against `GET …/events`):

| event | payload | meaning |
|-------|---------|---------|
| `user.message` | content | history only (`GET …/events`) and the POST echo — user messages are not sent on the live stream; `content` is the CMA block list you sent, every image/document source rewritten to a `file` source |
| `system.message` | content | history only and the POST echo — the per-turn system text sent alongside a user.message |
| `user.interrupt` | by, mode?, deadline_at?, cause? | an interrupt was accepted — echoed on the live stream and kept in history; the pod's `session.status_idle` follows. `mode: "save"` asks the run to start no new work, save what it has and end its turn with a reply listing what was saved, by `deadline_at`; a run still going then is stopped by a second `user.interrupt` with `cause: "save_timeout"` |
| `agent.message` | parts, text | a user-facing agent post; a turn may carry several |
| `agent.reasoning` | part | raw engine event: thinking (live only) |
| `agent.tool_use` | part | raw engine event: a tool invocation (live only) |
| `agent.tool_use_delta` | part, offset | only on a stream opened with `?include=agent.tool_use_delta`: the next chunk of a tool call's input JSON (`part.args_partial`) at character `offset`, while the agent is still writing it; in order, the chunks are the input the call's `agent.tool_use` then carries in full (live only) |
| `agent.tool_result` | part | raw engine event: the tool's outcome (live only) |
| `agent.status` | part | raw engine event: working / waiting / … (live only) |
| `session.status_running` | — | a turn started |
| `session.status_idle` | stop_reason | the turn is over (`stop_reason.type` is `end_turn` — also after an interrupt — `budget_reached`, `retries_exhausted` after an exhausted engine error, or `provider_lost` after a confirmed runtime Pod loss); never break on bare idle; the stream stays open |
| `session.error` | error | a failure inside the turn (`error.type`, `error.message`, `error.retry_status` `retrying` or `exhausted`); the stream stays open and a `session.status_idle` follows |
| `session.status_terminated` | — | the session was archived; terminal — nothing follows; close the stream |
| `session.deleted` | — | terminal — nothing follows; close the stream |

One turn on the standing stream:

```
id: msg-77e0c4…
event: agent.message
data: {"id":"msg-77e0c4…","type":"agent.message","sessionId":"sess-8c41f0…","agent":"nemesis-ee87","at":"…","text":"Signups today: 42, up 12%.","parts":[…]}

id: api-user-9d52a1…#idle
event: session.status_idle
data: {"id":"api-user-9d52a1…#idle","type":"session.status_idle","sessionId":"sess-8c41f0…","agent":"nemesis-ee87","at":"…","stop_reason":{"type":"end_turn"}}
```
