The shape of it

An agent edits a doc in one POST:
Response on success:
The server fetches the current markdown, runs an LLM call as the doc owner to produce the edited markdown, encrypts it, pushes a new rack commit, and returns the new commit CID + the raw token counts that were billed to the owner.

Getting a token

Only the doc owner can mint agent tokens. From the owner’s browser:
Response:
The agentToken is shown exactly once. Paste it into the agent’s config and treat it like an API key — it carries the agent’s edit scope and nothing else.
Agents get a strict cap by default: 20 edits/day and 70 000 tokens/day (50 k input + 20 k output). The owner can override both at invite time via dailyEditCap and dailyTokenCap.

Billing

  • 1x metering invariant. The owner is billed the exact token count StackNet reports (input_tokens + output_tokens), with no multiplier for the encryption overhead. Encrypted and plaintext docs cost identically for the same LLM work.
  • Per-agent daily caps, per-doc global caps, and short-window burst limits (5 edits / 60 s per agent-doc pair) all enforce before any LLM call.
  • See Billing for details.

Revocation & rotation

Owner revokes by member id:
Effective immediately — the next agent-edit call with the revoked token returns 403 forbidden:document "Agent grant revoked". The JWT signature alone is not sufficient: every request re-checks DocMember.revokedAt in the DB. To rotate a compromised token: revoke + re-invite. The new invite gets a fresh jti and a fresh JWT.

Failure modes, by status code

Prompt-injection filter

The agent-edit endpoint runs a short-list regex filter on the instruction before calling StackNet. Current rules reject known exfil patterns (override-instructions, reveal-system-prompt, exfil-secrets, role-flip, tool-abuse) and log every hit. This is a bounded-damage defense, not prevention. The real money- preserving defense is the per-agent daily token cap. Don’t design around the filter — design around the cap.

Delegation expiry

Agent edits require a valid StackAuth JWT for the doc owner, captured at doc-create time (or on the owner’s next edit). StackAuth JWTs expire. When the captured JWT’s exp has passed, agent edits fail with 402 payment_required:document. Recovery: the owner signs in and touches the doc once (any PATCH). Their fresh session JWT is captured and re-wrapped, unblocking agents. A dedicated “refresh delegation” endpoint is on the roadmap so the owner doesn’t need to make a content edit.

End-to-end example