REST API3 min

How to call ToolKnife API from Python

Use the ToolKnife REST API from Python with the requests library. Calculate mortgages, convert currencies, generate UUIDs, and more.

Prerequisites

  • Python 3.8+
  • requests library (pip install requests)
1

Install the requests library

If you don't have it already, install the requests library.
pip install requests
2

Make your first API call

Every tool function is available at `POST /api/v1/tools/{tool-slug}_{function-name}`. Browse all available endpoints at toolknife.com/docs.
calculate_bmi.py
import requests

response = requests.post(
    "https://toolknife.com/api/v1/tools/bmi-calculator_calculate",
    json={"weightKg": 75, "heightCm": 180},
)

data = response.json()
print(f"BMI: {data['result']['bmi']}")
print(f"Category: {data['result']['category']}")
Output
BMI: 23.15
Category: Normal weight
3

Chain multiple tools

Call multiple tools in sequence to build workflows. Here is a home buying analysis that chains mortgage payment, affordability, and closing cost calculations.
home_buying_analysis.py
import requests

BASE = "https://toolknife.com/api/v1/tools"

# Step 1: Monthly payment
payment = requests.post(f"{BASE}/mortgage-calculator_monthly-payment", json={
    "principal": 360000,
    "annualRate": 6.5,
    "years": 30,
}).json()["result"]

print(f"Monthly payment: ${payment['monthlyPayment']:,.2f}")
print(f"Total interest: ${payment['totalInterest']:,.2f}")

# Step 2: Can they afford it?
afford = requests.post(f"{BASE}/mortgage-affordability-calculator_calculate", json={
    "annualIncome": 120000,
    "monthlyDebts": 500,
    "downPayment": 90000,
    "annualRate": 6.5,
    "years": 30,
}).json()["result"]

print(f"Max home price: ${afford['maxHomePrice']:,.0f}")
print(f"DTI ratio: {afford['backEndDTI']}%")
4

Add authentication for higher limits

Free tier gives you 200 calls/day. For production use, create an API key at toolknife.com/dashboard/api-keys and pass it in the header.
With API key
import requests

headers = {
    "x-api-key": "tk_your_api_key_here",
    "Content-Type": "application/json",
}

response = requests.post(
    "https://toolknife.com/api/v1/tools/currency-converter_convert",
    json={"amount": 1000, "from": "USD", "to": "EUR"},
    headers=headers,
)

print(response.json()["result"])
5

Error handling

The API returns standard HTTP status codes. Handle rate limits (429) and validation errors (400) gracefully.
error_handling.py
import requests
import time

def call_tool(slug: str, params: dict, api_key: str | None = None) -> dict:
    headers = {"Content-Type": "application/json"}
    if api_key:
        headers["x-api-key"] = api_key

    response = requests.post(
        f"https://toolknife.com/api/v1/tools/{slug}",
        json=params,
        headers=headers,
    )

    if response.status_code == 429:
        retry_after = int(response.headers.get("Retry-After", 60))
        time.sleep(retry_after)
        return call_tool(slug, params, api_key)

    response.raise_for_status()
    return response.json()["result"]

Related guides

Tools used in this guide

Ready to integrate? Browse all 273+ tools with interactive examples.