/v1.
Pagination
GET /v1/peers, GET /v1/resources, GET /v1/contracts, GET /v1/events, GET /v1/structs, GET /v1/admin/blocked-callers and GET /v1/admin/events/* return one page at a time. Pass ?offset= (default 0) and ?limit= (default 100, at most 500). Each response includes nextOffset, the offset of the next page, or null on the last page.
Public routes
GET /v1/
Liveness check.
GET /v1/self
This node’s identity, used by peers when bootstrapping.
GET /v1/peers
One page of the peers stored on this node.
GET /v1/resources
One page of the resources registered on this node, followed by the resources it learned from peers: { "resources", "nextOffset" }.
Each entry includes path, name, baseUrl, website, description, and functions with name, returnType, description, parameters (name, type, description), paymentManifest when the function is paid (costMicroUsd and recipientOrganizationId, or for an inference function inputCostMicroUsdPerMillionTokens, outputCostMicroUsdPerMillionTokens and recipientOrganizationId, or for a contract priceMicroUsdPerMillionTokens and recipientOrganizationId), restricted: true when the function needs a grant, kind: "inference" for an inference function, and kind: "contract" for a contract. A node lists its registered resources first, then its contracts, then the resources it learned from peers. Function implementations stay on the node that hosts them.
website and the descriptions are optional, and appear only when the node that registered the resource sets them. A node drops a description from a peer that isn’t a string, and a website that isn’t an http or https URL.
Running requests
POST /v1/run
Runs one RequestScript request. Requires Authorization: Bearer <API_KEY>, or Bearer <run token> from an API client. Run tokens need the node’s OPERATOR_URL, whose published keys verify them. A run token from another organization is billed: the node authorizes the run with the operator before running the script, and captures the tokens it executed afterwards. The script can read the run token’s claims as the built-in variable jwt, which is null for an API-key run.
A resource call that fails does not change the status code. The failure comes back as an
error value inside the script, which the script can check and handle.
Contracts
These routes deploy, list and delete contracts. Deploying and deleting takeAuthorization: Bearer <API_KEY> or a run token from an API client for this node.
POST /v1/contracts
Deploys a version of a contract. Body: { "source", "description"? }, where source is a RequestScript contract with a path and a return type, or an event contract, which has no return type. A run token’s organization becomes the contract’s owner. Another organization pays the node’s deploy fee from its API client’s run.
GET /v1/contracts
One page of every version of every contract on this node, with its source. Needs no authorization.
ownerOrganizationId is null for a contract deployed with the node’s API key.
GET /v1/contracts/:ref/state
A contract’s state, every variable and scope. :ref is path.Name, since state belongs to every version. Allowed for the contract owner’s API clients and the node’s API key: a contract shares its state with callers only through what it returns.
scope is null for a shared variable. Responds 400 for a reference with a version, 403 for another organization, and 404 if there is no such contract.
DELETE /v1/contracts/:ref
Deletes one version (com.example.Outlook@2), or every version (com.example.Outlook) and the contract’s state. Allowed for the contract owner’s API clients and the node’s API key. Responds { "success": true }, 400 for a reference that isn’t path.Name or path.Name@version, 403 for another organization, and 404 if there is no such contract or version.
Events
These routes declare, list and delete event types. Declaring and deleting takeAuthorization: Bearer <API_KEY> or a run token from an API client of the node’s own organization.
POST /v1/events
Declares a version of an event type, owned by the node’s organization. Body: { "source", "description"? }, where source is a RequestScript event declaration with a path.
GET /v1/events
One page of the event types this node knows: the ones it declared, then the ones it learned from peers. Needs no authorization.
baseUrl is the node that declared the event type.
DELETE /v1/events/:ref
Deletes one version (com.example.OrderPlaced@2), or every version (com.example.OrderPlaced), of an event type this node declared. Responds { "success": true }, 400 for a reference that isn’t path.Name or path.Name@version, 403 for another organization’s run token, and 404 if this node declared no such event type or version.
Structs
These routes declare and look up structs. Declaring takesAuthorization: Bearer <API_KEY> or a run token from an API client of the node’s own organization. Struct versions are never deleted, so there is no DELETE route.
POST /v1/structs
Declares a version of a struct, owned by the node’s organization. Body: { "source", "description"? }, where source is a RequestScript struct declaration with a path and a version.
GET /v1/structs
One page of the structs this node knows: the ones it declared, then the ones it learned from peers. Needs no authorization.
baseUrl is the node that declared the version.
GET /v1/structs/:ref
One struct, in the shape GET /v1/structs lists. :ref is path.Name@version, or path.Name for its latest version. Responds 400 for a reference that isn’t one of those, and 404 if the node doesn’t know the struct or version.
Node-to-node routes
These routes are called by other nodes. You don’t normally call them yourself.PUT /v1/peers
A peer announces itself. Body: { baseUrl, name, publicKey, signature, expiry }. The signature covers { baseUrl, name, publicKey, expiry } and must be made with the announced publicKey. expiry must be in the future and at most an hour away.
A known peer (same publicKey) can change its base URL and name. A new key can’t take a base URL or name that another peer holds.
PUT /v1/all-resources
A known peer broadcasts the resources it hosts. Body: { publicKey, resources, signature, expiry }. The signature covers { resources, expiry }, made with the peer’s key. expiry must be in the future and at most an hour away.
A peer may only publish resources served from its own base URL that no other peer owns. The node stores the others and responds { "success": true, "rejected": [...] }, where rejected lists the fully qualified names (com.example.Weather) it refused. An accepted resource replaces what was stored for it, including its functions, prices and descriptions.
Responds 400 Peer not found if publicKey belongs to no known peer, and 400 Invalid signature if the signature is invalid or expiry has passed or is too far away.
PUT /v1/all-events
A known peer announces its event types and event contracts. Body: { publicKey, membershipToken, eventTypes, subscriptions, expiry, signature }. The signature covers { membershipToken, eventTypes, subscriptions, expiry }, made with the peer’s key. expiry must be in the future and at most an hour away. The announcement replaces what the peer announced before.
The node learns an event type only if the peer’s membershipToken says it belongs to the type’s owner, no other node declared the type first, and the node knows every struct its fields name. It responds { "success": true, "rejected": [...] }, where rejected lists the event types it refused (com.example.OrderPlaced@1). Responds 400 Peer not found if publicKey belongs to no known peer, and 400 Invalid signature if the signature is invalid or expiry has passed or is too far away.
PUT /v1/all-structs
A known peer announces the structs its organization owns. Body: { publicKey, membershipToken, structs, expiry, signature }. The signature covers { membershipToken, structs, expiry }, made with the peer’s key. expiry must be in the future and at most an hour away.
The node learns a struct only if the peer’s membershipToken says it belongs to the struct’s owner, no other organization owns the path, and the node doesn’t already know the version with other fields. Structs it learned before stay, even if the announcement leaves them out. It responds { "success": true, "rejected": [...] }, where rejected lists the structs it refused (com.example.Address@1). Responds 400 Peer not found if publicKey belongs to no known peer, and 400 Invalid signature if the signature is invalid or expiry has passed or is too far away.
GET /v1/structs/announcement
This node’s own signed struct announcement, in the body PUT /v1/all-structs takes. A node joining the network fetches it from each peer, before their event types.
GET /v1/events/announcement
This node’s own signed announcement, in the body PUT /v1/all-events takes. A node joining the network fetches it from each peer.
POST /v1/events/deliver
A peer delivers an event it published, for this node’s event contracts. The body is the signed event: { id, type, version, ownerOrganizationId, data, publishedAt, depth, lineage, publisherPublicKey, membershipToken, signature }.
The same rate limit as
POST /v1/run/resource applies.
POST /v1/run/resource
Calls one function on a resource hosted by this node.
{ "value": ..., "error": null } on success. An inference function’s result also carries usage ({ "inputTokens", "outputTokens" }).
The node checks the call in this order:
A call to a contract always needs a contract voucher (
kind: "contract"), even at a price of 0, and is refused with 402 A contract voucher is required without one. The voucher must be bound to the call, pay this node’s organization, agree to at least the node’s current price, be unexpired and correctly signed, or the call is refused with 400. The body may also carry contractDepth, how many contracts deep the call is; the calling node sets it, and a call more than 8 deep is refused with 400. A call made by a script an event started also carries eventLineage ({ depth, types, contracts }), and a call to a contract already in that chain is refused with 400. The node then asks the operator to authorize a run for the call, and answers the operator’s status if it refuses.
After a paid function runs, the node captures the voucher, with the reported usage for an inference function, or releases the hold if the function returned an error. A voucher sent to a free function is ignored. A voucher with a runId comes from a script run by an API client, and that run’s hold pays for it. See Payments.
GET /v1/served-calls/:runTag/:callIndex
Whether this node answered a call from a payable contract’s run. A contract run tags each call it makes with a runTag and a callIndex, and this node signs its answer and keeps a record of it. The operator reads this record to check a hosting node that says the call failed. Needs no authorization.
404 if the node answered no call with that tag and index.
POST /v1/run/resource/estimate
Prices a call to a paid inference function hosted by this node, before the caller signs its voucher. The body is the same as POST /v1/run/resource, without paymentVoucher. The node runs the function’s estimateInputTokens and responds:
maxAmount is the charge for inputTokens input tokens plus maxTokens output tokens at the function’s rates. The node makes the same resource, parameter and authorization checks as POST /v1/run/resource, so a restricted function needs an authorization here too. It responds 400 if the function isn’t a paid inference function or maxTokens isn’t a positive int32, and 500 if the estimator fails. The same rate limit applies.
This route is rate limited per client IP, to 100 calls a minute by default. Set rateLimit ({ max, timeWindow }) in the start options to change it. The same limit applies to the grant routes.
POST /v1/grants/request
Asks this node for a new root grant. Body: { publicKey, capabilities, details, nonce, expiresAt, signature }, signed by publicKey. The node’s approveGrant hook decides each request.
Responds { "grants": [...] } when approved. Responds 403 if the node has no approveGrant hook, if the hook refuses, or if the key is blocked. See Permissions.
POST /v1/grants/renew
Asks this node to re-issue a grant it issued, with a new expiry. Body: { grantId, publicKey, nonce, expiresAt, signature }, signed by the grant’s audience. Responds { "grants": [...] }, or 403 Grant renewal refused if the grant is revoked, past its renewal window, or held by a blocked key.
Admin routes
These routes take the sameAuthorization: Bearer <API_KEY> as /v1/run.