Skip to content

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.

Local preview

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.

setup.http
# 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_8812

Create the agreement, then offer it.

agreement.http
# 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.

assent.http
# 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.

check.http
# 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.http
# 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.http
# 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

TermMeaning
IdentityThe authenticated caller, derived from the credential. Requests never name it.
PartyA person, organization or agent, acted for by its representative identity.
MandateA representative's time-limited grant to another identity.
AgreementA proposer, a counterparty and the current terms.
AssentOne 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.

HeaderValueRule
AuthorizationBearer, then a backend key or sign-in tokenRequired
X-Roye-Project, X-Roye-EnvironmentProject ID; development or productionRequired
Roye-Contract-Version1Optional. A missing header gets 1, any other value 400 contract_version_unsupported.
Roye-ReplayedtrueResponse header on a replay

Identities

  • A developer sign-in registers a person identity and a backend key a service identity. Register once, before any other act.
  • All keys of one /v1/keys rotation 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:

CreatorKindsRepresentative
A backend key's service identityAny kind, any numberThat identity
A signed-in personOne personThat person
The signed-in organization ownerorganization, agentNone until the owner designates a registered person of the project
  • externalRef is your reference, such as a user ID: letters, digits and . _ : @ / + = -, or null. It is not unique, and GET /v1/agreements/parties?externalRef= finds its parties.
  • metadata holds 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 organization or agent party can give another identity of the project a mandate for named agreements and any of offer, accept and terminate.
  • A new representation revision voids earlier mandates, and a delegate cannot delegate again.

Terms

FieldRule
titleRequired.
bodyThe terms text. Send exactly one of body or documentDigest.
documentDigestLowercase hex SHA-256 of a document the parties hold elsewhere, such as a signed PDF. Roye never fetches or stores it.
attributesOptional string, number or boolean values, such as a version, locale or plan. Keys as in metadata; an empty object when omitted.
startsAtEpoch milliseconds or null. A formed agreement becomes active then.
expiresAtEpoch 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 fieldValue
methodHow 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.
evidenceDigestSHA-256 (64 lowercase hex characters) of your evidence record, such as a signed log line.
signerRefYour 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 is 400 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 null evidence 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.

ActFromTo
CreateNonedraft
Revise termsdraftdraft
Offerdraftoffered
Acceptofferedoffered after one assent, active or formed after the second
Declineofferedended, rejected
Withdrawdraft, offeredended, withdrawn
Endformed, activeended, completed or terminated
  • The proposer names an existing counterparty party and cannot create, represent or sign for it. Both parties must be active and represented to create, offer or accept.
  • A formed agreement is active at once, or stays formed until startsAt and then reads as active.
  • Deadlines apply when read: past acceptBy an offer reads as ended with offer_expired, and past expiresAt an agreement reads as ended with expired.
  • Retiring a party ends its agreements with party_retired, and closing a project ends them with project_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 next is not null. Continue until next is null.

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`
offeredThe proposer offeredThe proposer
acceptedA party assentedThat party
formedThe second assent formed itnull
activatedIt became active, at formation or at startsAtnull
declinedA party declinedThat party
withdrawnThe proposer withdrewThe proposer
expiredIt passed acceptBy (endReason offer_expired) or expiresAt (endReason expired)null
endedA party ended itThat 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 null agreementRevision and 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 next never runs out: it points past the last event or repeats your cursor, and is null only before the party's first event. Keep it and poll again.
  • more is true when settled events follow the page. Deadline events no longer due are dropped after selection, so if a page is short or empty while more is 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.

RouteInputWho
GET /identities/bindingNoneAny caller, also before registration. Shows the credential's id, projectId, environment and kind; grants nothing.
POST /identitiesdisplayNameThe caller, once.
GET /identities/currentNoneThe caller. 404 not_found before registration.
GET /identities, /identities/:identityIdPage for the listAny identity of the project.
POST /partieskind, displayName; optional externalRef, metadataA creator in parties.
GET /parties, /parties/:partyIdOptional externalRef and page for the listAny identity of the project.
POST /parties/:partyId/representativeidentityId, reasonThe signed-in organization owner, for an organization or agent party.
POST /parties/:partyId/statestate, reasonThe representative, or the owner for a party that is not a person.
POST /parties/:partyId/mandatesidentityId, agreementIds, actions, expiresAtThe representative of an organization or agent party.
GET /parties/:partyId/mandatesOptional state; pageThat representative.
POST /parties/:partyId/mandates/:mandateId/revokereasonThat representative.
POST /v1/agreementspartyIds (proposer, counterparty), termsProposer (offer).
POST /:id/termstermsProposer (offer).
POST /:id/offeracceptByProposer (offer).
POST /:id/acceptSee assentEach party (accept).
POST /:id/declinereasonEither party (accept).
POST /:id/withdrawreasonProposer (offer).
POST /:id/endreason, outcome (completed or terminated)Either party (terminate).
GET /:id, /:id/revisionsPage for revisionsEither party's representative, or a delegate with a mandate for it.
GET /v1/agreementspartyId; optional state; pageThat party's representative.
GET /eventspartyId; pageThat party's representative.

Limits

BoundValue
Normalized request65,536 bytes
Page64 items, 32 by default
title, body1 to 200 and 1 to 20,000 characters
attributes, metadata32 and 16 entries; keys 1 to 64 characters; string values up to 1,000 and 500 characters
externalRef, signerRef, method1 to 200, 1 to 200 and 1 to 64 characters
Terms revisions64 per agreement
Offer window (acceptBy), mandate life30 days
Mandates16 valid and 128 over a party's life, 16 agreements each
Event settle delay2 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.

CodeHTTPWhen
invalid_request400Invalid body, query or cursor; a past expiresAt; an acceptBy over 30 days ahead; a service identity's assent without evidence.
contract_version_unsupported400A version other than 1.
unauthorized, credential_revoked, credential_expired401Authentication failed.
forbidden403A principal credential, a key without the agreements scope, or no current representation or mandate for the act.
not_found404An 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_conflict409expectedRevision is not the current revision.
invalid_transition409The 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_conflict409The same key with different input.
operation_replay_expired410A key past its replay window.
payload_limit413A normalized request over 65,536 bytes.
quota_exceeded429The 64-revision, 16-mandate or 128-mandate bound.

Recovery

  • Save the idempotencyKey with the exact input before sending. The same key and input replay the original response with Roye-Replayed: true, and other input is 409 idempotency_conflict.
  • After a lost response, POST /v1/operations/recover with the same credential, module agreements, the operation kind, its target and 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, createEmpty
parties.representative, parties.state, mandates.issuepartyId
mandates.revokepartyId, mandateId
terms.revise, offer, accept, decline, withdraw, endagreementId
recover.http
# 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.