Documentation menu

SDKs

TypeScript / JavaScript SDK

The official Wayline SDK for TypeScript / JavaScript: Node.js 18+, Bun, Deno, Cloudflare Workers, Vercel Edge. ESM and CommonJS. Zero dependencies (uses fetch).

Install

npm
npm install @wayline/sdk
# or: pnpm add @wayline/sdk · yarn add @wayline/sdk · bun add @wayline/sdk

Quickstart

Set WAYLINE_API_KEY to a test key (see the Quickstart), then:

TypeScript / JavaScript
import { Wayline } from "@wayline/sdk";

const wayline = new Wayline({ apiKey: process.env.WAYLINE_API_KEY! });

const d = await wayline.distance({
  origin: { lat: 23.7925, lng: 90.4078 },
  destination: "23.733,90.4172",
  units: "imperial",
});
console.log(d.distance_miles, d.duration_seconds);

const m = await wayline.matrix({
  origins: [{ lat: 23.7925, lng: 90.4078 }],
  destinations: [{ lat: 23.733, lng: 90.4172 }, { lat: 23.7937, lng: 90.4066 }],
});
console.log(m.rows[0].elements.map((e) => e.duration_seconds));

Errors

Non-2xx responses raise a typed error after retries are exhausted. Branch on code — the full list is in the error reference.

Error handling
import { WaylineError } from "@wayline/sdk";

try {
  await wayline.distance({ origin: "0,0", destination: "0,1" });
} catch (err) {
  if (err instanceof WaylineError) {
    console.error(err.code, err.status, err.requestId); // e.g. OUT_OF_COVERAGE 400 req_…
  }
}

Configuration

OptionDefaultDescription
API keyWAYLINE_API_KEYYour live or test key. Never logged.
Base URLhttps://api.wayline.cloudOverride for staging or a proxy.
Timeout30 secondsPer attempt.
Max retries3For 429 and 5xx, with exponential backoff + jitter, honoring Retry-After.

Source and releases

Package: @wayline/sdk on npm. Source: packages/sdk-js. Versions follow semantic versioning; see the CHANGELOG in the package and our product changelog.

Was this page helpful?