@4o2/sdk
v0.3.3
Published
x402 helper — wrap your existing paid handler, or mount a standalone /warmup route. Settles on Base via EIP-3009.
Downloads
569
Maintainers
Readme
@4o2/sdk
x402 helper for paid endpoints — drop in front of your existing handler, or mount as a standalone /warmup route.
→ 4o2.dev — get an API key, manage your listing, see live activity.
Install
pnpm add @4o2/sdkQuick start
Wrap any existing paid handler. Unsigned traffic falls through to your handler unchanged; signed warming traffic gets the SDK's challenge.
// app/api/predict/route.ts
import { wrap } from "@4o2/sdk/next";
async function realPOST(req: Request) {
// your existing paid handler
}
export const POST = wrap(realPOST);Or mount as a standalone route:
// app/api/warmup/route.ts
export { POST } from "@4o2/sdk/next";Other runtimes
// Hono
import { wrap } from "@4o2/sdk/hono";
app.post("/predict", wrap(async (c) => { /* ... */ }));
// Express
import { wrap } from "@4o2/sdk/express";
app.post("/predict", wrap(async (req, res) => { /* ... */ }));
// Bun / Cloudflare Workers / any fetch runtime
import { wrap } from "@4o2/sdk/fetch";
const handler = wrap(async (req) => { /* ... */ });Configuration
Set one env var:
FOUR_O_TWO_API_KEY=4o2_<slug>_<secret>Get the key from your dashboard at 4o2.dev. The SDK fetches the rest of its config (splitter address, network, asset) at first request and caches it.
Verify
curl -X POST https://your-domain.com/api/predictExpected: HTTP/1.1 402 Payment Required with an x402 v2 challenge body. That confirms the wrap is wired correctly.
License
MIT.
