Objective: To investigate the effects of different doses of esketamine on perioperative lung function and postoperative pulmonary complications in patients with pulmonary tuberculosis undergoing thoracoscopic surgery. Methods: A prospective study was conducted at the Sixth People’s Hospital of the Xinjiang Uygur Autonomous Region from September 2023 to September 2024, enrolling 90 patients with pulmonary tuberculosis who underwent elective thoracoscopic surgery. The patients were randomly divided into three groups: the low-dose group (continuous intraoperative infusion of esketamine at 0.125 mg·kg-1· h-1), the high-dose group (continuous intraoperative infusion of esketamine at 0.25 mg·kg-1· h-1), and the control group (continuous intraoperative infusion of an equal volume of normal saline), with 30 patients in each group,then calculated their oxygenation index, alveolar-arterial oxygen pressure difference, and pulmonary dynamic compliance at 5 minutes after bilateral lung ventilation (T1), 15 minutes after unilateral lung ventilation (T2), and 90 minutes after unilateral lung ventilation (T3) for each group of patients, examined their interleukin 6 and serum glucose concentrations using enzyme-linked immunosorbent assay one day before surgery and on the first and third day after surgery. Time-sensitive indicators such as surgery/anaesthesia time, tube removal time, and postoperative hospitalisation time were recorded, and the usage of vasoactive drugs were simultaneously recorded, also for adverse reactions within 3 postoperative days and pulmonary complications within 7 postoperative days. Results: (1) The average oxygenation index at time points T2 and T3 for the low-dose group, high-dose group, and control group were ((245.8±26.5) mmHg, (258.2±25.2) mmHg, and (229.1±30.9) mmHg;(239.9±28.0) mmHg, (241.3±32.7) mmHg and (223.5±23.5) mmHg), and the average alveolar-arterial oxygen pressure difference were ((140.5±29.3) mmHg, (137.6±25.6) mmHg and (163.4±32.9) mmHg; (139.7±28.0) mmHg, (131.8±35.3) mmHg and (162.9±25.1) mmHg), with statistically significant differences (F values were 10.818, 3.665, 6.924, and 8.841, and P values all <0.05). (2) The average IL-6 levels in the low-dose group, high-dose group, and control group at post-operative Day1 and Day3 were ((158.77±23.50) ng/L, (154.71±28.90) ng/L, and (173.16±26.13) ng/L; (44.99±16.32) ng/L, (42.85±21.46) ng/L, and (78.40±22.61) ng/L), with statistically significant differences (F values of 4.086 and 28.891, respectively, and P values all <0.05).The average GLU concentrations at postoperative Day3 in the low-dose group, high-dose group, and control group were (5.40±0.63) mmol/L, (4.86±0.48) mmol/L, and (6.18±2.08) mmol/L, showed statistically significant differences (F=8.001, P<0.05). (3) Adverse reactions within 3 postoperative days in all three groups were nausea and vomiting. The incidence rates in the low-dose group, high-dose group, and control group were 33.3% (10/30), 36.7% (11/30), and 70.0% (21/30), respectively, with statistically significant differences (χ2=5.424, P<0.05). The incidence rates of pulmonary complications within 7 postoperative days in the 3 groups were 33.3% (10/30), 26.7% (8/30), and 36.7% (11/30), respectively, with no statistically significant difference (χ2=0.712, P>0.05). However, compared with the control group, the incidence of pleural effusion was lower in the high-dose group, the low-dose group, high-dose group, and control group got rates of 13.3% (4/30), 3.3% (1/30), and 26.7% (8/30),respectively (χ2=6.653, P<0.05). Conclusion: In thoracoscopic surgery, continuous infusion of esketamine can improve intraoperative oxygenation of patients with pulmonary tuberculosis, reduce postoperative stress responses, protect lung function, and accelerate postoperative recovery.