Node 18 or higher. Works in Bun, Deno, and modern edge runtimes.
Never ship an API key to the browser. Call the SDK from a server
route (Next.js Route Handlers, tRPC procedures, Express endpoints)
and proxy the response to your client.
Pass idempotencyKey in options to make retries safe.
import { randomUUID } from "node:crypto";const idempotencyKey = randomUUID();const first = await client.calc(payload, { idempotencyKey });const second = await client.calc(payload, { idempotencyKey });// first.id === second.id
Error handling
Non-2xx responses throw ApiError with the status, machine code,
parsed body, and retryAfter (populated on 429).
import { ApiError } from "@landedfees/sdk";try { await client.calc(payload);} catch (err) { if (err instanceof ApiError) { if (err.status === 429) { await new Promise((r) => setTimeout(r, (err.retryAfter ?? 60) * 1000)); } else if (err.status === 422 && err.code === "MISSING_HS_CODE") { // Run classify first. } else { throw err; } }}
The client retries once by default on 429 and 5xx. Set
maxRetries: 0 on the constructor to disable.
Types
The full request and response shapes are typed. Some highlights:
import type { CalcRequest, CalcResponse, ClassificationResult, CompareResponse, RatesResponse, ComplianceFlag, CostLayer,} from "@landedfees/sdk";
Edge runtime notes
The SDK uses the global fetch. On Vercel Edge and Cloudflare
Workers, no additional configuration is needed. On Node 16 (which
does not have global fetch), inject undici:
import { fetch } from "undici";import { LandedFeesClient } from "@landedfees/sdk";const client = new LandedFeesClient({ apiKey: process.env.KEY!, fetch });