Integrations

JavaScript SDK

Official JS/TS SDK for the U2L API: typed client for creating short links and QR codes, listing and searching, and reading click analytics.

The official JavaScript/TypeScript client for the U2L REST API. Zero dependencies, full TypeScript types, and it runs anywhere fetch exists: Node.js 18+, browsers, Cloudflare Workers, Deno, and Bun.

Install

npm install @u2l/sdk

Quick start

import { U2L } from "@u2l/sdk";

const u2l = new U2L({ apiKey: "u2l_live_..." });

const link = await u2l.links.create({ url: "https://example.com/some/long/page" });
console.log(link.shortLink); // https://u2l.ai/abc1234

Create an API key at Settings → API — every plan includes API access. Keep the key server-side; do not ship it in public browser bundles.

// Create — all fields optional except url
await u2l.links.create({
  url: "https://mysite.com/launch",
  alias: "launch24",          // custom slug
  title: "Launch day",
  domain: "auto",             // or one of your domains from u2l.domains.list()
  type: "SL",                 // "QR" creates a QR code
  tags: ["campaign", "q3"],
});

// Read one
const link = await u2l.links.get("u2l.ai", "launch24");

// List and search (paginated)
const page = await u2l.links.list({ search: "launch", limit: 25, page: 1 });
for (const l of page.links) console.log(l.slug, l.clicks);

// Update
await u2l.links.update("u2l.ai", "launch24", { title: "Renamed", tags: ["archive"] });

// Delete (permanent)
await u2l.links.delete("u2l.ai", "launch24");

Analytics, domains, account

// Per-link analytics (Advanced plan and above)
const stats = await u2l.analytics.get("u2l.ai", "launch24", { timeRange: 30 });

// Domains available to your account
const { domains } = await u2l.domains.list();

// Account totals and limits
const account = await u2l.account.stats();
console.log(account.totalClicks, account.limits.apiRequestsPerDay);

Error handling

Every non-2xx response throws a typed U2LApiError:

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);
    if (e.status === 429) console.error(`retry in ${e.retryAfter}s`);
  }
}

Error codes match the REST API’s error reference.

Rate limit visibility

After any call, the client exposes the latest rate-limit headers:

await u2l.account.stats();
console.log(u2l.rateLimit);
// { limit, remaining, reset, dailyLimit, dailyRemaining }

TypeScript

All request and response shapes are exported:

import type { CreateLinkInput, Link, ListLinksParams, AccountStats } from "@u2l/sdk";

Other languages

Python has its own official client — see the Python SDK (pip install u2l). For any other language, generate a native client from our public OpenAPI 3.1 spec at /developers/openapi.json using standard tooling:

openapi-generator generate \
  -i https://u2l.ai/developers/openapi.json \
  -g go -o ./u2l-go
openapi-generator generate \
  -i https://u2l.ai/developers/openapi.json \
  -g java -o ./u2l-java

Any of the 50+ openapi-generator targets (PHP, Ruby, C#, Rust, Swift, Kotlin, …) work the same way, and the generated client stays current with the spec.

Package

On npm as @u2l/sdk (MIT). Questions or problems: u2l.ai/contact.