Ankylosing spondylitis (AS) is a chronic systemic inflammatory disease that significantly impairs physical function in young individuals. However, the identification of radiographic changes in AS is frequently delayed, and the diagnostic efficacy of biomarkers like HLA-B27 remains moderately effective, with unsatisfactory sensitivity and specificity. In contrast to existing literature, our current experiment utilized a larger sample size and employed both untargeted and targeted UHPLC-QTOF-MS/MS based metabolomics to identify the metabolite profile and potential biomarkers of AS. The results indicated a notable divergence between the two groups, and a total of 170 different metabolites were identified, which were associated with the 6 primary metabolic pathways exhibiting a correlation with AS. Among these, 26 metabolites exhibited high sensitivity and specificity with area under curve (AUC) values greater than 0.8. Subsequent targeted quantitative analysis discovered 3 metabolites, namely 3-amino-2-piperidone, hypoxanthine and octadecylamine, exhibiting excellent distinguishing ability based on the results of the ROC curve and the Random Forest model, thus qualifying as potential biomarkers for AS. Summarily, our untargeted and targeted metabolomics investigation offers novel and precise insights into potential biomarkers for AS, potentially enhancing diagnostic capabilities and furthering the comprehension of the condition's pathophysiology.