Developer API Reference
Integrate zero-rounding execution, multi-party clearing, multiscale zoom, and public-key cryptographic receipts over HTTPS JSON. Base URL: https://2data.org/api/v1.
Authentication & Idempotency
The 2Data engine runs exclusively as a sealed black-box cloud service. Production requests authenticate with a private enterprise API key in the Authorization header:
Authorization: Bearer 2d_live_YOUR_API_KEY Content-Type: application/json Idempotency-Key: 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d
Browser Sandbox Sessions
For interactive evaluation in the WebApp Console, call POST /api/v1/session to obtain a dedicated, short-lived sandbox token and pass it via X-2Data-Session. Enterprise credentials should remain exclusively in backend secret stores.
Idempotency Guarantees
Supply a unique Idempotency-Key on mutating queries and clearing settlements. Re-sending the identical payload with the same key safely yields the cached receipt with "idempotent_replay": true and settles at 0 Proof Units. Re-using the same key with a modified payload is strictly rejected with HTTP 409 Conflict.
Proof Units (PU) & Self-Serve Billing API
Every paid execution reserves and settles deterministically in Proof Units (PU) ($1.00 / 1,000 PU list rate; down to $0.60 / 1,000 PU on volume tiers). Validation errors, fail-closed 422 budget refusals, and idempotent replays settle at 0 PU.
Metered API responses return exact accounting headers: X-2Data-Proof-Units-Charged, X-2Data-Proof-Units-Remaining, and X-2Data-Plan-Tier. Unfunded or exhausted accounts fail closed with HTTP 402 (Insufficient Proof Units) before consuming engine compute.
| Operation Class | Proof Units | Covered Endpoints |
|---|---|---|
| Verification & Ledger Read | 1 PU | GET /api/v1/clearing/ledger, POST /api/v1/query/verify, POST /api/v1/zoom/verify, POST /api/v1/verify/receipt |
| Standard Exact SQL & Zoom Workspace | 2 PU | POST /api/v1/query ("prove": false), POST /api/v1/zoom/workspace |
| Cryptographically Proven SQL & Multiscale Zoom | 5 PU | POST /api/v1/query ("prove": true or PROVE), POST /api/v1/zoom/query, POST /api/v1/zoom/locate-anomaly |
| Black-Box Exact Compute (All 6 Operators) | 8 PU | POST /api/v1/compute |
| Zero-Dust Clearing & Vault Self-Heal | 10 PU | POST /api/v1/clearing/settle, POST /api/v1/clearing/resilience-check |
| Idempotent Replays & Refusals | 0 PU | Any cached retry with matching Idempotency-Key or 4xx / 422 guard response |
Billing, Checkout & Key Management Endpoints
Self-serve USD Proof-Unit packs are processed securely via certified PCI-DSS Level 1 payment partners with instant automated provisioning, atomic idempotency across settlement confirmation and return-URL verification, zero raw payment card storage by 2D Labs, and 14-day refund eligibility on unused prepaid Proof-Unit packs (helloworld@2dai.org).
# 1. Inspect pricing packs, Proof-Unit schedule & active checkout channels
curl -sS https://2data.org/api/v1/billing/plans
# 2. Provision a customer account (issues 2d_acct_... manager token & initial 2d_live_... key once)
curl -sS https://2data.org/api/v1/billing/accounts \
-H "Content-Type: application/json" \
-d '{"email":"eng@acme.example","organization":"Acme Clearing","key_name":"prod-primary"}'
# 3. Create a self-serve Proof-Unit checkout session via certified payment partners
curl -sS https://2data.org/api/v1/billing/checkout \
-H "Authorization: Bearer 2d_acct_YOUR_ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"plan_id":"growth"}'
# 4. Check live Proof-Unit balance (accepts Bearer 2d_acct_... OR 2d_live_...)
curl -sS https://2data.org/api/v1/billing/account \
-H "Authorization: Bearer 2d_acct_YOUR_ACCOUNT_TOKEN"
# 5. Mint additional scoped API keys (up to tier key cap)
curl -sS https://2data.org/api/v1/billing/keys \
-H "Authorization: Bearer 2d_acct_YOUR_ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"clearing-service-east","max_pu_per_request":25}'
Endpoint Reference
All request and response bodies use UTF-8 JSON. Exact decimal and rational values are transmitted losslessly as strings so clients never lose precision to 64-bit binary floats.
| Method | Path | Description |
|---|---|---|
| GET | /api/v1/status |
Live operational health, service availability, and active verification key identifier. |
| GET | /api/v1/keys |
Public cryptographic verification keyring (key IDs, status, raw hex, SPKI DER hex, and PEM) for independent zero-secret verification. |
| POST | /api/v1/session |
Issues a dedicated, short-lived sandbox session token for interactive WebApp evaluation. |
| POST | /api/v1/query |
Executes exact SQL with zero floating-point drift and optional cryptographic proof receipts ("prove": true). Supports Idempotency-Key. |
| POST | /api/v1/query/verify |
Verifies a query proof receipt and reports cryptographic integrity status and soundness bits. |
| POST | /api/v1/clearing/settle |
Executes an atomic, zero-dust multi-party waterfall settlement with deterministic rounding policy and Idempotency-Key safety. |
| GET | /api/v1/clearing/ledger |
Reads the live zero-sum trial balance snapshot and vault integrity summary. |
| POST | /api/v1/clearing/resilience-check |
Runs a live self-healing vault drill injecting a 10^-50 tamper delta and simultaneous node erasures to confirm bit-exact recovery. |
| POST | /api/v1/zoom/workspace |
Creates or seeds a multiscale spatial workspace (for example a 64-region 8x8 grid with an optional microscopic anomaly). |
| POST | /api/v1/zoom/query |
Executes a bounded multiscale spatial zoom query with exact rollup totals and completeness proof. |
| POST | /api/v1/zoom/verify |
Verifies a multiscale completeness proof bundle for a workspace. |
| POST | /api/v1/zoom/locate-anomaly |
Pinpoints microscopic discrepancies across a multiscale workspace while skipping clean regions automatically. |
| POST | /api/v1/compute |
Executes a sealed black-box exact compute capability with bounded complexity guards and a signed cryptographic receipt. |
| POST | /api/v1/verify/receipt |
Verifies a signed execution receipt envelope against the active verification keyring and optional pinned public key. |
Exact Compute Capabilities (POST /api/v1/compute)
Pass a capability identifier and structured payload (plus an optional budget object) to run deterministic, zero-rounding workloads.
| Capability | Guarantee & Typical Workload |
|---|---|
exact_aggregate |
Order-invariant exact summation across extreme magnitude differences without catastrophic cancellation. |
exact_linear_solve |
Exact rational linear system solving with zero residual even on severely ill-conditioned matrices. |
exact_geometry |
Exact spatial orientation predicates free of grazing-boundary floating-point contradictions. |
exact_waterfall |
Zero-dust multi-party payout allocation under statutory rounding policies. |
exact_algebraic_roots |
Exact real-root bounds for high-degree univariate polynomials with certified intervals. |
exact_ai_verify |
Deterministic neural classification and perturbation robustness certification. |
cURL Examples
1. Execute Exact SQL with Proof Receipt
curl -sS https://2data.org/api/v1/query \
-H "Authorization: Bearer 2d_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"sql": "SELECT 0.1 + 0.2 = 0.3 AS exact_match, 0.1 + 0.2 AS exact_sum",
"prove": true
}'
2. Zero-Drift Clearing Settlement with Idempotency-Key
curl -sS https://2data.org/api/v1/clearing/settle \
-H "Authorization: Bearer 2d_live_YOUR_API_KEY" \
-H "Idempotency-Key: settle-2026-batch-001" \
-H "Content-Type: application/json" \
-d '{
"settlement_id": "stl_batch_001",
"source_account": "clearing_omnibus",
"total_amount": "100.00",
"party_weights": [
{"party_id": "LP_A", "weight": "1"},
{"party_id": "LP_B", "weight": "1"},
{"party_id": "LP_C", "weight": "1"}
],
"currency": "USD",
"scale": 2,
"policy": "HALF_EVEN"
}'
3. Black-Box Exact Compute Request
curl -sS https://2data.org/api/v1/compute \
-H "Authorization: Bearer 2d_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"capability": "exact_aggregate",
"payload": {
"values": ["10000000000000000", "1", "-10000000000000000", "0.25", "0.5"]
}
}'
JavaScript Example (Fetch + Pinned Public-Key Verification)
Executes an exact query, checks the canonical SHA-256 payload digest locally via WebCrypto, and verifies the signed execution receipt against the pinned public keyring.
const BASE = "https://2data.org/api/v1";
const API_KEY = "2d_live_YOUR_API_KEY";
async function queryAndVerifyReceipt() {
// 1. Fetch pinned public keyring
const keysResp = await fetch(`${BASE}/keys`).then((r) => r.json());
// 2. Execute exact SQL query
const res = await fetch(`${BASE}/query`, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
sql: "SELECT 9007199254740993 + 2 AS exact_large_int",
prove: true,
}),
}).then((r) => r.json());
const env = res.signed_envelope;
const pinned = keysResp.keys.find((k) => k.key_id === env.key_id && !k.revoked);
if (!pinned) throw new Error("Receipt key_id is not in active keyring");
// 3. Verify SHA-256 of canonical JSON payload locally
const payloadBytes = new TextEncoder().encode(env.payload_canonical_json);
const digestBuf = await crypto.subtle.digest("SHA-256", payloadBytes);
const digestHex = Array.from(new Uint8Array(digestBuf))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
if (digestHex !== env.payload_sha256) throw new Error("Payload digest mismatch");
// 4. Verify asymmetric signature pinned to expected_public_key_hex
const check = await fetch(`${BASE}/verify/receipt`, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
envelope: env,
expected_public_key_hex: pinned.public_key_hex,
}),
}).then((r) => r.json());
console.log({ exactRows: res.rows, signatureVerified: check.verified });
}
queryAndVerifyReceipt();
Server-Side HTTP Client & Receipt Verifier
Minimal standard-library HTTP client with SHA-256 canonical digest verification and explicit public-key pinning against /api/v1/keys.
import hashlib
import json
import urllib.request
BASE = "https://2data.org/api/v1"
API_KEY = "2d_live_YOUR_API_KEY"
def api_call(method, path, payload=None, idempotency_key=None):
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
if idempotency_key:
headers["Idempotency-Key"] = idempotency_key
data = json.dumps(payload).encode("utf-8") if payload is not None else None
req = urllib.request.Request(f"{BASE}{path}", data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=15) as resp:
return json.loads(resp.read().decode("utf-8"))
keys_doc = api_call("GET", "/keys")
resp = api_call("POST", "/query", {
"sql": "SELECT 0.1 + 0.2 = 0.3 AS exact_match",
"prove": True,
})
env = resp["signed_envelope"]
pinned = next(k for k in keys_doc["keys"] if k["key_id"] == env["key_id"] and not k.get("revoked"))
canonical_bytes = env["payload_canonical_json"].encode("utf-8")
assert hashlib.sha256(canonical_bytes).hexdigest() == env["payload_sha256"]
ver = api_call("POST", "/verify/receipt", {
"envelope": env,
"expected_public_key_hex": pinned["public_key_hex"],
})
assert ver["verified"] is True and ver["pinned_against_keyring"] is True
print("Verified exact result:", resp["rows"])
Zero-Shared-Secret Verification Protocol
Every verifiable endpoint emits a signed_envelope object containing schema, key_id, payload_canonical_json, payload_sha256, and signature_hex. Third-party auditors verify receipts in three deterministic checks:
- Key Pinning: Match
envelope.key_idagainst a non-revoked entry fromGET /api/v1/keys. Never rely solely on an unpinned key inside the receipt itself. - Digest Integrity: Confirm
SHA-256(UTF8(payload_canonical_json)) === payload_sha256. - Asymmetric Signature Verification: Verify
signature_hexover the domain-separated canonical payload using the pinned SPKI public key in the WebApp Receipt Auditor or viaPOST /api/v1/verify/receiptwithexpected_public_key_hex.
Try live local browser verification right now inside the Cryptographic Receipt Auditor ↗.
Rate Limits & HTTP Status Codes
Sandbox sessions enforce protective per-minute request budgets and payload size ceilings. Production 2d_live_... keys support dedicated throughput quotas and burst allowances. Always honor Retry-After headers when rate limited.
Request succeeded. Result and signed receipt envelope are included in the JSON body.
Insufficient Proof Units (PU) or sandbox allowance exhausted. Top up credits in the Billing Portal (0 PU deducted).
Missing, expired, or invalid Authorization: Bearer key or X-2Data-Session token.
Idempotency-Key was reused with a different request payload than the original call.
HTTP request body exceeded the strict maximum size bound for the active tier.
Fail-closed complexity guard refused an over-budget request and issued a signed refusal receipt.
Rate limit reached for the current session or API key. Back off using Retry-After.