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 install @wayline/sdk
# or: pnpm add @wayline/sdk · yarn add @wayline/sdk · bun add @wayline/sdkQuickstart
Set WAYLINE_API_KEY to a test key (see the Quickstart), then:
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.
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
| Option | Default | Description |
|---|---|---|
| API key | WAYLINE_API_KEY | Your live or test key. Never logged. |
| Base URL | https://api.wayline.cloud | Override for staging or a proxy. |
| Timeout | 30 seconds | Per attempt. |
| Max retries | 3 | For 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.