TypeScript runtime for machine commerce
Turn any TypeScript function into a paid API.
Define a typed capability once. Let agents and applications discover, pay for, and call it over the verified Stable x402 path from the web framework you already use. Qualified Next pages cover the newer MPP surface.
Start with your coding agent
Seller
Sell a paid API
Define a typed capability, advertise one clear price, and receive x402 payments.
Buyer
Build a budgeted buyer
Call paid services from a server-side wallet with recipient and spending policy.
Application
Keep your framework
Add Lucid to Hono, Express, Next.js, or TanStack Start without duplicating runtime logic.
One application transaction
More than a 402 response
Lucid composes schema validation, payment admission, policy, fulfillment, settlement, idempotency, tasks, discovery, and durable state around the payment rail.
- 01Advertise one typed capability and price
- 02Challenge and verify the buyer
- 03Reserve policy capacity before fulfillment
- 04Settle, record, and return the typed result
import { createAgent } from '@lucid-agents/core';
import { createAgentApp } from '@lucid-agents/hono';
import { http } from '@lucid-agents/http';
import { payments, paymentsFromEnv } from '@lucid-agents/payments';
import { z } from 'zod';
const runtime = await createAgent({
name: 'text-service',
version: '0.1.0',
description: 'Paid text analysis',
})
.use(http())
.use(payments({ config: paymentsFromEnv() }))
.build();
const { app, addEntrypoint } = await createAgentApp(runtime);
addEntrypoint({
key: 'analyze',
description: 'Count the words and characters in text',
price: '0.01',
input: z.object({ text: z.string().min(1) }),
output: z.object({ words: z.number(), characters: z.number() }),
handler: async ({ input }) => ({
output: {
words: input.text.trim().split(/\s+/u).length,
characters: input.text.length,
},
}),
});
export { app };Framework-portable
One canonical HTTP route and authorization contract across Hono, Express, Next.js, and TanStack Start.
Protocol-composable
Use the verified x402 v2 exact path first; add only the versioned Next protocol subsets documented in each compatibility page.
Production-shaped
Move from in-memory defaults to explicit durable payment, entitlement, task, and scheduler ports.
Start with one paid call.
Observe the x402 challenge, complete a Base Sepolia payment, then follow the production checklist before moving real funds.
Open the paid API quickstart