Use the Surface API¶
The Surface API is how a surface (a web app, a chat bot, an IDE extension, a scheduler) submits work, answers the
agent, reviews results and follows what happens. It is HTTPS and JSON, versioned under /v1. The
API reference lists every operation and field; this page explains the rules they share.
Getting started uses most of them against a local stack.
Authentication¶
Every request carries an access token from an issuer listed under issuers in the
identity configuration:
Authorization: Bearer <access token>
The token's issuer and subject must be bound to a principal of the tenant in the path
(provision bind). A principal reads and acts on the tasks it submitted; one granted
tenant reader reads every task in the tenant. A token issued for the adapter
endpoint's audience is refused here.
Paths¶
Everything belongs to a tenant: https://HOST:8443/v1/tenants/{tenant}/.... Identifiers are UUIDv7 strings.
| Area | Operations |
|---|---|
| Providers | List the runtime and environment providers you may name. |
| Agents | Create an agent; list, read, revise, suspend, resume and retire agents; read an earlier revision of one. |
| Tasks | Submit a task, to an agent or to providers you name; list the tasks you may read; read one with its attempt, open attention and revisions; read one attempt or revision; request cancellation. |
| Attention | List open attention requests; read one; read question text; inspect a runtime action or connector proposal; decide it. |
| Results | Read an artifact of a revision and download its content; review a revision: accept, request changes or reject. |
| Budgets | Complete a submission or rework that is waiting on a spend challenge. |
| Events | Read or stream a task's events, or the whole tenant's. |
| Administration | Migration passes for moving work between runtime harnesses, and revoking a standing authority grant. |
Commands¶
A request that changes something is a command, and two headers make commands safe to retry and to race.
Idempotency-Key is required on every POST and PUT: 1 to 128 bytes you choose, such as a UUID. Repeating a command
with the same key returns the original result instead of acting twice, so a client can retry after a timeout without
submitting a task twice. Reusing a key with a different body is refused with 422.
If-Match is required on commands that change an existing record: deciding an attention request, reviewing,
cancelling, completing a spend challenge, and revising or retiring an agent. It carries the record version you based the command on, from the ETag
of the response you read it in (attention requests also carry it as version). If the record changed since, the
command is refused with 412 and you read it again; without the header, 428.
Errors¶
Errors are RFC 9457 problem documents, application/problem+json, with a
type, a title and sometimes a detail. The ones a client should handle:
| Status | Meaning | What to do |
|---|---|---|
400 |
Malformed body or header, or Idempotency-Key missing. |
Fix the request. |
401 |
No valid token. | Get a new token. |
403 |
The token's principal may not do this. | Check the binding and permissions. |
404 |
No such record, or one this principal may not read: the two look the same, so a response never reveals what it hides. | |
409 |
The lifecycle refused the command in the record's current state; detail names the reason. Or another non-retired agent already has the name. |
Read the record; the command may no longer apply. Choose another name. |
412 |
The record changed since you read it. | Read it again and decide again. |
422 |
Valid JSON that is not a valid command, a reused Idempotency-Key, a provider with no qualified harness or registration, or an agent that does not exist, is suspended or is retired. |
Fix the command or the provisioning. |
428 |
If-Match missing. |
Send it. |
503 |
The operation needs a database migration that has not run yet, during an upgrade. | Retry after the upgrade completes. |
Agents¶
An agent is a named role your tenant delegates work to: a name, a role, optional standing instructions, and the
runtime and environment providers its work goes to by default. Submit a task to it by giving agent_id instead of the
providers; the task keeps the agent's revision at submission. Delegate work to agents covers creating,
revising and retiring agents and what the runtime receives.
Events¶
Each event names the record, what changed, and the state before and after. When an attention request is created,
both feeds emit record_kind: attention_request, event: create, record_version: 1 and
to_state: pending before the attempt's waiting_input event. Use the event's record_id to read the new
request and update an inbox.
Read them as pages of JSON, up to limit (default 100, at most 500) at a time, and pass the last page's
next_cursor as after to continue:
GET /v1/tenants/{tenant}/tasks/{task}/events?after=CURSOR&limit=100
Or send Accept: text/event-stream to receive them as Server-Sent Events
as they happen. Each event's id is its cursor, so a client that reconnects with Last-Event-ID resumes where it
stopped. If the cursor can no longer be honoured, the server sends a reset carrying the cursor to restart from; the
client then reads the record again rather than assuming it missed nothing.
/v1/tenants/{tenant}/events is the same for every task in the tenant the principal can read.
Listing tasks¶
GET /tasks lists the tasks the principal may read, newest first by creation: its own, or the tenant's for a tenant
reader. Narrow it with state and agent, and page it with limit (1 to 200, 50 by default) and cursor. A page
carries next_cursor while another follows; send it back as cursor, and stop when it is absent.
Repeat state to match any of several states. Use context for one conversation and
updated_after for tasks last updated at or after an RFC 3339 timestamp. With include_total=true,
total counts visible matches before cursor pagination. With include_contexts=true, contexts
maps task IDs to their conversation roots when those differ from the task IDs.
Pages are keyed by creation time, which never changes. A task submitted while you page is not skipped or repeated: it
sorts before the first page, so you meet it by listing again, and a task whose state changes does not move. Each entry
is the task record, without its attempt or revisions; read GET /tasks/{task} for those. To learn what changed,
read the event stream from a cursor rather than listing again
(ADR-0028).
On GET /tasks/{task}, set history_limit to 1–10 to request the most recent interactions in
chronological order. The task owner receives the history. A tenant reader can read the task
record and its status.
Providers¶
GET /providers lists the tenant's runtime and environment providers, the two roles you name when you create an agent
or submit a task, so a person can choose one instead of pasting an identifier. Filter with role. Each entry has its
provider_id, its role, a name when the operator gave one with provision register-provider -name, and, for a
runtime, its harness_mode: work is steered only through a live harness. Every principal of the tenant may read it.
Adapter identities, endpoints, credentials and the artifact store a runtime uses are not listed, and neither is
whether an adapter is connected, which no single replica can say for the others.
Artifacts¶
A result revision lists its artifacts by identifier. Read one with
GET /tasks/{task}/artifacts/{artifact}: its kind, media type, size, SHA-256 digest, producer and commit time. Download
its bytes with GET /tasks/{task}/artifacts/{artifact}/content. Both are readable by whoever may read the task
(ADR-0025).
dac-plane relays the content from the artifact store, which a surface never reaches, and checks it on the way:
- The response carries the record's media type and length, its digest as
Repr-Digest: sha-256=:...:and as theETag, and is sent as an attachment withX-Content-Type-Options: nosniffand a sandboxingContent-Security-Policy. The bytes are agent output; open them in a viewer, not in the surface's own page. - A store that answers with another length is refused with
502 artifact-mismatchbefore anything is sent. - Bytes whose digest differs are found while relaying, and the response is aborted before its last bytes. A response that ends early did not deliver the artifact; read it again.
503 artifact-unavailablemeans the content cannot be read now: the store is not connected to this replica, does not offer downloads, refused, or the deployment has not setDAC_ARTIFACT_DOWNLOAD_ORIGINS. The record stays readable.
Questions¶
A runtime that asks a person something in words raises an attention request of kind question. When the adapter
supplies the text, read it with GET /attention/{attention}/question: an ordered list of prompts, each with an id,
a header, the text and optional options (a label and a description; other means a free-text answer is also
accepted). Only the task owner may read it. Everyone else, including a tenant reader, a request that is not a
question and a question without stored text, gets 404. The ETag is the attention version to send as If-Match
when deciding. Prompts a runtime marks secret are never offered: dac-plane declines them before any text is stored
(ADR-0026).
Answer with a decision of kind answer. Its answer maps each prompt id to a one-element array holding the
answer, as in {"scope": ["unit"], "why": ["Faster feedback"]}, and answer_digest is the SHA-256 of that object in
the canonical form of
RFC 8785: keys sorted, no whitespace, strings escaped as JSON.stringify
writes them. dac-plane refuses an answer whose digest differs, that leaves a prompt unanswered, or whose text for a
prompt with options is not one of its labels (422). A question that has stored text must be answered with text. A
request without stored text, such as one raised by an adapter that does not send it, is answered by digest alone, and
text sent for it is refused. While a deployment has not run the schema migration that adds question text, an answer
with text is refused with 503 not-migrated.
Action approvals¶
For a pending runtime action approval, read GET /attention/{attention}/action-proposal before showing the
decision controls. A process.exec proposal carries the exact command and its working directory.
An fs.write proposal carries the exact target path when the provider supplies it. Render the returned
command as text. It can include literal arguments from the provider. Separate environment values, file
contents and raw callbacks stay private.
The response gives the proposal, its action_digest, the attention version, and its scope when set.
Use the ETag as If-Match when posting the decision. An approval once is bound to that action.
Where policy allows standing approval, its authority follows the scope shown on the request.
Only a named responder can read the proposal. Other callers and requests that are closed, expired, or
have no stored proposal receive 404. Codex supplies proposals for ordinary command approvals.
Codex file approvals remain digest-only because their callback supplies no exact target path.
Connector proposals use their separate /attention/{attention}/connector-call route.
Connections and grants¶
A connection names an external account whose credential stays with its connector
adapter. Register one with POST /connections, specifying provider_id and
name. The response includes the connection and, when the adapter is reachable,
an authorization URL. Open that URL to consent at the connector, then send
POST /connections/{connection}/complete with the connection's ETag in
If-Match and a JSON confirmation proof received only by the callback browser.
The proof is never returned by polling. Pending consent returns 409 authorization-pending.
If the initial response has no URL, request one with
POST /connections/{connection}/authorize and an empty JSON object. This command
requires Idempotency-Key: retrying it returns the same URL, while a new key starts
consent again. It also renews an active connection's consent. Consent URLs are
returned only to the connection's owner.
The tenant can read /connections, /connections/{connection} and
/connections/{connection}/tools. Only the owner can grant access with
POST /connections/{connection}/grants. Supply exactly one of agent_id and
task_id, distinct tools, permission (ask or always), call_limit per task
and expires_at. An agent must be active; a task must belong to the connection's
owner. Grants apply only to work owned by that same principal.
Read grants at /connections/{connection}/grants or
/connection-grants/{grant}. Revoke one with
POST /connection-grants/{grant}/revoke, an empty JSON object, an
Idempotency-Key and its If-Match ETag. Remove a connection with
POST /connections/{connection}/remove using the same command headers.
Removal revokes its grants atomically. A 202 response means the connection is
removing: the adapter has not confirmed credential revocation. Retry removal
until it returns 200 with state removed.
Connector writes return 503 not-migrated until schema 18 is installed. Reads
on the previous schema return empty connection lists or 404 for a named record.