Gastric subepithelial lesions (SEL) are covered by healthy mucosa, which makes it difficult to determine their original layer by conventional endoscopy, so endoscopic ultrasonography (EUS) is used for diagnosis. However, EUS is more challenging and its interpretation varies between doctors. The study developed an artificial intelligence system based on the MedMamba model to identify the layer of origin of gastric SELs. The data came from 320 images from 188 patients in the First Affiliated Hospital of Nanjing Medical University between May 1, 2016 and May 1, 2023. The images were divided into training, validation, and test sets in an 8:1:1 ratio at the patient level. The MedMamba model achieved an overall accuracy of 92.04% (95% CI: 90.33–93.75%), a specificity of 94.83% (95% CI: 93.22–96.44%), and a sensitivity of 75.19–87.03% in the five-category classification. This model outperformed other AI models and endoscopists. The system has demonstrated the potential to reduce variability in the diagnosis of SEL and improve clinical practices.