Oral lichen planus (OLP) was a chronic inflammatory disease of unknown etiology with a 1.4% chance of progressing to malignancy. However, it has been suggested in several studies that immune system disorders played a dominant role in the onset and progression of OLP. Therefore, this experiment aimed to develop a diagnostic prediction model for OLP based on immunopathogenesis to achieve early diagnosis and treatment and prevent cancer. In this study, 2 publicly available OLP datasets from the gene expression omnibus database were filtered. In the experimental group (GSE52130), the level of immune cell infiltration was assessed using MCPcounter and ssGSEA algorithms. Subsequently, differential expression analysis and gene set enrichment analysis were performed between the OLP and control groups. The resulting differentially expressed genes were intersected with immunologically relevant genes provided on the immunology database and analysis portal database (ImmPort) website to obtain differentially expressed immunologically relevant genes (DEIRGs). Furthermore, the gene ontology and kyoto encyclopedia of genes and genomes analyses were carried out. Finally, protein–protein interaction network and least absolute shrinkage and selection operator regression analyses constructed a model for OLP. Receiver operating characteristic curves for the experimental and validation datasets (GSE38616) were plotted separately to validate the model’s credibility. In addition, real-time quantitative PCR experiment was performed to verify the expression level of the diagnostic genes. Immune cell infiltration analysis revealed a more significant degree of inflammatory infiltration in the OLP group compared to the control group. In addition, the gene set enrichment analysis results were mainly associated with keratinization, antibacterial and immune responses, etc. A total of 774 differentially expressed genes was obtained according to the screening criteria, of which 65 were differentially expressed immunologically relevant genes. Ultimately, an immune-related diagnostic prediction model for OLP, which was composed of 5 hub genes (BST2, RNASEL, PI3, DEFB4A, CX3CL1), was identified. The verification results showed that the model has good diagnostic ability. There was a significant correlation between the 5 hub diagnostic biomarkers and immune infiltrating cells. The development of this model gave a novel insight into the early diagnosis of OLP.