{"openapi":"3.0.0","info":{"title":"QRNG API","version":"1.0.0","description":"HTTP API for source-selectable random data and signed digests. See the Developer guide for WebSocket and runtime policy details.","contact":{"name":"API Support","url":"https://qrngapi.com/contact"}},"servers":[{"url":"/","description":"Current origin"}],"externalDocs":{"url":"https://qrngapi.com/docs.html","description":"API reference (HTML)"},"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authentication (format: qnrk_...)"},"SessionAuth":{"type":"apiKey","in":"cookie","name":"connect.sid","description":"Signed-in QRNG API browser session. Mutations also require a trusted Origin."}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"message":{"type":"string","description":"Additional error details"}},"required":["error"]},"HealthMetric":{"type":"object","required":["pass","pValue"],"properties":{"pass":{"type":"boolean"},"pValue":{"type":"number"}}},"HealthResponse":{"type":"object","required":["status","metrics","timestamp","entropySource","sources","availableMethods"],"properties":{"status":{"type":"string","enum":["operational","degraded","critical"]},"metrics":{"type":"object","properties":{"monobit":{"$ref":"#/components/schemas/HealthMetric"},"runs":{"$ref":"#/components/schemas/HealthMetric"},"approximateEntropy":{"$ref":"#/components/schemas/HealthMetric"}}},"timestamp":{"type":"integer","format":"int64","description":"Unix timestamp in milliseconds"},"entropySource":{"type":"object","additionalProperties":true},"sources":{"type":"object","additionalProperties":true},"availableMethods":{"type":"array","items":{"type":"string"}}}},"User":{"type":"object","required":["user"],"properties":{"user":{"type":"object","properties":{"id":{"type":"string"},"email":{"type":"string"},"firstName":{"type":"string","nullable":true},"lastName":{"type":"string","nullable":true},"profileImageUrl":{"type":"string","nullable":true},"emailVerified":{"type":"boolean"}}},"organization":{"$ref":"#/components/schemas/Organization"}}},"Organization":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string"},"subscriptionTier":{"type":"string","enum":["free","starter","developer","pro"]},"stripeCustomerId":{"type":"string"},"stripeSubscriptionId":{"type":"string"},"subscriptionStatus":{"type":"string","nullable":true},"effectiveTier":{"type":"string"},"entitlementSource":{"type":"string"},"beta":{"type":"object","additionalProperties":true},"monthlyQuota":{"type":"integer","description":"Monthly quota in bytes"},"usageThisMonth":{"type":"integer","description":"Current month's usage in bytes"},"createdAt":{"type":"string","format":"date-time"}}},"ApiKey":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"organizationId":{"type":"string","format":"uuid"},"name":{"type":"string"},"keyPrefix":{"type":"string","description":"First 12 characters for display"},"quantumMethod":{"type":"string","enum":["auto","hardware","crypta","photon","tunneling","vacuum","simulator"],"description":"Quantum method preference for this API key"},"lastUsedAt":{"type":"string","format":"date-time"},"createdAt":{"type":"string","format":"date-time"},"revokedAt":{"type":"string","format":"date-time"}}},"CreateApiKeyRequest":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Descriptive name for the API key"},"quantumMethod":{"type":"string","enum":["auto","hardware","crypta","photon","tunneling","vacuum","simulator"],"default":"auto","description":"Preferred method. Check GET /api/keys/methods for runtime-supported, available and allowed choices."}}},"CreateApiKeyResponse":{"type":"object","properties":{"key":{"type":"string","description":"Full API key (only shown once at creation)"},"apiKey":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string"},"keyPrefix":{"type":"string"},"quantumMethod":{"type":"string","enum":["auto","hardware","crypta","photon","tunneling","vacuum","simulator"]},"createdAt":{"type":"string","format":"date-time"}}}}},"UsageStats":{"type":"object","properties":{"organization":{"type":"object","properties":{"tier":{"type":"string","enum":["free","starter","developer","pro"]},"monthlyQuota":{"type":"integer"},"usageThisMonth":{"type":"integer"},"effectiveTier":{"type":"string"},"entitlementSource":{"type":"string"},"beta":{"type":"object","additionalProperties":true},"percentUsed":{"type":"number"}}},"breakdown":{"type":"array","items":{"type":"object","description":"Usage breakdown by time period or category"}}}},"SignatureInfo":{"type":"object","properties":{"algorithm":{"type":"string"},"securityLevel":{"type":"string"},"quantumResistant":{"type":"boolean"},"signatureSize":{"type":"integer","description":"Length of base64 string, not raw signature bytes"}}},"EntropyProof":{"type":"object","required":["id","hash","signature","publicKey","signatureType"],"properties":{"id":{"type":"string","description":"Opaque proof identifier (not a UUID)"},"hash":{"type":"string","pattern":"^[a-f0-9]{64}$","description":"SHA3-256 of original bytes, hex"},"signature":{"type":"string","format":"byte","description":"Base64 signature over decoded digest bytes"},"publicKey":{"type":"string","format":"byte","description":"Base64 DER/SPKI (Ed25519) or raw ML-DSA public key"},"signatureType":{"type":"string"},"signatureInfo":{"$ref":"#/components/schemas/SignatureInfo"},"metadata":{"type":"object","additionalProperties":true}}},"RandomResponse":{"type":"object","required":["data","bytes","format","method","source","proof"],"properties":{"data":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"integer","minimum":0,"maximum":4294967295}}]},"bytes":{"type":"integer"},"format":{"type":"string"},"method":{"type":"string"},"source":{"type":"string","enum":["hardware","simulator"]},"proof":{"$ref":"#/components/schemas/EntropyProof"},"entropySource":{"type":"object","additionalProperties":true,"description":"Present with enabled integration"},"provenance":{"type":"object","additionalProperties":true,"description":"Present with enabled integration"}}},"VerifyProofResponse":{"type":"object","required":["valid","status","proof","signatureInfo","verification","note"],"properties":{"valid":{"type":"boolean","description":"Stored signature check; does not establish that the original bytes match"},"status":{"type":"string","enum":["invalid","unverifiable","unsupported"]},"proof":{"type":"object","properties":{"id":{"type":"string"},"hash":{"type":"string"},"signature":{"type":"string"},"publicKey":{"type":"string"},"signatureType":{"type":"string","nullable":true},"metadata":{"type":"object","additionalProperties":true,"nullable":true}}},"signatureInfo":{"type":"object","nullable":true,"properties":{"algorithm":{"type":"string"},"securityLevel":{"type":"string"},"quantumResistant":{"type":"boolean"}}},"note":{"type":"string"},"verification":{"type":"object","required":["valid","signatureValid","hashValid","dataAvailable","status","reason"],"properties":{"valid":{"type":"boolean"},"signatureValid":{"type":"boolean","nullable":true},"hashValid":{"type":"boolean","nullable":true},"dataAvailable":{"type":"boolean"},"status":{"type":"string","enum":["invalid","unverifiable","unsupported"]},"reason":{"type":"string"}}}}},"CheckoutRequest":{"type":"object","required":["tier"],"properties":{"billingCycle":{"type":"string","enum":["monthly","annual"],"default":"annual"},"tier":{"type":"string","enum":["starter","developer","pro"],"description":"Subscription tier to upgrade to"}}},"CheckoutResponse":{"type":"object","properties":{"url":{"type":"string","format":"uri","description":"Stripe Checkout session URL"}}},"QuotaExceededError":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"},"usageThisMonth":{"type":"integer"},"monthlyQuota":{"type":"integer"}},"required":["error"]}}},"tags":[{"name":"Public","description":"Public endpoints (no authentication required)"},{"name":"Authentication","description":"User authentication endpoints"},{"name":"API Keys","description":"API key management (requires session auth)"},{"name":"Usage","description":"Usage tracking and statistics (requires session auth)"},{"name":"Random","description":"Generate quantum random numbers (requires API key)"},{"name":"Billing","description":"Billing and subscription management (requires session auth)"}],"paths":{"/api/health":{"get":{"tags":["Public"],"summary":"Get system health","description":"Sample source health and software statistical metrics. No authentication required; not certification or uptime.","responses":{"200":{"description":"System health metrics","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"}}}},"500":{"description":"Failed to fetch health metrics","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/auth/user":{"get":{"tags":["Authentication"],"summary":"Get current user","description":"Retrieve the authenticated user's information including organization details. Requires session authentication.","security":[{"SessionAuth":[]}],"responses":{"200":{"description":"Current user information","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User"}}}},"401":{"description":"Not authenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Failed to fetch user","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/keys":{"get":{"tags":["API Keys"],"summary":"List API keys","description":"Get all API keys for the authenticated user's organization. Requires session authentication.","security":[{"SessionAuth":[]}],"responses":{"200":{"description":"List of API keys","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ApiKey"}}}}},"401":{"description":"Not authenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Organization not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Failed to fetch API keys","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"post":{"tags":["API Keys"],"summary":"Create API key","description":"Generate a new API key for the authenticated user's organization. The full key is only returned once at creation. Requires session authentication.","security":[{"SessionAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateApiKeyRequest"}}}},"responses":{"200":{"description":"API key created successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateApiKeyResponse"}}}},"400":{"description":"Name is required","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Not authenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Organization not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Failed to create API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/keys/{id}":{"delete":{"tags":["API Keys"],"summary":"Revoke API key","description":"Revoke an API key belonging to the authenticated user's organization. Requires session authentication.","security":[{"SessionAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"},"description":"API key ID to revoke"}],"responses":{"200":{"description":"API key revoked successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"}}}}}},"401":{"description":"Not authenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Organization not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Failed to revoke API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/usage":{"get":{"tags":["Usage"],"summary":"Get usage statistics","description":"Retrieve usage statistics for the authenticated user's organization including quota, current usage, and breakdown. Requires session authentication.","security":[{"SessionAuth":[]}],"responses":{"200":{"description":"Usage statistics","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UsageStats"}}}},"401":{"description":"Not authenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Organization not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Failed to fetch usage statistics","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/methods":{"get":{"tags":["Public"],"summary":"Discover current source availability","responses":{"200":{"description":"Available selectors and source status","content":{"application/json":{"schema":{"type":"object","required":["available","hardware","simulator"],"properties":{"available":{"type":"array","items":{"type":"string"}},"hardware":{"type":"array","items":{"type":"object","additionalProperties":true}},"simulator":{"type":"object","additionalProperties":true}}}}}},"500":{"description":"Discovery failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/keys/methods":{"get":{"tags":["API Keys"],"summary":"Supported, available and allowed methods for key creation","security":[{"SessionAuth":[]}],"responses":{"200":{"description":"Method capabilities","content":{"application/json":{"schema":{"type":"object","required":["supportedMethods","availableMethods","allowedMethods"],"properties":{"supportedMethods":{"type":"array","items":{"type":"string"}},"availableMethods":{"type":"array","items":{"type":"string"}},"allowedMethods":{"type":"array","items":{"type":"string"}}}}}}},"401":{"description":"No session","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No organization","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Discovery unavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/random":{"get":{"tags":["Random"],"summary":"Generate random bytes and a signed digest","description":"Requires an API key. Inspect returned source: simulator is software. Runtime policy, key defaults, effective Beta/paid entitlements, provider readiness and WebSocket message semantics cannot be enforced by this schema. See /docs.html.","security":[{"ApiKeyAuth":[]}],"responses":{"200":{"description":"Generated data and proof","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RandomResponse"}}}},"400":{"description":"Invalid method or signature type","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing, invalid or revoked API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Method or signature not allowed by effective plan or organization settings","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Organization rate limit or monthly byte quota exceeded","content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/Error"},{"$ref":"#/components/schemas/QuotaExceededError"}]}},"text/html":{"schema":{"type":"string"}}},"headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Rate window retry delay, when provided"}}},"500":{"description":"Auth, storage or random generation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Required source unavailable","content":{"application/json":{"schema":{"type":"object","required":["error","code","message","source","retryable"],"properties":{"error":{"type":"string","example":"HARDWARE_ENTROPY_UNAVAILABLE"},"code":{"type":"string","example":"ENTROPY_PROVIDER_UNAVAILABLE"},"message":{"type":"string"},"source":{"type":"string"},"retryable":{"type":"boolean"}}}}}}},"parameters":[{"name":"bytes","in":"query","schema":{"type":"integer","minimum":1,"maximum":1024,"default":32,"description":"Recommended input range; runtime parses/clamps and treats zero or an unparseable input as default."}},{"name":"format","in":"query","schema":{"type":"string","enum":["hex","base64","binary","uint8","uint32"],"default":"hex","description":"binary is a bit string; uint8/uint32 are arrays. Request a multiple of four for uint32. Undocumented format values echo but return hex."}},{"name":"method","in":"query","schema":{"type":"string","enum":["auto","hardware","crypta","photon","tunneling","vacuum","simulator","simulation"],"description":"Omitted or auto uses the key's stored method. hardware/crypta require a runtime flag; recognized selectors do not imply availability or entitlement. Values are trimmed and case-normalized; simulation aliases simulator."}},{"name":"signatureType","in":"query","schema":{"type":"string","enum":["ed25519","dilithium2","dilithium3","dilithium5"],"description":"Defaults to Ed25519, except PQC-enabled Pro (dilithium2) or Enterprise (dilithium3)."}}]},"post":{"tags":["Random"],"summary":"Generate random bytes and a signed digest","description":"Requires an API key. Inspect returned source: simulator is software. Runtime policy, key defaults, effective Beta/paid entitlements, provider readiness and WebSocket message semantics cannot be enforced by this schema. See /docs.html.","security":[{"ApiKeyAuth":[]}],"responses":{"200":{"description":"Generated data and proof","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RandomResponse"}}}},"400":{"description":"Invalid method or signature type","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing, invalid or revoked API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Method or signature not allowed by effective plan or organization settings","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Organization rate limit or monthly byte quota exceeded","content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/Error"},{"$ref":"#/components/schemas/QuotaExceededError"}]}},"text/html":{"schema":{"type":"string"}}},"headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Rate window retry delay, when provided"}}},"500":{"description":"Auth, storage or random generation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Required source unavailable","content":{"application/json":{"schema":{"type":"object","required":["error","code","message","source","retryable"],"properties":{"error":{"type":"string","example":"HARDWARE_ENTROPY_UNAVAILABLE"},"code":{"type":"string","example":"ENTROPY_PROVIDER_UNAVAILABLE"},"message":{"type":"string"},"source":{"type":"string"},"retryable":{"type":"boolean"}}}}}}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"bytes":{"type":"integer","minimum":1,"maximum":1024,"default":32,"description":"Recommended input range; runtime parses/clamps and treats zero or an unparseable input as default."},"format":{"type":"string","enum":["hex","base64","binary","uint8","uint32"],"default":"hex","description":"binary is a bit string; uint8/uint32 are arrays. Request a multiple of four for uint32. Undocumented format values echo but return hex."},"method":{"type":"string","enum":["auto","hardware","crypta","photon","tunneling","vacuum","simulator","simulation"],"description":"Omitted or auto uses the key's stored method. hardware/crypta require a runtime flag; recognized selectors do not imply availability or entitlement. Values are trimmed and case-normalized; simulation aliases simulator."},"signatureType":{"type":"string","enum":["ed25519","dilithium2","dilithium3","dilithium5"],"description":"Defaults to Ed25519, except PQC-enabled Pro (dilithium2) or Enterprise (dilithium3)."}}}}}}}},"/api/notarization/proof/{proofId}":{"get":{"tags":["Public"],"summary":"Read Merkle inclusion record","parameters":[{"name":"proofId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Merkle proof included in a finalized batch","content":{"application/json":{"schema":{"type":"object","required":["proofId","merkleProof","verified"],"properties":{"proofId":{"type":"string"},"verified":{"type":"boolean"},"merkleProof":{"type":"object","properties":{"leaf":{"type":"string"},"root":{"type":"string"},"proof":{"type":"array","items":{"type":"string"}},"positions":{"type":"array","items":{"type":"integer","enum":[0,1]}}}}}}}}},"404":{"description":"Record missing or not batched yet","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Proof lookup failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/notarization/batch/{batchId}":{"get":{"tags":["Public"],"summary":"Read process-local batch and optional anchor state","parameters":[{"name":"batchId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Batch metadata","content":{"application/json":{"schema":{"type":"object","required":["batchId","merkleRoot","proofsCount","createdAt","blockchainAnchor"],"properties":{"batchId":{"type":"string"},"merkleRoot":{"type":"string"},"proofsCount":{"type":"integer"},"createdAt":{"type":"integer","format":"int64"},"blockchainAnchor":{"type":"object","additionalProperties":true,"nullable":true}}}}}},"404":{"description":"Batch not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Batch lookup failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/notarization/stats":{"get":{"tags":["Public"],"summary":"Read server-side notarization statistics","responses":{"200":{"description":"Process-local Merkle and anchor counts","content":{"application/json":{"schema":{"type":"object","properties":{"merkle":{"type":"object","additionalProperties":true},"blockchain":{"type":"object","additionalProperties":true}}}}}},"500":{"description":"Stats unavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/verify/{proofId}":{"get":{"tags":["Public"],"summary":"Verify entropy proof","description":"Check the stored signature against the stored digest. Original bytes are not persisted. No authentication required.","parameters":[{"name":"proofId","in":"path","required":true,"schema":{"type":"string"},"description":"Unique proof identifier"}],"responses":{"200":{"description":"Proof verification result","content":{"application/json":{"schema":{"$ref":"#/components/schemas/VerifyProofResponse"}}}},"404":{"description":"Proof not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Failed to verify proof","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/billing/checkout":{"post":{"tags":["Billing"],"summary":"Create checkout session","description":"Create a Stripe Checkout session. Requires session and trusted Origin; successful checkout creation does not activate access.","security":[{"SessionAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CheckoutRequest"}}}},"responses":{"200":{"description":"Checkout session created successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CheckoutResponse"}}}},"400":{"description":"Invalid tier or billing cycle","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Not authenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Organization not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Failed to create checkout session","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}