PHASE 30 — ENGINEERING NOTE
API keys are the wrong tool for autonomous agents.
For a human running a server, an API key is fine. You can store it somewhere safe, rotate it on a schedule, revoke it when a contractor leaves. For an AI agent calling our gateway a thousand times an hour, with no human in the loop, a shared secret is a misfit. The agent has to manage it, pass it across every call, and trust the storage on every hop.
Today we ship a different auth path: the open x402 (HTTP 402) protocol, settled in QUBIC on Qubic mainnet. The wallet is the identity. The chain is the audit log. No API key, no signup, no card on file.
What changed
The gateway now recognises three auth paths on every paid route: JWT, gateway API key (ak_live_…), and an x402 payment envelope in an X-PAYMENT header. The protocol is opt-in: a request without a Bearer that includes a valid X-PAYMENT runs as x402.
- The gateway returns
HTTP 402with a structuredWWW-Authenticate: X402header. - The challenge body carries the cost in QUBIC, the recipient address, and a single-use nonce.
- The agent signs a Qubic tx and retries with proof of payment in the
X-PAYMENTheader. - A successful retry returns the response with an
X-PAYMENT-RESPONSEreceipt header.
Why QUBIC, not USDT, for v1
QUBIC is the currency that compute providers on Aigarth already earn when they serve work. Adding a stablecoin rail is straightforward when the protocol is in place, but shipping the protocol first against the currency the network already understands closes the loop without an FX step. USDT and USDC slot in next, behind the same scheme dispatcher, with no protocol change.
How an agent integrates
The new @aigarth/sdk/x402 entry point handles the 402 dance on the caller’s behalf:
import { payAndCall, QubicSigner } from "@aigarth/sdk/x402";
const signer = await QubicSigner.fromEnv("QUBIC_MNEMONIC");
const { body, receipt } = await payAndCall(
{
gatewayURL: "https://api.aigarth.cloud",
method: "POST",
resource: "/v1/chat/completions",
body: {
model: "aigarth-meridian-1",
messages: [{ role: "user", content: "Hello" }],
},
},
signer,
);That call returns the chat completion, plus the on-chain receipt: a paymentId, a txHash, the settlement timestamp, and a link to claim those receipts into a full account later if the user wants one.
Accountless by design
A wallet is the identity. The first x402 payment from a new Qubic address creates a shadow user keyed by the address. The dashboard’s existing usage history keeps working because gateway_requests.user_id is just the shadow UUID. When the user signs up later and links the same wallet, the receipts fold into the new account in a single transaction.
What ships next
USDC on Base and USDT on Ethereum + Polygon go in next, using the same envelope. The Qubic transaction broadcast inside the SDK reference signer is wired against our own services/qubic tx-monitor once the Qubic K12 signature integration lands. Refunds for over-payment ship in a follow-up. The protocol is the part that sticks: every future rail plugs into the same scheme modules under lib/x402/schemes/.