@u2l/sdk
v0.1.0
Published
Official JavaScript/TypeScript SDK for the U2L URL shortener API. Create short links and QR codes, list and search them, and read click analytics.
Maintainers
Readme
@u2l/sdk
Official JavaScript/TypeScript SDK for the U2L URL shortener API.
Zero dependencies. Works in Node.js 18+, browsers, Cloudflare Workers, Deno, and Bun. Full TypeScript types included.
npm install @u2l/sdkQuick start
import { U2L } from "@u2l/sdk";
const u2l = new U2L({ apiKey: "u2l_live_..." }); // free at u2l.ai -> Settings -> API
const link = await u2l.links.create({ url: "https://example.com/some/long/page" });
console.log(link.shortLink); // https://u2l.ai/abc1234Usage
// Create with options
await u2l.links.create({
url: "https://mysite.com/launch",
alias: "launch24",
title: "Launch day",
domain: "auto", // or one of your domains
type: "SL", // "QR" for a QR code
});
// Read, list, update, delete
await u2l.links.get("u2l.ai", "launch24");
await u2l.links.list({ search: "launch", limit: 25 });
await u2l.links.update("u2l.ai", "launch24", { title: "Renamed" });
await u2l.links.delete("u2l.ai", "launch24");
// Analytics and account
await u2l.analytics.get("u2l.ai", "launch24", { timeRange: 30 });
await u2l.domains.list();
await u2l.account.stats();Error handling and rate limits
import { U2L, U2LApiError } from "@u2l/sdk";
try {
await u2l.links.create({ url: "https://example.com" });
} catch (e) {
if (e instanceof U2LApiError) {
console.error(e.status, e.code, e.message); // e.retryAfter on 429s
}
}
// After any call, the latest X-RateLimit-* state is available:
console.log(u2l.rateLimit); // { limit, remaining, reset, dailyLimit, dailyRemaining }API keys and docs
Every plan includes API access, including the free plan. Create a key at u2l.ai under Settings -> API.
- REST API reference: u2l.ai/developers
- OpenAPI spec (generate clients for any other language): u2l.ai/developers/openapi.json
