Onviction AgentOnviction Agent home

Integration architecture

One client, one registry, one ledger.

A single chokepoint

Every request goes through one client. Cost lookup, budget enforcement, rate limiting and ledger recording all live there, so none of them can be bypassed by adding a call somewhere new. There is no second path to the API, deliberately, including no MCP path, because a parallel route would break the counting guarantee the whole submission rests on.

The ledger

Every request appends a row: endpoint, credits, Nansen request id, remaining balance, status, latency, and, critically, its source.

source TEXT NOT NULL CHECK (source IN ('live','cache','fixture'))

That constraint is enforced by the database rather than left to convention. Only live rows are real network calls against the API key, and only those are ever counted. See Verification.

Record and replay

A response is recorded once and replayed at zero credits thereafter. This is how the application was developed against a trial key without burning the budget on iteration.

Credit accounting

The client trusts x-nansen-credits-used from the response header rather than assuming the endpoint’s list price. A rejected request bills zero, and an early version that charged itself for its own 422s reported a credit burn that never happened.

const usedHeader = res.headers.get('x-nansen-credits-used');
const parsed = usedHeader === null ? NaN : Number(usedHeader);
const used = Number.isFinite(parsed)
  ? parsed
  : res.ok ? spec.credits : 0;