Collaboration and automation
Agreements API
Record a contract between two parties: the parties and their representatives, the offered terms, each party's assent with evidence, and the lifecycle from offer to end. Use it for your users' acceptance of your terms, a contract with another business, or an AI agent's operator accepting for the agent.
Contract 1 is the only version: a preview that is never pinned and may change before publication. Only the local service serves it, not the hosted service. A request without Roye-Contract-Version gets contract 1. This page establishes no hosted or paid availability.
Quickstart
A SaaS backend records that a user accepted Terms of Service version 3. Its backend key registers a service identity, then creates an organization party for the service and a person party for the user, with the user's ID as externalRef.
# Your backend key, with the agreements scope, registers its service identity once.
# Every request carries these headers.
POST /v1/agreements/identities
Authorization: Bearer <backend key>
X-Roye-Project: <project id>
X-Roye-Environment: production
Roye-Contract-Version: 1
Content-Type: application/json
{ "idempotencyKey": "identity-backend", "displayName": "SaaS backend" }
# One organization party for your service and one person party per end user.
POST /v1/agreements/parties
{ "idempotencyKey": "party-service", "kind": "organization", "displayName": "Example SaaS", "externalRef": "service" }
POST /v1/agreements/parties
{ "idempotencyKey": "party-user_8812", "kind": "person", "displayName": "End user",
"externalRef": "user_8812", "metadata": { "plan": "team" } }
# Find the user's party later by your own user ID.
GET /v1/agreements/parties?externalRef=user_8812Create the agreement, then offer it.
# Terms of Service version 3 between your service and the user. The response is a draft with revision 1.
POST /v1/agreements
{ "idempotencyKey": "tos-v3-user_8812", "partyIds": ["<servicePartyId>", "<userPartyId>"],
"terms": { "title": "Terms of Service", "body": "<full terms text>", "attributes": { "version": 3 },
"startsAt": null, "expiresAt": null } }
# Offer it. acceptBy is epoch milliseconds, at most 30 days ahead.
POST /v1/agreements/<agreementId>/offer
{ "idempotencyKey": "tos-v3-user_8812-offer", "expectedRevision": 1, "acceptBy": <epoch ms, at most 30 days ahead> }Record both assents. The user's assent carries click_through evidence. The second assent forms the agreement, and it is active at once.
# Your service accepts. A backend key always sends evidence.
POST /v1/agreements/<agreementId>/accept
{ "idempotencyKey": "tos-v3-user_8812-service", "expectedRevision": 2, "termsRevision": 1,
"termsDigest": "<termsDigest>", "partyId": "<servicePartyId>",
"evidence": { "method": "publisher_policy", "evidenceDigest": "<SHA-256 of your publication record>", "signerRef": "service" } }
# The user clicked "I agree" in your app. Roye keeps only the digest of your record.
POST /v1/agreements/<agreementId>/accept
{ "idempotencyKey": "tos-v3-user_8812-user", "expectedRevision": 3, "termsRevision": 1,
"termsDigest": "<termsDigest>", "partyId": "<userPartyId>",
"evidence": { "method": "click_through", "evidenceDigest": "<SHA-256 of your click record>", "signerRef": "user_8812" } }
# Response: state "active" with two acceptances, each with its evidence.Later, check the user's agreements or events feed.
# Has this user accepted? Read their agreements or their events feed.
GET /v1/agreements?partyId=<userPartyId>&state=active
GET /v1/agreements/events?partyId=<userPartyId>Two organizations sign a document
Each backend creates its organization party in its own project, and they exchange party IDs. The seller offers an agreement whose documentDigest is the contract PDF's SHA-256. Roye never receives the document.
# Seller backend, in its own project: its party, then the agreement naming the buyer's party.
POST /v1/agreements/parties
{ "idempotencyKey": "party-seller", "kind": "organization", "displayName": "Seller Ltd", "externalRef": "org_seller" }
POST /v1/agreements
{ "idempotencyKey": "supply-sa-2611", "partyIds": ["<sellerPartyId>", "<buyerPartyId>"],
"terms": { "title": "Supply agreement", "documentDigest": "<SHA-256 of the contract PDF>",
"attributes": { "reference": "SA-2611" }, "startsAt": null, "expiresAt": null } }
POST /v1/agreements/<agreementId>/offer
{ "idempotencyKey": "supply-sa-2611-offer", "expectedRevision": 1, "acceptBy": <epoch ms, at most 30 days ahead> }The buyer sees the offer in its events feed, compares the digest with its copy and accepts with electronic_signature evidence. The seller accepts the same way.
# Buyer backend, in its own project: the offer appears in its events feed.
GET /v1/agreements/events?partyId=<buyerPartyId>
{ "items": [{ "id": "<eventId>", "agreementId": "<agreementId>", "type": "offered", "state": "offered",
"endReason": null, "partyId": "<sellerPartyId>", "agreementRevision": 2, "at": 1796083200000 }], "next": "<cursor>", "more": false }
GET /v1/agreements/<agreementId>
# Compare terms.documentDigest with the SHA-256 of the document you hold, then accept.
POST /v1/agreements/<agreementId>/accept
{ "idempotencyKey": "supply-sa-2611-buyer", "expectedRevision": 2, "termsRevision": 1,
"termsDigest": "<termsDigest>", "partyId": "<buyerPartyId>",
"evidence": { "method": "electronic_signature", "evidenceDigest": "<SHA-256 of your signature record>", "signerRef": "signer_204" } }
# The seller accepts the same way for its own party. The second assent forms the agreement.Concepts
| Term | Meaning |
|---|---|
| Identity | The authenticated caller, derived from the credential. Requests never name it. |
| Party | A person, organization or agent, acted for by its representative identity. |
| Mandate | A representative's time-limited grant to another identity. |
| Agreement | A proposer, a counterparty and the current terms. |
| Assent | One party's acceptance of the exact offered terms, with your evidence. |
Everything happens in one project environment. A party belongs to the project and environment that created it, and an agreement may name a counterparty in another project of the same environment.
Agreements certifies no legal enforceability or electronic signature, holds no identity documents and creates no payment or entitlement. A Roye module that gates its own resource on an agreement reads the agreement's standing; Agreements never calls into that module. A Work board's agreement gate reads only whether one agreement is active under a terms digest for a party of the board's project, from stored records, so no representative's key or membership state shows through it.
Authentication and headers
Use a backend key (ryk_) with the agreements scope or no scope restriction, or a project member's developer sign-in token. Actor, member, participant and invoker credentials get 403 forbidden. Each request rechecks the credential, project access, your identity and each party you act for.
| Header | Value | Rule |
|---|---|---|
Authorization | Bearer, then a backend key or sign-in token | Required |
X-Roye-Project, X-Roye-Environment | Project ID; development or production | Required |
Roye-Contract-Version | 1 | Optional. A missing header gets 1, any other value 400 contract_version_unsupported. |
Roye-Replayed | true | Response header on a replay |
Identities
- A developer sign-in registers a
personidentity and a backend key aserviceidentity. Register once, before any other act. - All keys of one
/v1/keysrotation chain (keys) are one service identity, so a successor key keeps the parties, events and agreements of the key it replaced without registering. Any other key, including each legacy-route key, is a separate identity. - Revoking the chain's newest key, or the key that registered the identity, ends its representation. Let a rotation overlap run out instead.
- Views never expose the private subject, key binding or credential.
Parties and representation
A party is active, suspended or retired, and a retired party cannot resume. Its creator decides its representative:
| Creator | Kinds | Representative |
|---|---|---|
| A backend key's service identity | Any kind, any number | That identity |
| A signed-in person | One person | That person |
| The signed-in organization owner | organization, agent | None until the owner designates a registered person of the project |
externalRefis your reference, such as a user ID: letters, digits and. _ : @ / + = -, ornull. It is not unique, andGET /v1/agreements/parties?externalRef=finds its parties.metadataholds string values under keys that start with a letter. Roye never interprets it.- A service identity represents its parties, so your backend attests its users' assent with evidence.
- Designation creates no assent. Project roles, titles, control of an agent and the owner's key never imply signature authority.
- The representative of an
organizationoragentparty can give another identity of the project a mandate for named agreements and any ofoffer,acceptandterminate. - A new representation revision voids earlier mandates, and a delegate cannot delegate again.
Terms
| Field | Rule |
|---|---|
title | Required. |
body | The terms text. Send exactly one of body or documentDigest. |
documentDigest | Lowercase hex SHA-256 of a document the parties hold elsewhere, such as a signed PDF. Roye never fetches or stores it. |
attributes | Optional string, number or boolean values, such as a version, locale or plan. Keys as in metadata; an empty object when omitted. |
startsAt | Epoch milliseconds or null. A formed agreement becomes active then. |
expiresAt | Epoch milliseconds or null, after startsAt and in the future. Afterwards the agreement reads as ended with expired. |
termsDigest is the canonical SHA-256 of the stored terms. Draft terms can be revised, but offered terms never change: to offer different terms, withdraw and create a new agreement.
Assent and evidence
Accept with the exact offered termsRevision and termsDigest, the partyId you accept for, and optional mandateId and evidence. You must be that party's representative or hold a current mandate with accept for this agreement.
| Evidence field | Value |
|---|---|
method | How you collected the assent, such as click_through, electronic_signature or wet_ink: lowercase letters, digits or underscores, starting with a letter. Roye does not interpret it. |
evidenceDigest | SHA-256 (64 lowercase hex characters) of your evidence record, such as a signed log line. |
signerRef | Your reference to the signer in the externalRef format, such as user_8812. Use an opaque ID, not an email address. |
- You authenticate the signer, not Roye. A service identity must send
evidence, or the request is400 invalid_request; a signed-in person may send it. - Roye stores only your evidence digest and signer reference. Each assent also records the party, identity, mandate, representation revision, terms revision and digest, and time, with
nullevidence when none was sent. Later representation changes never rewrite it.
Lifecycle
An agreement is draft, offered, formed, active or ended. There is no separate activation step.
| Act | From | To |
|---|---|---|
| Create | None | draft |
| Revise terms | draft | draft |
| Offer | draft | offered |
| Accept | offered | offered after one assent, active or formed after the second |
| Decline | offered | ended, rejected |
| Withdraw | draft, offered | ended, withdrawn |
| End | formed, active | ended, completed or terminated |
- The proposer names an existing counterparty party and cannot create, represent or sign for it. Both parties must be
activeand represented to create, offer or accept. - A formed agreement is
activeat once, or staysformeduntilstartsAtand then reads asactive. - Deadlines apply when read: past
acceptByan offer reads asendedwithoffer_expired, and pastexpiresAtan agreement reads asendedwithexpired. - Retiring a party ends its agreements with
party_retired, and closing a project ends them withproject_deleted. The earliest ending counts.
Reads and events
- A draft is visible only to the proposer, even after it ends. After an offer, both parties see the terms and history for the content lifetime. Anyone else gets
404 not_found. - Filters apply after a page is selected, so a page can be empty while
nextis notnull. Continue untilnextisnull.
Events feed
GET /v1/agreements/events?partyId= lists the offers and state changes of every agreement the party can read, oldest first. An event has id, agreementId, type, state, endReason, partyId, agreementRevision and at, and no terms or evidence.
| `type` | When | `partyId` |
|---|---|---|
offered | The proposer offered | The proposer |
accepted | A party assented | That party |
formed | The second assent formed it | null |
activated | It became active, at formation or at startsAt | null |
declined | A party declined | That party |
withdrawn | The proposer withdrew | The proposer |
expired | It passed acceptBy (endReason offer_expired) or expiresAt (endReason expired) | null |
ended | A party ended it | That party |
- An event appears once it is 2 seconds old, so a slow commit cannot land behind a cursor you hold.
- A deadline event has a
nullagreementRevisionand appears at its time. A party act that ends the agreement first removes it, but a reached event is never removed. - A withdrawn draft's event reaches only the proposer. Retirement and project exit end agreements without an event, and no deadline event follows.
- Events are observations, not grants: act on a fresh read of the agreement.
- There is no long poll. The feed's
nextnever runs out: it points past the last event or repeats your cursor, and isnullonly before the party's first event. Keep it and poll again. moreis true when settled events follow the page. Deadline events no longer due are dropped after selection, so if a page is short or empty whilemoreis true, read again at once.
Endpoints
Routes are under /v1/agreements. Every POST takes idempotencyKey, plus expectedRevision on an existing party, mandate or agreement (expectedPartyRevision to issue a mandate). Page means optional cursor and limit. An action in parentheses needs the party's representative, or a delegate whose mandate names the agreement and that action.
| Route | Input | Who |
|---|---|---|
GET /identities/binding | None | Any caller, also before registration. Shows the credential's id, projectId, environment and kind; grants nothing. |
POST /identities | displayName | The caller, once. |
GET /identities/current | None | The caller. 404 not_found before registration. |
GET /identities, /identities/:identityId | Page for the list | Any identity of the project. |
POST /parties | kind, displayName; optional externalRef, metadata | A creator in parties. |
GET /parties, /parties/:partyId | Optional externalRef and page for the list | Any identity of the project. |
POST /parties/:partyId/representative | identityId, reason | The signed-in organization owner, for an organization or agent party. |
POST /parties/:partyId/state | state, reason | The representative, or the owner for a party that is not a person. |
POST /parties/:partyId/mandates | identityId, agreementIds, actions, expiresAt | The representative of an organization or agent party. |
GET /parties/:partyId/mandates | Optional state; page | That representative. |
POST /parties/:partyId/mandates/:mandateId/revoke | reason | That representative. |
POST /v1/agreements | partyIds (proposer, counterparty), terms | Proposer (offer). |
POST /:id/terms | terms | Proposer (offer). |
POST /:id/offer | acceptBy | Proposer (offer). |
POST /:id/accept | See assent | Each party (accept). |
POST /:id/decline | reason | Either party (accept). |
POST /:id/withdraw | reason | Proposer (offer). |
POST /:id/end | reason, outcome (completed or terminated) | Either party (terminate). |
GET /:id, /:id/revisions | Page for revisions | Either party's representative, or a delegate with a mandate for it. |
GET /v1/agreements | partyId; optional state; page | That party's representative. |
GET /events | partyId; page | That party's representative. |
Limits
| Bound | Value |
|---|---|
| Normalized request | 65,536 bytes |
| Page | 64 items, 32 by default |
title, body | 1 to 200 and 1 to 20,000 characters |
attributes, metadata | 32 and 16 entries; keys 1 to 64 characters; string values up to 1,000 and 500 characters |
externalRef, signerRef, method | 1 to 200, 1 to 200 and 1 to 64 characters |
| Terms revisions | 64 per agreement |
Offer window (acceptBy), mandate life | 30 days |
| Mandates | 16 valid and 128 over a party's life, 16 agreements each |
| Event settle delay | 2 seconds |
Errors
Errors use the shared error envelope. Read the agreement again before acting on a 409, and never treat a refusal as completed work.
| Code | HTTP | When |
|---|---|---|
invalid_request | 400 | Invalid body, query or cursor; a past expiresAt; an acceptBy over 30 days ahead; a service identity's assent without evidence. |
contract_version_unsupported | 400 | A version other than 1. |
unauthorized, credential_revoked, credential_expired | 401 | Authentication failed. |
forbidden | 403 | A principal credential, a key without the agreements scope, or no current representation or mandate for the act. |
not_found | 404 | An unknown, unregistered or invisible identity, party, mandate or agreement. This includes another project's or environment's identity in any credential state, and an agreement acted on after the key that registered your identity was revoked. |
revision_conflict | 409 | expectedRevision is not the current revision. |
invalid_transition | 409 | The act does not fit the current state, a party is not active and represented, the terms differ from the offer, or the party already assented. |
idempotency_conflict | 409 | The same key with different input. |
operation_replay_expired | 410 | A key past its replay window. |
payload_limit | 413 | A normalized request over 65,536 bytes. |
quota_exceeded | 429 | The 64-revision, 16-mandate or 128-mandate bound. |
Recovery
- Save the
idempotencyKeywith the exact input before sending. The same key and input replay the original response withRoye-Replayed: true, and other input is409 idempotency_conflict. - After a lost response,
POST /v1/operations/recoverwith the same credential,moduleagreements, the operationkind, itstargetand the key returns the original record. - Recovery rechecks current read authority, so a revoked delegate or an exited project cannot read the result. It never repeats an assent or creates another agreement.
- Every operation completes synchronously, so there is nothing to cancel. Withdraw, decline and end are contract acts, not cancellations.
| `kind` | `target` |
|---|---|
identities.register, parties.create, create | Empty |
parties.representative, parties.state, mandates.issue | partyId |
mandates.revoke | partyId, mandateId |
terms.revise, offer, accept, decline, withdraw, end | agreementId |
# Lost the user's accept response: recover it with the same credential and key.
POST /v1/operations/recover
{ "module": "agreements", "kind": "accept", "target": { "agreementId": "<agreementId>" },
"idempotencyKey": "tos-v3-user_8812-user" }Usage
Nothing is metered or charged. Each request that creates or advances a record passes the common preview admission once. Suspension, retirement, mandate revocation, decline, withdraw and end are cleanup and always admitted.