Liver cancer is a public disease burden with an increasing incidence rate globally. Bile acid and bile salt’s metabolic pathways participate in liver tumorigenesis and regulate the tumor microenvironment. However, there still remains a lack of systematic analysis of the genes related to bile acid and bile salt metabolic pathways in hepatocellular carcinoma (HCC). The mRNA expression data and clinical follow-up information of patients with HCC were obtained from public databases, including The Cancer Genome Atlas, Hepatocellular Carcinoma Database, Gene Expression Omnibus, and IMvigor210. The bile acid and bile salt metabolism-related genes were extracted from Molecular Signatures Database. Univariate Cox and logistic least absolute shrinkage and selection operator regression analyses were conducted to establish the risk model. Single sample gene set enrichment analysis, Estimation of STromal and Immune cells in MAlignant Tumour tissues using Expression data, and Tumor Immune Dysfunction and Exclusion were adopted to analyze immune status. The efficiency of the risk model was tested using a decision tree and a nomogram. We determined two molecular subtypes based on bile acid and bile salt metabolism-related genes, with the prognosis of the S1 subtype being markedly superior to the S2 subtype. Next, we established a risk model based on the differentially expressed genes between the two molecular subtypes. The high-risk and low-risk groups showed significant differences in the biological pathways, immune score, immunotherapy response, and drug susceptibility. Our results demonstrated the good predictive performance of the risk model in immunotherapy datasets and established that it could be an essential factor affecting the prognosis of HCC. In conclusion, we identified two molecular subtypes based on bile acid and bile salt metabolism-related genes. The risk model established in our study could effectively predict the prognosis of patients with HCC and their immunotherapeutic response, which may contribute to targeted immunotherapy in HCC.