BusinessHS Code
HS Code Lookup API: Classify Products into HS, HTS and CN Codes
HS code lookup API guide: classify products into HS, US HTS and EU CN codes with Python, with GRI reasoning, confidence scores and US duty rates.
Take a 40 oz stainless steel tumbler. Declared as a stainless steel kitchen article (7323.93), it enters the US at a 2 % general duty. Declared as a vacuum vessel (9617.00), it pays 6.9 %. Both codes look plausible on a commercial invoice filled in at 6 pm, and only one fits a vacuum-insulated tumbler. Choose the other and you pay the wrong duty or wait while customs asks questions.
An HS code lookup API should settle that in one call, for a whole catalogue. Most small exporters still classify by hand, one SKU at a time, and a general chatbot happily returns codes that do not exist.
This article explains how classification works, then builds a pipeline on the HS Code Classifier: send a product title, description, page URL or photo, get back a validated HS code with its official texts, a confidence score, the facts that would change the answer, and the US or EU national line on request.
How HS, HTS and CN codes fit together
The Harmonized System (HS) is maintained by the World Customs Organization and used by more than 200 countries and economies. It is a six-digit tree:
- Chapters (2 digits), 97 of them, grouped into 21 sections: 64 is footwear, 85 electrical machinery.
- Headings (4 digits): 6404 is footwear with uppers of textile materials.
- Subheadings (6 digits): 6404.11 is sports footwear within that heading.
The first six digits are the same everywhere; countries extend them for their tariffs and statistics:
| Code | Digits | Maintained by | What the extra digits carry |
|---|---|---|---|
| HS | 6 | World Customs Organization | The international base |
| US HTS (HTSUS) | 10 | US International Trade Commission | 8-digit tariff lines with duty rates, plus a 2-digit statistical suffix |
| EU CN (Combined Nomenclature) | 8 | European Commission, updated every year | EU tariff and trade statistics |
| EU TARIC | 10 | European Commission | EU measures: suspensions, quotas, anti-dumping duties |
The HS is revised about every five years. The current edition is HS 2022; HS 2027 enters into force on 1 January 2027.
Why classification is hard
Classification follows the General Rules for the Interpretation of the Harmonized System (GRI), six rules applied in order:
- GRI 1: classify by the terms of the headings and the section and chapter notes. Section and chapter titles are for reference only.
- GRI 2: an incomplete or unassembled article with the essential character of the finished one is classified as the finished one, and a material named in a heading includes mixtures of it.
- GRI 3: when two headings fit, take the most specific description (3a), then what gives the essential character (3b, for sets and composite goods), then the last heading in numerical order (3c).
- GRI 4: goods that fit no heading go with the most similar goods.
- GRI 5: cases and packing that come with the goods.
- GRI 6: the same logic between subheadings at the same level.
The tumbler is a GRI 1 case: heading 9617 names vacuum vessels, so it beats the general heading for steel household articles. Most mistakes come from facts the title omits: jeans can be cotton or synthetic, woven or knitted, and each combination is a different subheading with a different duty.
Ways to find an HS code compared
| Approach | Speed per product | Codes always real | Explains the choice | Scales to a catalogue |
|---|---|---|---|---|
| Manual search on tariff websites | Minutes | Yes | Only if you write it down | No |
| Keyword search over tariff texts | Seconds | Yes | No | Partly: titles rarely use tariff wording |
| General chatbot or LLM | Seconds | No: invented codes happen | Sometimes | Yes, with silent errors |
| Candidate retrieval + model choice + validation (this API) | 2 to 8 seconds | Yes, checked against HS 2022 | Reasoning, alternatives and facts to confirm | Yes |
| Customs broker or binding ruling | Days | Yes | Yes, with legal weight | Too costly for every SKU |
The API works like the fourth row. A first model call restates the product in customs terms and lists plausible headings; code gathers their subheadings plus the best matches from a local search of the tariff texts; a second call chooses among those real candidates under the GRI, and every returned code is validated against the nomenclature.
Classify a product and get its US duty rate
POST /v1/hs-codes/classify needs one of description, url (a product page) or image_url; material and use are optional but often decisive, and country (US or EU) adds the national line.
import requests
HOST = "hs-code-classifier-ai-customs-tariff-lookup.p.rapidapi.com"
API = f"https://{HOST}"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}
product = {
"description": "Stanley Quencher H2.0 FlowState Tumbler 40 oz, stainless steel, vacuum insulated, with handle and straw",
"country": "US",
}
response = requests.post(
f"{API}/v1/hs-codes/classify", headers=HEADERS, json=product, timeout=60
)
response.raise_for_status()
result = response.json()
best = result["results"][0]
print(best["formatted"], best["confidence"])
print(best["national"]["formatted"], best["national"]["general_duty"])
The real response, trimmed:
{
"product": "A 40-ounce vacuum-insulated tumbler made of stainless steel, featuring a handle and a straw, designed for holding beverages.",
"hs_code": "961700",
"results": [
{
"hs_code": "961700",
"formatted": "9617.00",
"confidence": 0.95,
"reasoning": "The item is a vacuum-insulated vessel designed for beverages, which is specifically provided for in heading 9617 per GIR 1.",
"national": {
"country": "US",
"code": "9617003000",
"formatted": "9617.00.30.00",
"description": "Vessels › Having a capacity exceeding 1 liter but not exceeding 2 liters",
"general_duty": "6.9%",
"units": ["No."]
}
},
{
"hs_code": "732393",
"formatted": "7323.93",
"confidence": 0.05,
"national": { "country": "US", "formatted": "7323.93.00.60", "general_duty": "2%" }
}
],
"to_confirm": [
"Is the vacuum insulation a permanent feature of the vessel construction?",
"Does the vessel meet the technical definition of a vacuum flask or vessel?"
],
"edition": "HS 2022",
"disclaimer": "Classification aid, not a binding ruling: have the code confirmed by a licensed customs broker before you declare goods."
}
Brand words were ignored. Heading 9617 won at 0.95, with 7323.93 and its duty kept as the alternative. The HTS line went further than the title: 40 oz is about 1.18 litres, hence the line for vessels of 1 to 2 litres. The product sentence restates the article in customs terms and is worth storing for audits.
The same call with curl, for a cotton T-shirt:
curl -X POST "https://hs-code-classifier-ai-customs-tariff-lookup.p.rapidapi.com/v1/hs-codes/classify" \
-H "X-RapidAPI-Key: YOUR_API_KEY" \
-H "X-RapidAPI-Host: hs-code-classifier-ai-customs-tariff-lookup.p.rapidapi.com" \
-H "Content-Type: application/json" \
-d '{"description": "Men'\''s short-sleeve crew-neck T-shirt, 100% cotton jersey", "country": "US"}'
It returns 6109.10 at confidence 1.0, with the HTS line 6109.10.00.12 and a 16.5 % general duty.
HS code classification from messy titles, in any language
Catalogues are not written in tariff language. Titles with brand names work, and so do descriptions in French, German, Spanish or Chinese; country=EU adds the 8-digit CN line:
products = [
{
"description": "Anker Power Bank 10000mAh, USB-C portable charger for iPhone and Samsung"
},
{
"description": "Chaussures de running femme, dessus en mesh textile, semelle en caoutchouc",
"country": "EU",
},
]
for payload in products:
r = requests.post(
f"{API}/v1/hs-codes/classify", headers=HEADERS, json=payload, timeout=60
)
r.raise_for_status()
best = r.json()["results"][0]
print(best["formatted"], best["confidence"], best["subheading"]["description"])
The power bank comes back as 8507.60 (lithium-ion accumulators) at 0.95, with 8504.40 (static converters) as the alternative. The French running shoes, trimmed:
{
"product": "Women's running shoes with a textile mesh upper and a rubber outer sole.",
"results": [
{
"formatted": "6404.11",
"confidence": 0.95,
"reasoning": "The footwear has a textile upper and a rubber outer sole, which classifies it under heading 6404. As it is specifically described as running shoes, it falls under the sports footwear subheading 640411.",
"national": { "country": "EU", "code": "64041100", "formatted": "6404.11.00" }
}
],
"to_confirm": ["Confirm the outer sole is made of rubber or plastics.", "Confirm the upper is predominantly textile material."]
}
Use to_confirm to fix missing product data
"Levi's 501 Original Fit Women's Jeans" alone comes back as 6204.62 (women's cotton trousers, not knitted) at 0.95, HTS line 6204.62.80.11 at a 16.6 % general duty, with three facts to confirm:
{
"to_confirm": [
"Confirm the garment is not knitted or crocheted",
"Confirm the primary material is cotton",
"Confirm the garment is for women"
]
}
The code is right but rests on assumptions, and the API names them. Pass what you know in material, and in use when the purpose matters:
payload = {
"description": "Levi's 501 Original Fit Women's Jeans",
"material": "99% cotton, 1% elastane denim, woven",
"country": "US",
}
r = requests.post(
f"{API}/v1/hs-codes/classify", headers=HEADERS, json=payload, timeout=60
)
r.raise_for_status()
{
"hs_code": "620462",
"results": [
{
"formatted": "6204.62",
"confidence": 1.0,
"reasoning": "The product is a woven garment for women, classified under heading 6204. As it is composed of 99% cotton, it falls under the subheading for trousers of cotton."
}
],
"to_confirm": []
}
Same code, confidence 1.0, nothing left to confirm. Across a catalogue, frequent to_confirm items show which column your product data is missing.
HTS and CN code lookup and search, without AI
Two endpoints answer instantly without AI, for 1 credit instead of 10. GET /v1/hs-codes/code takes 2 to 10 digits (8 and 10 need country) and returns the hierarchy, children and national lines; GET /v1/hs-codes/search ranks subheadings by relevance to keywords.
lookup = requests.get(
f"{API}/v1/hs-codes/code",
headers=HEADERS,
params={"code": "8507.60", "country": "US"},
timeout=30,
)
lookup.raise_for_status()
for line in lookup.json()["national"]:
print(line["formatted"], line["general_duty"], line["description"])
search = requests.get(
f"{API}/v1/hs-codes/search",
headers=HEADERS,
params={"q": "lithium ion battery", "limit": 5},
timeout=30,
)
search.raise_for_status()
The lookup lists every US line under the subheading (trimmed):
{
"hs_code": "850760",
"level": "subheading",
"national": [
{ "formatted": "8507.60.00.10", "description": "Lithium-ion batteries › Of a kind used as the primary source of electrical power for electrically powered vehicles of subheadings 8703.40, 8703.50, 8703.60, 8703.70 or 8703.80", "general_duty": "3.4%" },
{ "formatted": "8507.60.00.30", "description": "Lithium-ion batteries › Other › Battery energy storage systems fully encased within a housing, as described in statistical note 2 to this chapter", "general_duty": "3.4%" },
{ "formatted": "8507.60.00.90", "description": "Lithium-ion batteries › Other › Other", "general_duty": "3.4%" }
]
}
The search for "lithium ion battery" ranks 8507.60 first, then 8506.50 (primary lithium cells) and 8507.80. US lines come live from the USITC, EU lines from the 2026 Combined Nomenclature.
Classify a whole catalogue to CSV
A products.csv with sku, title and an optional material goes in; rows come out with HS code, HTS line, US duty and a review flag. Clear descriptions score 0.95 to 1.0 and ambiguous ones 0.4 to 0.8, so anything under 0.8 goes to a person. Identical titles are classified once, and 503 errors are retried (failed calls are not billed).
import csv
import time
import requests
HOST = "hs-code-classifier-ai-customs-tariff-lookup.p.rapidapi.com"
API = f"https://{HOST}"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}
REVIEW_BELOW = 0.8
cache: dict[tuple[str, str], dict] = {}
def classify(title: str, material: str, attempts: int = 3) -> dict:
key = (title.strip().lower(), material.strip().lower())
if key in cache:
return cache[key]
payload = {"description": title, "country": "US"}
if material:
payload["material"] = material
for attempt in range(attempts):
r = requests.post(
f"{API}/v1/hs-codes/classify", headers=HEADERS, json=payload, timeout=60
)
if r.status_code != 503:
break
time.sleep(5 * 2**attempt) # AI or USITC unavailable: not billed, try again
if r.status_code == 400:
cache[key] = r.json() # not physical goods or too vague: not billed
else:
r.raise_for_status()
cache[key] = r.json()
return cache[key]
with (
open("products.csv", newline="", encoding="utf-8") as src,
open("products_hs.csv", "w", newline="", encoding="utf-8") as out,
):
writer = csv.writer(out)
writer.writerow(
[
"sku",
"title",
"hs_code",
"hts_code",
"us_duty",
"confidence",
"to_confirm",
"status",
]
)
for row in csv.DictReader(src):
data = classify(row["title"], row.get("material") or "")
if "error" in data:
writer.writerow(
[row["sku"], row["title"], "", "", "", "", "", data["error"]["code"]]
)
continue
best = data["results"][0]
national = best.get("national") or {}
status = "ok" if best["confidence"] >= REVIEW_BELOW else "REVIEW"
writer.writerow(
[
row["sku"],
row["title"],
best["formatted"],
national.get("formatted"),
national.get("general_duty"),
best["confidence"],
" | ".join(data["to_confirm"]),
status,
]
)
The 400 branch catches the gift cards, services and placeholder rows of real catalogues. For "SEO consulting for e-commerce websites", billed 0 credits:
{
"error": {
"status": 400,
"code": "not_classifiable",
"message": "Describe physical goods precisely enough to classify them: what the article is, its material and its use."
}
}
For products with only a link or a photo, send url or image_url instead of description, or upload the image to /v1/hs-codes/classify/upload as a multipart file. A description takes 2 to 4 seconds, a photo or US line 5 to 8. For a Shopify catalogue, the Shopify Store Scraper API returns titles and descriptions ready for this loop.
How accurate it is, and what it costs
The test battery covered 108 products: 62 clear descriptions (textiles, electronics, food, chemicals, auto parts, toys and more, in English and four other languages), 24 rule-driven cases including HS 2022 additions such as drones (8806), and 22 real marketplace titles with brand names. 106 were classified exactly at 6 digits on the first answer (98 %), and all 108 had the expected code in the top 3. The two misses (a garlic press, a Kindle) were debatable, and the expected code came second both times.
A classification uses 10 credits, a lookup or search 1. BASIC is free with 20 credits a day (2 classifications); PRO is $4.99 a month for 600 classifications, about $0.008 each; ULTRA gives 1,800 for $14.99 and MEGA 6,000 for $49.99. HS classification APIs on RapidAPI charge $0.03 to $0.10 per call, Zonos Classify $0.011 to $0.05. Plans are on the HS code classifier page, parameters in the API reference. Related reading: how invoice totals are re-added and how the AI web scraper checks every value against the page.
Classify a spreadsheet with the Apify Actor
If the catalogue lives in a spreadsheet, the same classifier runs as an Apify Actor, HS Code Classifier. Paste product titles, page links or another scraper's dataset ID, choose the US or EU line, and get one row per product with code, confidence, reasoning, national line, duty and alternatives, for $0.0075 per product classified.
What the HS code lookup API does not do
- Not a binding ruling. Have the code confirmed by a licensed customs broker, or request Binding Tariff Information (BTI) in the EU or a ruling from US Customs and Border Protection when the stakes are high.
- No additional US duties.
general_dutyis the column 1 general rate; Section 301 and other Chapter 99 duties are not included. - No EU duty rates. You get the 8-digit CN code, not the TARIC measures.
- No legal notes. The WCO Explanatory Notes and rulings are not included; the model applies the GRI from its training.
- Sets, parts and multi-function goods get lower confidence and 2 or 3 candidates.
- Pages that need JavaScript return
400 page_empty: send the description instead.
Frequently asked questions
What is the difference between HS, HTS and CN codes?
The HS code is the international 6-digit code. The US Harmonized Tariff Schedule (HTS) extends it to 10 digits, where the first 8 set the duty rate and the last 2 serve statistics. The EU Combined Nomenclature (CN) extends it to 8 digits, and TARIC adds two more for EU-specific measures.
How do I find the HS code of a product?
Establish what the article is, what it is made of and what it is for, then apply the General Rules of Interpretation, starting with the heading texts and chapter notes. An HS code lookup API does that first pass in seconds; keep a person for low-confidence results.
Can I put an AI-suggested HS code on a customs declaration?
The declarant remains responsible for the code, whoever suggested it. Classify the catalogue with the API, review where confidence is low or to_confirm is not empty, and have doubtful or high-value codes confirmed by a broker or a binding ruling.
Does the US duty rate include Section 301 or reciprocal tariffs?
No. general_duty is the general (most-favoured-nation) rate of the HTS line. Chapter 99 duties depend on the origin and change often; add them before quoting a landed cost.
What happens when HS 2027 comes into force?
HS 2027 applies from 1 January 2027 and amends a number of headings and subheadings; unaffected codes stay the same. The API moves to HS 2027 once the open 6-digit nomenclature is published. Until then every response states edition: "HS 2022", so you know which edition a stored code came from.
Get started
HS Code Classifier API
Product description, page or photo to its HS code, with confidence, US HTS duty and EU CN line.
- HS Code
- Customs
- International Trade
- Python
- Ecommerce



