Persistent postsurgical pain (PPP) after thoracotomy effect 50% to 80%. Nerve damage and central sensitization involving NDMDAr activation may play an important role. This study evaluates the efficacy of adding intravenous (IV) or epidural ketamine to thoracic epidural analgesia (TEA) after thoracotomy. Double-blind randomized study on patients undergoing thoracotomy allocated to one of the following: group Kiv (IV racemic ketamine 0.5 mg/kg preincisional +0.25 mg/kg/h for 48 h), group Kep (epidural racemic ketamine 0.5 mg/kg preincisional +0.25 mg/kg/h for 48 h), or group S (saline). Postoperative analgesia was ensured by TEA with ropivacaine and fentanyl. Pain visual analog scales (VAS), Neuropathic Pain Symptom Inventory, Catastrophizing Scale, and Quantitative Sensory Testing, measuring both the peri-incisional and distant hyperalgesia area, were conducted preoperatively and postoperatively until 6 months. Plasma ketamine levels and stability of the analgesic solutions were analyzed. A total of 104 patients were included. PPP incidence was 20% at 6 months. Pain scores on coughing were significantly lower in Kiv and Kep than in S at 24 and 72 hours, but there were no differences afterwards. There were no significant differences in pain at rest, Neuropathic Pain Symptom Inventory, and Catastrophizing Scale, or in the area of mechanical allodynia at any time. Adverse effects were mild. Plasma ketamine levels did not differ significantly between groups. Analgesic solutions were stable. Adding epidural or IV racemic ketamine to TEA after thoracotomy did not lead to any reduction in PPP or allodynia. Epidural administration produced similar plasma ketamine levels to the IV route.