An open-source, faster Devin alternative
TypeScript
docs: document Agent URLs Hooks and usage
Igor Zalutski53a6993f16b5
diff --git a/docs/agent-sessions/agent-urls.mdx b/docs/agent-sessions/agent-urls.mdxnew file mode 100644index 00000000..55b1ca0c--- /dev/null+++ b/docs/agent-sessions/agent-urls.mdx@@ -0,0 +1,136 @@+---+mode: "wide"+title: "Agent URLs"+description: "Start a durable session from an agent's permanent HTTP address"+---++Every agent has an `invoke_url`. A trusted backend can `POST` JSON to its exact+root path to start one ordinary durable [session](/agent-sessions/sessions) on+the agent's active revision.++<Warning>+ Root invocation requires your OpenComputer org API key. Keep that key on your+ backend; do not put it in browser code or an external webhook configuration.+ For a pasteable, independently revocable URL, create an [Agent+ Hook](/agent-sessions/hooks).+</Warning>++## Invoke an agent++<CodeGroup>++```ts TypeScript+import { OpenComputer, connectSession } from "@opencomputer/sdk";++const oc = new OpenComputer({ apiKey: process.env.OPENCOMPUTER_API_KEY! });+const agent = await oc.agents.get("agt_...");++const response = await fetch(`${agent.invokeUrl}/`, {+ method: "POST",+ headers: {+ Authorization: `Bearer ${process.env.OPENCOMPUTER_API_KEY}`,+ "Content-Type": "application/json",+ "Idempotency-Key": "alert-018f",+ },+ body: JSON.stringify({+ source: "sentry",+ title: "Checkout errors increased",+ }),+});+const receipt = await response.json();++const session = await connectSession({+ sessionId: receipt.session.id,+ clientToken: receipt.client_token,+});+```++```bash oc CLI+oc agent invoke reviewer \+ --data '{"source":"sentry","title":"Checkout errors increased"}' \+ --idempotency-key alert-018f+```++```bash curl+curl "$AGENT_URL/" \+ -H "Authorization: Bearer $OPENCOMPUTER_API_KEY" \+ -H "Content-Type: application/json" \+ -H "Idempotency-Key: alert-018f" \+ -d '{"source":"sentry","title":"Checkout errors increased"}'+```++</CodeGroup>++`POST /` accepts any JSON value. The body is capped at 24 KiB and cannot select+a model, revision, sources, destinations, or limits; those values come from the+agent. The request becomes a structured `http.request` event:++```json+{+ "type": "http.request",+ "level": "user",+ "body": {+ "payload": {+ "source": "sentry",+ "title": "Checkout errors increased"+ }+ }+}+```++Transport headers and credentials are not included in the event or sent to the+agent.++## Receipt and continuation++Success returns `202 Accepted` after the session, input, and retryable runtime+dispatch are durable. It does not wait for the agent's answer.++```json+{+ "request_id": "req_...",+ "session": { "id": "ses_...", "status": "queued", "head": 1 },+ "client_token": "eyJ...",+ "links": {+ "events": "https://api.opencomputer.dev/v3/sessions/ses_.../events",+ "messages": "https://api.opencomputer.dev/v3/sessions/ses_.../messages"+ },+ "replayed": false+}+```++The one-hour `client_token` can read, stream, and steer only the returned+session. Use it with `connectSession` or the canonical Sessions API. The agent+hostname does not expose session reads, streams, steering, or arbitrary paths.++## Idempotency and retries++Send an `Idempotency-Key` when a timeout or network failure may leave the+outcome unknown. Reusing the same key and JSON against the same agent returns+the original session, even if the active revision changed after the first+acceptance. Reusing the key with different JSON returns `409`. Without a key,+every accepted request creates a new session.++The CLI generates one key and keeps it stable across its automatic transport+retries. Supply `--idempotency-key` when separate CLI runs must converge.++## Routes and errors++The Agent URL has two application routes:++| Route | Credential | Result |+| --------------------- | ------------------------ | ----------------------------------------- |+| `POST /` | OpenComputer org API key | `202` receipt with a session client token |+| `POST /hooks/<token>` | Hook URL itself | `200` receipt without session access |++Queries, redirects, trailing path variants, and every other route are rejected.+Root invocation is server-to-server and does not advertise browser CORS.++Common errors are `400` invalid JSON/query/idempotency key, `401` invalid org+key, `402` insufficient credits, `404` missing or inaccessible agent, `409`+idempotency conflict, `413` oversized input, `415` unsupported media/encoding,+`422` agent/runtime configuration failure, and `429` rate limited. Retry an+ambiguous `5xx` with the same idempotency key.++For richer session creation—model overrides, working repositories,+destinations, or per-session limits—use [`oc.sessions.create()`](/agent-sessions/sessions).diff --git a/docs/agent-sessions/agents.mdx b/docs/agent-sessions/agents.mdxindex d7e1cc67..d74b9ca1 100644--- a/docs/agent-sessions/agents.mdx+++ b/docs/agent-sessions/agents.mdx@@ -4,7 +4,7 @@ title: "Agents"description: "Reusable agent configuration"----An **agent** is a reusable identity, runtime, model, and deployed behavior. Every [session](/agent-sessions/sessions) runs on an agent, so create one first, then start as many sessions on it as you like. For the built-in runtimes, behavior is `prompt` plus optional skills and is frozen into independently routable [revisions](/agent-sessions/revisions). A [Flue](/agent-sessions/flue) agent instead carries its instructions, tools, and packaged skills in a compiled Flue app.+An **agent** is a reusable identity, runtime, model, and deployed behavior. Every [session](/agent-sessions/sessions) runs on an agent, so create one first, then start as many sessions on it as you like. Every agent also has one permanent [Agent URL](/agent-sessions/agent-urls): a trusted backend can invoke its root with an OpenComputer key, and external systems can use named, revocable [Hook URLs](/agent-sessions/hooks). For the built-in runtimes, behavior is `prompt` plus optional skills and is frozen into independently routable [revisions](/agent-sessions/revisions). A [Flue](/agent-sessions/flue) agent instead carries its instructions, tools, and packaged skills in a compiled Flue app.<Note>The [dashboard](https://app.opencomputer.dev) starts with **Import from@@ -47,7 +47,7 @@ Content-Type: application/json</CodeGroup>-Pass your model `key` inline and it's stored as a [credential](/agent-sessions/credentials) and attached to the agent — sessions run the model on it. The provider is taken from `model` (Anthropic for `anthropic/…`, OpenAI for `openai/…`), so the key has to be for that provider. Already have a credential? Reference it with `credential: "cred_…"` instead. Or skip keys entirely with `credential: "managed"` to run the model **via OpenComputer, billed to your credits** (the default for new orgs). Omit both `key` and `credential` to use your org default. Optionally set default [`limits`](/agent-sessions/sessions#limits) (`tokens`/`turn_seconds`/`turns`) too; sessions inherit them.+Pass your model `key` inline and it's stored as a [credential](/agent-sessions/credentials) and attached to the agent — sessions run the model on it. The provider is taken from `model` (Anthropic for `anthropic/…`, OpenAI for `openai/…`), so the key has to be for that provider. Already have a credential? Reference it with `credential: "cred_…"` instead. Or skip keys entirely with `credential: "managed"` to run the model **via OpenComputer, billed to your credits** (the default for new orgs). Omit both `key` and `credential` to use your org default. Optionally set default [`limits`](/agent-sessions/sessions#usage-and-limits) (`tokens`/`turn_seconds`/`turns`) too; sessions inherit them.<Tip>Keep the org key and model key on your backend. Only return session-scopeddiff --git a/docs/agent-sessions/api-reference.mdx b/docs/agent-sessions/api-reference.mdxindex 34765847..c74a82d8 100644--- a/docs/agent-sessions/api-reference.mdx+++ b/docs/agent-sessions/api-reference.mdx@@ -30,6 +30,74 @@ oc agent build --dir . --check-only --json # validate a Flue app without credenprints a table, or raw JSON with `--json`.</Note>+## Agent URLs and Hooks++Every `Agent` includes `invoke_url` (SDK: `invokeUrl`), its permanent+application address. The hostname exposes exactly two invocation routes; all+session reads and steering remain on the canonical Sessions API.++| Agent-host route | Authentication | Response |+| --- | --- | --- |+| `POST /` | `Authorization: Bearer <org-key>` | `202` receipt, canonical links, read+steer client token |+| `POST /hooks/<token>` | Hook URL bearer secret; no auth header | `200` receipt without client token or links |++Both use the same durable session-start path. Root requires one JSON value;+Hooks allow either an empty body or one JSON value. Neither returns agent+output synchronously. Queries, redirects, arbitrary paths, session routes, and+browser CORS are absent. See [Agent URLs](/agent-sessions/agent-urls) and+[Hooks](/agent-sessions/hooks) for the complete request contracts.++<Tabs>++<Tab title="TypeScript SDK">++| Call | Purpose |+| --- | --- |+| `agent.invokeUrl` | Ordinary HTTP URL for trusted-backend `POST /`. |+| `oc.agents.hooks.create(agentId, params)` | Create a named Hook; only this call returns `hookUrl`. |+| `oc.agents.hooks.list(agentId, params)` | List Hook metadata, optionally including revoked rows. |+| `oc.agents.hooks.get(agentId, hookId)` | Fetch Hook metadata without a usable URL. |+| `oc.agents.hooks.delete(agentId, hookId)` | Irreversibly revoke a Hook. |++</Tab>++<Tab title="REST API">++| Method · Path | Purpose |+| --- | --- |+| `POST https://<agent-host>/` | Start a session with an org key. |+| `POST https://<agent-host>/hooks/<token>` | Start a session with one invoke-only Hook. |+| `POST /agents/:id/hooks` | Create a Hook (`{ name, expires_at? }`). |+| `GET /agents/:id/hooks` · `GET …/hooks/:hookId` | List / fetch secret-free Hook metadata. |+| `DELETE /agents/:id/hooks/:hookId` | Revoke a Hook. |++</Tab>++<Tab title="oc CLI">++| Command | Purpose |+| --- | --- |+| `oc agent invoke <id\|name> [--data JSON\|--file PATH\|--stdin]` | Invoke exact root with the configured org key. |+| `oc agent hook create <name> --agent <id\|name>` | Create and print a Hook URL once. |+| `oc agent hooks --agent <id\|name> [--include-revoked]` | List Hook metadata. |+| `oc agent hook get <id\|name> --agent <agent>` | Fetch Hook metadata. |+| `oc agent hook revoke <id\|name> --agent <agent>` | Irreversibly revoke a Hook. |++</Tab>++</Tabs>++Root accepts an optional `Idempotency-Key`. A successful receipt contains+`request_id`, `session { id, status, head }`, `client_token`, canonical+`links { events, messages }`, and `replayed`. Hooks use `Idempotency-Key`, then+`webhook-id` when the first is absent, and return only `request_id`,+`session { id, status }`, and `replayed`.++Hook creation returns `{ hook, hook_url }` once. `Hook` contains `id`,+`agent_id`, `name`, `status` (`active|expired|revoked`), `secret_last4`, nullable+`revoked_reason` (`manual|secret_exposure`), nullable `expires_at`, and+`created_at`.+## Sessions<Tabs>@@ -44,7 +112,7 @@ oc agent build --dir . --check-only --json # validate a Flue app without creden| `session.archive()` | Cancel any active turn, then close (read-only). || `session.cancel()` | Cooperatively stop the active turn (no-op if not running). || `session.result()` | `{ lastTurn, result? }` — the resolved final event. |-| `session.turns()` · `session.turn(id)` | Per-turn history: timing, error. |+| `session.turns()` · `session.turn(id)` | Per-turn history: timing, normalized usage, error. || `session.sources` · `session.listSources()` | Source checkout status — create snapshot · live poll. || `session.mintClientToken(opts)` | Mint a client token. |@@ -60,7 +128,7 @@ oc agent build --dir . --check-only --json # validate a Flue app without creden| `POST /sessions/:id/archive` | Cancel any active turn, then close (read-only). || `POST /sessions/:id/cancel` | Cooperatively stop the active turn (no-op if not running). || `GET /sessions/:id/result` | The result helper — `{ last_turn, result? }`. |-| `GET /sessions/:id/turns` · `…/turns/:turnId` | Per-turn history: timing, error. |+| `GET /sessions/:id/turns` · `…/turns/:turnId` | Per-turn history: timing, normalized usage, error. || `GET /sessions/:id/sources` | Source checkout status (`SourceSummary[]`). || `POST /sessions/:id/client-tokens` | Mint a client token. |@@ -88,7 +156,7 @@ oc agent build --dir . --check-only --json # validate a Flue app without creden- `model?` — run this session on a different model than the agent's (same `provider/model` form; its provider must match the agent's [runtime](/agent-sessions/runtimes), e.g. `anthropic/…` for `claude`). Default = the agent's model. Pinned for the session's life like the rest of the snapshot. Rejected (`400 invalid`) for [flue](/agent-sessions/flue) agents — their model is fixed in the deployed artifact.- `key?` — get-or-create (one session per key). Keyless: an `Idempotency-Key` header makes create retry-safe.- `metadata?` — opaque routing state (≤ 16 KB); on get/list + **verbatim in webhooks**; never sent to the model, not indexed.-- `limits?` `{ tokens, turn_seconds, turns }`: non-monetary; tripping one ends a built-in runtime turn with the matching `yield_reason`. These limits are stored but not yet enforced for Flue sessions.+- `limits?` `{ tokens, turn_seconds, turns }`: non-monetary. On built-in runtimes, `tokens` is checked from committed usage before the next turn and can overshoot by one in-flight turn; `turn_seconds` and `turns` remain separate. These limits are stored but not enforced for Flue sessions.- `sources?`: working repositories (the token never enters the agent sandbox; see [GitHub](#github-apps-and-repos)). Built-in runtimes prepare them before turn one; Flue materializes them lazily. Each registered `{ repo, ref, sha?, name? }` or inline `{ url, ref, sha, name?, auth }`. `ref` is required; `sha` is required for inline sources but **optional for a registered repo**. Flue accepts only repositories allowed by the agent's repository-access policy.- Client tokens: `scopes?` (`read`/`steer`), `ttl?` 60–86400 s (SDK `ttlSeconds`).@@ -102,19 +170,28 @@ A built-in runtime session pins the agent's active revision for its whole life.| `agent_id` `credential_id` | string | resolved + pinned at create || `agent_snapshot` | object | `{ prompt_hash, model, runtime, revision }` — `revision` = the pinned revision number || `last_turn` | `Turn`-ish | `{ id, state, yield_reason?, result_event_id? }` |+| `usage` | object | terminal-turn rollup: active time, reported/unreported counts, completeness, tokens, optional runtime-reported cost/attribution || `limits?` | object | `{ tokens?, turn_seconds?, turns? }` || `metadata?` | object | opaque app routing state || `key?` `created_at` | | get-or-create key, timestamp |**`Turn`**-| Field | Notes |-| ----------------------------- | ----------------------------- |-| `id` `state` | turn id, current state |-| `yield_reason?` | why it ended (below) |-| `result_event_id?` | the event carrying the result |-| `error?` | failure detail, if any |-| `started_at?` `completed_at?` | timing |+| Field | Notes |+| ----------------------------- | --------------------------------------------------------------------- |+| `id` `state` | turn id, current state |+| `yield_reason?` | why it ended (below) |+| `result_event_id?` | the event carrying the result |+| `error?` | failure detail, if any |+| `started_at?` `completed_at?` | timing |+| `active_seconds` | database-derived active runtime seconds |+| `usage` | `{ reported:true, …tokens, total_cost_usd? }` or `{ reported:false }` |++Session usage includes `reported_turns`, `unreported_turns`, and `complete`.+When `complete:false`, any token/cost total present is a lower bound. Missing+`total_cost_usd` means unknown, not zero; historical rows may contain `{}`.+Flue session attribution may be `best_effort`, while its agent/org gateway+remains the spend-enforcement authority. See [usage and limits](/agent-sessions/sessions#usage-and-limits).A turn's **`yield_reason`** tells you why it stopped:@@ -299,6 +376,10 @@ _Managed with the SDK (`session.watches.create/list/delete`), the CLI (`oc sessiBody: `name`, `prompt`, `model`, `runtime?` (`claude`|`codex`), `key?`, `credential?`, `limits?`. PATCH takes the same **minus `runtime`** (fixed at create). `runtime`/`model` provider must agree (`claude`↔`anthropic/…`, `codex`↔`openai/…`). `credential`: a `cred_…` id (BYO, provider-matched) **or** `"managed"` (via OpenComputer, billed to credits) — mutually exclusive with `key`.+Create, get, and list responses include the permanent computed `invoke_url`+(SDK `invokeUrl`). It has no trailing slash; join `/` or `/hooks/<token>` with+URL semantics. See [Agent URLs and Hooks](#agent-urls-and-hooks).+`POST /agents` is **idempotent by `name`**: fresh → `201`, matching config → `200`, differing → `409`. Editing `prompt`/`model` (here or via [deploy](#deployments-and-revisions)) creates a **revision**; the agent keeps a pointer to its **active revision** (`GET /agents/:id` → `active_revision`) and sessions pin it. The agent row holds only identity + bindings.`POST /agents/import` is the reviewed repository-import command described below. It deliberately createsdiff --git a/docs/agent-sessions/authentication.mdx b/docs/agent-sessions/authentication.mdxindex 8d12fb0c..58f74fff 100644--- a/docs/agent-sessions/authentication.mdx+++ b/docs/agent-sessions/authentication.mdx@@ -4,7 +4,7 @@ title: "Authentication"description: "Org keys, browser-safe client tokens, and bring-your-own model keys"----Durable Agent Sessions use three credential types.+Durable Agent Sessions use four credential types.## Org API key@@ -64,7 +64,7 @@ Content-Type: application/jsonBrowser pattern: your backend creates the session with the org key, then hands the `client_token` to the browser, which uses it directly for the SSE stream and steer calls.-<Warning>A client token isn't free to hand out: each `steer` starts a turn, which **consumes tokens on your model key** for the session it's scoped to. Mint short-lived tokens, and rely on the session's [limits](/agent-sessions/sessions#limits) (`tokens`/`turn_seconds`/`turns`) to cap exposure.</Warning>+<Warning>A client token isn't free to hand out: each `steer` starts a turn, which consumes model usage for the session it's scoped to. Mint short-lived tokens and set [session limits](/agent-sessions/sessions#usage-and-limits). The token threshold is checked between turns on built-in runtimes and may overshoot by one in-flight turn; it is not a currency or aggregate spend cap.</Warning>```browser -> your backend: create task@@ -75,6 +75,25 @@ browser -> OpenComputer: stream + steer (client_token)For the SSE stream the browser passes the client token as `?token=` (native `EventSource` can't set an `Authorization` header); other calls use the `Authorization` header normally.+## Hook URLs++A [Hook URL](/agent-sessions/hooks) is a bearer credential embedded in one+agent's `/hooks/<token>` path. It grants only the ability to start a fresh+session on that agent. It cannot read or steer the created session, invoke+another agent, or call management routes. The sender supplies no Authorization+header.++The complete URL is returned once on creation and stored only as a hash. Create+one per external system so you can revoke it independently. Do not put Hook+URLs in source control, logs, analytics, browser URLs, or public documentation.++| Surface | Credential | Capability |+| --- | --- | --- |+| Agent URL `POST /` | org API key | create a session; receive a scoped client token |+| Agent URL `POST /hooks/<token>` | Hook URL | create a session only |+| Sessions API read/stream/steer | client token or org API key | one scoped session, or full org authority |+| Management API | org API key | agents, sessions, Hooks, credentials, and other account resources |+## Model credentialsSessions run the model either **Managed** — via OpenComputer, billed to your **credits**, with no key (the default for new orgs) — or on **your own provider key** (Anthropic for the `claude` [runtime](/agent-sessions/runtimes), OpenAI for `codex`). A bring-your-own key is stored at rest in a dedicated secrets vault ([Infisical](https://infisical.com)), write-only, and **never returned** by the API. The real key never enters a sandbox: the runtime gets an opaque placeholder, and a [secret-store egress proxy](/sandboxes/secrets) swaps in the real value in flight, only on the outbound HTTPS call to the provider. A key isn't required — Managed needs none; a session fails to start (`422 no_credential`) only when it resolves to neither Managed nor a usable key.diff --git a/docs/agent-sessions/flue.mdx b/docs/agent-sessions/flue.mdxindex e0346359..1cfece63 100644--- a/docs/agent-sessions/flue.mdx+++ b/docs/agent-sessions/flue.mdx@@ -408,6 +408,9 @@ and dashboard as the other runtimes. The important differences are:not part of the public API.- Follow-up messages queue behind the working turn and run in order.- The model is compiled into the deployed app. Per-session model overrides are rejected.+- Durable model-call usage is folded into turn and session usage with+ `attribution: "best_effort"`. Use it for visibility; the agent/org gateway is+ the hard spend-enforcement authority.- Generic `tokens`, `turn_seconds`, and `turns` limits are not yet enforced on the Flue executionpath. Do not use them as a safety boundary for this runtime.- Archiving makes the OpenComputer session read-only but retains the Flue conversation in Durablediff --git a/docs/agent-sessions/hooks.mdx b/docs/agent-sessions/hooks.mdxnew file mode 100644index 00000000..a6b7ee30--- /dev/null+++ b/docs/agent-sessions/hooks.mdx@@ -0,0 +1,160 @@+---+mode: "wide"+title: "Hooks (inbound)"+description: "Pasteable, scoped URLs that send external events to an agent"+---++Hooks send external events **to your agent**. Create a named Hook URL for each+external system, then paste it into that system's HTTP or webhook destination.+Each accepted `POST` starts one ordinary durable session on the agent's active+revision.++<Warning>+ The complete URL is a secret. Anyone with it can run this agent. It cannot+ read sessions, manage your account, or invoke another agent. Copy it when it+ is created—the complete URL cannot be retrieved again.+</Warning>++## Create a Hook URL++<CodeGroup>++```ts TypeScript SDK+const created = await oc.agents.hooks.create("agt_...", {+ name: "grafana-prod",+ expiresAt: null,+});++console.log(created.hookUrl); // shown once+```++```bash oc CLI+oc agent hook create grafana-prod --agent reviewer+```++```http REST API+POST https://api.opencomputer.dev/v3/agents/agt_.../hooks+Authorization: Bearer $OPENCOMPUTER_API_KEY+Content-Type: application/json++{ "name": "grafana-prod", "expires_at": null }+```++</CodeGroup>++Names match `^[a-z0-9][a-z0-9-]{0,63}$`. Expiry is optional and must be a+future RFC 3339 timestamp. An agent may have up to 20 non-revoked Hooks; expired+Hooks keep a slot until revoked. Hook lifecycle is operational credential state,+not agent revision state, so deploys and rollbacks do not copy or replace Hooks.++Hook creation is deliberately not idempotent because the secret is stored only+as a hash. If the creation response is lost, list by name, revoke the+inaccessible Hook, and create a replacement.++## Send an event++```bash+curl "$HOOK_URL" \+ -H "Content-Type: application/json" \+ -H "Idempotency-Key: alert-018f" \+ -d '{"status":"firing","service":"checkout","summary":"error rate above 5%"}'+```++The URL authenticates the request; do not add an OpenComputer API key. The+contract is exact `POST`, no query string, and either an empty body or one JSON+value. Non-empty bodies require a JSON content type and are capped at 24 KiB.+The Hook name and parsed payload become a structured `http.request` event; the+secret URL and transport headers never do.++```json+{+ "type": "http.request",+ "actor": { "type": "trigger", "display": "grafana-prod" },+ "body": {+ "payload": {+ "status": "firing",+ "service": "checkout",+ "summary": "error rate above 5%"+ }+ }+}+```++Success returns `200 OK` only after session admission is durable:++```json+{+ "request_id": "req_...",+ "session": { "id": "ses_...", "status": "queued" },+ "replayed": false+}+```++This is an asynchronous receipt, not the agent's output. It contains no client+token and grants no session read or steer access. Watch the session in the+dashboard or configure an outbound [webhook](/agent-sessions/webhooks) for+results.++## Retries and duplicates++For retry-safe delivery, send `Idempotency-Key`; when absent, OpenComputer uses+the Standard Webhooks `webhook-id` header if present. A repeated identifier and+payload returns the same session. Reusing it with different JSON returns `409`.+Without either header, identical requests are separate events and create+separate sessions—OpenComputer does not guess duplicates from the body.++Grafana's standard webhook does not provide either supported delivery-id+header. Do not configure one constant idempotency key for all Grafana alerts;+later alerts would conflict or replay. Accept possible redelivery duplicates,+deduplicate their side effects, or use a provider-verified connector when that+is unacceptable.++## List, replace, and revoke++<CodeGroup>++```ts TypeScript SDK+const page = await oc.agents.hooks.list("agt_...", {+ includeRevoked: true,+});++await oc.agents.hooks.delete("agt_...", "hk_...");+```++```bash oc CLI+oc agent hooks --agent reviewer --include-revoked+oc agent hook get grafana-prod --agent reviewer+oc agent hook revoke grafana-prod --agent reviewer+```++```http REST API+GET /v3/agents/agt_.../hooks?include_revoked=true+GET /v3/agents/agt_.../hooks/hk_...+DELETE /v3/agents/agt_.../hooks/hk_...+```++</CodeGroup>++Lists contain the name, public Hook id, status, expiry, creation time, secret+last four, and revoke reason—never the usable URL. To rotate, create a new Hook,+update the external system, then revoke the old one. Revocation is irreversible+and does not affect sessions the Hook already created.++## Security, usage, and limits++Hook names record intended custody; they do not prove that a named provider sent+the request. A Hook does not validate provider signatures, challenge requests,+or raw-body semantics. Use a provider connector for those guarantees, and do+not send payloads the agent is not allowed to receive.++Rate limits reduce bursts; they are not a spend cap. Every accepted POST creates+a fresh session, so all per-session limits reset on every call. On built-in+runtimes, `limits.tokens` is checked between turns from reported usage and can+overshoot by one in-flight turn; it does not interrupt a model request. It is+not a currency limit or an aggregate Hook quota. Set agent turn/time/token+limits, monitor session usage, and revoke unexpected activity. Your+organization's credit halt is the aggregate fuse.++Flue sessions expose best-effort per-session token attribution; the agent/org+gateway remains their spend-enforcement authority. See [session usage and+limits](/agent-sessions/sessions#usage-and-limits).diff --git a/docs/agent-sessions/schedules.mdx b/docs/agent-sessions/schedules.mdxindex e5c4ea66..e6e56154 100644--- a/docs/agent-sessions/schedules.mdx+++ b/docs/agent-sessions/schedules.mdx@@ -244,7 +244,7 @@ Fields: `id` (`srn_…`), `scheduled_for?` (the slot; `null` for a manual fire),- Cron floor **1 minute**.<Warning>-Scheduled sessions run unattended — cap them. Set agent [`limits`](/agent-sessions/sessions#limits) `turns` and `turn_seconds` (every run inherits them). `limits.tokens` is not enforced yet, so don't rely on it to bound spend.+Scheduled sessions run unattended—set agent [`limits`](/agent-sessions/sessions#usage-and-limits), which every run inherits. On built-in runtimes, `limits.tokens` is an observed inter-turn threshold and may overshoot by one turn; it is not a currency or cross-session spend cap. The current Flue execution path does not enforce the generic session limits.</Warning>## Dashboarddiff --git a/docs/agent-sessions/sessions.mdx b/docs/agent-sessions/sessions.mdxindex 7e7e62cf..9660eb3c 100644--- a/docs/agent-sessions/sessions.mdx+++ b/docs/agent-sessions/sessions.mdx@@ -39,7 +39,7 @@ Pass [`sources`](/agent-sessions/repos) to give a session working repositories.| `failed` | The session errored out. || `archived` | Closed; read-only. |-A session also carries `last_turn = { id, state, yield_reason?, result_event_id? }`; the fuller turn record (`started_at`, `completed_at`, `error`) comes from [`GET …/result`](/agent-sessions/api-reference) and `…/turns`. The **`yield_reason`** tells you why the last turn ended: `completed`, `needs_input` (the agent asked a question and the session is now `awaiting_input`), `budget_exceeded`, `deadline_exceeded`, `max_turns`, or `canceled`. Limit outcomes require runtime enforcement; the current Flue path does not enforce the generic session limits below.+A session also carries `last_turn = { id, state, yield_reason?, result_event_id? }`; the fuller turn record (`started_at`, `completed_at`, `active_seconds`, `usage`, `error`) comes from [`GET …/result`](/agent-sessions/api-reference) and `…/turns`. The **`yield_reason`** tells you why the last turn ended: `completed`, `needs_input` (the agent asked a question and the session is now `awaiting_input`), `budget_exceeded`, `deadline_exceeded`, `max_turns`, or `canceled`. Limit outcomes require runtime enforcement; the current Flue path does not enforce the generic session limits below.## Fetch the result@@ -96,14 +96,54 @@ Three independent knobs — don't overload one for another:- **`Idempotency-Key`** (header) — _retry-safe create_. Makes a keyless create safe to retry (e.g. on a webhook redelivery) without spawning duplicates.- **`metadata`** — _routing / app state_. Opaque JSON (≤ 16 KB) echoed back on get/list and **verbatim in webhooks**, so your callback can route to the right record. Never use `key` for routing — that's what `metadata` is for.-## Limits+## Usage and limits-Cap a session at create (or default it on the [agent](/agent-sessions/agents)) with `limits: { tokens, turn_seconds, turns }` — a token budget, per-turn wall-clock, and auto-run count. These are runtime limits, not spend controls; model usage is billed to your provider key (BYO) or to your OpenComputer credits (Managed). Hitting one ends the turn with the matching `yield_reason`.+Terminal turns expose `active_seconds` and normalized `usage`. A reported turn+contains four disjoint token components, their `tokens` sum, and optional+`total_cost_usd`. Missing cost means unknown, not zero. A turn without a+trustworthy runtime result returns `reported: false` instead of inventing a+zero.++The session `usage` rollup contains:++```json+{+ "active_seconds": 42,+ "reported_turns": 2,+ "unreported_turns": 0,+ "complete": true,+ "input_tokens": 8200,+ "output_tokens": 640,+ "cache_creation_input_tokens": 0,+ "cache_read_input_tokens": 1200,+ "tokens": 10040,+ "total_cost_usd": 0.0231,+ "attribution": "exact"+}+```++If `complete` is false, any token or cost total present is a **lower bound**.+Historical sessions created before usage reporting may return an empty object;+clients should show that as unknown. `total_cost_usd` is runtime/provider-+reported visibility, not the billing ledger.++Cap a session at create (or default it on the [agent](/agent-sessions/agents))+with `limits: { tokens, turn_seconds, turns }`: an observed token threshold,+per-turn wall-clock limit, and auto-run count. These are runtime limits, not+currency or aggregate spend controls.++On built-in runtimes, `limits.tokens` is evaluated from committed usage before+the next model turn. It does not interrupt an in-flight request and can+overshoot by one turn. `turn_seconds` and the organization's credit halt are+separate controls. A [Hook](/agent-sessions/hooks) starts a fresh session, so+all three limits reset on every accepted Hook POST.<Warning>- These limits are not yet enforced for [Flue](/agent-sessions/flue) sessions.- Do not use them as a deadline, turn-count, or token safety boundary for that- runtime.+ [Flue](/agent-sessions/flue) exposes best-effort per-session usage+ attribution; its agent/org gateway remains the spend-enforcement authority.+ The generic session limits are not enforced on the current Flue execution+ path, so do not use them as its deadline, turn-count, or token safety+ boundary.</Warning>## Modeldiff --git a/docs/agent-sessions/webhooks.mdx b/docs/agent-sessions/webhooks.mdxindex 0492ee38..a4f2de4d 100644--- a/docs/agent-sessions/webhooks.mdx+++ b/docs/agent-sessions/webhooks.mdx@@ -6,6 +6,11 @@ description: "Deliver session events to your backend"Register a **destination** to receive a session's [events](/agent-sessions/events) as a **delivery envelope**. Deliveries are at-least-once, signed when a secret is set, and retried. The envelope carries routing fields, session [`metadata`](/agent-sessions/api-reference#sessions), and the full event under `event`:+<Note>+ Webhooks send your agent's events **to your application**. To send external+ events **to an agent**, use an inbound [Hook URL](/agent-sessions/hooks).+</Note>+```json{"type": "turn.completed", // the event type (route on this)diff --git a/docs/cli/overview.mdx b/docs/cli/overview.mdxindex f4cd7177..db3439a6 100644--- a/docs/cli/overview.mdx+++ b/docs/cli/overview.mdx@@ -132,6 +132,7 @@ oc exec $ID2 --wait -- ./test-b.sh| [`oc checkpoint`](/cli/checkpoint) | Snapshot, fork, restore || [`oc patch`](/cli/patch) | Checkpoint-attached scripts || [`oc preview`](/cli/preview) | Expose ports to the internet |+| [`oc agent`](/reference/cli/agent) | Invoke durable agents and manage Hook URLs || [`oc config`](/reference/cli#oc-config) | Configure API key and API URL |<Tip>diff --git a/docs/docs.json b/docs/docs.jsonindex 713e5d3a..b5d902c8 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -76,6 +76,8 @@"agent-sessions/revisions","agent-sessions/skills","agent-sessions/sessions",+ "agent-sessions/agent-urls",+ "agent-sessions/hooks","agent-sessions/credentials","agent-sessions/repos","agent-sessions/events",@@ -188,6 +190,7 @@"reference/cli/checkpoint","reference/cli/patch","reference/cli/preview",+ "reference/cli/agent","reference/cli/config"]},diff --git a/docs/reference/cli/agent.mdx b/docs/reference/cli/agent.mdxnew file mode 100644index 00000000..1a0bed5b--- /dev/null+++ b/docs/reference/cli/agent.mdx@@ -0,0 +1,65 @@+---+title: "Agent URLs and Hooks"+description: "Invoke agents and manage scoped Hook URLs"+---++These commands use the Durable Agent Sessions API and the API key configured by+`oc login`, `OPENCOMPUTER_API_KEY`, or `--api-key`.++## oc agent invoke++Start a durable session through an agent's canonical URL:++```bash+oc agent invoke <id|name> \+ [--data '<json>' | --file <path> | --stdin] \+ [--idempotency-key <key>] \+ [--json]+```++`--data` defaults to `{}`. The CLI rejects non-JSON input locally, calls exact+`POST /` with the configured org key, and prints the accepted session id plus+follow/steer commands. It generates one idempotency key and keeps it stable+across automatic retries; supply your own key when separate command runs must+converge.++Use `oc session create` instead when you need model, source, destination, or+per-session limit overrides.++## oc agent hook create++```bash+oc agent hook create <name> --agent <id|name> \+ [--expires-at <rfc3339>] [--json]+```++Creates a named Hook and prints its complete secret URL once. If `--agent` is+omitted, the CLI resolves the agent from `agent.toml` in the current directory.++## oc agent hooks++```bash+oc agent hooks --agent <id|name> \+ [--include-revoked] [--cursor <cursor>] [--limit <n>] [--json]+```++Lists secret-free Hook metadata. Pagination is newest-first and the server caps+`--limit` at 100.++## oc agent hook get++```bash+oc agent hook get <hook-id|name> --agent <id|name> [--json]+```++Shows status, expiry, secret last four, and revoke reason. It cannot recover the+complete URL.++## oc agent hook revoke++```bash+oc agent hook revoke <hook-id|name> --agent <id|name> [--yes] [--json]+```++Irreversibly revokes the Hook after confirmation. Create and install a+replacement first if the external integration must stay available.diff --git a/docs/reference/cli/overview.mdx b/docs/reference/cli/overview.mdxindex fd00e480..0e40f6d2 100644--- a/docs/reference/cli/overview.mdx+++ b/docs/reference/cli/overview.mdx@@ -40,6 +40,9 @@ These flags apply to all commands.<Card title="oc preview" icon="globe" href="/reference/cli/preview">Manage preview URLs</Card>+ <Card title="oc agent" icon="robot" href="/reference/cli/agent">+ Invoke agents and manage Hook URLs+ </Card><Card title="oc config" icon="gear" href="/reference/cli/config">CLI configuration</Card>