Skip to content
Rapadura NetworkPHP Com Rapadura
On this page

API examples

These curl examples show request and response bodies for common agent calls. Every token is a placeholder. $RAPADURA_TOKEN is a token you hold: use a person's login token to mint an agent token, and an agent token for the other calls. rpd_... represents a token secret, which the gateway shows once. Replace https://agents.example.test with your gateway's address.

The shapes come from the wire types in internal/api (the JSON names are their json tags) and from the end-to-end tests. An answer marked abridged leaves fields out; its values are illustrative. Detailed operations and request-key contracts for staff/organizers live in /docs/staff/.

Send one Idempotency-Key header per change. Repeat it on a retry. A change that ended failed replays its failure for the same key. After you fix the cause, send a new key to try again. The response includes the operation in the Rapadura-Operation header. The body includes an operation that is final only when its state is succeeded.

Minting an agent token

Only a person's token mints one (an agent's token is refused: e2e_agent_token_test.go). The secret is shown once.

shell
curl -sS -X POST https://agents.example.test/v1/agents/tokens \
  -H "Authorization: Bearer $RAPADURA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "ci-bot",
    "apps": ["meetup.rapadura.net"],
    "actions": ["site.read", "site.publish", "operation.read", "env.write"],
    "ttl": "720h",
    "max_pending": 2
  }'

apps is a list of hosts or ["*"]; actions is a subset of the grantable actions (api.AgentActions plus api.RecipeActions). Omitting it grants only the default api.AgentActions. Recipe permissions require explicit actions and exact hosts; * is refused when any recipe action is requested. ttl is 720h or 30d, at most 90 days, default 30 days; max_pending is 0 for the gateway's default. Response, 201 Created (abridged):

JSON
{
  "token": {
    "id": 42,
    "name": "ci-bot",
    "user": "example-user",
    "kind": "agent",
    "expires_at": "2026-11-28T12:00:00Z",
    "grant": {
      "tenant": 7,
      "apps": ["meetup.rapadura.net"],
      "actions": ["env.write", "operation.read", "site.publish", "site.read"],
      "limits": {"max_pending": 2}
    }
  },
  "secret": "rpd_..."
}

Reading the grant

GET /v1/me/grant tells a token what it can do now. For an agent, actions and apps are what is effective (after the kill switch), and notes says why they differ from the stored grant. Response, 200 OK (abridged: notes is omitted when empty):

shell
curl -sS https://agents.example.test/v1/me/grant \
  -H "Authorization: Bearer $RAPADURA_TOKEN"
JSON
{
  "kind": "agent",
  "grant": {
    "tenant": 7,
    "apps": ["meetup.rapadura.net"],
    "actions": ["env.write", "operation.read", "site.publish", "site.read"],
    "limits": {"max_pending": 2}
  },
  "actions": ["env.write", "operation.read", "site.publish", "site.read"],
  "apps": ["meetup.rapadura.net"],
  "expires_at": "2026-11-28T12:00:00Z",
  "limits": {"max_pending": 2}
}

Publishing with an Idempotency-Key

A publish is multipart/form-data: the zip in the archive part, an optional message, and an optional request_key. The X-Archive-Size header is the archive's size in bytes; the CLI sends it with the archive. The answer is 201 Created with the receipt; the site must exist already (POST /v1/sites). If you send the key as a form field instead of the header, put it before archive: the archive is accepted as soon as it is received, and a key read after it is too late to bind.

shell
curl -sS -X POST https://agents.example.test/v1/sites/meetup.rapadura.net/versions \
  -H "Authorization: Bearer $RAPADURA_TOKEN" \
  -H "Idempotency-Key: publish-meetup-2026-10-29-001" \
  -H "X-Archive-Size: $(stat -c %s dist.zip)" \
  -F "message=release 2026-10-29" \
  -F "archive=@dist.zip;type=application/zip"

Response, 201 Created (abridged). The header Rapadura-Operation: op_01JB3Q8Z0M6W0V1K7T4N2R9XYA carries the same id as operation.id:

JSON
{
  "site": {"id": 3, "slug": "meetup", "zone": "rapadura.net", "host": "meetup.rapadura.net", "kind": "static"},
  "version": {"num": 4, "status": "live", "size_bytes": 48213, "file_count": 12, "message": "release 2026-10-29", "created_by": "example-user"},
  "live_url": "https://meetup.rapadura.net/",
  "changed": {"files": 12, "bytes": 48213},
  "share_blurb": "...",
  "operation": {
    "id": "op_01JB3Q8Z0M6W0V1K7T4N2R9XYA",
    "action": "site.publish",
    "state": "succeeded",
    "reason": "ok",
    "reason_text": "version 4 is live",
    "next_actions": ["read the result; the change is live only if the result says so"]
  },
  "recovery": {
    "code": "rollback to a retained version is possible with rapadura rollback",
    "data": "a database migration the code ran is not reversed by a rollback",
    "external": "messages sent and changes made outside the app are not reversed"
  }
}

The receipt is read back from the system. The operation can still be queued or running, for example while an app builds or a change waits its turn. Poll the operation below until it is succeeded. A publish held for a person's approval is succeeded with reason held and pending set. For example, an agent's publish on an app with secrets may be held. A held publish is not live.

Reading, listing and cancelling an operation

shell
curl -sS https://agents.example.test/v1/operations/op_01JB3Q8Z0M6W0V1K7T4N2R9XYA \
  -H "Authorization: Bearer $RAPADURA_TOKEN"

curl -sS "https://agents.example.test/v1/operations?host=meetup.rapadura.space&state=running" \
  -H "Authorization: Bearer $RAPADURA_TOKEN"

curl -sS -X POST https://agents.example.test/v1/operations/op_01JB3Q8Z0M6W0V1K7T4N2R9XYA/cancel \
  -H "Authorization: Bearer $RAPADURA_TOKEN"

GET /v1/operations/{id} answers an Operation (abridged). GET /v1/operations answers {"operations": [...]} (newest first, at most 100). The cancel answers the operation as it is then: a queued one is cancelled at once; a running one keeps its state and sets cancel_requested until it stops at its next safe point. One that is needs_attention is the owner's to resolve: only the owner acting as a person cancels it; anyone else gets 409 (the message says that the owner resolves it) and the operation stays as it was.

JSON
{
  "id": "op_01JB3Q8Z0M6W0V1K7T4N2R9XYA",
  "seq": 17,
  "host": "meetup.rapadura.space",
  "action": "site.publish",
  "state": "running",
  "actor": "example-user",
  "actor_kind": "agent",
  "attempt": 1,
  "progress": [
    {"step": "received", "at": "2026-10-29T12:01:02Z", "status": "ok"},
    {"step": "stage", "at": "2026-10-29T12:01:03Z", "status": "ok"}
  ],
  "cancel_requested": true,
  "created_at": "2026-10-29T12:01:02Z",
  "started_at": "2026-10-29T12:01:02Z",
  "next_actions": [
    "poll until it is final: rapadura ops wait op_01JB3Q8Z0M6W0V1K7T4N2R9XYA",
    "ask it to stop at its next safe point: rapadura ops cancel op_01JB3Q8Z0M6W0V1K7T4N2R9XYA (what ran already is not undone)"
  ],
  "recovery": {"code": "...", "data": "...", "external": "..."}
}

A final operation keeps result: the receipt when it succeeded, or the error envelope when it failed ({"error": {...}, "status": 409}). It is kept for seven days after it finished (expires_at).

Planning a change

POST /v1/sites/{host}/plans answers what a change would be, and stores nothing. The body is the change in its own words: action (site.publish, site.rollback, site.delete, site.restore, env.apply, cron.set, caps.set, domain.add, domain.remove, site.purge), and for env.apply the env object with set (key, kind, value) and unset (key). A secret's value is never part of a plan: a secret is set by a person. Response, 200 OK (abridged):

shell
curl -sS -X POST https://agents.example.test/v1/sites/agenda.example.test/plans \
  -H "Authorization: Bearer $RAPADURA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "env.apply",
    "env": {
      "set": [{"key": "APP_URL", "kind": "variable", "value": "https://agenda.example.test"}],
      "unset": [{"key": "OLD_FLAG"}]
    }
  }'
JSON
{
  "plan": {"v": 1, "action": "env.apply", "target": "agenda.example.test", "...": "..."},
  "digest": "<sha256 hex of the canonical plan>",
  "requires_approval": true,
  "why": "...",
  "conditions": ["..."],
  "recovery": {"code": "...", "data": "...", "external": "..."}
}

requires_approval and why say whether the change waits for a person (the code gate, the owner's approval). An approval of this plan is stale once one of its conditions moves; then plan again.

An environment batch

PUT /v1/sites/{host}/env changes many keys in one change: every entry is checked first, and if one is refused nothing is written. set entries take key, value and kind (variable or secret; for an agent, a variable). unset entries take key (and kind when given). dry_run: true checks and answers the plan only. The same key as the header may also be sent as request_key in the body.

shell
curl -sS -X PUT https://agents.example.test/v1/sites/agenda.example.test/env \
  -H "Authorization: Bearer $RAPADURA_TOKEN" \
  -H "Idempotency-Key: env-agenda-2026-10-29-01" \
  -H "Content-Type: application/json" \
  -d '{
    "set": [
      {"key": "APP_URL", "value": "https://agenda.example.test", "kind": "variable"},
      {"key": "FEATURE_SIGNUPS", "value": "on", "kind": "variable"}
    ],
    "unset": [{"key": "OLD_FLAG"}],
    "dry_run": false
  }'

Response, 200 OK (abridged). It is 202 Accepted when a member's change waits for the owner (then request is set and nothing was written). A change that leaves the environment as it was answers "changed": false, with no operation:

JSON
{
  "host": "agenda.example.test",
  "keys": [
    {"key": "APP_URL", "kind": "variable", "value": "https://agenda.example.test", "set_by": "example-user", "set_at": "2026-10-29T12:05:00Z"},
    {"key": "DB_PASSWORD", "kind": "secret", "set_by": "example-user", "set_at": "2026-10-20T09:00:00Z"}
  ],
  "applied": true,
  "version": 4,
  "revision": 12,
  "changed": true,
  "operation": {
    "id": "op_01JB3RA0X4Z7K2M9P5Q8T1V3WD",
    "action": "env.apply",
    "state": "succeeded",
    "reason": "ok",
    "reason_text": "...",
    "next_actions": ["read the result; the change is live only if the result says so"]
  },
  "state": {"desired": 12, "applied": 12, "healthy": 12, "status": "in_sync"}
}

On an app with a secret whose agent_code is ask, an agent's change answers 200 with pending set (the request for the person): nothing is written, and keys is the environment as it still is.

A secret's value is never in an answer; a variable's is. state.status is in_sync, pending, unhealthy or degraded; degraded is set when a failed change could not be taken back.

Reading limits

GET /v1/me/limits (the MCP tool show_limits) gives the caller's tenant's limits, usage and live reservations. A 0 limit is no limit. Response, 200 OK (abridged; the numbers are illustrative):

shell
curl -sS https://agents.example.test/v1/me/limits \
  -H "Authorization: Bearer $RAPADURA_TOKEN"
JSON
{
  "limits": {
    "max_sites_per_user": 5,
    "max_bytes_per_user": 524288000,
    "max_apps_per_user": 0,
    "max_cpus_per_user": 0,
    "max_memory_mb_per_user": 0,
    "max_pending": 2,
    "max_uploads": 2,
    "max_builds": 1,
    "requests_per_minute": 120,
    "worker_slots": 4,
    "max_retries": 3
  },
  "role": "member",
  "allowance_source": "default",
  "usage": {"sites": 2, "apps": 0, "deleted_sites": 0, "deleted_apps": 0, "bytes": 1048576, "pending": 1, "uploads": 0, "builds": 0, "cpus": 0, "memory_mb": 0, "worker_slots_busy": 1},
  "reservations": [
    {"kind": "publish", "amount": 1, "holder": "op:op_01JB3Q8Z0M6W0V1K7T4N2R9XYA", "expires_at": "2026-10-29T12:31:02Z"}
  ],
  "apps": [],
  "notes": ["..."]
}

Organizers (staff) have role: "organizer", higher site allowances (10 by default), and container app caps (max_apps_per_user, max_cpus_per_user, max_memory_mb_per_user, plus the apps list).

Refusals an agent meets most

Every refusal is {"error": {"code", "message", "hint?", "docs_url?", "retry_after?", "operation_id?"}}. The wording of message and hint varies with the path; the code and the status are the contract (error codes). The examples are abridged.

grant_denied: the token's grant does not cover the action on this app (403). Nothing was changed. The hint says what a person does.

JSON
{"error": {
  "code": "grant_denied",
  "message": "this agent's grant does not allow site.publish on agenda.example.test",
  "hint": "a person mints an agent a wider token: rapadura agent create --apps <hosts or *> --actions <list>; rapadura agent grant shows what this one holds"
}}

operation_conflict: another change to the site is running (409). The change was not recorded. operation_id names the one that holds the site.

JSON
{"error": {
  "code": "operation_conflict",
  "message": "another change to agenda.example.test is running: op_01JB3Q8Z0M6W0V1K7T4N2R9XYA (site.publish, started 2026-10-29T12:01:02Z)",
  "hint": "wait for it: rapadura ops wait op_01JB3Q8Z0M6W0V1K7T4N2R9XYA, then send the change again",
  "operation_id": "op_01JB3Q8Z0M6W0V1K7T4N2R9XYA"
}}

request_key_conflict: the key was used for a different change (409). Nothing was changed, and the key stays on that other change. A new change takes a new key. The message names the other operation, and operation_id carries it, only for a caller who may read that operation; an agent whose grant does not cover its app gets the message without them.

JSON
{"error": {
  "code": "request_key_conflict",
  "message": "request key \"publish-meetup-2026-10-29-001\" was used for another change: op_01JB3Q8Z0M6W0V1K7T4N2R9XYA (site.publish meetup.rapadura.space)",
  "hint": "a new change takes a new key; a retry of the same change keeps its key and gets the same operation back",
  "operation_id": "op_01JB3Q8Z0M6W0V1K7T4N2R9XYA"
}}

capacity_exhausted: the person's or the agent's changes in flight are at the limit (429). The same number is in the Retry-After header (abridged; the message names the kind and the numbers).

http
HTTP/1.1 429 Too Many Requests
Retry-After: 15
Content-Type: application/json
JSON
{"error": {
  "code": "capacity_exhausted",
  "message": "you have 2 changes queued or running and the limit is 2",
  "hint": "retry in 15 seconds; wait for one to finish, then try again; GET /v1/me/limits (show_limits) lists them",
  "retry_after": 15
}}

stale_approval: what was approved is not what would run now (409). It is the error the approved change ended with, so the operation is failed. Read it with GET /v1/operations/{id}: its reason is refused and its result holds the envelope (abridged). A new plan and a new approval are needed.

JSON
{
  "id": "op_01JB3RB7M2N9Q4T6V8X0Z3CE5F",
  "action": "env.apply",
  "host": "agenda.example.test",
  "state": "failed",
  "reason": "refused",
  "result": {
    "error": {
      "code": "stale_approval",
      "message": "request #12 was approved for another state of agenda.example.test: what would run now is not what was approved, so nothing ran"
    },
    "status": 409
  }
}

The same calls as MCP tools

The hosted MCP endpoint (/mcp) takes an agent's token. Each tool's arguments are its JSON fields; request_key is the MCP form of the Idempotency-Key header; the write tools that take one are marked in the table by the request_key? argument. Tools with no REST call of their own are noted. For the full tool inventory split by member vs. staff capabilities, see Agent inventory (source: internal/mcpserver/tools.go and tools_plan.go). Container app (*_app_*, create_app) and Laravel (list_apps, artisan) tools require staff/organizer access.

MCP tool arguments REST call
whoami none GET /v1/me
show_limits none GET /v1/me/limits
list_sites none GET /v1/sites
show_site host GET /v1/sites/{host}
list_zones none GET /v1/zones
create_site slug? (leave it out for a generated name in the hosting zone), zone?, title?, request_key? POST /v1/sites (kind static)
publish_site host, files? ([{path, content, encoding?}]), path? (local lane only), message?, create?, zone?, title?, runtime?, request_key? POST /v1/sites/{host}/versions (multipart)
list_versions host GET /v1/sites/{host}/versions
rollback_site host, version, request_key? POST /v1/sites/{host}/rollback
delete_site host, request_key? DELETE /v1/sites/{host}
restore_site host, request_key? POST /v1/sites/{host}/restore
site_logs host, lines? (default 200, max 2000) GET /v1/sites/{host}/logs
request_domain host, domain, rationale? POST /v1/sites/{host}/domains
list_domains host GET /v1/sites/{host}/domains
remove_domain host, domain, request_key? DELETE /v1/sites/{host}/domains/{domain}
list_approvals none GET /v1/approvals
list_apps none GET /v1/apps
artisan app, args (array, no leading artisan), request_key? POST /v1/apps/{app}/artisan
create_app slug? (generated like create_site), runtime (php8.4 or node22), zone?, title?, request_key? POST /v1/sites (kind app)
list_app_env host, history? GET /v1/sites/{host}/env (history: GET /v1/sites/{host}/env/revisions)
set_app_env host, key, value, not_secret? PUT /v1/sites/{host}/env/{key}
apply_app_env host, set ([{key, value, not_secret?}]), unset (array of key names), dry_run?, request_key? PUT /v1/sites/{host}/env (set and unset as objects; not_secret as a list of names)
unset_app_env host, key DELETE /v1/sites/{host}/env/{key}
request_app_secret host, key none: returns the secret page link and a command for the person
list_app_cron host GET /v1/sites/{host}/cron
set_app_cron host, jobs ([{name, schedule, command}]), request_key? PUT /v1/sites/{host}/cron
plan_change host, action, version?, jobs?, env? ({set, unset}), domain?, caps? POST /v1/sites/{host}/plans
get_operation id GET /v1/operations/{id}
list_operations host?, state? GET /v1/operations?host=&state=
cancel_operation id POST /v1/operations/{id}/cancel

Not on MCP: minting and reading tokens and grants (POST /v1/agents/tokens, GET /v1/me/grant: a person's act), and resolving an operation (POST /v1/operations/{id}/resolve, the owner's).