{"openapi":"3.1.0","info":{"title":"Empress Behavioral Substrate — Tenant API","version":"1.0.0","description":"Granular behavioral observability as a service. Emit any valid xAPI statement to an immutable, tenant-isolated ledger; read it back, export it wholesale, and consume the computed layer (analytics, per-actor personalization, spaced-repetition belief state). Unknown verbs are logged, never refused — Empress validates structure, not vocabulary."},"servers":[{"url":"https://empress-api.jdnyzio.workers.dev"}],"security":[{"tenantKey":[]}],"components":{"securitySchemes":{"tenantKey":{"type":"http","scheme":"bearer","description":"Your tenant API key (emp_<slug>_…)"}},"schemas":{"Statement":{"type":"object","required":["actor","verb","object"],"properties":{"actor":{"type":"object","description":"xAPI Agent; account.name carries your platform identity"},"verb":{"type":"object","required":["id"],"properties":{"id":{"type":"string","format":"uri"},"display":{"type":"object"}}},"object":{"type":"object","required":["id"],"description":"Activity; id convention https://empress.eco/objects/<publicId>"},"result":{"type":"object"},"context":{"type":"object"},"timestamp":{"type":"string","format":"date-time"}}},"StatementResult":{"type":"object","required":["statements","more"],"properties":{"statements":{"type":"array","items":{"$ref":"#/components/schemas/Statement"}},"more":{"type":"string","description":"Relative URL of the next page (/statements?more=<cursor>), or \"\" at the end"}}},"RerankRequest":{"type":"object","required":["actorId","candidates"],"properties":{"actorId":{"type":"string"},"candidates":{"type":"array","maxItems":500,"items":{"type":"object","required":["id"],"properties":{"id":{"type":"string"},"publicId":{"type":"string"},"templateType":{"type":"string","nullable":true},"creator":{"type":"string","nullable":true},"tags":{"type":"array","items":{"type":"string"}}}}}}},"RerankResult":{"type":"object","properties":{"signal":{"type":"boolean","description":"false = no meaningful history; use your default order"},"order":{"type":"array","items":{"type":"string"}},"scores":{"type":"object","additionalProperties":{"type":"number"}}}}}},"paths":{"/statements":{"post":{"summary":"Emit a statement (immutable ledger; quota-enforced per tier)","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Statement"}}}},"responses":{"200":{"description":"Stored"},"400":{"description":"xAPI validation failed"},"429":{"description":"Tenant quota exceeded"}}},"get":{"summary":"Query your tenant's statements: lrsql's xAPI GET /statements query language, tenant-scoped","description":"The first-class read path. Every xAPI 1.0.3 GET /statements parameter is forwarded to the learning record store (lrsql on Neon) unchanged. Every row returned belongs to the tenant of the key on the request; no parameter can name another tenant (a tenant parameter is ignored). Paging: when `more` is non-empty, GET it (it is `/statements?more=<cursor>`, re-scoped on every use) until it comes back empty. A short page with a non-empty `more` is normal; only an empty `more` means the end. Same reader at GET /xapi/statements. Worked example: docs/architecture/READ-PATH.md.","parameters":[{"name":"agent","in":"query","schema":{"type":"string"},"description":"xAPI Agent JSON with a full IFI (matched by the LRS), or a plain actor id / {account:{name}} (matched by Empress across account.name, name, mbox)"},{"name":"verb","in":"query","schema":{"type":"string","format":"uri"},"description":"Exact verb IRI"},{"name":"activity","in":"query","schema":{"type":"string","format":"uri"},"description":"Exact activity IRI"},{"name":"registration","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"related_activities","in":"query","schema":{"type":"boolean"},"description":"Also match activity in context/sub-statements"},{"name":"related_agents","in":"query","schema":{"type":"boolean"},"description":"Also match agent in authority, team, instructor, sub-statements"},{"name":"since","in":"query","schema":{"type":"string","format":"date-time"},"description":"Stored strictly after"},{"name":"until","in":"query","schema":{"type":"string","format":"date-time"},"description":"Stored at or before"},{"name":"limit","in":"query","schema":{"type":"integer","minimum":0,"maximum":2000,"default":100},"description":"Statements per response; 0 = the server maximum (2000)"},{"name":"format","in":"query","schema":{"type":"string","enum":["ids","exact","canonical"]}},{"name":"attachments","in":"query","schema":{"type":"boolean"},"description":"true is refused with 501 for now (the LRS answers multipart)"},{"name":"ascending","in":"query","schema":{"type":"boolean"},"description":"Oldest first"},{"name":"statementId","in":"query","schema":{"type":"string","format":"uuid"},"description":"One statement; 404 when it is not yours"},{"name":"voidedStatementId","in":"query","schema":{"type":"string","format":"uuid"},"description":"One voided statement; 404 when it is not yours"},{"name":"more","in":"query","schema":{"type":"string"},"description":"The opaque cursor from a previous response's `more`; every other parameter is ignored when present"}],"responses":{"200":{"description":"Your statements only","content":{"application/json":{"schema":{"$ref":"#/components/schemas/StatementResult"}}}},"400":{"description":"Invalid cursor, or the LRS refused the query"},"401":{"description":"No key, or a key with no tenant"},"404":{"description":"statementId not found in your tenant"},"501":{"description":"attachments=true"},"502":{"description":"The LRS could not be read"}}}},"/export":{"get":{"summary":"Export your entire ledger (NDJSON, cursor-paged; your data is portable by construction)","parameters":[{"name":"since","in":"query","schema":{"type":"string","format":"date-time"},"description":"Cursor from the previous page's X-Next-Since header"},{"name":"limit","in":"query","schema":{"type":"integer","maximum":1000}}],"responses":{"200":{"description":"application/x-ndjson lines {stored, statement}; X-Next-Since + X-Count headers"}}}},"/analytics/trending":{"post":{"summary":"Population play-counts over a window (test traffic excluded)","responses":{"200":{"description":"{ counts: { [objectId]: number } }"}}}},"/analytics/rerank":{"post":{"summary":"Per-actor personalized ordering over your candidates","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RerankRequest"}}}},"responses":{"200":{"description":"Personalized order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RerankResult"}}}}}}},"/analytics/actor/{actorId}/stats":{"get":{"summary":"An actor's aggregate stats (sessions, scores, skill profile)","parameters":[{"name":"actorId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Actor stats"}}}},"/analytics/difficulty/{objectId}":{"get":{"summary":"Population-derived difficulty for an object","parameters":[{"name":"objectId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Difficulty"}}}},"/analytics/summary":{"get":{"summary":"Tenant activity summary","responses":{"200":{"description":"Summary"}}}},"/belief/{actorId}":{"get":{"summary":"Full FSRS belief map for an actor (spaced-repetition state per concept)","parameters":[{"name":"actorId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Belief state"}}}},"/belief/{actorId}/recommended":{"get":{"summary":"What this actor should engage next (due reviews / ready-to-learn / at-boundary)","parameters":[{"name":"actorId","in":"path","required":true,"schema":{"type":"string"}},{"name":"strategy","in":"query","schema":{"type":"string","enum":["review","learn","challenge"]}}],"responses":{"200":{"description":"Recommendations"}}}}}}