The official Node.js client calls the TariffTrust API from any server-side JavaScript or TypeScript code: an HTS code, a country of origin and a customs value go in; every US import duty and fee that applies comes back, each with its rate, its amount and its official source. It needs Node.js 20 or later, has no dependency, includes its TypeScript types, and runs in any server-side runtime with fetch.
Install it and estimate a product
npm install tarifftrust
Create a key in your workspace and set it as TARIFFTRUST_API_KEY on your server:
import { TariffTrust } from "tarifftrust"; const client = new TariffTrust(); // reads TARIFFTRUST_API_KEY const result = await client.estimate({ hts: "6109.10.00.12", origin: "CN", customs_value: "10000" }); console.log(result.status, result.estimated_duty); for (const duty of result.duties ?? []) { console.log(duty.name, duty.rate, duty.amount, duty.source?.url); }
Keep the key on the server
Never import the client into code that runs in a browser or a mobile app: that would ship your key with it. Call it from your backend, an API route or a serverless function, and let your front end call that. The Next.js example shows the pattern.
Read the answer
Read status first, then the amounts: decimal strings in US dollars, so that nothing is lost to floating point. Unknown is never zero: when estimated_duty is null or left out, the duty is not established; missing says what to send again and withheld what is left out for now.
A whole declaration
Several products entered together go in one call, estimateEntry, so that the entry fees count once:
const entry = await client.estimateEntry({ transport_mode: "ocean", lines: [ { reference: "PO-1042-1", hts: "6109.10.00.12", origin: "CN", customs_value: "1000" }, { reference: "PO-1042-2", hts: "6109.10.00.12", origin: "VN", customs_value: "2500" }, ], }); console.log(entry.estimated_duty, entry.estimated_fees, entry.estimated_landed_cost);
Like the Python client, it retries safely with an idempotency key, counted once in your quota, and raises one error class per refusal, with the request id to quote to support. See the package on npm.
The whole example
The complete, runnable example is in the public repository of the official clients, under the MIT license. The API reference describes every field of the request and of the answer, the errors and how to retry safely, and the integration guides how to read an answer and estimate a declaration.