{
  "openapi": "3.0.3",
  "info": {
    "title": "TariffCodeCheck HS Code API",
    "description": "Free HS code lookup: one HS6 subheading with its description, US HTS lines with duty rates, EU CN codes and UK commodity lines, plus alias-aware search. Reference data from official schedules (USITC HTS, public domain; UK Integrated Online Tariff, OGL v3.0), not a binding classification ruling. Keyless use is limited per IP per day; a free IPNOVA API key raises the limit.",
    "version": "1.0.0",
    "contact": {
      "email": "hello@ipnova.com",
      "url": "https://tariffcodecheck.com/hs-code-api"
    }
  },
  "servers": [
    {
      "url": "https://tariffcodecheck.com"
    }
  ],
  "paths": {
    "/api/hs/{code}": {
      "get": {
        "summary": "Look up one HS6 subheading",
        "description": "Six digits expected; longer codes are truncated to their HS6 parent. Dots are ignored (6203.42 and 620342 both work).",
        "operationId": "getHsCode",
        "security": [
          {},
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "description": "HS code, e.g. 620342 or 6203.42",
            "schema": {
              "type": "string",
              "example": "620342"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subheading found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HsCodeResult"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/search": {
      "get": {
        "summary": "Search HS subheadings by keyword",
        "description": "Alias-aware search over descriptions, max 25 results.",
        "operationId": "searchHsCodes",
        "security": [
          {},
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "Search query, e.g. laptop",
            "schema": {
              "type": "string",
              "maxLength": 80,
              "example": "laptop"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Search results (count may be 0)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "Free IPNOVA API key from https://api.ipnova.com (also accepted as ?key= query parameter). Keyless requests share a per-IP daily limit."
      }
    },
    "schemas": {
      "HsCodeResult": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "hs6": {
            "type": "string",
            "example": "620342"
          },
          "code": {
            "type": "string",
            "example": "6203.42"
          },
          "description": {
            "type": "string",
            "example": "Of cotton"
          },
          "chapter": {
            "type": "object",
            "properties": {
              "number": {
                "type": "string",
                "example": "62"
              },
              "title": {
                "type": "string"
              }
            }
          },
          "us_hts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "hts": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "context": {
                  "type": "string"
                },
                "duty_general": {
                  "type": "string"
                },
                "duty_special": {
                  "type": "string"
                },
                "duty_col2": {
                  "type": "string"
                },
                "units": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "statistical": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "code": {
                        "type": "string"
                      },
                      "description": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "eu_cn": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "cn_code": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "taric_url": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "uk_commodities": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "commodity_code": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                }
              }
            }
          },
          "page": {
            "type": "string",
            "format": "uri"
          },
          "disclaimer": {
            "type": "string"
          },
          "attribution": {
            "type": "string"
          },
          "docs": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "SearchResult": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "query": {
            "type": "string",
            "example": "laptop"
          },
          "count": {
            "type": "integer",
            "example": 3
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "hs6": {
                  "type": "string"
                },
                "code": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "page": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "attribution": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "boolean",
            "example": true
          },
          "reason": {
            "type": "string",
            "enum": [
              "invalid_input",
              "not_found",
              "rate_limit",
              "daily_limit",
              "unknown_endpoint",
              "method_not_allowed"
            ]
          },
          "message": {
            "type": "string"
          },
          "docs": {
            "type": "string",
            "format": "uri"
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Error envelope with a machine-readable reason field",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
