Install via npm
Add the SDK to your Node.js or browser project.
npm install lix-url
Official JavaScript SDK for the Lix.li URL shortening API. Works in Node.js and browser environments. Create short links, manage groups, and track clicks with async/await and clean class-based DTOs.
// npm install lix-url const { Client } = require('lix-url'); const client = new Client('lix_live_xxx'); async function main() { const result = await client.links().create('https://example.com'); console.log(result.link.shortUrl); // https://lix.li/a3b7k2 } main();
Built with async/await, plain class-based DTOs, and a swappable fetch function for Node.js or browser.
Create, get, update, delete, and list short links. Full CRUD with typed class responses.
Organize links into groups. Create rotating groups for A/B testing landing pages.
Fetch account profile, plan details, and real-time usage limits for links and API calls.
Every API response is a plain JavaScript class instance. No raw objects — predictable structure with dot-notation access.
6 dedicated exception types for validation, authorization, rate limits, server errors, and transport failures.
Inject any fetch-compatible function. Works with Node.js fetch, undici, or browser fetch out of the box.
Works in any Node.js or browser environment with fetch support. No heavy dependencies — just a clean HTTP client layer.
Add the SDK to your Node.js or browser project.
npm install lix-url
Pass your API key. Optionally inject a custom fetch function for testing or edge runtimes.
const { Client } = require('lix-url'); const client = new Client('lix_live_xxx'); // With custom fetch (e.g., for testing) const client = new Client('lix_live_xxx', myFetchFn);
Shorten a URL and get back a typed LinkShortenResult with the short URL and usage info.
const result = await client.links().create('https://example.com'); console.log(result.link.shortUrl); // https://lix.li/a3b7k2 // Links used: 42 / 100 console.log(result.usage.used, '/', result.usage.limit);
Create short links with custom aliases, UTM parameters, tracking pixels, password protection, and expiration dates. Every operation returns a typed class instance.
// Create a basic link const result = await client.links().create('https://example.com'); // With custom alias and UTM const result = await client.links().create( 'https://example.com', 'summer-sale', // alias 'My Summer Sale', // title null, // groupId ['marketing', '2026'], // tags [], // meta { // utm source: 'newsletter', medium: 'email', campaign: 'summer-sale', }, [1, 2], // trackingPixelIds null, // activeBeforeDatetime null, // password true // isPublic ); // Password protection + expiration const result = await client.links().create( 'https://example.com', null, null, null, [], [], [], [], '2026-12-31T23:59:59Z', // activeBeforeDatetime 'secret123' // password );
Pagination example: $client->links()->list(limit: 100, fromId: 500) returns the next 100 links starting after ID 500, with ResponseMeta containing total count and next URL.
Groups help you categorize links by campaign, team, or project. Rotating groups enable A/B testing by distributing traffic across multiple links.
// Create a regular group const group = await client.groups().create('Marketing'); console.log(group.name); // Create a rotating group for A/B testing const group = await client.groups().create( 'Landing Pages', null, true // isRotate ); // Update group const group = await client.groups().update( 10, null, 'Updated description' ); // List with pagination const response = await client.groups().list(10, 1000); for (const group of response.groups) { console.log(group.name); }
Fetch your profile, plan, and real-time usage limits — all returned as nested class instances with full property access.
const profile = await client.profile().me(); // Account info console.log(profile.client.name, profile.client.email); console.log(profile.user.email); // Plan details console.log(profile.plan.name, profile.plan.endDatetime); // Usage limits console.log(profile.usages.links.remaining); console.log(profile.usages.apiLinks.used); console.log(profile.usages.massLinks.limit);
Organization and account metadata.
Authenticated user information and account details.
Current subscription and billing period.
API limits, link quotas, and remaining usage.
Catch exactly what you need. All exceptions extend LixException. ValidationException includes the full field-level error data in err.data.
const { ValidationException, NotFoundException, UnauthorizedException, RateLimitException, ServerException } = require('lix-url'); try { await client.links().create('invalid-url'); } catch (err) { if (err instanceof ValidationException) { // Field-level validation errors console.error('Validation:', err.data); } else if (err instanceof NotFoundException) { console.error('Not found:', err.message); } else if (err instanceof UnauthorizedException) { // Invalid API key } else if (err instanceof RateLimitException) { // Too many requests — retry after } else if (err instanceof ServerException) { // 5xx server error } else { // Generic Lix or network error console.error('Error:', err.message); } }
400 — Invalid input. Access err.data for field errors.
401 — Missing, invalid, or expired API credentials.
404 — Link, group or resource not found.
429 — Rate limit exceeded.
500 — Unexpected server error.
Network / transport failure.
All exceptions extend LixException, which extends native Error. Catch the base class for any SDK error, or target specific classes for granular handling.
Use the same Lix.li API from PHP, JavaScript, Python, or Go with SDKs tailored to each ecosystem.
Install the SDK, get your API key, and start creating short links in under a minute.