REST API3 min
How to call ToolKnife API from JavaScript/Node.js
Integrate ToolKnife tools into your JavaScript or Node.js application with fetch. No SDK needed.
Prerequisites
- Node.js 18+ (or any modern browser)
1
Make your first API call
Use the native `fetch` API. No SDK or package needed. Works in Node.js 18+, Deno, Bun, and all modern browsers.
calculate-bmi.ts
const response = await fetch(
"https://toolknife.com/api/v1/tools/bmi-calculator_calculate",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ weightKg: 75, heightCm: 180 }),
}
);
const { result } = await response.json();
console.log(`BMI: ${result.bmi}, Category: ${result.category}`);
// BMI: 23.15, Category: Normal weight2
Create a reusable client
Wrap the API in a simple function for cleaner code. No need for an npm package when fetch does the job.
toolknife.ts
const TOOLKNIFE_API = "https://toolknife.com/api/v1/tools";
async function callTool<T>(
slug: string,
params: Record<string, unknown>,
apiKey?: string
): Promise<T> {
const headers: Record<string, string> = {
"Content-Type": "application/json",
};
if (apiKey) headers["x-api-key"] = apiKey;
const res = await fetch(`${TOOLKNIFE_API}/${slug}`, {
method: "POST",
headers,
body: JSON.stringify(params),
});
if (!res.ok) {
throw new Error(`ToolKnife API error: ${res.status} ${res.statusText}`);
}
const data = await res.json();
return data.result as T;
}
// Usage
const bmi = await callTool<{ bmi: number; category: string }>(
"bmi-calculator_calculate",
{ weightKg: 75, heightCm: 180 }
);3
Build a multi-tool workflow
Chain tools together for complex calculations. This example builds a SaaS metrics dashboard.
saas-metrics.ts
// SaaS metrics from raw business data
const [mrr, churn, ltv] = await Promise.all([
callTool("mrr-arr-calculator_calculate", {
subscribers: 250,
avgMonthlyRevenue: 49,
}),
callTool("churn-rate-calculator_calculate", {
startCustomers: 250,
lostCustomers: 12,
period: "monthly",
}),
callTool("ltv-calculator_calculate", {
avgRevenue: 49,
churnRate: 4.8,
}),
]);
console.log({ mrr, churn, ltv });4
Use in Next.js Server Components
ToolKnife API calls work great in Next.js Server Components and Route Handlers. The response is cacheable.
app/mortgage/page.tsx (Next.js)
export default async function MortgagePage() {
const res = await fetch(
"https://toolknife.com/api/v1/tools/mortgage-calculator_monthly-payment",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
principal: 360000,
annualRate: 6.5,
years: 30,
}),
next: { revalidate: 3600 }, // Cache for 1 hour
}
);
const { result } = await res.json();
return (
<div>
<p>Monthly payment: ${result.monthlyPayment.toFixed(2)}</p>
</div>
);
}5
Add authentication
Pass your API key in the `x-api-key` header. Get your key at toolknife.com/dashboard/api-keys.
With API key
const result = await callTool(
"currency-converter_convert",
{ amount: 1000, from: "USD", to: "EUR" },
process.env.TOOLKNIFE_API_KEY // "tk_..."
);Related guides
Tools used in this guide
Ready to integrate? Browse all 273+ tools with interactive examples.