ResourceCost common.resource-cost@1

Generated at from openvibe-contracts v0.79.0 and openvibe-sdk v0.25.0.

Version
1.0.0
Owner
contracts
Visibility
first-party
Status
active
Compatibility
backward
Decision
ADR-034
Schema
https://openvibe.network/contracts/common/resource-cost.v1.json

One charge in weighted cost units (roadmap WS-Z1): which subject used what, reserved and committed or released, with an idempotency key so a retried charge counts once.

Fields

FieldTypeRequiredDescriptionConstraints
subjectidentity.subject-refyes
project_idstring
  • pattern ^prj_[0-9A-HJKMNP-TV-Z]{26}$
unitenumyes
  • one of "browser-second", "ai-token", "ai-usd", "gpu-second", "video-minute", "bandwidth-byte", "storage-byte-day", "event", "watch-check", "bot-control-second", "job-run", "upload-byte", "download-byte"
amountnumberyes
  • minimum 0
stateenumyes
  • one of "reserved", "committed", "released"
idempotency_keystringyes
  • minLength 8
  • maxLength 200
servicestringyes
atstringyes
  • format date-time

Examples

From the contract's own test fixtures: valid ones validate, rejected ones must fail.

Valid: browser-seconds
{
  "subject": {
    "type": "agent",
    "id": "agt_01J0000000000000000000000A"
  },
  "project_id": "prj_01J0000000000000000000000A",
  "unit": "browser-second",
  "amount": 12.5,
  "state": "committed",
  "idempotency_key": "run_01J-step-4",
  "service": "actor",
  "at": "2026-09-28T23:00:00Z"
}
Rejected: short-key
{
  "subject": {
    "type": "user",
    "id": "usr_01J0000000000000000000000A"
  },
  "unit": "job-run",
  "amount": 1,
  "state": "reserved",
  "idempotency_key": "k",
  "service": "x",
  "at": "2026-09-28T23:00:00Z"
}
Rejected: unknown-unit
{
  "subject": {
    "type": "user",
    "id": "usr_01J0000000000000000000000A"
  },
  "unit": "coins",
  "amount": 1,
  "state": "committed",
  "idempotency_key": "abcdefgh",
  "service": "x",
  "at": "2026-09-28T23:00:00Z"
}

Validate

const contracts = require('openvibe-contracts');
contracts.validate('common.resource-cost@1', value);   // { valid, errors: [{ path, message }] }