API Documentation
Welcome to the HTS Tariff Calculator API. Calculate US import tariffs programmatically using our RESTful API.
Getting Started
To use the API, you'll need to:
- Create an account at https://tariffcalc.com/signup
- Subscribe to a Starter, Professional, or Enterprise plan
- Generate your API key from the API Keys page
- Include your API key in the Authorization header of all requests
Authentication
All API requests must include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY
API keys are tied to your account and count against your monthly quota.
API Endpoints
Base URL: https://tariffcalc.com
Available Endpoints
Method | Endpoint | Description |
---|---|---|
GET | /api/calculate | Calculate tariff for HTS code and inputs |
GET | /api/search | Search HTS codes by keyword or code prefix |
Calculate Tariff
Calculate the import duty for a specific HTS code with given parameters.
Request
GET /api/calculate?hts_code=0102.21.00&country=MX&quantity=1000&value=10000
Authorization: Bearer YOUR_API_KEY
Query Parameters
Parameter | Type | Required | Description |
---|---|---|---|
hts_code | string | Yes | HTS code (with or without dots) |
country | string | Yes | ISO 2-letter country code |
quantity | number | Yes | Quantity in units |
value | integer | Yes | Value in USD cents |
Response
{
"success": true,
"hts_code": "0102.21.00",
"duty_rate": "5.1%",
"duty_usd": "510.50",
"total_cost_usd": "10510.50"
}
Rate Limits
API rate limits vary by subscription tier:
Plan | API Calls/Month | Rate Limit |
---|---|---|
Free | 0 | No API access |
Starter | 1,000 | 10 requests/minute |
Professional | 10,000 | 60 requests/minute |
Enterprise | 100,000 | 300 requests/minute |
Rate limit headers are included in every response:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 847
X-RateLimit-Reset: 1699920000
Pricing
Subscribe to get API access:
- Starter ($5/month): 1,000 API calls, 10 saved formulas
- Professional ($20/month): 10,000 API calls, 50 saved formulas
- Enterprise ($75/month): 100,000 API calls, unlimited formulas
Code Examples
Python
import requests
api_key = "YOUR_API_KEY"
base_url = "https://tariffcalc.com"
# Calculate tariff
response = requests.get(
f"{base_url}/api/calculate",
headers={"Authorization": f"Bearer {api_key}"},
params={
"hts_code": "0102.21.00",
"country": "MX",
"quantity": 1000,
"value": 10000
}
)
data = response.json()
print(f"Duty: ${data['duty_usd']}")
JavaScript/Node.js
const apiKey = "YOUR_API_KEY";
const baseUrl = "https://tariffcalc.com";
// Calculate tariff
const response = await fetch(
`${baseUrl}/api/calculate?hts_code=0102.21.00&country=MX&quantity=1000&value=10000`,
{
headers: {
"Authorization": `Bearer ${apiKey}`
}
}
);
const data = await response.json();
console.log(`Duty: $${data.duty_usd}`);
cURL
curl -X GET "https://tariffcalc.com/api/calculate?hts_code=0102.21.00&country=MX&quantity=1000&value=10000" \
-H "Authorization: Bearer YOUR_API_KEY"
Excel Integration
=WEBSERVICE("https://tariffcalc.com/api/calculate?hts_code=0102.21.00&country=" & A1 & "&quantity=" & B1 & "&value=" & C1 & "&apikey=YOUR_API_KEY")
Replace A1, B1, C1 with your cell references for country, quantity, and value.
Error Codes
The API uses standard HTTP status codes:
Code | Meaning | Description |
---|---|---|
200 | OK | Request succeeded |
400 | Bad Request | Invalid parameters or missing required fields |
401 | Unauthorized | Invalid or missing API key |
429 | Too Many Requests | Rate limit exceeded |
500 | Internal Server Error | Something went wrong on our end |
Error Response Format
{
"success": false,
"error": "Invalid HTS code",
"error_code": "INVALID_HTS_CODE"
}
Questions? Contact us at support@tariffcalc.com