SDK
A typed client for /agent/*: retries, idempotency keys, one error class and webhook helpers. Runs in Node 20+ and edge runtimes. It carries your API key, so it belongs on your server, never in the browser: the browser piece is the buy button.
Install
pnpm add @lidpro/sdkEvery route, body and response is typed from the same contract the REST reference documents.
import { createLid } from '@lidpro/sdk';
const lid = createLid({ apiKey: process.env.LID_API_KEY! });
const created = await lid.products.create({
name: 'Notion template pack',
priceUsdc: 12.5,
maxSupply: 100,
});
const me = await lid.me.get();
const { sales } = await lid.sales.list({ limit: 2 });Generate it in Settings → Development, where you can also show it again. Use it as the authorization header on every request: Settings → Development.
Every operation the SDK exposes is documented, with its SDK call, curl and a sample response, in the API reference.
Environments
mainnet is the default; baseUrl overrides either one for a proxy or a local API.
| Environment | Base URL | Money |
|---|---|---|
mainnet | https://api.lid.pro | Digital dollars (USDC) |
devnet | https://api-devnet.lid.pro | Test USDC, no value |
import { createLid } from '@lidpro/sdk';
const lid = createLid({ apiKey, environment: 'devnet' });Errors
Every non-2xx response throws a LidError with the API error envelope plus the HTTP status. type is a stable slug from the contract; branch on it, not on message.
import { isLidError } from '@lidpro/sdk';
try {
await lid.products.create(body);
} catch (e) {
if (!isLidError(e)) throw e;
switch (e.type) {
case 'insufficient_scope':
// details.permission: the one the key lacks (sitio, catalogo or dinero)
console.error('The key lacks a permission', e.details);
break;
case 'product_creation_limit':
// details carries the quota and the seconds to wait for this slug
console.error('Daily product quota reached', e.details);
break;
default:
console.error(e.type, e.message, e.requestId);
}
}import { isLidErrorOfType } from '@lidpro/sdk';
if (isLidErrorOfType(e, 'rate_limited')) {
await sleep((e.details?.retryAfter ?? 1) * 1000);
}Retries and idempotency
The client retries up to maxRetries times, and only when repeating the call cannot do something twice. A 429 is retried on any route, after Retry-After. A 502, 503, 504 or a request with no response is retried only on reads and on the routes the API deduplicates by Idempotency-Key (create product, buy, create challenge); any other POST surfaces the error, because it may have run. Every POST and PATCH gets an Idempotency-Key unless you send your own; pass one you control (an order id) so a retry returns the stored response instead of charging again.
await lid.products.create(body, { idempotencyKey: orderId });Types
Every schema and operation of the contract gets a generated name (ProductSummary, ProductsCreateBody…). A handful also get a friendlier hand-picked alias:
import type {
Product,
CreateProductInput,
MethodInput,
MethodResult,
} from '@lidpro/sdk';
const input: CreateProductInput = {
name: 'Notion template pack',
priceUsdc: 12.5,
maxSupply: 100,
};
// same shape as the flat input lid.products.create takes
const sameInput: MethodInput<'products.create'> = input;
function isOnSale(p: Product): boolean {
return p.status === 'confirmed' && !p.archived;
}
type CreateResult = MethodResult<'products.create'>; // same as CreateProductResultProductCreateProductInputCreateProductResultPurchaseBountySubmissionMeUsageCreditsSiteSiteSummaryCreateSiteInputLidaRunApiErrorEnvelope
Escape hatch: lid.api
lid.api is the typed HTTP client the methods call underneath: GET/POST/PATCH/DELETE keyed by path, for anything a namespaced method does not cover yet. unwrap turns its { data, response } into data alone.
import { unwrap } from '@lidpro/sdk';
const usage = await unwrap(lid.api.GET('/api/v1/agent/usage'));