URL Shortener API & TypeScript SDK: Integrate Link Shortening into Any App

· Developers · 6 min read

Learn how to use the Alias REST API and official TypeScript SDK (aliaslive-sdk) to shorten URLs, manage links, and fetch analytics programmatically.

Need to create short links from your app, automate link generation in a script, or build a custom dashboard? The Alias REST API and official TypeScript SDK make integration straightforward — with full type safety, zero runtime dependencies, and support for both ESM and CommonJS.

Getting Started: Install the SDK

Install the package from npm: npm install aliaslive-sdk. Generate an API key from your Alias account settings under API Keys.

Shortening a URL

Import AliasClient and call shorten() with the destination URL. The result includes the slug, the full short URL, and the original destination.

  • import { AliasClient } from "aliaslive-sdk";
  • const alias = new AliasClient({ apiKey: "alias_xxxx" });
  • const { shortUrl } = await alias.shorten("https://example.com");
  • Optional: pass a slug, password, or expiresAt in the second argument.

Bulk Shortening via SDK

Use bulkShorten() to shorten up to 50 URLs in one API call. Each item has its own error field so a single failure does not block the rest.

  • Pass an array of { destination, slug? } objects.
  • Returns an array of { destination, slug, shortUrl, error? }.
  • Maximum 50 items per call.
  • Failed items include an error string; successful items include the shortUrl.

Managing Links

The links namespace on AliasClient covers listing, deleting, and fetching analytics for any of your links.

  • alias.links.list(page, limit) — paginated list of all your links.
  • alias.links.delete(slug) — delete a link by slug.
  • alias.links.analytics(slug, { days: 30 }) — click stats including country, device, browser, and referrer breakdowns.

Error Handling

The SDK throws an AliasHttpError on non-2xx responses. It exposes status (HTTP status code), code (e.g. CONFLICT, UNAUTHORIZED), and message — so you can handle specific cases like a slug already being taken.

Using the REST API Directly

All endpoints accept an X-Api-Key header for authentication. The base URL is https://aliasurlshortener.com/api/v1. Core endpoints include POST /customShort to create a link, POST /links/bulk for batch creation, GET /links for list, DELETE /links/:slug to remove, and GET /links/:slug/analytics for stats.

CommonJS Support

The SDK ships dual ESM and CJS builds. In a CommonJS project, use: const { AliasClient } = require("aliaslive-sdk");

Get your free API key